Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8100.yml
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))
31 changes: 23 additions & 8 deletions src/plugins/data/public/ui/query_editor/language_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, removed extra prop

}

const mapExternalLanguageToOptions = (language: LanguageConfig) => {
Expand All @@ -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) {
Expand All @@ -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);

Check warning on line 68 in src/plugins/data/public/ui/query_editor/language_selector.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/query_editor/language_selector.tsx#L68

Added line #L68 was not covered by tests
}
return true;
})
.forEach((language) => {
if (
(language && props.appName && !language.editorSupportedAppNames?.includes(props.appName)) ||
languageService.getUserQueryLanguageBlocklist().includes(language?.id)
)
return;

Check warning on line 77 in src/plugins/data/public/ui/query_editor/language_selector.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/ui/query_editor/language_selector.tsx#L77

Added line #L77 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be in filter(), since it's basically just filtering it again but in the forEach() loop? Then, we can pass the mapExternalLanguageOptions() function into a .map() instead of a for loop. Not a blocking comment, just something that might make it a bit easier more readable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combined forEach and filter

languageOptions.unshift(mapExternalLanguageToOptions(language));
});

const selectedLanguage = {
label:
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export default class QueryEditorUI extends Component<Props, State> {
anchorPosition={this.props.languageSwitcherPopoverAnchorPosition}
onSelectLanguage={this.onSelectLanguage}
appName={this.services.appName}
dataset={this.props.query.dataset}
/>
);

Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { QueryStatus } from '../query';
import { IndexPatternSelectProps } from './index_pattern_select';
import { StatefulSearchBarProps } from './search_bar';
import { SuggestionsComponentProps } from './typeahead/suggestions_component';
Expand Down
Loading