Skip to content

Commit

Permalink
[workspace]add 2 step loading in 'Associate data sources' modal (open…
Browse files Browse the repository at this point in the history
…search-project#8999)

* add 2 step loading

Signed-off-by: Qxisylolo <[email protected]>

* Changeset file for PR opensearch-project#8999 created/updated

* ifx ut

Signed-off-by: Qxisylolo <[email protected]>

* resolve comments

Signed-off-by: Qxisylolo <[email protected]>

* delete functions

Signed-off-by: Qxisylolo <[email protected]>

* separately fetch dqc

Signed-off-by: Qxisylolo <[email protected]>

* small mistakes

Signed-off-by: Qxisylolo <[email protected]>

* dqc should not show data source without dqc

Signed-off-by: Qxisylolo <[email protected]>

* fix tests

Signed-off-by: Qxisylolo <[email protected]>

* new update

Signed-off-by: Qxisylolo <[email protected]>

* delete non-used import

Signed-off-by: Qxisylolo <[email protected]>

* delete if

Signed-off-by: Qxisylolo <[email protected]>

* add try catch

Signed-off-by: Qxisylolo <[email protected]>

---------

Signed-off-by: Qxisylolo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Yulong Ruan <[email protected]>
  • Loading branch information
3 people authored and AMoo-Miki committed Jan 10, 2025
1 parent d24ac74 commit 06d67a1
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 198 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8999.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add two-steps loading for associating data sources ([#8999](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8999))
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,80 @@ import {
AssociationDataSourceModalProps,
} from './association_data_source_modal';
import { AssociationDataSourceModalMode } from 'src/plugins/workspace/common/constants';
import { DataSourceEngineType } from '../../../../data_source/common/data_sources';
const dataSourcesList = [
{
id: 'ds1',
title: 'Data Source 1',
description: 'Description of data source 1',
auth: '',
dataSourceEngineType: '' as DataSourceEngineType,
workspaces: [],
// This is used for mocking saved object function
get: () => {
return 'Data Source 1';
},
},
{
id: 'dqs1',
title: 'Data Connection 1',
description: 'Description of data connection 1',
auth: '',
dataSourceEngineType: '' as DataSourceEngineType,
workspaces: [],
get: () => {
return 'Data Connection 1';
},
},
];

const setupAssociationDataSourceModal = ({
mode,
excludedConnectionIds,
handleAssignDataSourceConnections,
}: Partial<AssociationDataSourceModalProps> = {}) => {
const coreServices = coreMock.createStart();
jest.spyOn(utilsExports, 'getDataSourcesList').mockResolvedValue([]);
jest.spyOn(utilsExports, 'fetchDataSourceConnections').mockResolvedValue([
const openSearchAndDataConnectionsMock = {
openSearchConnections: [
{
id: 'ds1',
name: 'Data Source 1',
connectionType: DataSourceConnectionType.OpenSearchConnection,
type: 'OpenSearch',
relatedConnections: [
{
id: 'ds1-dqc1',
name: 'dqc1',
parentId: 'ds1',
connectionType: DataSourceConnectionType.DirectQueryConnection,
type: 'Amazon S3',
},
],
},
{
id: 'ds1-dqc1',
name: 'dqc1',
parentId: 'ds1',
connectionType: DataSourceConnectionType.DirectQueryConnection,
type: 'Amazon S3',
},
{
id: 'ds2',
name: 'Data Source 2',
connectionType: DataSourceConnectionType.OpenSearchConnection,
type: 'OpenSearch',
relatedConnections: [],
},
],
dataConnections: [
{
id: 'dqs1',
name: 'Data Connection 1',
connectionType: DataSourceConnectionType.DataConnection,
type: 'AWS Security Lake',
},
],
};
const setupAssociationDataSourceModal = ({
mode,
excludedConnectionIds,
handleAssignDataSourceConnections,
}: Partial<AssociationDataSourceModalProps> = {}) => {
const coreServices = coreMock.createStart();
jest.spyOn(utilsExports, 'getDataSourcesList').mockResolvedValue(dataSourcesList);

jest
.spyOn(utilsExports, 'convertDataSourcesToOpenSearchAndDataConnections')
.mockReturnValue(openSearchAndDataConnectionsMock);

jest.spyOn(utilsExports, 'fetchDirectQueryConnectionsByIDs').mockResolvedValue([
{
id: 'ds1-dqc1',
name: 'dqc1',
type: 'Amazon S3',
connectionType: DataSourceConnectionType.DirectQueryConnection,
parentId: 'ds1',
},
]);

const { logos } = chromeServiceMock.createStartContract();
render(
<IntlProvider locale="en">
<AssociationDataSourceModal
logos={logos}
mode={mode ?? AssociationDataSourceModalMode.OpenSearchConnections}
mode={mode ?? AssociationDataSourceModalMode.DirectQueryConnections}
http={coreServices.http}
notifications={coreServices.notifications}
savedObjects={coreServices.savedObjects}
Expand Down Expand Up @@ -108,17 +132,14 @@ describe('AssociationDataSourceModal', () => {
});

it('should display opensearch connections', async () => {
setupAssociationDataSourceModal();
setupAssociationDataSourceModal({ mode: AssociationDataSourceModalMode.OpenSearchConnections });
expect(screen.getByText('Associate OpenSearch data sources')).toBeInTheDocument();
expect(
screen.getByText(
'Add data sources that will be available in the workspace. If a selected data source has related Direct Query data sources, they will also be available in the workspace.'
)
).toBeInTheDocument();
await waitFor(() => {
expect(screen.getByRole('option', { name: 'Data Source 1' })).toBeInTheDocument();
expect(screen.getByRole('option', { name: 'Data Source 2' })).toBeInTheDocument();
});
await waitFor(() => expect(screen.getByText('Data Source 1')).toBeInTheDocument());
});

it('should display direct query connections after opensearch connection selected', async () => {
Expand All @@ -127,6 +148,7 @@ describe('AssociationDataSourceModal', () => {
});
expect(screen.getByText('Associate direct query data sources')).toBeInTheDocument();
await waitFor(() => {
expect(screen.getByText('Data Source 1')).toBeInTheDocument();
expect(screen.queryByRole('option', { name: 'dqc1' })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('option', { name: 'Data Source 1' }));
expect(screen.getByRole('option', { name: 'dqc1' })).toBeInTheDocument();
Expand All @@ -135,30 +157,29 @@ describe('AssociationDataSourceModal', () => {

it('should hide associated connections', async () => {
setupAssociationDataSourceModal({
excludedConnectionIds: ['ds2'],
excludedConnectionIds: ['ds1'],
});
expect(
screen.getByText(
'Add data sources that will be available in the workspace. If a selected data source has related Direct Query data sources, they will also be available in the workspace.'
)
).toBeInTheDocument();
await waitFor(() => {
expect(screen.getByRole('option', { name: 'Data Source 1' })).toBeInTheDocument();
expect(screen.queryByRole('option', { name: 'Data Source 2' })).not.toBeInTheDocument();
});
expect(screen.queryByRole('option', { name: 'Data Source 1' })).not.toBeInTheDocument();
});

it('should call handleAssignDataSourceConnections with opensearch connections after assigned', async () => {
const handleAssignDataSourceConnectionsMock = jest.fn();
setupAssociationDataSourceModal({
handleAssignDataSourceConnections: handleAssignDataSourceConnectionsMock,
});

await waitFor(() => {
fireEvent.click(screen.getByRole('option', { name: 'Data Source 1' }));
fireEvent.click(screen.getByRole('button', { name: 'Associate data sources' }));
expect(screen.getByText('Data Source 1')).toBeInTheDocument();
expect(screen.getByText('Associate data sources')).toBeInTheDocument();
});

fireEvent.click(screen.getByText('Data Source 1'));
fireEvent.click(screen.getByText('Associate data sources'));

expect(handleAssignDataSourceConnectionsMock).toHaveBeenCalledWith([
{
id: 'ds1',
Expand All @@ -182,14 +203,17 @@ describe('AssociationDataSourceModal', () => {
const handleAssignDataSourceConnectionsMock = jest.fn();
setupAssociationDataSourceModal({
handleAssignDataSourceConnections: handleAssignDataSourceConnectionsMock,
mode: AssociationDataSourceModalMode.DirectQueryConnections,
mode: AssociationDataSourceModalMode.OpenSearchConnections,
});

await waitFor(() => {
fireEvent.click(screen.getByRole('option', { name: 'Data Connection 1' }));
fireEvent.click(screen.getByRole('button', { name: 'Associate data sources' }));
expect(screen.getByText('Data Source 1')).toBeInTheDocument();
expect(screen.getByText('Data Connection 1')).toBeInTheDocument();
});

expect(screen.getByText('Associate data sources')).toBeInTheDocument();
fireEvent.click(screen.getByText('Data Connection 1'));
fireEvent.click(screen.getByText('Associate data sources'));

expect(handleAssignDataSourceConnectionsMock).toHaveBeenCalledWith([
{
id: 'dqs1',
Expand Down
Loading

0 comments on commit 06d67a1

Please sign in to comment.