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

[Workspace] Support to dissociate data connection object since DSM list has supported to display #9164

Merged
merged 3 commits into from
Jan 9, 2025
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
2 changes: 2 additions & 0 deletions changelogs/fragments/9164.yml
Original file line number Diff line number Diff line change
@@ -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))

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
<ManageDirectQueryDataConnectionsTable
featureFlagStatus={true}
history={history}
location={({} as unknown) as RouteComponentProps['location']}
match={({} as unknown) as RouteComponentProps['match']}
/>
),
{
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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 [];
Expand Down Expand Up @@ -236,7 +241,13 @@ export const ManageDirectQueryDataConnectionsTable = ({
const onDissociate = useCallback(
async (item: DataSourceTableItem | DataSourceTableItem[]) => {
const itemsToDissociate = Array<DataSourceTableItem>().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:
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data_source_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Loading