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

Refactor with getDefaultDataSourceId$ #197

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -15,3 +15,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- 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))
- Refactor default data source retriever ([#197](https://github.com/opensearch-project/dashboards-assistant/pull/197))
4 changes: 2 additions & 2 deletions public/services/__tests__/data_source_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { first } from 'rxjs/operators';

import { uiSettingsServiceMock } from '../../../../../src/core/public/mocks';
import { DataSourceOption } from '../../../../../src/plugins/data_source_management/public/components/data_source_menu/types';
import { DataSourceManagementPluginSetup } from '../../types';
import { DataSourceManagementPluginSetup } from '../../../../../src/plugins/data_source_management/public';
import { DataSourceService } from '../data_source_service';

const setup = (options?: {
Expand All @@ -24,10 +24,10 @@ const setup = (options?: {
dataSourceSelection: {
getSelection$: () => dataSourceSelection$,
},
getDefaultDataSourceId$: jest.fn(() => defaultDataSourceSelection$),
};
const dataSource = new DataSourceService();
const defaultDataSourceSelection$ = new BehaviorSubject(options?.defaultDataSourceId ?? null);
uiSettings.get$.mockReturnValue(defaultDataSourceSelection$);
const setupResult = dataSource.setup({
uiSettings,
dataSourceManagement:
Expand Down
4 changes: 2 additions & 2 deletions public/services/data_source_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { first, map } from 'rxjs/operators';

import type { IUiSettingsClient } from '../../../../src/core/public';
import type { DataSourceOption } from '../../../../src/plugins/data_source_management/public/components/data_source_menu/types';
import type { DataSourceManagementPluginSetup } from '../types';
import { DataSourceManagementPluginSetup } from '../../../../src/plugins/data_source_management/public';

export enum DataSourceIdFrom {
UiSettings,
Expand Down Expand Up @@ -83,7 +83,7 @@ export class DataSourceService {
getDataSourceId$() {
return combineLatest([
this.dataSourceId$,
this.uiSettings?.get$('defaultDataSource', null) ?? of(null),
this.dataSourceManagement?.getDefaultDataSourceId$?.(this.uiSettings) ?? of(null),
]).pipe(
map(([selectedDataSourceId, defaultDataSourceId]) => {
if (selectedDataSourceId !== null) {
Expand Down
10 changes: 1 addition & 9 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import type { BehaviorSubject } from 'rxjs';
import { DashboardStart } from '../../../src/plugins/dashboard/public';
import { EmbeddableSetup, EmbeddableStart } from '../../../src/plugins/embeddable/public';
import { IMessage, ISuggestedAction } from '../common/types/chat_saved_object_attributes';
import { IChatContext } from './contexts/chat_context';
import { MessageContentProps } from './tabs/chat/messages/message_content';
import { DataSourceServiceContract, IncontextInsightRegistry } from './services';
import { DataSourceOption } from '../../../src/plugins/data_source_management/public';

// TODO: should replace from DataSourceManagementPluginSetup in DSM plugin after data selection merged
export interface DataSourceManagementPluginSetup {
dataSourceSelection?: {
getSelection$: () => BehaviorSubject<Map<string, DataSourceOption[]>>;
};
}
import { DataSourceManagementPluginSetup } from '../../../src/plugins/data_source_management/public';

export interface RenderProps {
props: MessageContentProps;
Expand Down
Loading