Skip to content

Commit

Permalink
[Workspace] add data-connection type support for association modal (#…
Browse files Browse the repository at this point in the history
…8620) (#8646)

* add DQS type support for association modal



* Changeset file for PR #8620 created/updated

---------



(cherry picked from commit 32b11de)

Signed-off-by: tygao <tygao@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 18, 2024
1 parent 5a7042a commit d9c5c78
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8620.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add data-connection type support for association modal ([#8620](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8620))
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,43 @@ describe('<DataSourceAssociation />', () => {
});
});

it('should associate data connections successfully', async () => {
const associateMock = jest
.fn()
.mockResolvedValue({ success: true, result: [{ id: 'id1' }, { id: 'id2' }] });
servicesMock.workspaces.client$ = new BehaviorSubject<IWorkspaceClient | null>({
associate: associateMock,
copy: jest.fn(),
dissociate: jest.fn(),
ui: jest.fn(),
});
servicesMock.workspaces.currentWorkspaceId$ = new BehaviorSubject<string>('workspace_test');

(AssociationDataSourceModalContent as jest.Mock).mockImplementation((props: any) => (
<button
onClick={() =>
props.handleAssignDataSourceConnections([
{ id: 'id1', connectionType: DataSourceConnectionType.DataConnection },
{ id: 'id2', connectionType: DataSourceConnectionType.DataConnection },
])
}
>
Mocked association button
</button>
));

render(<DataSourceAssociation excludedDataSourceIds={[]} />);
fireEvent.click(screen.getByTestId('workspaceAssociateDataSourceButton'));
fireEvent.click(screen.getByText('Direct query data sources'));
fireEvent.click(screen.getByText('Mocked association button'));
await waitFor(() => {
expect(associateMock).toHaveBeenCalled();
expect(servicesMock.notifications.toasts.addSuccess).toHaveBeenCalledWith(
expect.objectContaining({ title: '2 data sources been associated to the workspace' })
);
});
});

it('should display error toast when associate data source failed', async () => {
const associateMock = jest.fn().mockRejectedValue(new Error());
servicesMock.workspaces.client$ = new BehaviorSubject<IWorkspaceClient | null>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {
import { AssociationDataSourceModalContent } from './association_data_source_modal';
import { AssociationDataSourceModalMode } from '../../../common/constants';
import { DataSourceConnection, DataSourceConnectionType } from '../../../common/types';
import {
DATA_CONNECTION_SAVED_OBJECT_TYPE,
DATA_SOURCE_SAVED_OBJECT_TYPE,
} from '../../../../data_source/common';

interface Props {
excludedDataSourceIds: string[];
Expand Down Expand Up @@ -54,10 +58,13 @@ export const DataSourceAssociation = ({ excludedDataSourceIds, onComplete, onErr

const onAssociateDataSource = useCallback(
async (ds: DataSourceConnection[]) => {
const objects = ds
const dataSourceObjects = ds
.filter((d) => d.connectionType === DataSourceConnectionType.OpenSearchConnection)
.map((d) => ({ id: d.id, type: 'data-source' }));

.map((d) => ({ id: d.id, type: DATA_SOURCE_SAVED_OBJECT_TYPE }));
const dataConnectionObjects = ds
.filter((d) => d.connectionType === DataSourceConnectionType.DataConnection)
.map((d) => ({ id: d.id, type: DATA_CONNECTION_SAVED_OBJECT_TYPE }));
const objects = [...dataSourceObjects, ...dataConnectionObjects];
if (workspaceClient && currentWorkspaceId) {
let failedCount = 0;
try {
Expand Down

0 comments on commit d9c5c78

Please sign in to comment.