-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add query assist icons to clusters if available
Signed-off-by: Joshua Li <[email protected]>
- Loading branch information
1 parent
91c47c8
commit 03dcec7
Showing
5 changed files
with
99 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/plugins/data/public/query/query_string/dataset_service/lib/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DataStructure, DataStructureMeta } from '../../../../../common'; | ||
import { getQueryService } from '../../../../services'; | ||
|
||
/** | ||
* Inject {@link DataStructureMeta} to DataStructures based on | ||
* {@link QueryEditorExtensions}. | ||
* | ||
* This function combines the meta fields from QueryEditorExtensions and in | ||
* provided data structures. Lower extension order is higher priority, and | ||
* existing meta fields have highest priority. | ||
* | ||
* @param dataStructures - {@link DataStructure} | ||
* @returns data structures with meta | ||
*/ | ||
export const injectMetaToDataStructures = async (dataStructures: DataStructure[]) => { | ||
const queryEditorExtensions = Object.values( | ||
getQueryService().queryString.getLanguageService().getQueryEditorExtensionMap() | ||
); | ||
queryEditorExtensions.sort((a, b) => b.order - a.order); | ||
|
||
return Promise.all( | ||
dataStructures.map(async (dataStructure) => { | ||
const metaArray = await Promise.allSettled( | ||
queryEditorExtensions.map((curr) => curr.getDataStructureMeta?.(dataStructure.id)) | ||
).then((settledResults) => | ||
settledResults | ||
.filter( | ||
<T>(result: PromiseSettledResult<T>): result is PromiseFulfilledResult<T> => | ||
result.status === 'fulfilled' | ||
) | ||
.map((result) => result.value) | ||
); | ||
const meta = metaArray.reduce( | ||
(acc, curr) => (acc || curr ? ({ ...acc, ...curr } as DataStructureMeta) : undefined), | ||
undefined | ||
); | ||
return { meta, ...dataStructure }; | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters