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) (#8678)

* 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.



* Changeset file for PR #8674 created/updated

---------



(cherry picked from commit e94cf0c)

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
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>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent 6c33d0d commit 426a167
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 426a167

Please sign in to comment.