Skip to content

Commit

Permalink
add modal for DQL
Browse files Browse the repository at this point in the history
Signed-off-by: Eric <[email protected]>
  • Loading branch information
mengweieric committed Feb 6, 2024
1 parent 7cf0519 commit 899e63c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 20 deletions.
93 changes: 78 additions & 15 deletions public/components/common/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ import {
EuiIcon,
EuiPopover,
EuiPopoverFooter,
EuiSuperSelect,
EuiSuperSelectOption,
EuiText,
EuiToolTip,
EuiContextMenuItem,
EuiModal,
EuiModalHeader,
EuiModalBody,
EuiModalHeaderTitle,
EuiModalFooter,
} from '@elastic/eui';
import { isEqual } from 'lodash';
import React, { useEffect, useState } from 'react';
Expand Down Expand Up @@ -144,6 +148,9 @@ export const Search = (props: any) => {
const sqlService = new SQLService(coreRefs.http);
const { application } = coreRefs;
const [nlqInput, setNlqInput] = useState('');
const [isModalVisible, setIsModalVisible] = useState(false);
const closeModal = () => setIsModalVisible(false);
const showModal = () => setIsModalVisible(true);

const showQueryArea = !appLogEvents && coreRefs.queryAssistEnabled;

Expand Down Expand Up @@ -207,7 +214,7 @@ export const Search = (props: any) => {

const handleQueryLanguageChange = (lang: string) => {
if (lang === QUERY_LANGUAGE.DQL) {
application!.navigateToUrl('../app/data-explorer/discover');
showModal();
return;
}
dispatch(
Expand All @@ -224,9 +231,19 @@ export const Search = (props: any) => {
setLanguagePopoverOpen(false);
};

const languageOptions: Array<EuiSuperSelectOption<QUERY_LANGUAGE>> = [
{ value: QUERY_LANGUAGE.PPL, inputDisplay: <EuiText>PPL</EuiText> },
{ value: QUERY_LANGUAGE.DQL, inputDisplay: <EuiText>DQL</EuiText> },
const languagePopOverItems = [
<EuiContextMenuItem
key={QUERY_LANGUAGE.SQL}
onClick={() => handleQueryLanguageChange(QUERY_LANGUAGE.PPL)}
>
PPL
</EuiContextMenuItem>,
<EuiContextMenuItem
key={QUERY_LANGUAGE.PPL}
onClick={() => handleQueryLanguageChange(QUERY_LANGUAGE.DQL)}
>
DQL - Opens in Discover
</EuiContextMenuItem>,
];

const onQuerySearch = () => {
Expand Down Expand Up @@ -294,6 +311,50 @@ export const Search = (props: any) => {
: undefined;
const loading = indicesLoading || indexPatternsLoading;

const onLanguagePopoverClick = () => {
setLanguagePopoverOpen(!_isLanguagePopoverOpen);
};

const languagePopOverButton = (
<EuiButton iconType="arrowDown" iconSide="right" onClick={onLanguagePopoverClick} color="text">
{queryLang}
</EuiButton>
);

const redirectToDiscover = () => {
application!.navigateToUrl('../app/data-explorer/discover');
};

let redirectionModal = null;
if (isModalVisible) {
redirectionModal = (
<EuiModal onClose={closeModal}>
<EuiModalHeader>
<EuiModalHeaderTitle>
<h1>Open in Discover</h1>
</EuiModalHeaderTitle>
</EuiModalHeader>
<EuiModalBody>
<EuiText>
The OpenSearch Dashboards Query Language (DQL) offers a simplified query syntax and
support for scripted fields. Selecting this option will open the Discover application.
</EuiText>
</EuiModalBody>
<EuiModalFooter>
<EuiButtonEmpty onClick={closeModal}>Cancel</EuiButtonEmpty>
<EuiButton
onClick={() => {
redirectToDiscover();
}}
fill
>
Open in Discover
</EuiButton>
</EuiModalFooter>
</EuiModal>
);
}

return (
<div className="globalQueryBar">
<EuiFlexGroup direction="column" gutterSize="s">
Expand All @@ -311,14 +372,16 @@ export const Search = (props: any) => {
{!appLogEvents && (
<>
<EuiFlexItem key="lang-selector" className="search-area lang-selector" grow={false}>
<EuiSuperSelect
options={languageOptions}
valueOfSelected={queryLang}
onChange={(lang: QUERY_LANGUAGE) => {
handleQueryLanguageChange(lang);
setQueryLang(lang);
}}
/>
<EuiPopover
id="smallContextMenuExample"
button={languagePopOverButton}
isOpen={_isLanguagePopoverOpen}
closePopover={closeLanguagePopover}
panelPaddingSize="none"
anchorPosition="downLeft"
>
<EuiContextMenuPanel size="m" items={languagePopOverItems} />
</EuiPopover>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiIcon
Expand All @@ -329,7 +392,6 @@ export const Search = (props: any) => {
size="l"
onClick={() => showFlyout()}
color="#159D8D"
// onClickAriaLabel={'pplLinkShowFlyout'}
/>
</EuiFlexItem>
{coreRefs.queryAssistEnabled && (
Expand Down Expand Up @@ -539,6 +601,7 @@ export const Search = (props: any) => {
</>
)}
</EuiFlexGroup>
{redirectionModal}
{flyout}
</div>
);
Expand Down
5 changes: 0 additions & 5 deletions public/components/common/search/sql_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export const DirectSearch = (props: any) => {
const [isLanguagePopoverOpen, setLanguagePopoverOpen] = useState(false);
const [queryLang, setQueryLang] = useState(explorerSearchMetadata.lang || QUERY_LANGUAGE.SQL);
const sqlService = new SQLService(coreRefs.http);
const { application } = coreRefs;

const {
data: pollingResult,
Expand Down Expand Up @@ -140,10 +139,6 @@ export const DirectSearch = (props: any) => {
);

const handleQueryLanguageChange = (lang: QUERY_LANGUAGE) => {
if (lang === 'DQL') {
application!.navigateToUrl('../app/data-explorer/discover');
return;
}
dispatch(updateSearchMetaData({ tabId, data: { lang } }));
setQueryLang(lang);
closeLanguagePopover();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
SELECTED_TIMESTAMP,
} from '../../../../../common/constants/explorer';

const DATA_SOURCE_SELECTOR_CONFIGS = { customGroupTitleExtension: '' };

const getDataSourceState = (selectedSourceState: SelectedDataSource[]) => {
if (selectedSourceState.length === 0) return [];
return [
Expand Down Expand Up @@ -255,6 +257,7 @@ export const DataSourceSelection = ({ tabId }: { tabId: string }) => {
onDataSourceSelect={handleSourceChange}
onFetchDataSetError={handleDataSetFetchError}
singleSelection={{ asPlainText: true }}
dataSourceSelectorConfigs={DATA_SOURCE_SELECTOR_CONFIGS}
/>
);
};

0 comments on commit 899e63c

Please sign in to comment.