Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Sep 20, 2024
1 parent db41ee2 commit c87b2d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { i18n } from '@osd/i18n';
import { DataSourceConnection, DataSourceConnectionType } from '../../../common/types';
import { AssociationDataSourceModalMode } from '../../../common/constants';
import { DataSourceConnectionTable } from '../workspace_form';

interface WorkspaceDetailConnectionTableProps {
isDashboardAdmin: boolean;
connectionType: string;
Expand Down
47 changes: 24 additions & 23 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export const getDataSourcesList = (
const description = source.get('description');
const dataSourceEngineType = source.get('dataSourceEngineType');
const type = source.type;
// This is a field only for detail type of data connection in order not to mix saved object type.
// This is a field only for detail type of data connection in order not to mix with saved object type.
const connectionType = source.get('type');
return {
id,
Expand Down Expand Up @@ -290,10 +290,10 @@ export const getDirectQueryConnections = async (dataSourceId: string, http: Http
return directQueryConnections;
};

export const convertDataSourcesToOpenSearchConnections = (
export const convertDataSourcesToOpenSearchAndDataConnections = (
dataSources: DataConnection[] | DataSource[]
): DataSourceConnection[] =>
dataSources
): Record<'openSearchConnections' | 'dataConnections', DataSourceConnection[]> => {
const openSearchConnections = dataSources
.filter((ds) => ds.type === DATA_SOURCE_SAVED_OBJECT_TYPE)
.map((ds: DataSource) => {
return {
Expand All @@ -305,22 +305,21 @@ export const convertDataSourcesToOpenSearchConnections = (
relatedConnections: [],
};
});

export const convertDataSourcesToDataConnections = (
dataSources: DataConnection[] | DataSource[]
): DataSourceConnection[] => {
const dataConnections = dataSources.filter(
(ds) => ds.type === DATA_CONNECTION_SAVED_OBJECT_TYPE
) as DataConnection[];
return dataConnections.map((ds) => {
return {
id: ds.id,
type: ds.connectionType,
connectionType: DataSourceConnectionType.DataConnection,
name: ds.title,
description: ds.description,
};
});
const dataConnections = dataSources
.filter((ds) => ds.type === DATA_CONNECTION_SAVED_OBJECT_TYPE)
.map((ds) => {
return {
id: ds.id,
type: (ds as DataConnection).connectionType,
connectionType: DataSourceConnectionType.DataConnection,
name: ds.title,
description: ds.description,
};
});
return {
openSearchConnections,
dataConnections,
};
};

export const fulfillRelatedConnections = (
Expand All @@ -343,13 +342,15 @@ export const mergeDataSourcesWithConnections = (
dataSources: DataSource[] | DataConnection[],
directQueryConnections: DataSourceConnection[]
): DataSourceConnection[] => {
const openSearchConnections = convertDataSourcesToOpenSearchConnections(dataSources);
const dataConnections = convertDataSourcesToDataConnections(dataSources);
const {
openSearchConnections,
dataConnections,
} = convertDataSourcesToOpenSearchAndDataConnections(dataSources);
const result = [
...fulfillRelatedConnections(openSearchConnections, directQueryConnections),
...directQueryConnections,
...dataConnections,
].sort((a, b) => a?.name?.localeCompare(b?.name));
].sort((a, b) => a.name.localeCompare(b.name));

return result;
};
Expand Down

0 comments on commit c87b2d8

Please sign in to comment.