forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (opensearch-project#7871) * fix query editor extensions enhance key Signed-off-by: Joshua Li <joshuali925@gmail.com> * add query assist icons to clusters if available Signed-off-by: Joshua Li <joshuali925@gmail.com> * allow custom icon for `DATA_STRUCTURE_META_TYPES.FEATURE` Signed-off-by: Joshua Li <joshuali925@gmail.com> * Changeset file for PR opensearch-project#7871 created/updated --------- Signed-off-by: Joshua Li <joshuali925@gmail.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: Ashwin P Chandran <ashwinpc@amazon.com>
- Loading branch information
1 parent
5e0ce2b
commit 9bc2433
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