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] Refactor 'Associate data sources' in create page to support direct query connections #7961

Merged
merged 29 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
57db44d
support DQC
Kapian1234 Sep 2, 2024
6111eb3
Fix UTs in workspace form select data source panel
wanglam Sep 2, 2024
affc9ba
Remove no need IntlProvider
wanglam Sep 2, 2024
cff1491
Add aria-labelledby for permission inputs
wanglam Sep 2, 2024
8490ca0
Modify UTs
Kapian1234 Sep 2, 2024
473e058
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
Kapian1234 Sep 2, 2024
8701a3f
Merge branch 'creator_association' of github.com:Kapian1234/OpenSearc…
Kapian1234 Sep 2, 2024
b7916d0
Changeset file for PR #7961 created/updated
opensearch-changeset-bot[bot] Sep 2, 2024
a362c4d
Modify UTs
Kapian1234 Sep 2, 2024
fb07145
Merge branch 'creator_association' of github.com:Kapian1234/OpenSearc…
Kapian1234 Sep 2, 2024
18b4294
Resolve some issues
Kapian1234 Sep 3, 2024
00875c0
Modify UTs
Kapian1234 Sep 3, 2024
d70ead6
Merge branch 'main' of https://github.com/opensearch-project/OpenSear…
Kapian1234 Sep 3, 2024
d3bd99f
Fix UT errror
wanglam Sep 3, 2024
cd360e8
Merge branch 'creator_association' of github.com:Kapian1234/OpenSearc…
Kapian1234 Sep 3, 2024
c816ecd
update button text
Kapian1234 Sep 3, 2024
65eed8b
rename onSelectItems()
Kapian1234 Sep 4, 2024
06e7e74
Merge branch 'main' into creator_association
Kapian1234 Sep 4, 2024
53d0fc3
Fix an error
Kapian1234 Sep 4, 2024
439c4d8
Merge branch 'creator_association' of github.com:Kapian1234/OpenSearc…
Kapian1234 Sep 4, 2024
2b4362a
Refactor data source connection table
wanglam Sep 4, 2024
64363b4
resolve some issues
Kapian1234 Sep 4, 2024
308c318
resolve some issues
Kapian1234 Sep 4, 2024
5c8d72f
resolve conflicts
Kapian1234 Sep 5, 2024
46e78c3
Fix the data source URL reference
Kapian1234 Sep 5, 2024
1400600
Move restProps to tableProps
wanglam Sep 5, 2024
ea60cb3
Fix table not unmont after connection type changed
wanglam Sep 5, 2024
2451b92
Refactor selectedDataSources to selectedDataSourceConnections
wanglam Sep 5, 2024
b4b1ac7
Load direct query connections after data source tab selected
wanglam Sep 5, 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/7961.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Support DQCs in create page ([#7961](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7961))
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
WorkspaceCreator as WorkspaceCreatorComponent,
WorkspaceCreatorProps,
} from './workspace_creator';
import { DataSourceEngineType } from '../../../../data_source/common/data_sources';
import { DataSourceConnectionType } from '../../../common/types';
import * as utils from '../../utils';

const workspaceClientCreate = jest
.fn()
Expand All @@ -32,21 +35,50 @@ const dataSourcesList = [
{
id: 'id1',
title: 'ds1',
description: 'Description of data source 1',
auth: '',
dataSourceEngineType: '' as DataSourceEngineType,
workspaces: [],
// This is used for mocking saved object function
get: () => {
return 'ds1';
},
},
{
id: '2',
id: 'id2',
title: 'ds2',
description: 'Description of data source 1',
auth: '',
dataSourceEngineType: '' as DataSourceEngineType,
workspaces: [],
get: () => {
return 'ds2';
},
},
];

const dataSourceConnectionsList = [
{
id: 'id1',
name: 'ds1',
connectionType: DataSourceConnectionType.OpenSearchConnection,
type: 'OpenSearch',
relatedConnections: [],
},
{
id: 'id2',
name: 'ds2',
connectionType: DataSourceConnectionType.OpenSearchConnection,
type: 'OpenSearch',
},
];

const mockCoreStart = coreMock.createStart();
jest.spyOn(utils, 'fetchDataSourceConnections').mockImplementation(async (passedDataSources) => {
return dataSourceConnectionsList.filter(({ id }) =>
passedDataSources.some((dataSource) => dataSource.id === id)
);
});

const WorkspaceCreator = ({
isDashboardAdmin = false,
Expand Down Expand Up @@ -304,7 +336,15 @@ describe('WorkspaceCreator', () => {
});

it('create workspace with customized selected dataSources', async () => {
const { getByTestId, getByTitle, getByText } = render(
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
configurable: true,
value: 600,
});
Object.defineProperty(HTMLElement.prototype, 'offsetWidth', {
configurable: true,
value: 600,
});
const { getByTestId, getAllByText, getByText } = render(
<WorkspaceCreator isDashboardAdmin={true} />
);

Expand All @@ -317,10 +357,17 @@ describe('WorkspaceCreator', () => {
target: { value: 'test workspace name' },
});
fireEvent.click(getByTestId('workspaceUseCase-observability'));
fireEvent.click(getByTestId('workspaceForm-select-dataSource-addNew'));
fireEvent.click(getByTestId('workspaceForm-select-dataSource-comboBox'));
fireEvent.click(getByText('Select'));
fireEvent.click(getByTitle(dataSourcesList[0].title));
fireEvent.click(getByTestId('workspace-creator-dataSources-assign-button'));
await waitFor(() => {
expect(
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();
expect(getByText(dataSourcesList[0].title)).toBeInTheDocument();
});
fireEvent.click(getByText(dataSourcesList[0].title));
fireEvent.click(getAllByText('Associate data sources')[1]);

fireEvent.click(getByTestId('workspaceForm-bottomBar-createButton'));
expect(workspaceClientCreate).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import { getUseCaseFeatureConfig } from '../../../common/utils';
import { formatUrlWithWorkspaceId } from '../../../../../core/public/utils';
import { WorkspaceClient } from '../../workspace_client';
import { convertPermissionSettingsToPermissions } from '../workspace_form';
import { DataSource } from '../../../common/types';
import { DataSourceManagementPluginSetup } from '../../../../../plugins/data_source_management/public';
import { WorkspaceUseCase } from '../../types';
import { getFirstUseCaseOfFeatureConfigs } from '../../utils';
import { useFormAvailableUseCases } from '../workspace_form/use_form_available_use_cases';
import { NavigationPublicPluginStart } from '../../../../../plugins/navigation/public';
import { DataSourceConnectionType } from '../../../common/types';
import { WorkspaceCreatorForm } from './workspace_creator_form';

export interface WorkspaceCreatorProps {
Expand Down Expand Up @@ -72,10 +72,14 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
}
setIsFormSubmitting(true);
try {
const { permissionSettings, selectedDataSources, ...attributes } = data;
const selectedDataSourceIds = (selectedDataSources ?? []).map((ds: DataSource) => {
return ds.id;
});
const { permissionSettings, selectedDataSourceConnections, ...attributes } = data;
const selectedDataSourceIds = (selectedDataSourceConnections ?? [])
.filter(
({ connectionType }) => connectionType === DataSourceConnectionType.OpenSearchConnection
)
.map(({ id }) => {
return id;
});
result = await workspaceClient.create(attributes, {
dataSources: selectedDataSourceIds,
permissions: convertPermissionSettingsToPermissions(permissionSettings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const WorkspaceCreatorForm = (props: WorkspaceCreatorFormProps) => {
handleColorChange,
handleUseCaseChange: handleUseCaseChangeInHook,
setPermissionSettings,
setSelectedDataSources,
setSelectedDataSourceConnections,
} = useWorkspaceForm(props);
const nameManualChangedRef = useRef(false);

Expand Down Expand Up @@ -86,7 +86,7 @@ export const WorkspaceCreatorForm = (props: WorkspaceCreatorFormProps) => {

return (
<EuiFlexGroup className="workspaceCreateFormContainer">
<EuiFlexItem style={{ maxWidth: 650 }}>
<EuiFlexItem style={{ maxWidth: 768 }}>
<EuiForm
id={formId}
onSubmit={handleFormSubmit}
Expand Down Expand Up @@ -173,11 +173,11 @@ export const WorkspaceCreatorForm = (props: WorkspaceCreatorFormProps) => {
})}
</EuiText>
<SelectDataSourcePanel
errors={formErrors.selectedDataSources}
onChange={setSelectedDataSources}
onChange={setSelectedDataSourceConnections}
savedObjects={savedObjects}
selectedDataSources={formData.selectedDataSources}
assignedDataSourceConnections={formData.selectedDataSourceConnections}
data-test-subj={`workspaceForm-dataSourcePanel`}
showDataSourceManagement={true}
/>
<EuiSpacer size="s" />
<EuiSpacer size="s" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ describe('WorkspaceFormSummaryPanel', () => {
name: 'Test Workspace',
description: 'This is a test workspace',
color: '#000000',
selectedDataSources: [
{ id: 'data-source-1', title: 'Data Source 1' },
{ id: 'data-source-2', title: 'Data Source 2' },
{ id: 'data-source-3', title: 'Data Source 3' },
selectedDataSourceConnections: [
{ id: 'data-source-1', name: 'Data Source 1' },
{ id: 'data-source-2', name: 'Data Source 2' },
{ id: 'data-source-3', name: 'Data Source 3' },
],
permissionSettings: [
{ id: 1, type: WorkspacePermissionItemType.User, userId: 'user1' },
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('WorkspaceFormSummaryPanel', () => {
<WorkspaceFormSummaryPanel
formData={{
name: '',
selectedDataSources: [],
selectedDataSourceConnections: [],
permissionSettings: [],
features: [],
useCase: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ export const WorkspaceFormSummaryPanel = ({
)}
</FieldSummaryItem>
<FieldSummaryItem field={RightSidebarScrollField.DataSource}>
{formData.selectedDataSources.length > 0 && (
{formData.selectedDataSourceConnections.length > 0 && (
<ExpandableTextList
texts={formData.selectedDataSources.map(({ title }) => title)}
texts={formData.selectedDataSourceConnections.map(({ name }) => name)}
collapseDisplayCount={2}
/>
)}
Expand Down
Loading
Loading