Skip to content

Commit

Permalink
Refactor with getDefaultDataSourceId$ (#197)
Browse files Browse the repository at this point in the history
* Refactor with getDefaultDataSourceId$

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

* Update change log

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

---------

Signed-off-by: Lin Wang <[email protected]>
(cherry picked from commit ec49168)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] committed Jun 3, 2024
1 parent 75905d3 commit a1502f8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
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

0 comments on commit a1502f8

Please sign in to comment.