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>
(cherry picked from commit e94cf0c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 6c33d0d commit 9f46e2b
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();

Check warning on line 229 in src/plugins/data/public/query/query_string/query_string_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_string_manager.ts#L229

Added line #L229 was not covered by tests
if (!currentAppId) {
return false;

Check warning on line 231 in src/plugins/data/public/query/query_string/query_string_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_string_manager.ts#L231

Added line #L231 was not covered by tests
}

return containsWildcardOrValue(

Check warning on line 234 in src/plugins/data/public/query/query_string/query_string_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_string_manager.ts#L234

Added line #L234 was not covered by tests
this.languageService.getLanguage(languageId)?.supportedAppNames,
currentAppId
);
}

private getDefaultLanguage() {
const lastUsedLanguage = this.storage.get('userQueryLanguage');
if (lastUsedLanguage && this.isLanguageSupported(lastUsedLanguage)) {
return lastUsedLanguage;

Check warning on line 243 in src/plugins/data/public/query/query_string/query_string_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/query_string_manager.ts#L243

Added line #L243 was not covered by tests
}

return this.uiSettings.get(UI_SETTINGS.SEARCH_QUERY_LANGUAGE);
}

private getCurrentAppId = () => {
let appId;
try {
Expand Down

0 comments on commit 9f46e2b

Please sign in to comment.