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

New query bar #30

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
55 changes: 55 additions & 0 deletions src/plugins/data/public/ui/query_editor/collapsed_query_bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import React, { RefObject, createRef, useState } from 'react';
import { i18n } from '@osd/i18n';

import { EuiFieldText, EuiOutsideClickDetector, EuiPortal, Query } from '@elastic/eui';
import { SuggestionsComponent } from '../typeahead';

export interface CollapsedQueryBarInputProps {
initialValue: string;
onChange?: (query: string) => void;
}

export const CollapsedQueryBarInput: React.FC<CollapsedQueryBarInputProps> = (props) => {
const [isSuggestionsVisible, setIsSuggestionsVisible] = useState(false);
const [suggestionIndex, setSuggestionIndex] = useState<number | null>(null);
const [value, setValue] = useState(props.initialValue ?? '');

return (
<EuiOutsideClickDetector onOutsideClick={() => setIsSuggestionsVisible(false)}>
<div>
<EuiFieldText
data-test-subj="collapsed-query-bar-input-field-text"
value={value}
onClick={() => setIsSuggestionsVisible(true)}
onChange={(e) => setValue(e.target.value)}
onKeyDown={() => setIsSuggestionsVisible(true)}
placeholder={''}
fullWidth
/>
<EuiPortal>
<SuggestionsComponent
show={isSuggestionsVisible}
suggestions={[]}
index={suggestionIndex}
onClick={(suggestion) => {
return;
}}
onMouseEnter={(i) => setSuggestionIndex(i)}
loadMore={() => {}}
size="s"
/>
</EuiPortal>
</div>
</EuiOutsideClickDetector>
);
};
68 changes: 50 additions & 18 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import { fetchIndexPatterns } from './fetch_index_patterns';
import { QueryLanguageSelector } from './language_selector';
import { QueryEditorExtensions } from './query_editor_extensions';
import { QueryEditorBtnCollapse } from './query_editor_btn_collapse';
import { CollapsedQueryBarInput } from './collapsed_query_bar';

export interface QueryEditorProps {
indexPatterns: Array<IIndexPattern | string>;
Expand Down Expand Up @@ -47,6 +49,8 @@
queryLanguage?: string;
headerClassName?: string;
bannerClassName?: string;
isCollapsed: boolean;
onToggleCollapsed: () => void;
}

