diff --git a/CHANGELOG.md b/CHANGELOG.md index e08ec4c4878b..6b1f2274ea31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Workspace] Add base path when parse url in http service ([#6233](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6233)) - [Multiple Datasource] Fix sslConfig for multiple datasource to handle when certificateAuthorities is unset ([#6282](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6282)) - [BUG][Multiple Datasource]Fix bug in data source aggregated view to change it to depend on displayAllCompatibleDataSources property to show the badge value ([#6291](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6291)) +- [BUG][Multiple Datasource]Read hideLocalCluster setting from yml and set in data source selector and data source menu ([#6361](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6361)) ### 🚞 Infrastructure diff --git a/src/plugins/data_source_management/public/components/data_source_menu/__snapshots__/create_data_source_menu.test.tsx.snap b/src/plugins/data_source_management/public/components/data_source_menu/__snapshots__/create_data_source_menu.test.tsx.snap index c462fe38e73a..28d689c660d5 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/__snapshots__/create_data_source_menu.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/data_source_menu/__snapshots__/create_data_source_menu.test.tsx.snap @@ -1,5 +1,130 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`create data source menu should ignore props.hideLocalCluster, and show local cluster when data_source.hideLocalCluster is set to false 1`] = ` +Object { + "asFragment": [Function], + "baseElement": +
+
+
+ +
+
+
+ , + "container":
+
+
+ +
+
+
, + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], +} +`; + exports[`create data source menu should render data source selectable normally 1`] = ` Object { "asFragment": [Function], diff --git a/src/plugins/data_source_management/public/components/data_source_menu/create_data_source_menu.test.tsx b/src/plugins/data_source_management/public/components/data_source_menu/create_data_source_menu.test.tsx index 52aaefe5ea75..75a223363a12 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/create_data_source_menu.test.tsx +++ b/src/plugins/data_source_management/public/components/data_source_menu/create_data_source_menu.test.tsx @@ -5,15 +5,17 @@ import { createDataSourceMenu } from './create_data_source_menu'; import { MountPoint, SavedObjectsClientContract } from '../../../../../core/public'; -import { notificationServiceMock } from '../../../../../core/public/mocks'; +import { coreMock, notificationServiceMock } from '../../../../../core/public/mocks'; import React from 'react'; -import { act, render } from '@testing-library/react'; +import { act, getByText, render } from '@testing-library/react'; import { DataSourceComponentType, DataSourceSelectableConfig } from './types'; import { ReactWrapper } from 'enzyme'; +import { mockDataSourcePluginSetupWithShowLocalCluster } from '../../mocks'; describe('create data source menu', () => { let client: SavedObjectsClientContract; const notifications = notificationServiceMock.createStartContract(); + const { uiSettings } = coreMock.createSetup(); beforeEach(() => { client = { @@ -26,13 +28,16 @@ describe('create data source menu', () => { componentType: DataSourceComponentType.DataSourceSelectable, componentConfig: { fullWidth: true, - hideLocalCluster: true, onSelectedDataSources: jest.fn(), savedObjects: client, notifications, }, }; - const TestComponent = createDataSourceMenu(); + const TestComponent = createDataSourceMenu( + uiSettings, + mockDataSourcePluginSetupWithShowLocalCluster + ); + const component = render(); expect(component).toMatchSnapshot(); expect(client.find).toBeCalledWith({ @@ -42,6 +47,36 @@ describe('create data source menu', () => { }); expect(notifications.toasts.addWarning).toBeCalledTimes(0); }); + + it('should ignore props.hideLocalCluster, and show local cluster when data_source.hideLocalCluster is set to false', async () => { + let component; + const props = { + componentType: DataSourceComponentType.DataSourceSelectable, + hideLocalCluster: true, + componentConfig: { + fullWidth: true, + onSelectedDataSources: jest.fn(), + savedObjects: client, + notifications, + }, + }; + const TestComponent = createDataSourceMenu( + uiSettings, + mockDataSourcePluginSetupWithShowLocalCluster + ); + await act(async () => { + component = render(); + }); + + expect(component).toMatchSnapshot(); + expect(client.find).toBeCalledWith({ + fields: ['id', 'title', 'auth.type'], + perPage: 10000, + type: 'data-source', + }); + expect(notifications.toasts.addWarning).toBeCalledTimes(0); + expect(getByText(component.container, 'Local cluster')).toBeInTheDocument(); + }); }); describe('when setMenuMountPoint is provided', () => { @@ -52,6 +87,7 @@ describe('when setMenuMountPoint is provided', () => { let client: SavedObjectsClientContract; const notifications = notificationServiceMock.createStartContract(); + const { uiSettings } = coreMock.createSetup(); const refresh = () => { new Promise(async (resolve) => { @@ -91,7 +127,10 @@ describe('when setMenuMountPoint is provided', () => { notifications, }, }; - const TestComponent = createDataSourceMenu(); + const TestComponent = createDataSourceMenu( + uiSettings, + mockDataSourcePluginSetupWithShowLocalCluster + ); const component = render(); act(() => { mountPoint(portalTarget); diff --git a/src/plugins/data_source_management/public/components/data_source_menu/create_data_source_menu.tsx b/src/plugins/data_source_management/public/components/data_source_menu/create_data_source_menu.tsx index 484f3e6630d8..4654ae9589b8 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/create_data_source_menu.tsx +++ b/src/plugins/data_source_management/public/components/data_source_menu/create_data_source_menu.tsx @@ -6,21 +6,32 @@ import React from 'react'; import { EuiHeaderLinks } from '@elastic/eui'; import { IUiSettingsClient } from 'src/core/public'; +import { DataSourcePluginSetup } from 'src/plugins/data_source/public'; import { DataSourceMenu } from './data_source_menu'; import { DataSourceMenuProps } from './types'; import { MountPointPortal } from '../../../../opensearch_dashboards_react/public'; -export function createDataSourceMenu(uiSettings: IUiSettingsClient) { +export function createDataSourceMenu( + uiSettings: IUiSettingsClient, + dataSource: DataSourcePluginSetup +) { return (props: DataSourceMenuProps) => { + const { hideLocalCluster } = dataSource; if (props.setMenuMountPoint) { return ( - + ); } - return ; + return ( + + ); }; } diff --git a/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.test.tsx b/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.test.tsx index e7df411a9e8a..4353dfc0bbf7 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.test.tsx +++ b/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.test.tsx @@ -29,7 +29,6 @@ describe('DataSourceMenu', () => { componentType={DataSourceComponentType.DataSourceSelectable} componentConfig={{ fullWidth: true, - hideLocalCluster: false, onSelectedDataSources: jest.fn(), savedObjects: client, notifications, @@ -43,9 +42,9 @@ describe('DataSourceMenu', () => { component = shallow( { componentType={DataSourceComponentType.DataSourceView} componentConfig={{ fullWidth: true, - hideLocalCluster: true, savedObjects: client, notifications, }} @@ -76,7 +74,6 @@ describe('DataSourceMenu', () => { componentType={DataSourceComponentType.DataSourceView} componentConfig={{ fullWidth: true, - hideLocalCluster: true, notifications, }} /> @@ -90,7 +87,6 @@ describe('DataSourceMenu', () => { componentType={DataSourceComponentType.DataSourceView} componentConfig={{ fullWidth: true, - hideLocalCluster: true, savedObjects: client, notifications, activeOption: [{ id: 'test', label: 'test-label' }], @@ -106,7 +102,6 @@ describe('DataSourceMenu', () => { componentType={DataSourceComponentType.DataSourceView} componentConfig={{ fullWidth: true, - hideLocalCluster: true, savedObjects: client, notifications, activeOption: [{ id: 'test' }], @@ -122,7 +117,6 @@ describe('DataSourceMenu', () => { componentType={DataSourceComponentType.DataSourceAggregatedView} componentConfig={{ fullWidth: true, - hideLocalCluster: true, savedObjects: client, notifications, displayAllCompatibleDataSources: true, @@ -138,7 +132,6 @@ describe('DataSourceMenu', () => { componentType={''} componentConfig={{ fullWidth: true, - hideLocalCluster: true, savedObjects: client, notifications, }} diff --git a/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx b/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx index b1f7ed1eaadd..a9030ec6c9d9 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx +++ b/src/plugins/data_source_management/public/components/data_source_menu/data_source_menu.tsx @@ -19,7 +19,7 @@ import { import { DataSourceSelectable } from '../data_source_selectable'; export function DataSourceMenu(props: DataSourceMenuProps): ReactElement | null { - const { componentType, componentConfig, uiSettings } = props; + const { componentType, componentConfig, uiSettings, hideLocalCluster } = props; function renderDataSourceView(config: DataSourceViewConfig): ReactElement | null { const { activeOption, fullWidth, savedObjects, notifications } = config; @@ -36,13 +36,7 @@ export function DataSourceMenu(props: DataSourceMenuProps): ReactElement | function renderDataSourceMultiSelectable( config: DataSourceMultiSelectableConfig ): ReactElement | null { - const { - fullWidth, - hideLocalCluster, - savedObjects, - notifications, - onSelectedDataSources, - } = config; + const { fullWidth, savedObjects, notifications, onSelectedDataSources } = config; return ( (props: DataSourceMenuProps): ReactElement | onSelectedDataSources, disabled, activeOption, - hideLocalCluster, fullWidth, savedObjects, notifications, @@ -85,7 +78,6 @@ export function DataSourceMenu(props: DataSourceMenuProps): ReactElement | ): ReactElement | null { const { fullWidth, - hideLocalCluster, activeDataSourceIds, displayAllCompatibleDataSources, savedObjects, diff --git a/src/plugins/data_source_management/public/components/data_source_menu/types.ts b/src/plugins/data_source_management/public/components/data_source_menu/types.ts index ba274f5178de..32edbddf09a7 100644 --- a/src/plugins/data_source_management/public/components/data_source_menu/types.ts +++ b/src/plugins/data_source_management/public/components/data_source_menu/types.ts @@ -24,6 +24,7 @@ export interface DataSourceBaseConfig { export interface DataSourceMenuProps { componentType: DataSourceComponentType; componentConfig: T; + hideLocalCluster?: boolean; uiSettings?: IUiSettingsClient; setMenuMountPoint?: (menuMount: MountPoint | undefined) => void; } @@ -47,7 +48,6 @@ export interface DataSourceAggregatedViewConfig extends DataSourceBaseConfig { savedObjects: SavedObjectsClientContract; notifications: NotificationsStart; activeDataSourceIds?: string[]; - hideLocalCluster?: boolean; displayAllCompatibleDataSources?: boolean; dataSourceFilter?: (dataSource: SavedObject) => boolean; } @@ -57,7 +57,6 @@ export interface DataSourceSelectableConfig extends DataSourceBaseConfig { savedObjects: SavedObjectsClientContract; notifications: NotificationsStart; activeOption?: DataSourceOption[]; - hideLocalCluster?: boolean; dataSourceFilter?: (dataSource: SavedObject) => boolean; } @@ -65,5 +64,4 @@ export interface DataSourceMultiSelectableConfig extends DataSourceBaseConfig { onSelectedDataSources: (dataSources: DataSourceOption[]) => void; savedObjects: SavedObjectsClientContract; notifications: NotificationsStart; - hideLocalCluster?: boolean; } diff --git a/src/plugins/data_source_management/public/components/data_source_selector/__snapshots__/create_data_source_selector.test.tsx.snap b/src/plugins/data_source_management/public/components/data_source_selector/__snapshots__/create_data_source_selector.test.tsx.snap index 5babe5d1eae3..45cec4abd572 100644 --- a/src/plugins/data_source_management/public/components/data_source_selector/__snapshots__/create_data_source_selector.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/data_source_selector/__snapshots__/create_data_source_selector.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`create data source selector should render normally 1`] = ` +exports[`create data source selector should ignore props.hideLocalCluster, and show local cluster when data_source.hideLocalCluster is set to false 1`] = ` Object { "asFragment": [Function], "baseElement": @@ -214,3 +214,194 @@ Object { "unmount": [Function], } `; + +exports[`create data source selector should render normally 1`] = ` +Object { + "asFragment": [Function], + "baseElement": +
+ + , + "container":
+ , + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], +} +`; diff --git a/src/plugins/data_source_management/public/components/data_source_selector/create_data_source_selector.test.tsx b/src/plugins/data_source_management/public/components/data_source_selector/create_data_source_selector.test.tsx index c0324b8d1d15..9049c6767c7c 100644 --- a/src/plugins/data_source_management/public/components/data_source_selector/create_data_source_selector.test.tsx +++ b/src/plugins/data_source_management/public/components/data_source_selector/create_data_source_selector.test.tsx @@ -6,8 +6,12 @@ import { createDataSourceSelector } from './create_data_source_selector'; import { SavedObjectsClientContract } from '../../../../../core/public'; import { notificationServiceMock } from '../../../../../core/public/mocks'; import React from 'react'; -import { render } from '@testing-library/react'; +import { getByText, render } from '@testing-library/react'; import { coreMock } from '../../../../../core/public/mocks'; +import { + mockDataSourcePluginSetupWithHideLocalCluster, + mockDataSourcePluginSetupWithShowLocalCluster, +} from '../../mocks'; describe('create data source selector', () => { let client: SavedObjectsClientContract; @@ -29,7 +33,10 @@ describe('create data source selector', () => { hideLocalCluster: false, fullWidth: false, }; - const TestComponent = createDataSourceSelector(uiSettings); + const TestComponent = createDataSourceSelector( + uiSettings, + mockDataSourcePluginSetupWithHideLocalCluster + ); const component = render(); expect(component).toMatchSnapshot(); expect(client.find).toBeCalledWith({ @@ -39,4 +46,22 @@ describe('create data source selector', () => { }); expect(toasts.addWarning).toBeCalledTimes(0); }); + + it('should ignore props.hideLocalCluster, and show local cluster when data_source.hideLocalCluster is set to false', () => { + const props = { + savedObjectsClient: client, + notifications: toasts, + onSelectedDataSource: jest.fn(), + disabled: false, + hideLocalCluster: true, + fullWidth: false, + }; + const TestComponent = createDataSourceSelector( + uiSettings, + mockDataSourcePluginSetupWithShowLocalCluster + ); + const component = render(); + expect(component).toMatchSnapshot(); + expect(getByText(component.container, 'Local cluster')).toBeInTheDocument(); + }); }); diff --git a/src/plugins/data_source_management/public/components/data_source_selector/create_data_source_selector.tsx b/src/plugins/data_source_management/public/components/data_source_selector/create_data_source_selector.tsx index 485d192668a5..ddd8e297386b 100644 --- a/src/plugins/data_source_management/public/components/data_source_selector/create_data_source_selector.tsx +++ b/src/plugins/data_source_management/public/components/data_source_selector/create_data_source_selector.tsx @@ -5,10 +5,15 @@ import React from 'react'; import { IUiSettingsClient } from 'src/core/public'; +import { DataSourcePluginSetup } from 'src/plugins/data_source/public'; import { DataSourceSelector, DataSourceSelectorProps } from './data_source_selector'; -export function createDataSourceSelector(uiSettings: IUiSettingsClient) { +export function createDataSourceSelector( + uiSettings: IUiSettingsClient, + dataSource: DataSourcePluginSetup +) { + const { hideLocalCluster } = dataSource; return (props: DataSourceSelectorProps) => ( - + ); } diff --git a/src/plugins/data_source_management/public/components/data_source_selector/data_source_selector.tsx b/src/plugins/data_source_management/public/components/data_source_selector/data_source_selector.tsx index 1f4782c8b896..9674d4e0c9c8 100644 --- a/src/plugins/data_source_management/public/components/data_source_selector/data_source_selector.tsx +++ b/src/plugins/data_source_management/public/components/data_source_selector/data_source_selector.tsx @@ -23,8 +23,8 @@ export interface DataSourceSelectorProps { notifications: ToastsStart; onSelectedDataSource: (dataSourceOption: DataSourceOption[]) => void; disabled: boolean; - hideLocalCluster: boolean; fullWidth: boolean; + hideLocalCluster?: boolean; defaultOption?: DataSourceOption[]; placeholderText?: string; removePrepend?: boolean; diff --git a/src/plugins/data_source_management/public/mocks.ts b/src/plugins/data_source_management/public/mocks.ts index acab48df52db..f0b65d7343c3 100644 --- a/src/plugins/data_source_management/public/mocks.ts +++ b/src/plugins/data_source_management/public/mocks.ts @@ -7,6 +7,7 @@ import React from 'react'; import { throwError } from 'rxjs'; import { SavedObjectsClientContract } from 'opensearch-dashboards/public'; import { IUiSettingsClient } from 'src/core/public'; +import { DataSourcePluginSetup } from 'src/plugins/data_source/public'; import { AuthType, DataSourceAttributes } from './types'; import { coreMock } from '../../../core/public/mocks'; import { @@ -362,3 +363,16 @@ export const createAuthenticationMethod = ( }, ...authMethod, }); + +export const mockDataSourcePluginSetupWithShowLocalCluster: DataSourcePluginSetup = { + dataSourceEnabled: true, + hideLocalCluster: false, + noAuthenticationTypeEnabled: true, + usernamePasswordAuthEnabled: true, + awsSigV4AuthEnabled: true, +}; + +export const mockDataSourcePluginSetupWithHideLocalCluster: DataSourcePluginSetup = { + ...mockDataSourcePluginSetupWithShowLocalCluster, + hideLocalCluster: true, +}; diff --git a/src/plugins/data_source_management/public/plugin.ts b/src/plugins/data_source_management/public/plugin.ts index d07911dacfc4..abcc532b8a7e 100644 --- a/src/plugins/data_source_management/public/plugin.ts +++ b/src/plugins/data_source_management/public/plugin.ts @@ -103,8 +103,8 @@ export class DataSourceManagementPlugin return { registerAuthenticationMethod, ui: { - DataSourceSelector: createDataSourceSelector(uiSettings), - getDataSourceMenu: () => createDataSourceMenu(uiSettings), + DataSourceSelector: createDataSourceSelector(uiSettings, dataSource), + getDataSourceMenu: () => createDataSourceMenu(uiSettings, dataSource), }, }; }