From b6f55d15a85d682774917735a5a79150d400c437 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Mon, 26 Aug 2024 06:31:41 +0000 Subject: [PATCH] index pattern updates Signed-off-by: Kawika Avilla --- .../dataset_service/lib/index_pattern_type.ts | 33 +++++++++++++++---- .../utils/use_index_pattern.ts | 2 +- 2 files changed, 28 insertions(+), 7 deletions(-) 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 5fc81fe95e8f..098f954214f4 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 @@ -4,7 +4,13 @@ */ import { SavedObjectsClientContract } from 'opensearch-dashboards/public'; -import { DEFAULT_DATA, DataStructure, DatasetField, Dataset } from '../../../../../common'; +import { + DEFAULT_DATA, + DataStructure, + DatasetField, + Dataset, + IIndexPattern, +} from '../../../../../common'; import { DatasetTypeConfig } from '../types'; import { getIndexPatterns } from '../../../../services'; @@ -60,11 +66,26 @@ export const indexPatternTypeConfig: DatasetTypeConfig = { }; const fetchIndexPatterns = async (client: SavedObjectsClientContract): Promise => { - const indexPatterns = await getIndexPatterns().getIdsWithTitle(); - - return indexPatterns.map((indexPattern) => ({ - id: indexPattern.id, - title: indexPattern.title, + const resp = await client.find({ + type: 'index-pattern', + fields: ['title', 'timeFieldName', 'references'], + search: `*`, + searchFields: ['title'], + perPage: 100, + }); + return resp.savedObjects.map((savedObject) => ({ + id: savedObject.id, + title: savedObject.attributes.title, + timeFieldName: savedObject.attributes.timeFieldName, type: DEFAULT_DATA.SET_TYPES.INDEX_PATTERN, + ...(savedObject.references[0] + ? { + dataSource: { + id: savedObject.references[0]?.id, + name: savedObject.references[0]?.name, + type: 'data-source', + }, + } + : {}), })); }; diff --git a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts index 56dcf72e3ba2..2f8bd6fbebf6 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts @@ -46,7 +46,7 @@ export const useIndexPattern = (services: DiscoverViewServices) => { const handleIndexPattern = async () => { if (isQueryEnhancementEnabled && query?.dataset) { - const pattern = await data.indexPatterns.get(query.dataset.id, true); + const pattern = await data.indexPatterns.get(query.dataset.id); if (isMounted && pattern) { setIndexPattern(pattern);