interface Props extends QueryEditorProps {
Expand Down Expand Up @@ -289,12 +293,29 @@
const headerClassName = classNames('osdQueryEditorHeader', this.props.headerClassName);
const bannerClassName = classNames('osdQueryEditorBanner', this.props.bannerClassName);

const useQueryEditor =
this.props.query.language === 'SQLAsync' ||
Copy link

Choose a reason for hiding this comment

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

this.props.query.language === 'SQL' ||
this.props.query.language === 'PPL';

console.log('this.state.isDataSourcesVisible', this.state.isDataSourcesVisible);

Check failure on line 301 in src/plugins/data/public/ui/query_editor/query_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement
console.log('this.state.isDataSetsVisible', this.state.isDataSetsVisible);

Check failure on line 302 in src/plugins/data/public/ui/query_editor/query_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement

console.log('this.props.dataSourceContainerRef', this.props.dataSourceContainerRef);

Check failure on line 304 in src/plugins/data/public/ui/query_editor/query_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement
console.log('this.props.containerRef', this.props.containerRef);

Check failure on line 305 in src/plugins/data/public/ui/query_editor/query_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement

return (
<div className={className}>
<div ref={this.bannerRef} className={bannerClassName} />
<EuiFlexGroup gutterSize="xs" direction="column">
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="xs" alignItems="center" className={`${className}__wrapper`}>
<EuiFlexItem grow={false}>
<QueryEditorBtnCollapse
onClick={this.props.onToggleCollapsed}
isCollapsed={this.props.isCollapsed}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>{this.props.prepend}</EuiFlexItem>
{this.state.isDataSourcesVisible && (
<EuiFlexItem grow={false} className={`${className}__dataSourceWrapper`}>
Expand All @@ -314,28 +335,39 @@
<div ref={this.props.containerRef} />
</EuiFlexItem>
)}
{(!this.props.isCollapsed || !useQueryEditor) && (
<EuiFlexItem>
<CollapsedQueryBarInput
initialValue={this.getQueryString()}
onChange={this.onInputChange}
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>

<EuiFlexItem onClick={this.onClickInput} grow={true}>
<div ref={this.headerRef} className={headerClassName} />
<CodeEditor
height={70}
languageId="opensearchql"
value={this.getQueryString()}
onChange={this.onInputChange}
options={{
lineNumbers: 'on',
lineHeight: 24,
fontSize: 14,
fontFamily: 'Roboto Mono',
minimap: {
enabled: false,
},
scrollBeyondLastLine: false,
wordWrap: 'on',
wrappingIndent: 'indent',
}}
/>
{this.props.isCollapsed && useQueryEditor && (
<CodeEditor
height={70}
languageId="opensearchql"
value={this.getQueryString()}
onChange={this.onInputChange}
options={{
lineNumbers: 'on',
lineHeight: 24,
fontSize: 14,
fontFamily: 'Roboto Mono',
minimap: {
enabled: false,
},
scrollBeyondLastLine: false,
wordWrap: 'on',
wrappingIndent: 'indent',
}}
/>
)}
</EuiFlexItem>
</EuiFlexGroup>
{this.renderQueryEditorExtensions()}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import React from 'react';
import { i18n } from '@osd/i18n';
import { EuiToolTip, EuiButtonIcon } from '@elastic/eui';

export interface Props {
onClick: () => void;
isCollapsed: boolean;
}

export function QueryEditorBtnCollapse({ onClick, isCollapsed }: Props) {
const label = i18n.translate('queryEditor.collapse', {
defaultMessage: 'Toggle query editor',
});
return (
<EuiToolTip content={label}>
<EuiButtonIcon
aria-expanded={!isCollapsed}
aria-label={label}
data-test-subj="queryEditorCollapseBtn"
onClick={() => onClick()}
iconType={!isCollapsed ? 'arrowRight' : 'arrowDown'}
iconSize={'s'}
/>
</EuiToolTip>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
return () => subscription.unsubscribe();
}, [props.dependencies, props.config]);

console.log('isEnabled', isEnabled);

Check failure on line 102 in src/plugins/data/public/ui/query_editor/query_editor_extensions/query_editor_extension.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement
console.log('props.config', props.config);

Check failure on line 103 in src/plugins/data/public/ui/query_editor/query_editor_extensions/query_editor_extension.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement
console.log('banner', props.bannerContainer, banner);

Check failure on line 104 in src/plugins/data/public/ui/query_editor/query_editor_extensions/query_editor_extension.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement
console.log('component', props.componentContainer, component);

Check failure on line 105 in src/plugins/data/public/ui/query_editor/query_editor_extensions/query_editor_extension.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement
if (!isEnabled) return null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
return Object.values(configMap).sort((a, b) => a.order - b.order);
}, [configMap]);

console.log('sortedConfigs', sortedConfigs);

Check failure on line 27 in src/plugins/data/public/ui/query_editor/query_editor_extensions/query_editor_extensions.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux (ciGroup1)

Unexpected console statement

return (
<>
{sortedConfigs.map((config) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface QueryEditorTopRowProps {
export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
const [isDateRangeInvalid, setIsDateRangeInvalid] = useState(false);
const [isQueryEditorFocused, setIsQueryEditorFocused] = useState(false);
const [isQueryEditorCollapsed, setIsQueryEditorCollapsed] = useState(false);

const opensearchDashboards = useOpenSearchDashboards<IDataPluginServices>();
const { uiSettings, storage, appName } = opensearchDashboards.services;
Expand Down Expand Up @@ -247,6 +248,8 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
className="osdQueryEditor"
dataTestSubj={props.dataTestSubj}
queryLanguage={queryLanguage}
isCollapsed={isQueryEditorCollapsed}
onToggleCollapsed={() => setIsQueryEditorCollapsed(!isQueryEditorCollapsed)}
/>
</EuiFlexItem>
);
Expand Down Expand Up @@ -377,10 +380,15 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
>
{renderQueryEditor()}
<EuiFlexItem>
<EuiFlexGroup responsive={false} gutterSize="none">
<EuiFlexItem grow={false}>{props.filterBar}</EuiFlexItem>
<EuiFlexItem>{renderSharingMetaFields()}</EuiFlexItem>
<EuiFlexItem grow={false}>{renderUpdateButton()}</EuiFlexItem>
<EuiFlexGroup responsive={false} gutterSize="none" direction="column">
{isQueryEditorCollapsed && <EuiFlexItem grow={false}>{props.filterBar}</EuiFlexItem>}

<EuiFlexItem grow={false}>
<EuiFlexGroup>
<EuiFlexItem>{renderSharingMetaFields()}</EuiFlexItem>
<EuiFlexItem grow={false}>{renderUpdateButton()}</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Loading