Skip to content

Commit 20430ff

Browse files
chrisbmarniros1
authored andcommitted
[Agent Builder] Don't scroll to bottom of conversation if its the first round (#235827)
1 parent ec77b0a commit 20430ff

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

x-pack/platform/plugins/shared/onechat/public/application/components/conversations/conversation.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { EuiButtonIcon, EuiResizableContainer, useEuiScrollBar, useEuiTheme } from '@elastic/eui';
99
import { css } from '@emotion/react';
1010
import React, { useEffect, useRef } from 'react';
11+
import { useLocation } from 'react-router-dom';
1112
import { useHasActiveConversation } from '../../hooks/use_conversation';
1213
import { ConversationInputForm } from './conversation_input/conversation_input_form';
1314
import { ConversationRounds } from './conversation_rounds/conversation_rounds';
@@ -18,6 +19,7 @@ import { useSendMessage } from '../../context/send_message_context';
1819
import { useConversationScrollActions } from '../../hooks/use_conversation_scroll_actions';
1920
import { useConversationStatus } from '../../hooks/use_conversation';
2021
import { ConversationContent } from './conversation_grid';
22+
import type { LocationState } from '../../hooks/use_navigation';
2123

2224
const fullHeightStyles = css`
2325
height: 100%;
@@ -33,6 +35,9 @@ export const Conversation: React.FC<{}> = () => {
3335
const { euiTheme } = useEuiTheme();
3436
const { isResponseLoading } = useSendMessage();
3537
const { isFetched } = useConversationStatus();
38+
const location = useLocation<LocationState>();
39+
40+
const shouldStickToBottom = location.state?.shouldStickToBottom ?? true;
3641

3742
const scrollContainerRef = useRef<HTMLDivElement | null>(null);
3843
const {
@@ -48,14 +53,14 @@ export const Conversation: React.FC<{}> = () => {
4853

4954
const scrollContainerHeight = scrollContainerRef.current?.clientHeight ?? 0;
5055

51-
// Stick to bottom only on initial conversation load or when {conversationId} is changed
56+
// Stick to bottom only when user returns to an existing conversation (conversationId is defined and changes)
5257
useEffect(() => {
53-
if (isFetched && conversationId) {
58+
if (isFetched && conversationId && shouldStickToBottom) {
5459
requestAnimationFrame(() => {
5560
stickToBottom();
5661
});
5762
}
58-
}, [stickToBottom, isFetched, conversationId]);
63+
}, [stickToBottom, isFetched, conversationId, shouldStickToBottom]);
5964

6065
const scrollContainerStyles = css`
6166
overflow-y: auto;

x-pack/platform/plugins/shared/onechat/public/application/hooks/use_conversation_actions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export const useConversationActions = () => {
5757
const navigateToConversation = ({ nextConversationId }: { nextConversationId: string }) => {
5858
// Navigate to the new conversation if user is still on the "new" conversation page
5959
if (!conversationId && shouldAllowConversationRedirectRef.current) {
60-
navigateToOnechatUrl(appPaths.chat.conversation({ conversationId: nextConversationId }));
60+
const path = appPaths.chat.conversation({ conversationId: nextConversationId });
61+
const params = undefined;
62+
const state = { shouldStickToBottom: false };
63+
navigateToOnechatUrl(path, params, state);
6164
}
6265
};
6366

x-pack/platform/plugins/shared/onechat/public/application/hooks/use_navigation.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ import { useCallback } from 'react';
99
import { ONECHAT_APP_ID } from '../../../common/features';
1010
import { useKibana } from './use_kibana';
1111

12+
export interface LocationState {
13+
shouldStickToBottom?: boolean;
14+
}
15+
1216
export const useNavigation = () => {
1317
const {
1418
services: { application },
1519
} = useKibana();
1620

1721
const navigateToOnechatUrl = useCallback(
18-
(path: string, params?: Record<string, string>) => {
22+
(path: string, params?: Record<string, string>, state?: LocationState) => {
1923
const queryParams = new URLSearchParams(params);
2024
application.navigateToApp(ONECHAT_APP_ID, {
2125
path: queryParams.size ? `${path}?${queryParams}` : path,
26+
state,
2227
});
2328
},
2429
[application]

0 commit comments

Comments
 (0)