Skip to content

Commit

Permalink
index pattern updates
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Aug 26, 2024
1 parent 182792d commit b6f55d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -60,11 +66,26 @@ export const indexPatternTypeConfig: DatasetTypeConfig = {
};

const fetchIndexPatterns = async (client: SavedObjectsClientContract): Promise<DataStructure[]> => {
const indexPatterns = await getIndexPatterns().getIdsWithTitle();

return indexPatterns.map((indexPattern) => ({
id: indexPattern.id,
title: indexPattern.title,
const resp = await client.find<IIndexPattern>({
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',
},
}
: {}),
}));
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b6f55d1

Please sign in to comment.