Skip to content

Commit

Permalink
fix: fixed unsupported language issue due to cached language in local…
Browse files Browse the repository at this point in the history
…Storage (#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 <[email protected]>

* Changeset file for PR #8674 created/updated

---------

Signed-off-by: Yulong Ruan <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
ruanyl and opensearch-changeset-bot[bot] authored Oct 22, 2024
1 parent 5d74306 commit e94cf0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8674.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fixed unsupported language is used from localStorage ([#8674](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8674))
22 changes: 18 additions & 4 deletions src/plugins/data/public/query/query_string/query_string_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e94cf0c

Please sign in to comment.