Skip to content

Commit

Permalink
rebase and address comments
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <[email protected]>
  • Loading branch information
abbyhu2000 committed Jan 3, 2024
1 parent d8d2e5c commit 5bf8243
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: removed the following CSS
// when https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5628 is completed
.languageSwitcher {
max-width: 150px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ export function QueryLanguageSwitcher(props: Props) {
{
label: 'PPL',
},
{
label: 'SQL',
},
];
const [selectedLanguage, setSelectedLanguage] = useState([dataExplorerOptions[0]]);

const osdDQLDocs = useOpenSearchDashboards().services.docLinks?.links.opensearchDashboards.dql
.base;
Expand Down Expand Up @@ -109,20 +111,26 @@ export function QueryLanguageSwitcher(props: Props) {
);

const handleLanguageChange = (newLanguage: EuiComboBoxOptionOption[]) => {
if (['PPL', 'SQL'].includes(newLanguage[0].label)) {
application?.navigateToUrl('../observability-logs#/explorer');
return;
}
const queryLanguage = newLanguage[0].label === 'DQL' ? 'kuery' : newLanguage[0].label;
props.onSelectLanguage(queryLanguage);
setSelectedLanguage(newLanguage);
};

// The following is a temporary solution for adding PPL navigation, and should be replaced once final solution is determined.
// Follow-up issue: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5628
if (useObservable(currentApp$!, '') === 'data-explorer' && useNewQuerySelector) {
const selectedLanguage = {
label: props.language === 'kuery' ? 'DQL' : props.language,
};
return (
<EuiComboBox
className="languageSwitcher"
data-test-subj="languageSelect"
options={dataExplorerOptions}
selectedOptions={selectedLanguage}
selectedOptions={[selectedLanguage]}
onChange={handleLanguageChange}
singleSelection={{ asPlainText: true }}
isClearable={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ interface State {
selectionEnd: number | null;
indexPatterns: IIndexPattern[];
queryBarRect: DOMRect | undefined;
currentApp: string | undefined;
}

const KEY_CODES = {
Expand All @@ -120,7 +119,6 @@ export default class QueryStringInputUI extends Component<Props, State> {
selectionEnd: null,
indexPatterns: [],
queryBarRect: undefined,
currentApp: undefined,
};

public inputRef: HTMLTextAreaElement | null = null;
Expand Down Expand Up @@ -459,10 +457,6 @@ export default class QueryStringInputUI extends Component<Props, State> {
};

private onSelectLanguage = (language: string) => {
if (language === 'PPL') {
this.services.application?.navigateToUrl('../observability-logs#/explorer');
return;
}
// Send telemetry info every time the user opts in or out of kuery
// As a result it is important this function only ever gets called in the
// UI component's change handler.
Expand Down

0 comments on commit 5bf8243

Please sign in to comment.