-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support injecting
DataStructureMeta
from QueryEditorExtensions
fo…
…r Query Assist (#7871) (#7888) * fix query editor extensions enhance key * add query assist icons to clusters if available * allow custom icon for `DATA_STRUCTURE_META_TYPES.FEATURE` * Changeset file for PR #7871 created/updated --------- (cherry picked from commit 9bc2433) Signed-off-by: Joshua Li <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: Ashwin P Chandran <[email protected]>
- Loading branch information
1 parent
8c779c1
commit a9e7068
Showing
10 changed files
with
129 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- Support injecting `DataStructureMeta` from `QueryEditorExtensions` for Query Assist ([#7871](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7871)) |
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
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
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
/* | ||
* 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 | ||
* 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[], | ||
selectDataSourceId: (dataStructure: DataStructure) => string | undefined = ( | ||
dataStructure: DataStructure | ||
) => dataStructure.id | ||
) => { | ||
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?.(selectDataSourceId(dataStructure)) | ||
) | ||
).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 | ||
); | ||
if (meta || dataStructure.meta) { | ||
dataStructure.meta = { ...meta, ...dataStructure.meta } as DataStructureMeta; | ||
} | ||
return 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
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
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