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] Enable direct query connections to support in workspace #7839

Merged
merged 36 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
38b004a
add dqc
yubonluo Aug 23, 2024
f19871f
solve the code conflict
yubonluo Aug 23, 2024
689e0f6
add dircet query connections on the detail page
yubonluo Aug 26, 2024
13d5ba8
Changeset file for PR #7839 created/updated
opensearch-changeset-bot[bot] Aug 26, 2024
c8141e3
delete useless code
yubonluo Aug 26, 2024
51441e4
Merge branch '2.17/support-DQC' of github.com:yubonluo/OpenSearch-Das…
yubonluo Aug 26, 2024
0e6ad2f
optimize the code
yubonluo Aug 26, 2024
0ef40b6
optimize the code
yubonluo Aug 26, 2024
810651c
Refactor association modal
Kapian1234 Aug 27, 2024
2409005
Integrate modal with workspace detail page
wanglam Aug 27, 2024
4f6d8d9
Fix parent data source unchecked
wanglam Aug 27, 2024
20db731
Merge pull request #1 from Kapian1234/associate_datasource_modal
yubonluo Aug 27, 2024
49377ce
Merge pull request #2 from wanglam/fix-dqc-selection
yubonluo Aug 28, 2024
f1a54af
Remove all tab and sort connections by name alphabetical
wanglam Aug 28, 2024
724170e
Merge pull request #3 from wanglam/feat-remove-all-data-source-modal
yubonluo Aug 28, 2024
2a252b9
optimzie
yubonluo Aug 28, 2024
28a62aa
Fix checked status disappear after modal tab change
wanglam Aug 28, 2024
fe9635e
Merge pull request #5 from wanglam/fix-check-status-disappear-after-m…
yubonluo Aug 28, 2024
ef78bf2
optimize the dqc table
yubonluo Aug 28, 2024
6bd0b12
Merge branch '2.17/support-DQC' of github.com:yubonluo/OpenSearch-Das…
yubonluo Aug 28, 2024
1519652
resolve the code conflict
yubonluo Aug 28, 2024
99de2f4
optimize the code
yubonluo Aug 28, 2024
679d689
update the table css
yubonluo Aug 29, 2024
97a5c9f
Simplify options update logic
wanglam Aug 29, 2024
c32b960
Add unit tests for AssociationDataSourceModal
wanglam Aug 29, 2024
9fee0d2
Merge pull request #6 from wanglam/refactor-modal-options-update-logic
yubonluo Aug 29, 2024
c4dc217
Merge branch 'main' into 2.17/support-DQC
ruanyl Aug 30, 2024
f6d240d
add unit test
yubonluo Aug 30, 2024
651f43d
resolve code conflict
yubonluo Aug 30, 2024
5a1e5a5
optimize the code
yubonluo Aug 30, 2024
b29e3f7
Add nested support in associate data source modal
wanglam Aug 30, 2024
c160ba2
delete useless code
yubonluo Aug 30, 2024
49517b8
Change back type
wanglam Aug 30, 2024
284a54a
Update type in modal UT
wanglam Aug 30, 2024
5b99112
Merge pull request #7 from wanglam/feat-support-nested-in-dqc-tab
yubonluo Aug 30, 2024
a261a25
optimize the code
yubonluo Aug 30, 2024
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/7839.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Enable direct query connections to support in workspace ([#7839](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7839))
3 changes: 2 additions & 1 deletion src/plugins/data_source_management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function plugin() {
return new DataSourceManagementPlugin();
}

export { DataSourceManagementPluginStart } from './types';
export { DataSourceManagementPluginStart, DirectQueryDatasourceDetails } from './types';
export { DataSourceSelector, DataSourceOption } from './components/data_source_selector';
export { DataSourceMenu } from './components/data_source_menu';
export { DataSourceManagementPlugin, DataSourceManagementPluginSetup } from './plugin';
Expand All @@ -26,3 +26,4 @@ export {
} from './components/data_source_menu';
export { DataSourceSelectionService } from './service/data_source_selection_service';
export { getDefaultDataSourceId, getDefaultDataSourceId$ } from './components/utils';
export { DATACONNECTIONS_BASE, DatasourceTypeToDisplayName } from './constants';
4 changes: 4 additions & 0 deletions src/plugins/workspace/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,8 @@ export const CURRENT_USER_PLACEHOLDER = '%me%';
export const MAX_WORKSPACE_NAME_LENGTH = 40;
export const MAX_WORKSPACE_DESCRIPTION_LENGTH = 200;

export enum AssociationDataSourceModalMode {
OpenSearchConnections = 'opensearch-connections',
DirectQueryConnections = 'direction-query-connections',
}
export const USE_CASE_PREFIX = 'use-case-';
15 changes: 15 additions & 0 deletions src/plugins/workspace/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ export type DataSource = Pick<
// Id defined in SavedObjectAttribute could be single or array, here only should be single string.
id: string;
};

export enum DataSourceConnectionType {
OpenSearchConnection,
DirectQueryConnection,
}

export interface DataSourceConnection {
id: string;
type: string | undefined;
parentId?: string;
connectionType: DataSourceConnectionType;
name: string;
description?: string;
relatedConnections?: DataSourceConnection[];
}
2 changes: 1 addition & 1 deletion src/plugins/workspace/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"navigation"
],
"optionalPlugins": ["savedObjectsManagement","management","dataSourceManagement","contentManagement"],
"requiredBundles": ["opensearchDashboardsReact","dataSource","contentManagement"]
"requiredBundles": ["opensearchDashboardsReact","dataSource", "dataSourceManagement","contentManagement"]
}
9 changes: 9 additions & 0 deletions src/plugins/workspace/public/assets/prometheus_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/plugins/workspace/public/assets/s3_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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
@@ -0,0 +1,181 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { IntlProvider } from 'react-intl';

import { DataSourceConnectionType } from '../../../common/types';
import { chromeServiceMock, coreMock } from '../../../../../core/public/mocks';
import * as utilsExports from '../../utils';

import {
AssociationDataSourceModal,
AssociationDataSourceModalProps,
} from './association_data_source_modal';
import { AssociationDataSourceModalMode } from 'src/plugins/workspace/common/constants';

const setupAssociationDataSourceModal = ({
mode,
assignedConnections,
handleAssignDataSourceConnections,
}: Partial<AssociationDataSourceModalProps> = {}) => {
const coreServices = coreMock.createStart();
jest.spyOn(utilsExports, 'getDataSourcesList').mockResolvedValue([]);
jest.spyOn(utilsExports, 'fetchDataSourceConnections').mockResolvedValue([
{
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',
},
]);
const { logos } = chromeServiceMock.createStartContract();
render(
<IntlProvider locale="en">
<AssociationDataSourceModal
logos={logos}
mode={mode ?? AssociationDataSourceModalMode.OpenSearchConnections}
http={coreServices.http}
notifications={coreServices.notifications}
savedObjects={coreServices.savedObjects}
closeModal={jest.fn()}
assignedConnections={assignedConnections ?? []}
handleAssignDataSourceConnections={handleAssignDataSourceConnections ?? jest.fn()}
/>
</IntlProvider>
);
return {};
};

describe('AssociationDataSourceModal', () => {
const originalOffsetHeight = Object.getOwnPropertyDescriptor(
HTMLElement.prototype,
'offsetHeight'
);
const originalOffsetWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetWidth');
beforeEach(() => {
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
configurable: true,
value: 600,
});
Object.defineProperty(HTMLElement.prototype, 'offsetWidth', {
configurable: true,
value: 600,
});
});

afterEach(() => {
Object.defineProperty(
HTMLElement.prototype,
'offsetHeight',
originalOffsetHeight as PropertyDescriptor
);
Object.defineProperty(
HTMLElement.prototype,
'offsetWidth',
originalOffsetWidth as PropertyDescriptor
);
});

it('should display opensearch connections', async () => {
setupAssociationDataSourceModal();
expect(screen.getByText('Associate OpenSearch connections')).toBeInTheDocument();
expect(
screen.getByText(
'Add data sources that will be available in the workspace. If a selected data source has related Direct Query connection, 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();
});
});

it('should display direct query connections after opensearch connection selected', async () => {
setupAssociationDataSourceModal({
mode: AssociationDataSourceModalMode.DirectQueryConnections,
});
expect(screen.getByText('Associate direct query connections')).toBeInTheDocument();
await waitFor(() => {
expect(screen.queryByRole('option', { name: 'dqc1' })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('option', { name: 'Data Source 1' }));
expect(screen.getByRole('option', { name: 'dqc1' })).toBeInTheDocument();
});
});

it('should hide associated connections', async () => {
setupAssociationDataSourceModal({
assignedConnections: [
{
id: 'ds2',
name: 'Data Source 2',
connectionType: DataSourceConnectionType.OpenSearchConnection,
type: 'OpenSearch',
},
],
});
expect(
screen.getByText(
'Add data sources that will be available in the workspace. If a selected data source has related Direct Query connection, 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();
});
});

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(handleAssignDataSourceConnectionsMock).toHaveBeenCalledWith([
{
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',
},
],
},
]);
});
});
Loading
Loading