Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Discover] Display inner properties in the left navigation bar [#5429](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5429)
- [Chrome] Introduce registerCollapsibleNavHeader to allow plugins to customize the rendering of nav menu header ([#5244](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5244))
- [Custom Branding] Relative URL should be allowed for logos ([#5572](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5572))
- [Data Explorer] Adding PPL to query language selector ([#5623](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5623))

### 🐛 Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import "./query_bar";
@import "./language_switcher"
Original file line number Diff line number Diff line change
@@ -0,0 +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 @@ -41,6 +41,7 @@ describe('LanguageSwitcher', () => {
const services = {
uiSettings: startMock.uiSettings,
docLinks: startMock.docLinks,
application: startMock.application,
};

return (
Expand Down
181 changes: 121 additions & 60 deletions src/plugins/data/public/ui/query_string_input/language_switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import {
EuiButtonEmpty,
EuiComboBox,
EuiComboBoxOptionOption,
EuiForm,
EuiFormRow,
EuiLink,
Expand All @@ -42,7 +44,9 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@osd/i18n/react';
import React, { useState } from 'react';
import { useObservable } from 'react-use';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { IDataPluginServices } from '../../types';

interface Props {
language: string;
Expand All @@ -51,6 +55,34 @@ interface Props {
}

export function QueryLanguageSwitcher(props: Props) {
const opensearchDashboards = useOpenSearchDashboards<IDataPluginServices>();
const { application } = opensearchDashboards.services;
const currentApp$ = application?.currentAppId$;
let useNewQuerySelector;
application?.applications$.subscribe((applications) => {
applications.forEach((applicationEntry) => {
if (applicationEntry.id === 'observability-dashboards') {
useNewQuerySelector = true;
return;
}
});
});

const dataExplorerOptions = [
{
label: 'DQL',
},
{
label: 'lucene',
},
{
label: 'PPL',
},
{
label: 'SQL',
},
];

const osdDQLDocs = useOpenSearchDashboards().services.docLinks?.links.opensearchDashboards.dql
.base;
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
Expand Down Expand Up @@ -78,66 +110,95 @@ export function QueryLanguageSwitcher(props: Props) {
</EuiButtonEmpty>
);

return (
<EuiPopover
id="queryLanguageSwitcherPopover"
anchorClassName="euiFormControlLayout__append"
ownFocus
anchorPosition={props.anchorPosition || 'downRight'}
button={button}
isOpen={isPopoverOpen}
closePopover={() => setIsPopoverOpen(false)}
repositionOnScroll
>
<EuiPopoverTitle>
<FormattedMessage
id="data.query.queryBar.syntaxOptionsTitle"
defaultMessage="Syntax options"
/>
</EuiPopoverTitle>
<div style={{ width: '350px' }}>
<EuiText>
<p>
<FormattedMessage
id="data.query.queryBar.syntaxOptionsDescription"
defaultMessage="The {docsLink} (DQL) offers a simplified query
syntax and support for scripted fields. If you turn off DQL,
OpenSearch Dashboards uses Lucene."
values={{
docsLink: (
<EuiLink href={osdDQLDocs} target="_blank">
{dqlFullName}
</EuiLink>
),
}}
/>
</p>
</EuiText>
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);
};

<EuiSpacer size="m" />
// 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]}
onChange={handleLanguageChange}
singleSelection={{ asPlainText: true }}
isClearable={false}
async
/>
);
} else {
return (
<EuiPopover
id="queryLanguageSwitcherPopover"
anchorClassName="euiFormControlLayout__append"
ownFocus
anchorPosition={props.anchorPosition || 'downRight'}
button={button}
isOpen={isPopoverOpen}
closePopover={() => setIsPopoverOpen(false)}
repositionOnScroll
>
<EuiPopoverTitle>
<FormattedMessage
id="data.query.queryBar.syntaxOptionsTitle"
defaultMessage="Syntax options"
/>
</EuiPopoverTitle>
<div style={{ width: '350px' }}>
<EuiText>
<p>
<FormattedMessage
id="data.query.queryBar.syntaxOptionsDescription"
defaultMessage="The {docsLink} (DQL) offers a simplified query
syntax and support for scripted fields. If you turn off DQL,
OpenSearch Dashboards uses Lucene."
values={{
docsLink: (
<EuiLink href={osdDQLDocs} target="_blank">
{dqlFullName}
</EuiLink>
),
}}
/>
</p>
</EuiText>

<EuiForm>
<EuiFormRow label={dqlFullName}>
<EuiSwitch
id="queryEnhancementOptIn"
name="popswitch"
label={
props.language === 'kuery' ? (
<FormattedMessage id="data.query.queryBar.dqlOnLabel" defaultMessage="On" />
) : (
<FormattedMessage id="data.query.queryBar.dqlOffLabel" defaultMessage="Off" />
)
}
checked={props.language === 'kuery'}
onChange={() => {
const newLanguage = props.language === 'lucene' ? 'kuery' : 'lucene';
props.onSelectLanguage(newLanguage);
}}
data-test-subj="languageToggle"
/>
</EuiFormRow>
</EuiForm>
</div>
</EuiPopover>
);
<EuiSpacer size="m" />

<EuiForm>
<EuiFormRow label={dqlFullName}>
<EuiSwitch
id="queryEnhancementOptIn"
name="popswitch"
label={
props.language === 'kuery' ? (
<FormattedMessage id="data.query.queryBar.dqlOnLabel" defaultMessage="On" />
) : (
<FormattedMessage id="data.query.queryBar.dqlOffLabel" defaultMessage="Off" />
)
}
checked={props.language === 'kuery'}
onChange={() => {
const newLanguage = props.language === 'lucene' ? 'kuery' : 'lucene';
props.onSelectLanguage(newLanguage);
}}
data-test-subj="languageToggle"
/>
</EuiFormRow>
</EuiForm>
</div>
</EuiPopover>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ export default class QueryStringInputUI extends Component<Props, State> {
if (this.persistedLog) {
this.persistedLog.add(query.query);
}

this.props.onSubmit({ query: fromUser(query.query), language: query.language });
}
};
Expand Down