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 6 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 } from './constants';
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", "home","dataSource"]
"requiredBundles": ["opensearchDashboardsReact", "home","dataSource", "dataSourceManagement"]
}
9 changes: 9 additions & 0 deletions src/plugins/workspace/public/assets/prometheus_logo.svg
yubonluo marked this conversation as resolved.
Show resolved Hide resolved
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.
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,114 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useMemo, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import {
EuiSpacer,
EuiButton,
EuiFlexItem,
EuiFlexGroup,
EuiFieldSearch,
EuiInMemoryTable,
EuiBasicTableColumn,
EuiTableSelectionType,
EuiTableActionsColumnType,
EuiConfirmModal,
EuiSearchBarProps,
EuiText,
EuiListGroup,
EuiListGroupItem,
EuiIcon,
EuiPopover,
EuiButtonEmpty,
EuiPopoverTitle,
EuiSmallButton,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { CoreStart, WorkspaceObject } from '../../../../../core/public';
import { DataSource } from '../../../common/types';
import { DataSource, DataSourceConnection, DataSourceConnectionType } from '../../../common/types';
import { WorkspaceClient } from '../../workspace_client';
import { convertPermissionSettingsToPermissions, useWorkspaceFormContext } from '../workspace_form';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import PrometheusLogo from '../../assets/prometheus_logo.svg';
import S3Logo from '../../assets/s3_logo.svg';

interface OpenSearchConnectionTableProps {
assignedDataSources: DataSource[];
isDashboardAdmin: boolean;
currentWorkspace: WorkspaceObject;
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
connectionType: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use connectionType?: DataSourceConnectionType?Then we can use undefined as all connection types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not use DataSourceConnectionType, because the passed parameter is toggleButton id which must be the type of string.

{
      id: 'openSearchConnections',
      label: i18n.translate('workspace.detail.dataSources.openSearchConnections', {
        defaultMessage: 'OpenSearch connections',
      }),
    },

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I see. Shall we separate a string enum for the toggle buttons? Then we can map it to DataSourceConnectionType in outside.

dataSourceConnections: DataSourceConnection[];
}

export const OpenSearchConnectionTable = ({
assignedDataSources,
isDashboardAdmin,
currentWorkspace,
setIsLoading,
connectionType,
dataSourceConnections,
}: OpenSearchConnectionTableProps) => {
const {
services: { notifications, workspaceClient },
} = useOpenSearchDashboards<{ CoreStart: CoreStart; workspaceClient: WorkspaceClient }>();
const { formData, setSelectedDataSources } = useWorkspaceFormContext();
const [searchTerm, setSearchTerm] = useState('');
const [selectedItems, setSelectedItems] = useState<DataSource[]>([]);
const [selectedItems, setSelectedItems] = useState<DataSourceConnection[]>([]);
const [modalVisible, setModalVisible] = useState(false);
const [popoversState, setPopoversState] = useState<Record<string, boolean>>({});

const filteredDataSources = useMemo(
() =>
assignedDataSources.filter((dataSource) =>
dataSource.title.toLowerCase().includes(searchTerm.toLowerCase())
),
[searchTerm, assignedDataSources]
);
const filteredDataSources = useMemo(() => {
yubonluo marked this conversation as resolved.
Show resolved Hide resolved
// Reset the item when switching connectionType.
setSelectedItems([]);
if (connectionType === 'openSearchConnections') {
return dataSourceConnections.filter(
(dqc) => dqc.connectionType === DataSourceConnectionType.OpenSearchConnection

Check warning on line 61 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L60-L61

Added lines #L60 - L61 were not covered by tests
);
} else if (connectionType === 'directQueryConnections') {
return dataSourceConnections.filter(
(dqc) => dqc.connectionType === DataSourceConnectionType.DirectQueryConnection

Check warning on line 65 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L64-L65

Added lines #L64 - L65 were not covered by tests
);
}
return dataSourceConnections;
}, [connectionType, dataSourceConnections]);

const onSelectionChange = (selectedDataSources: DataSource[]) => {
const renderToolsLeft = useCallback(() => {
return selectedItems.length > 0 && !modalVisible
? [
<EuiSmallButton
color="danger"
onClick={() => setModalVisible(true)}

Check warning on line 76 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L76

Added line #L76 was not covered by tests
data-test-subj="workspace-detail-dataSources-table-bulkRemove"
>
{i18n.translate('workspace.detail.dataSources.table.remove.button', {
defaultMessage: 'Remove {numberOfSelect} association(s)',
values: { numberOfSelect: selectedItems.length },
})}
</EuiSmallButton>,
]
: [];
}, [selectedItems, modalVisible]);

const onSelectionChange = (selectedDataSources: DataSourceConnection[]) => {
setSelectedItems(selectedDataSources);
};

const handleUnassignDataSources = async (dataSources: DataSource[]) => {
const search: EuiSearchBarProps = {
toolsLeft: renderToolsLeft(),
box: {
incremental: true,
},
filters: [
{
type: 'field_value_selection',
field: 'type',
name: 'Type',
multiSelect: 'or',
options: Array.from(
new Set(filteredDataSources.map(({ type }) => type).filter(Boolean))
).map((type) => ({

Check warning on line 105 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L104-L105

Added lines #L104 - L105 were not covered by tests
value: type!,
name: type!,
})),
},
],
};

const handleUnassignDataSources = async (dataSources: DataSourceConnection[]) => {
try {
setIsLoading(true);
setModalVisible(false);
Expand Down Expand Up @@ -93,16 +147,33 @@
}
};

const columns: Array<EuiBasicTableColumn<DataSource>> = [
const directQueryConnectionIcon = (connector: string | undefined) => {
switch (connector) {
case 'S3GLUE':
return <EuiIcon type={S3Logo} />;

Check warning on line 153 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L153

Added line #L153 was not covered by tests
case 'PROMETHEUS':
return <EuiIcon type={PrometheusLogo} />;

Check warning on line 155 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L155

Added line #L155 was not covered by tests
default:
return <></>;

Check warning on line 157 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L157

Added line #L157 was not covered by tests
}
};
const togglePopover = (itemId: string) => {
setPopoversState((prevState) => ({

Check warning on line 161 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L161

Added line #L161 was not covered by tests
...prevState,
[itemId]: !prevState[itemId],
}));
};

const columns: Array<EuiBasicTableColumn<DataSourceConnection>> = [
{
field: 'title',
field: 'name',
name: i18n.translate('workspace.detail.dataSources.table.title', {
defaultMessage: 'Title',
}),
truncateText: true,
},
{
field: 'dataSourceEngineType',
field: 'type',
name: i18n.translate('workspace.detail.dataSources.table.type', {
defaultMessage: 'Type',
}),
Expand All @@ -115,6 +186,54 @@
}),
truncateText: true,
},
{
field: 'relatedConnections',
name: i18n.translate('workspace.detail.dataSources.table.relatedConnections', {
defaultMessage: 'Related connections',
}),
align: 'right',
truncateText: true,
render: (relatedConnections: DataSourceConnection[], record) =>
relatedConnections?.length > 0 ? (
<EuiPopover
key={record.id}
panelPaddingSize="s"
anchorPosition="downRight"
isOpen={popoversState[record.id] || false}
closePopover={() => togglePopover(record.id)}

Check warning on line 203 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L203

Added line #L203 was not covered by tests
button={
<EuiButtonEmpty
size="xs"
flush="right"
color="text"
onClick={() => togglePopover(record.id)}

Check warning on line 209 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L209

Added line #L209 was not covered by tests
>
{relatedConnections?.length}
</EuiButtonEmpty>
}
>
<EuiPopoverTitle>RELATED CONNECTIONS</EuiPopoverTitle>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss i18n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, updated

<EuiListGroup
flush
maxWidth={200}
className="eui-yScrollWithShadows"
style={{ maxHeight: '90px' }}
>
{relatedConnections.map((item) => (
<EuiListGroupItem

Check warning on line 223 in src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_detail/opensearch_connections_table.tsx#L223

Added line #L223 was not covered by tests
key={item.id}
size="xs"
label={item.name}
icon={directQueryConnectionIcon(item.type)}
style={{ maxHeight: '30px' }}
/>
))}
</EuiListGroup>
</EuiPopover>
) : (
<EuiText>—</EuiText>
),
},
...(isDashboardAdmin
? [
{
Expand All @@ -135,7 +254,7 @@
),
icon: 'unlink',
type: 'icon',
onClick: (item: DataSource) => {
onClick: (item: DataSourceConnection) => {
setSelectedItems([item]);
setModalVisible(true);
},
Expand All @@ -147,48 +266,21 @@
: []),
];

const selection: EuiTableSelectionType<DataSource> = {
const selection: EuiTableSelectionType<DataSourceConnection> = {
selectable: () => isDashboardAdmin,
onSelectionChange,
};

const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearchTerm(e.target.value);
};
return (
<>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
{selectedItems.length > 0 && !modalVisible && (
<EuiFlexItem grow={false}>
<EuiButton
color="danger"
onClick={() => setModalVisible(true)}
data-test-subj="workspace-detail-dataSources-table-bulkRemove"
>
{i18n.translate('workspace.detail.dataSources.table.remove.button', {
defaultMessage: 'Remove {numberOfSelect} association(s)',
values: { numberOfSelect: selectedItems.length },
})}
</EuiButton>
</EuiFlexItem>
)}
<EuiFlexItem>
<EuiFieldSearch
placeholder="Search"
value={searchTerm}
onChange={handleSearch}
isClearable={true}
fullWidth
aria-label="Search data sources"
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="s" />
<EuiInMemoryTable
items={filteredDataSources}
itemId="id"
columns={columns}
selection={selection}
search={search}
key={connectionType}
isSelectable={true}
pagination={{
initialPageSize: 10,
pageSizeOptions: [10, 20, 30],
Expand All @@ -199,7 +291,7 @@
<EuiConfirmModal
data-test-subj="workspaceForm-cancelModal"
title={i18n.translate('workspace.detail.dataSources.modal.title', {
defaultMessage: 'Remove OpenSearch connections',
defaultMessage: 'Remove data source(s)',
})}
onCancel={() => {
setModalVisible(false);
Expand All @@ -212,7 +304,7 @@
defaultMessage: 'Cancel',
})}
confirmButtonText={i18n.translate('workspace.detail.dataSources.Modal.confirmButton', {
defaultMessage: 'Remove connections',
defaultMessage: 'Remove data source(s)',
})}
buttonColor="danger"
defaultFocusedButton="confirm"
Expand Down
Loading
Loading