Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <[email protected]>
  • Loading branch information
abbyhu2000 committed Sep 10, 2024
1 parent 1dafc7e commit 7392a6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
35 changes: 14 additions & 21 deletions src/plugins/data/public/ui/query_editor/language_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ import {
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) => {
Expand All @@ -39,8 +36,11 @@ export const QueryLanguageSelector = (props: QueryLanguageSelectorProps) => {
const queryString = getQueryService().queryString;
const languageService = queryString.getLanguageService();

const datasetSupportedLanguages = props.dataset
? queryString.getDatasetService().getType(props.dataset.type)?.supportedLanguages(props.dataset)
const datasetSupportedLanguages = props.query.dataset
? queryString
.getDatasetService()
.getType(props.query.dataset.type)
?.supportedLanguages(props.query.dataset)
: undefined;

useEffect(() => {
Expand All @@ -61,22 +61,15 @@ export const QueryLanguageSelector = (props: QueryLanguageSelectorProps) => {

const languageOptions: Array<{ label: string; value: string }> = [];

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;
languageOptions.unshift(mapExternalLanguageToOptions(language));
});
languageService.getLanguages().forEach((language) => {
if (
(language && props.appName && !language.editorSupportedAppNames?.includes(props.appName)) ||
languageService.getUserQueryLanguageBlocklist().includes(language?.id) ||
(datasetSupportedLanguages && !datasetSupportedLanguages.includes(language.id))
)
return;
languageOptions.unshift(mapExternalLanguageToOptions(language));
});

const selectedLanguage = {
label:
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ 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

0 comments on commit 7392a6f

Please sign in to comment.