From 8b1cf1aa1f9b59b50b3e6023d2b31f941e03587b Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 20:38:29 -0700 Subject: [PATCH] [BUG] Fix bug in data source aggregated view to change it to depend on displayAllCompatibleDataSources property to show the badge value (#6291) (#6323) * fix bug Signed-off-by: Lu Yu * add tests Signed-off-by: Lu Yu * add change log Signed-off-by: Lu Yu * fix lint error Signed-off-by: Lu Yu --------- Signed-off-by: Lu Yu (cherry picked from commit f13537cb15e276f57a2788a2737af3fd5637e733) Signed-off-by: github-actions[bot] # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] --- .../data_source_aggregated_view.test.tsx.snap | 456 +++++++++++++++--- .../data_source_aggregated_view.test.tsx | 25 +- .../data_source_aggregated_view.tsx | 13 +- .../data_source_menu.test.tsx.snap | 74 ++- .../data_source_menu.test.tsx | 13 +- 5 files changed, 502 insertions(+), 79 deletions(-) diff --git a/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap b/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap index 2c789f04da12..e4f4b1f67c67 100644 --- a/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/data_source_aggregated_view/__snapshots__/data_source_aggregated_view.test.tsx.snap @@ -1,7 +1,49 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DataSourceAggregatedView should render normally with data source filter 1`] = ` - + - Data sources + - All + + All + - +
+
+ + + +
+
-
+ `; exports[`DataSourceAggregatedView should render normally with local cluster and actice selections 1`] = ` - + - Data sources + - 1 + + 1 + - +
+
+ + + +
+
-
+ `; exports[`DataSourceAggregatedView should render normally with local cluster hidden and all options 1`] = ` - + - Data sources + - All + + 0 + - +
+
+ + + +
+
-
+ `; exports[`DataSourceAggregatedView should render normally with local cluster not hidden and all options 1`] = ` diff --git a/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.test.tsx b/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.test.tsx index 3f44bac61e5b..5bb518af2d06 100644 --- a/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.test.tsx +++ b/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.test.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ShallowWrapper, shallow } from 'enzyme'; +import { ShallowWrapper, mount, shallow } from 'enzyme'; import React from 'react'; import { DataSourceAggregatedView } from './data_source_aggregated_view'; import { SavedObjectsClientContract } from '../../../../../core/public'; @@ -43,26 +43,29 @@ describe('DataSourceAggregatedView', () => { }); it('should render normally with local cluster hidden and all options', () => { - component = shallow( + const container = mount( ); - expect(component).toMatchSnapshot(); + expect(container).toMatchSnapshot(); expect(client.find).toBeCalledWith({ fields: ['id', 'title', 'auth.type'], perPage: 10000, type: 'data-source', }); expect(toasts.addWarning).toBeCalledTimes(0); + const badge = container.find('EuiNotificationBadge').text(); + expect(badge).toEqual('0'); }); it('should render normally with local cluster and actice selections', () => { - component = shallow( + const container = mount( { activeDataSourceIds={['test1']} /> ); - expect(component).toMatchSnapshot(); + expect(container).toMatchSnapshot(); expect(client.find).toBeCalledWith({ fields: ['id', 'title', 'auth.type'], perPage: 10000, type: 'data-source', }); expect(toasts.addWarning).toBeCalledTimes(0); + const badge = container.find('EuiNotificationBadge').text(); + expect(badge).toEqual('1'); }); it('should render normally with data source filter', () => { - component = shallow( + const container = mount( ds.attributes.auth.type !== 'no_auth'} /> ); - expect(component).toMatchSnapshot(); + expect(container).toMatchSnapshot(); expect(client.find).toBeCalledWith({ fields: ['id', 'title', 'auth.type'], perPage: 10000, type: 'data-source', }); expect(toasts.addWarning).toBeCalledTimes(0); + const badge = container.find('EuiNotificationBadge').text(); + expect(badge).toEqual('All'); }); it('should render popup when clicking on info icon', async () => { diff --git a/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.tsx b/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.tsx index 015441773600..7c039c2f64f3 100644 --- a/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.tsx +++ b/src/plugins/data_source_management/public/components/data_source_aggregated_view/data_source_aggregated_view.tsx @@ -111,17 +111,17 @@ export class DataSourceAggregatedView extends React.Component< let items = []; // only display active data sources - if (this.props.activeDataSourceIds && this.props.activeDataSourceIds.length > 0) { - items = this.props.activeDataSourceIds.map((id) => { + if (this.props.displayAllCompatibleDataSources) { + items = [...this.state.allDataSourcesIdToTitleMap.values()].map((title) => { return { - name: this.state.allDataSourcesIdToTitleMap.get(id), + name: title, disabled: true, }; }); } else { - items = [...this.state.allDataSourcesIdToTitleMap.values()].map((title) => { + items = this.props.activeDataSourceIds!.map((id) => { return { - name: title, + name: this.state.allDataSourcesIdToTitleMap.get(id), disabled: true, }; }); @@ -155,7 +155,8 @@ export class DataSourceAggregatedView extends React.Component< {'Data sources'} - {this.props.activeDataSourceIds?.length || 'All'} + {(this.props.displayAllCompatibleDataSources && 'All') || + this.props.activeDataSourceIds!.length} -
+
+
+
+ + + 0 + +
+
+
, - "container":
, + "container":
+
+
+ + + 0 + +
+
+
, "debug": [Function], "findAllByAltText": [Function], "findAllByDisplayValue": [Function], 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 4f7914148ca8..538d579c4b6b 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 @@ -74,6 +74,7 @@ describe('DataSourceMenu', () => { hideLocalCluster: true, savedObjects: client, notifications, + displayAllCompatibleDataSources: true, }} /> ); @@ -98,12 +99,12 @@ describe('DataSourceMenu', () => { it('should render data source multi select component', () => { const container = render( ); expect(container).toMatchSnapshot();