diff --git a/src/plugins/data/common/datasets/types.ts b/src/plugins/data/common/datasets/types.ts index 69549a631ab9..c98d277b7c77 100644 --- a/src/plugins/data/common/datasets/types.ts +++ b/src/plugins/data/common/datasets/types.ts @@ -139,7 +139,7 @@ export enum DATA_STRUCTURE_META_TYPES { */ export interface DataStructureFeatureMeta { type: DATA_STRUCTURE_META_TYPES.FEATURE; - icon?: string; + icon?: EuiIconProps; tooltip?: string; } @@ -157,6 +157,8 @@ export interface DataStructureDataTypeMeta { */ export interface DataStructureCustomMeta { type: DATA_STRUCTURE_META_TYPES.CUSTOM; + icon?: EuiIconProps; + tooltip?: string; [key: string]: any; } diff --git a/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts b/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts index f346d1cb5ff7..e549a5abdf3d 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts @@ -124,5 +124,5 @@ const fetchIndexPatterns = async (client: SavedObjectsClientContract): Promise dataStructure.parent?.id); }; diff --git a/src/plugins/data/public/query/query_string/dataset_service/lib/utils.ts b/src/plugins/data/public/query/query_string/dataset_service/lib/utils.ts index 867b00befaec..aada2c2421cf 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/lib/utils.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/lib/utils.ts @@ -10,14 +10,20 @@ import { getQueryService } from '../../../../services'; * Inject {@link DataStructureMeta} to DataStructures based on * {@link QueryEditorExtensions}. * - * This function combines the meta fields from QueryEditorExtensions and in + * This function combines the meta fields from QueryEditorExtensions and * provided data structures. Lower extension order is higher priority, and * existing meta fields have highest priority. * * @param dataStructures - {@link DataStructure} + * @param selectDataSourceId - function to get data source id given a data structure * @returns data structures with meta */ -export const injectMetaToDataStructures = async (dataStructures: DataStructure[]) => { +export const injectMetaToDataStructures = async ( + dataStructures: DataStructure[], + selectDataSourceId: (dataStructure: DataStructure) => string | undefined = ( + dataStructure: DataStructure + ) => dataStructure.id +) => { const queryEditorExtensions = Object.values( getQueryService().queryString.getLanguageService().getQueryEditorExtensionMap() ); @@ -26,7 +32,9 @@ export const injectMetaToDataStructures = async (dataStructures: DataStructure[] return Promise.all( dataStructures.map(async (dataStructure) => { const metaArray = await Promise.allSettled( - queryEditorExtensions.map((curr) => curr.getDataStructureMeta?.(dataStructure.id)) + queryEditorExtensions.map((curr) => + curr.getDataStructureMeta?.(selectDataSourceId(dataStructure)) + ) ).then((settledResults) => settledResults .filter( @@ -39,7 +47,10 @@ export const injectMetaToDataStructures = async (dataStructures: DataStructure[] (acc, curr) => (acc || curr ? ({ ...acc, ...curr } as DataStructureMeta) : undefined), undefined ); - return { meta, ...dataStructure }; + if (meta || dataStructure.meta) { + dataStructure.meta = { ...meta, ...dataStructure.meta } as DataStructureMeta; + } + return dataStructure; }) ); }; diff --git a/src/plugins/data/public/ui/dataset_selector/advanced_selector.tsx b/src/plugins/data/public/ui/dataset_selector/advanced_selector.tsx index a319c9a376bd..8afaedbb492e 100644 --- a/src/plugins/data/public/ui/dataset_selector/advanced_selector.tsx +++ b/src/plugins/data/public/ui/dataset_selector/advanced_selector.tsx @@ -37,11 +37,11 @@ export const AdvancedSelector = ({ .getTypes() .map((type) => { return { - id: type!.id, - title: type!.title, - type: type!.id, + id: type.id, + title: type.title, + type: type.id, meta: { - ...type!.meta, + ...type.meta, type: DATA_STRUCTURE_META_TYPES.TYPE, }, } as DataStructure; diff --git a/src/plugins/data/public/ui/dataset_selector/dataset_explorer.tsx b/src/plugins/data/public/ui/dataset_selector/dataset_explorer.tsx index dd35ce8065b2..48a0dcac84b2 100644 --- a/src/plugins/data/public/ui/dataset_selector/dataset_explorer.tsx +++ b/src/plugins/data/public/ui/dataset_selector/dataset_explorer.tsx @@ -190,26 +190,24 @@ const LoadingEmptyColumn = ({ isLoading }: { isLoading: boolean }) => ); const appendIcon = (item: DataStructure) => { - if (item.meta?.type === DATA_STRUCTURE_META_TYPES.FEATURE) { + if (item.meta?.type === DATA_STRUCTURE_META_TYPES.TYPE) { + return ( + + + + ); + } else { if (item.meta?.icon && item.meta?.tooltip) { return ( - + ); } else if (item.meta?.icon) { - return ; + return ; } } - if (item.meta?.type === DATA_STRUCTURE_META_TYPES.TYPE) { - return ( - - - - ); - } - return null; }; diff --git a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx index ec8a219655c2..bebe250a91ce 100644 --- a/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx +++ b/src/plugins/query_enhancements/public/query_assist/utils/create_extension.tsx @@ -68,7 +68,7 @@ export const createQueryAssistExtension = ( ); if (isEnabled) { return { - type: DATA_STRUCTURE_META_TYPES.TYPE, + type: DATA_STRUCTURE_META_TYPES.FEATURE, icon: { type: assistantMark }, tooltip: 'Query assist is available', };