-
Notifications
You must be signed in to change notification settings - Fork 919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unsupported languages for dataset #8100
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fix: | ||
- Remove unsupported languages for dataset ([#8100](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8100)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,15 @@ | |
import { getQueryService } from '../../services'; | ||
import { LanguageConfig } from '../../query'; | ||
import { Query } from '../..'; | ||
import { Dataset } from '../../../common'; | ||
import { darkCssDistFilename } from '../../../../../../packages/osd-ui-shared-deps/index'; | ||
|
||
export interface QueryLanguageSelectorProps { | ||
query: Query; | ||
onSelectLanguage: (newLanguage: string) => void; | ||
anchorPosition?: PopoverAnchorPosition; | ||
appName?: string; | ||
dataset?: Dataset; | ||
} | ||
|
||
const mapExternalLanguageToOptions = (language: LanguageConfig) => { | ||
|
@@ -36,6 +39,10 @@ | |
const queryString = getQueryService().queryString; | ||
const languageService = queryString.getLanguageService(); | ||
|
||
const datasetSupportedLanguages = props.dataset | ||
? queryString.getDatasetService().getType(props.dataset.type)?.supportedLanguages(props.dataset) | ||
: undefined; | ||
|
||
useEffect(() => { | ||
const subscription = queryString.getUpdates$().subscribe((query: Query) => { | ||
if (query.language !== currentLanguage) { | ||
|
@@ -54,14 +61,22 @@ | |
|
||
const languageOptions: Array<{ label: string; value: string }> = []; | ||
|
||
languageService.getLanguages().forEach((language) => { | ||
if ( | ||
(language && props.appName && !language.editorSupportedAppNames?.includes(props.appName)) || | ||
languageService.getUserQueryLanguageBlocklist().includes(language?.id) | ||
) | ||
return; | ||
languageOptions.unshift(mapExternalLanguageToOptions(language!)); | ||
}); | ||
languageService | ||
.getLanguages() | ||
.filter((language) => { | ||
if (datasetSupportedLanguages) { | ||
return datasetSupportedLanguages.includes(language.id); | ||
} | ||
return true; | ||
}) | ||
.forEach((language) => { | ||
if ( | ||
(language && props.appName && !language.editorSupportedAppNames?.includes(props.appName)) || | ||
languageService.getUserQueryLanguageBlocklist().includes(language?.id) | ||
) | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. combined forEach and filter |
||
languageOptions.unshift(mapExternalLanguageToOptions(language)); | ||
}); | ||
|
||
const selectedLanguage = { | ||
label: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesnt the query object already contain the dataset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, removed extra prop