From 3f1f5cf30ead08a21d0aae982eef6159a2553b0d Mon Sep 17 00:00:00 2001 From: Suchit Sahoo Date: Fri, 30 Aug 2024 21:28:17 +0000 Subject: [PATCH] Fix Discover intial pageload for non DQL language Signed-off-by: Suchit Sahoo --- .../query_string/query_string_manager.ts | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/plugins/data/public/query/query_string/query_string_manager.ts b/src/plugins/data/public/query/query_string/query_string_manager.ts index 754b444435c0..30e8afe6098c 100644 --- a/src/plugins/data/public/query/query_string/query_string_manager.ts +++ b/src/plugins/data/public/query/query_string/query_string_manager.ts @@ -60,14 +60,32 @@ export class QueryStringManager { } public getDefaultQuery() { - return { - query: this.getDefaultQueryString(), - language: this.getDefaultLanguage(), - ...(this.uiSettings && - this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED) && { - dataset: this.datasetService?.getDefault(), - }), + const defaultLanguageId = this.getDefaultLanguage(); + const defaultQuery = this.getDefaultQueryString(); + const defaultDataset = this.datasetService?.getDefault(); + + const query = { + query: defaultQuery, + language: defaultLanguageId, + dataset: defaultDataset, }; + + if ( + this.uiSettings && + this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED) && + defaultDataset && + this.languageService + ) { + const language = this.languageService.getLanguage(defaultLanguageId); + const newQueryString = language?.getQueryString(query) || ''; + + return { + ...query, + query: newQueryString, + }; + } + + return query; } public formatQuery(query: Query | string | undefined): Query {