Skip to content

Commit 9005834

Browse files
committed
renaming
Signed-off-by: Eric <menwe@amazon.com>
1 parent 46d0b35 commit 9005834

File tree

5 files changed

+37
-34
lines changed

5 files changed

+37
-34
lines changed

src/plugins/data/public/data_sources/datasource/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
export { DataSource } from './datasource';
77
export {
88
IDataSourceMetadata,
9-
DataSourceDataSet,
9+
DataSetWithDataSource,
1010
IDataSetParams,
1111
IDataSourceQueryParams,
1212
IDataSourceQueryResult,

src/plugins/data/public/data_sources/datasource/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface IDataSourceGroup {
1818
name: string;
1919
}
2020

21-
export interface DataSourceDataSet<T = []> {
21+
export interface DataSetWithDataSource<T = []> {
2222
ds: DataSource;
2323
list: T;
2424
}
@@ -59,7 +59,7 @@ export interface IDataSourceUISelector {
5959
export interface IDataSourceUISettings {
6060
selector: IDataSourceUISelector;
6161
label: string; // the display name of data source
62-
typeGroup: string; // the group to which the data source belongs
62+
groupType: string; // the group to which the data source belongs
6363
typeLabel: string; // the display name of data source type
6464
displayOrder?: number; // the order in which the data source should be displayed in selector
6565
description?: string; // short description of your database

src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import React, { useEffect, useCallback, useMemo } from 'react';
77
import { EuiButtonIcon, EuiComboBox, EuiText, EuiToolTip } from '@elastic/eui';
88
import { i18n } from '@osd/i18n';
9-
import { DataSource, DataSourceDataSet, IndexPatternOption } from '../datasource';
10-
import { DataSourceGroup, DataSourceSelectableProps } from './types';
9+
import { DataSource, DataSetWithDataSource, IndexPatternOption } from '../datasource';
10+
import { DataSourceGroup, DataSourceOption, DataSourceSelectableProps } from './types';
1111

12-
// Get Index patterns for local cluster.
12+
// Asynchronously retrieves and formats dataset from a given data source.
1313
const getAndFormatDataSetFromDataSource = async (
1414
ds: DataSource
15-
): Promise<DataSourceDataSet<IndexPatternOption[]>> => {
15+
): Promise<DataSetWithDataSource<IndexPatternOption[]>> => {
1616
const { dataSets } = await ds.getDataSet();
17-
return { ds, list: dataSets } as DataSourceDataSet<IndexPatternOption[]>;
17+
return { ds, list: dataSets } as DataSetWithDataSource<IndexPatternOption[]>;
1818
};
1919

2020
// Map through all data sources and get their respective data sets.
@@ -28,11 +28,11 @@ export const isIndexPatterns = (dataSet: unknown) =>
2828
!!(dataSet as any).title &&
2929
!!(dataSet as any).id;
3030

31-
// Mapping function for datasets to get the option format for the combo box from the dataSource and dataSet.
31+
// Mapping function to get the option format for the combo box from the dataSource and dataSet.
3232
const mapToOption = (
3333
dataSource: DataSource,
34-
dataSet: DataSourceDataSet | undefined = undefined
35-
) => {
34+
dataSet: DataSetWithDataSource | undefined = undefined
35+
): DataSourceOption => {
3636
const baseOption = {
3737
type: dataSource.getType(),
3838
name: dataSource.getName(),
@@ -41,9 +41,9 @@ const mapToOption = (
4141
if (dataSet && 'title' in dataSet && 'id' in dataSet && isIndexPatterns(dataSet)) {
4242
return {
4343
...baseOption,
44-
label: dataSet.title,
45-
value: dataSet.id,
46-
key: dataSet.id,
44+
label: dataSet.title as string,
45+
value: dataSet.id as string,
46+
key: dataSet.id as string,
4747
};
4848
}
4949
return {
@@ -55,9 +55,13 @@ const mapToOption = (
5555
};
5656

5757
// Function to add or update groups in a reduction process
58-
const addOrUpdateGroup = (acc: DataSourceGroup[], dataSource: DataSource, option) => {
58+
const addOrUpdateGroup = (
59+
existingGroups: DataSourceGroup[],
60+
dataSource: DataSource,
61+
option: DataSourceOption
62+
) => {
5963
const metadata = dataSource.getMetadata();
60-
const groupType = metadata.ui.typeGroup;
64+
const groupType = metadata.ui.groupType;
6165
let groupName =
6266
metadata.ui.typeLabel ||
6367
i18n.translate('dataExplorer.dataSourceSelector.defaultGroupTitle', {
@@ -70,34 +74,34 @@ const addOrUpdateGroup = (acc: DataSourceGroup[], dataSource: DataSource, option
7074
});
7175
}
7276

73-
const group = acc.find((g: DataSourceGroup) => g.typeGroup === groupType);
74-
if (group) {
75-
if (!group.options.some((opt) => opt.key === option.key)) {
76-
group.options.push(option);
77-
}
77+
const group = existingGroups.find((g: DataSourceGroup) => g.id === groupType);
78+
if (group && !group.options.some((opt) => opt.key === option.key)) {
79+
group.options.push(option);
7880
} else {
79-
acc.push({
80-
typeGroup: groupType,
81+
existingGroups.push({
82+
groupType,
8183
label: groupName,
8284
options: [option],
83-
id: metadata.ui.typeGroup, // id for each group
85+
id: metadata.ui.groupType, // id for each group
8486
});
8587
}
86-
return acc;
8788
};
8889

89-
const consolidateDataSourceGroups = (dataSets: DataSourceDataSet[], dataSources: DataSource[]) => {
90-
return [...dataSets, ...dataSources].reduce((acc, item) => {
90+
const consolidateDataSourceGroups = (
91+
dataSets: DataSetWithDataSource[],
92+
dataSources: DataSource[]
93+
) => {
94+
return [...dataSets, ...dataSources].reduce((dsGroup, item) => {
9195
if ('list' in item && item.ds) {
9296
// Confirm item is a DataSet
9397
const options = item.list.map((dataset) => mapToOption(item.ds, dataset));
94-
options.forEach((option) => addOrUpdateGroup(acc, item.ds, option));
98+
options.forEach((option) => addOrUpdateGroup(dsGroup, item.ds, option));
9599
} else {
96100
// Handle DataSource directly
97101
const option = mapToOption(item as InstanceType<typeof DataSource>);
98-
addOrUpdateGroup(acc, item as InstanceType<typeof DataSource>, option);
102+
addOrUpdateGroup(dsGroup, item as InstanceType<typeof DataSource>, option);
99103
}
100-
return acc;
104+
return dsGroup;
101105
}, []);
102106
};
103107

@@ -125,7 +129,7 @@ export const DataSourceSelectable = ({
125129
.then((dataSetResults) => {
126130
setDataSourceOptionList(
127131
consolidateDataSourceGroups(
128-
dataSetResults as DataSourceDataSet[],
132+
dataSetResults as DataSetWithDataSource[],
129133
dataSources.filter((ds) => !ds.getMetadata().ui.selector.displayDatasetsAsSource)
130134
)
131135
);

src/plugins/data/public/data_sources/datasource_selector/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ export interface DataSourceGroup {
1414
label: string;
1515
id: string;
1616
options: DataSourceOption[];
17-
typeGroup: string;
17+
groupType: string;
1818
}
1919

2020
export interface DataSourceOption {
2121
key: string;
22-
id: string;
2322
name: string;
2423
label: string;
2524
value: string;

src/plugins/data/public/data_sources/register_default_datasource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const registerDefaultDataSource = (data: Omit<DataPublicPluginStart, 'ui'
2424
ui: {
2525
label: 'Index patterns', // display name of your data source,
2626
typeLabel: 'Index patterns', // display name of your data source type,
27-
typeGroup: 'DEFAULT_INDEX_PATTERNS',
27+
groupType: 'DEFAULT_INDEX_PATTERNS',
2828
selector: {
2929
displayDatasetsAsSource: true, // when true, selector UI will render data sets with source by calling getDataSets()
3030
},

0 commit comments

Comments
 (0)