From b26ed851d565b4905d07638548be95f5a0023cd0 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:00:20 +0800 Subject: [PATCH] [Workspace] Support to dissociate data connection object since DSM list has supported to display (#9164) (#9188) * support data connection object in DSM list to disassociate * test: add unit tests * Changeset file for PR #9164 created/updated --------- (cherry picked from commit 82689bbbccc586b198f3ea74cb03dce8e6c39738) Signed-off-by: tygao Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/9164.yml | 2 + ...query_data_connections_table.test.tsx.snap | 8 ++ ...rect_query_data_connections_table.test.tsx | 89 +++++++++++++++++++ ...ge_direct_query_data_connections_table.tsx | 15 +++- .../data_source_management/public/types.ts | 2 + 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/9164.yml diff --git a/changelogs/fragments/9164.yml b/changelogs/fragments/9164.yml new file mode 100644 index 000000000000..b11a3e07a7bc --- /dev/null +++ b/changelogs/fragments/9164.yml @@ -0,0 +1,2 @@ +feat: +- Support to dissociate data connection object since DSM list has supported to display ([#9164](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9164)) \ No newline at end of file diff --git a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/__snapshots__/manage_direct_query_data_connections_table.test.tsx.snap b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/__snapshots__/manage_direct_query_data_connections_table.test.tsx.snap index e34533542ab6..977ba7bd03ae 100644 --- a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/__snapshots__/manage_direct_query_data_connections_table.test.tsx.snap +++ b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/__snapshots__/manage_direct_query_data_connections_table.test.tsx.snap @@ -110,11 +110,13 @@ exports[`ManageDirectQueryDataConnectionsTable fetch security lake and cloudwatc Array [ Object { "id": "connection1", + "objectType": "data-connection", "title": "Connection 1", "type": "AWS CloudWatch", }, Object { "id": "connection2", + "objectType": "data-connection", "title": "Connection 2", "type": "AWS Security Lake", }, @@ -595,11 +597,13 @@ exports[`ManageDirectQueryDataConnectionsTable fetch security lake and cloudwatc Array [ Object { "id": "connection1", + "objectType": "data-connection", "title": "Connection 1", "type": "AWS CloudWatch", }, Object { "id": "connection2", + "objectType": "data-connection", "title": "Connection 2", "type": "AWS Security Lake", }, @@ -2110,11 +2114,13 @@ exports[`ManageDirectQueryDataConnectionsTable fetch security lake and cloudwatc Array [ Object { "id": "connection1", + "objectType": "data-connection", "title": "Connection 1", "type": "AWS CloudWatch", }, Object { "id": "connection2", + "objectType": "data-connection", "title": "Connection 2", "type": "AWS Security Lake", }, @@ -2595,11 +2601,13 @@ exports[`ManageDirectQueryDataConnectionsTable fetch security lake and cloudwatc Array [ Object { "id": "connection1", + "objectType": "data-connection", "title": "Connection 1", "type": "AWS CloudWatch", }, Object { "id": "connection2", + "objectType": "data-connection", "title": "Connection 2", "type": "AWS Security Lake", }, diff --git a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.test.tsx b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.test.tsx index 95ccea352c36..29c35a686f24 100644 --- a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.test.tsx +++ b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.test.tsx @@ -20,6 +20,7 @@ import { DATA_CONNECTION_SAVED_OBJECT_TYPE, DataConnectionType, } from '../../../../../data_source/common'; +import { waitFor } from '@testing-library/dom'; const deleteButtonIdentifier = '[data-test-subj="deleteDataSourceConnections"]'; const tableIdentifier = 'EuiInMemoryTable'; @@ -280,6 +281,94 @@ describe('ManageDirectQueryDataConnectionsTable', () => { expect(component).toMatchSnapshot(); }); }); + + describe('data source association', () => { + const mockDissociate = jest.fn(); + + beforeEach(async () => { + const mockedDataConnections = [ + { + type: 'data-connection', + id: 'data-connection-id', + attributes: { + connectionId: 'cloudWatch', + type: 'AWS CloudWatch', + }, + }, + ]; + spyOn(utils, 'getDataSources').and.returnValue(Promise.resolve(getMappedDataSources)); + spyOn(utils, 'fetchDataSourceConnections').and.returnValue( + Promise.resolve(getMappedDataSources) + ); + spyOn(utils, 'getDataConnections').and.returnValue(Promise.resolve(mockedDataConnections)); + spyOn(utils, 'getHideLocalCluster').and.returnValue(false); + spyOn(uiSettings, 'get$').and.returnValue(new BehaviorSubject('test1')); + const context = { + ...mockedContext, + application: { + ...mockedContext.application, + capabilities: { + ...mockedContext.application.capabilities, + dashboards: { + ...mockedContext.application.capabilities.dashboards, + isDashboardAdmin: true, + }, + }, + }, + workspaces: { + ...mockedContext.workspaces, + client$: new BehaviorSubject({ + ui: () => ({ + DataSourceAssociation: undefined, + }), + dissociate: mockDissociate, + }), + currentWorkspace$: new BehaviorSubject({ + id: 'workspace_id', + readonly: false, + }), + }, + overlays: { + ...mockedContext.overlays, + openConfirm: jest.fn().mockResolvedValue(true), + }, + }; + await act(async () => { + component = await mount( + wrapWithIntl( + + ), + { + wrappingComponent: OpenSearchDashboardsContextProvider, + wrappingComponentProps: { + services: context, + }, + } + ); + }); + component.update(); + }); + test('should be able to pass data-connection type to dissociate data connection object', async () => { + const cloudWatchRow = component + .find('tr') + .filterWhere((tr) => tr.text().includes('cloudWatch')); + cloudWatchRow + .find('button[data-test-subj="dataSourcesManagement-dataSourceTable-dissociateButton"]') + .simulate('click'); + component.update(); + await waitFor(() => { + expect(mockDissociate).toHaveBeenCalledWith( + [{ id: 'data-connection-id', type: 'data-connection' }], + 'workspace_id' + ); + }); + }); + }); }); describe('FetchDirectQueryConnections', () => { diff --git a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx index c96d846c29c3..63757ba404b8 100644 --- a/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx +++ b/src/plugins/data_source_management/public/components/direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table.tsx @@ -47,7 +47,10 @@ import { LoadingMask } from '../../loading_mask'; import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; import { DATACONNECTIONS_BASE, LOCAL_CLUSTER } from '../../../constants'; import { DatasourceTypeToDisplayName, DEFAULT_DATA_SOURCE_UI_SETTINGS_ID } from '../../constants'; -import { DataConnectionType } from '../../../../../data_source/common'; +import { + DataConnectionType, + DATA_CONNECTION_SAVED_OBJECT_TYPE, +} from '../../../../../data_source/common'; interface DirectQueryDataConnectionsProps extends RouteComponentProps { featureFlagStatus: boolean; @@ -179,6 +182,8 @@ export const ManageDirectQueryDataConnectionsTable = ({ id: obj.id, title: obj.attributes.connectionId, type: obj.attributes.type, + // This represents this is data connection type saved object not data source type saved object + objectType: DATA_CONNECTION_SAVED_OBJECT_TYPE, })); } catch (error: any) { return []; @@ -236,7 +241,13 @@ export const ManageDirectQueryDataConnectionsTable = ({ const onDissociate = useCallback( async (item: DataSourceTableItem | DataSourceTableItem[]) => { const itemsToDissociate = Array().concat(item); - const payload = itemsToDissociate.map((ds) => ({ id: ds.id, type: 'data-source' })); + const payload = itemsToDissociate.map((ds) => ({ + id: ds.id, + type: + ds?.objectType === DATA_CONNECTION_SAVED_OBJECT_TYPE + ? DATA_CONNECTION_SAVED_OBJECT_TYPE + : 'data-source', + })); const confirmed = await overlays.openConfirm('', { title: i18n.translate('dataSourcesManagement.dataSourcesTable.removeAssociation', { defaultMessage: diff --git a/src/plugins/data_source_management/public/types.ts b/src/plugins/data_source_management/public/types.ts index dfce014d0309..b18a96be970e 100644 --- a/src/plugins/data_source_management/public/types.ts +++ b/src/plugins/data_source_management/public/types.ts @@ -55,6 +55,8 @@ export interface DataSourceTableItem { description?: string; sort?: string; relatedConnections?: DataSourceTableItem[]; + // This is used to identify the type of the data connection saved object + objectType?: string; } /**