Skip to content

Commit

Permalink
Feat add back button to conversations page (#21)
Browse files Browse the repository at this point in the history
* feat: add back button to conversations page

Signed-off-by: Lin Wang <[email protected]>

* feat: remove back to chat for history icon

Signed-off-by: Lin Wang <[email protected]>

* refactor: remove style change to flush=left

Signed-off-by: Lin Wang <[email protected]>

* refactor: add setSelectedTabId to handleBack deps array

Signed-off-by: Lin Wang <[email protected]>

---------

Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam authored and ruanyl committed Nov 20, 2023
1 parent 537ddf9 commit 2b0ae05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 1 addition & 4 deletions public/tabs/chat_window_header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ export const ChatWindowHeader: React.FC<ChatWindowHeaderProps> = React.memo((pro
color="text"
onClick={() => {
chatContext.setFlyoutComponent(undefined);
// Back to chat tab if history page already visible
chatContext.setSelectedTabId(
chatContext.selectedTabId === 'history' ? 'chat' : 'history'
);
chatContext.setSelectedTabId('history');
}}
display={chatContext.selectedTabId === 'history' ? 'fill' : undefined}
/>
Expand Down
24 changes: 24 additions & 0 deletions public/tabs/history/chat_history_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
*/

import {
EuiButtonEmpty,
EuiFieldSearch,
EuiFieldSearchProps,
EuiFlyoutBody,
EuiPage,
EuiPageBody,
EuiPanel,
EuiPageHeader,
EuiSpacer,
EuiTablePagination,
EuiTablePaginationProps,
EuiText,
EuiTitle,
EuiButtonIcon,
EuiFlexGroup,
EuiFlexItem,
} from '@elastic/eui';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { FormattedMessage } from '@osd/i18n/react';
Expand All @@ -23,6 +28,7 @@ import cs from 'classnames';
import { SavedObjectsFindOptions } from '../../../../../src/core/public';
import { useChatActions } from '../../hooks/use_chat_actions';
import { useGetSessions } from '../../hooks/use_sessions';
import { useChatContext } from '../../contexts/chat_context';
import { ChatHistoryList, ChatHistoryListProps } from './chat_history_list';
import { EditConversationNameModal } from '../../components/edit_conversation_name_modal';
import { DeleteConversationConfirmModal } from './delete_conversation_confirm_modal';
Expand Down Expand Up @@ -136,6 +142,7 @@ interface ChatHistoryPageProps {

export const ChatHistoryPage: React.FC<ChatHistoryPageProps> = (props) => {
const { loadChat } = useChatActions();
const { setSelectedTabId, flyoutFullScreen } = useChatContext();
const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(10);
const [searchName, setSearchName] = useState<string>();
Expand Down Expand Up @@ -166,6 +173,10 @@ export const ChatHistoryPage: React.FC<ChatHistoryPageProps> = (props) => {
setPageSize(itemsPerPage);
}, []);

const handleBack = useCallback(() => {
setSelectedTabId('chat');
}, [setSelectedTabId]);

useDebounce(
() => {
setPageIndex(0);
Expand All @@ -183,6 +194,19 @@ export const ChatHistoryPage: React.FC<ChatHistoryPageProps> = (props) => {
<EuiFlyoutBody className={cs(props.className, 'llm-chat-flyout-body')}>
<EuiPage>
<EuiPageBody component="div">
<EuiPageHeader>
{flyoutFullScreen ? (
<EuiFlexGroup gutterSize="none" justifyContent="flexEnd">
<EuiFlexItem grow={false}>
<EuiButtonIcon iconType="cross" onClick={handleBack} />
</EuiFlexItem>
</EuiFlexGroup>
) : (
<EuiButtonEmpty flush="left" size="xs" onClick={handleBack} iconType="arrowLeft">
Back
</EuiButtonEmpty>
)}
</EuiPageHeader>
<EuiTitle size="s">
<h3>
<FormattedMessage id="assistant.olly.history.title" defaultMessage="Conversations" />
Expand Down

0 comments on commit 2b0ae05

Please sign in to comment.