From 9f46e2bf6cab5f1101990dfc061687be7d764eac Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 22 Oct 2024 13:36:09 +0000 Subject: [PATCH] fix: fixed unsupported language issue due to cached language in localStorage (#8674) * fix: fixed unsupported language issue due to cached language in localStorage The issue: If selecting `PPL` in discover, and navigate to visualization creating page which doesn't support `PPL`, the `PPL` is still be used. The fix: It will only use the cached language selection from localStorage if the current app supports the language. Signed-off-by: Yulong Ruan * Changeset file for PR #8674 created/updated --------- Signed-off-by: Yulong Ruan Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit e94cf0c434001f25dbe056268213b52585a3418d) Signed-off-by: github-actions[bot] --- changelogs/fragments/8674.yml | 2 ++ .../query_string/query_string_manager.ts | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/8674.yml diff --git a/changelogs/fragments/8674.yml b/changelogs/fragments/8674.yml new file mode 100644 index 00000000000..748d45a3dce --- /dev/null +++ b/changelogs/fragments/8674.yml @@ -0,0 +1,2 @@ +fix: +- Fixed unsupported language is used from localStorage ([#8674](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8674)) \ No newline at end of file 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 94d0eb31879..a45c78bb364 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 @@ -225,13 +225,27 @@ export class QueryStringManager { }; }; - private getDefaultLanguage() { - return ( - this.storage.get('userQueryLanguage') || - this.uiSettings.get(UI_SETTINGS.SEARCH_QUERY_LANGUAGE) + private isLanguageSupported(languageId: string) { + const currentAppId = this.getCurrentAppId(); + if (!currentAppId) { + return false; + } + + return containsWildcardOrValue( + this.languageService.getLanguage(languageId)?.supportedAppNames, + currentAppId ); } + private getDefaultLanguage() { + const lastUsedLanguage = this.storage.get('userQueryLanguage'); + if (lastUsedLanguage && this.isLanguageSupported(lastUsedLanguage)) { + return lastUsedLanguage; + } + + return this.uiSettings.get(UI_SETTINGS.SEARCH_QUERY_LANGUAGE); + } + private getCurrentAppId = () => { let appId; try {