Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update backend to support MDS #190

Merged
merged 11 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fetch root agent id before executing the agent ([#165](https://github.com/opensearch-project/dashboards-assistant/pull/165))
- Integrate chatbot with sidecar service ([#164](https://github.com/opensearch-project/dashboards-assistant/pull/164))
- Add data source service ([#191](https://github.com/opensearch-project/dashboards-assistant/pull/191))
- Update router and controller to support MDS ([#190](https://github.com/opensearch-project/dashboards-assistant/pull/190))
2 changes: 1 addition & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"dataSourceManagement"
],
"configPath": [
"assistant"
"assistant"
]
}
19 changes: 18 additions & 1 deletion public/chat_flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

import { EuiResizableContainer } from '@elastic/eui';
import cs from 'classnames';
import React, { useRef } from 'react';
import React, { useMemo, useRef } from 'react';
import { useObservable } from 'react-use';
import { BehaviorSubject } from 'rxjs';
import { useChatContext } from './contexts/chat_context';
import { ChatPage } from './tabs/chat/chat_page';
import { ChatWindowHeader } from './tabs/chat_window_header';
import { ChatHistoryPage } from './tabs/history/chat_history_page';
import { AgentFrameworkTracesFlyoutBody } from './components/agent_framework_traces_flyout_body';
import { TAB_ID } from './utils/constants';
import { useCore } from './contexts';

interface ChatFlyoutProps {
flyoutVisible: boolean;
Expand All @@ -22,7 +25,17 @@ interface ChatFlyoutProps {
export const ChatFlyout = (props: ChatFlyoutProps) => {
const chatContext = useChatContext();
const chatHistoryPageLoadedRef = useRef(false);
const core = useCore();
const defaultDataSourceSelection$ = new BehaviorSubject(new Map());
raintygao marked this conversation as resolved.
Show resolved Hide resolved

// TODO: use DataSourceService to replace
const selectedDS = useObservable(
core.services.setupDeps?.dataSourceManagement?.dataSourceSelection?.getSelection$() ??
defaultDataSourceSelection$
);
const currentDS = useMemo(() => {
return selectedDS?.values().next().value;
}, [selectedDS]);
let chatPageVisible = false;
let chatHistoryPageVisible = false;
let chatTraceVisible = false;
Expand Down Expand Up @@ -87,6 +100,10 @@ export const ChatFlyout = (props: ChatFlyoutProps) => {
<>
<div className={cs('llm-chat-flyout-header')}>
<ChatWindowHeader />
<div>
Data Source:
{currentDS?.[0]?.label}
</div>
raintygao marked this conversation as resolved.
Show resolved Hide resolved
</div>

{props.overrideComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as coreContextExports from '../../contexts/core_context';
import { IMessage } from '../../../common/types/chat_saved_object_attributes';

import { ChatWindowHeaderTitle } from '../chat_window_header_title';
import { DataSourceServiceMock } from '../../services/data_source_service.mock';

const setup = ({
messages = [],
Expand All @@ -37,6 +38,7 @@ const setup = ({
}),
reload: jest.fn(),
},
dataSource: new DataSourceServiceMock(),
},
};
useCoreMock.services.http.put.mockImplementation(() => Promise.resolve());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
EditConversationNameModalProps,
} from '../edit_conversation_name_modal';
import { HttpHandler } from '../../../../../src/core/public';
import { DataSourceServiceMock } from '../../services/data_source_service.mock';

const setup = ({ onClose, defaultTitle, conversationId }: EditConversationNameModalProps) => {
const useCoreMock = {
services: coreMock.createStart(),
services: { ...coreMock.createStart(), dataSource: new DataSourceServiceMock() },
};
jest.spyOn(coreContextExports, 'useCore').mockReturnValue(useCoreMock);

Expand Down Expand Up @@ -156,7 +157,10 @@ describe('<EditConversationNameModal />', () => {
expect(useCoreMock.services.http.put).not.toHaveBeenCalled();

fireEvent.click(renderResult.getByTestId('confirmModalConfirmButton'));
expect(useCoreMock.services.http.put).toHaveBeenCalled();

await waitFor(() => {
expect(useCoreMock.services.http.put).toHaveBeenCalled();
});

fireEvent.click(renderResult.getByTestId('confirmModalCancelButton'));

Expand Down
Loading
Loading