Skip to content

Commit

Permalink
UI changes
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Jul 19, 2024
1 parent 6f28170 commit 6e6ff41
Show file tree
Hide file tree
Showing 14 changed files with 1,475 additions and 88 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,4 @@ jobs:
#### Link to results:
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
edit-mode: replace

2 changes: 2 additions & 0 deletions changelogs/fragments/7309.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Update query enhancement UI ([#7309](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7309))

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/plugins/data/public/ui/query_editor/_language_selector.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
.languageSelector {
min-width: 140px;
border-bottom: $euiBorderThin !important;
.osdQueryBar__languageSelector {
font-size: small;
}

.osdQueryBar__languageSelectorFooter {
font-size: smaller;
padding-left: 0;
padding-top: 2px;
color: $ouiTextSubduedColor;
}
29 changes: 26 additions & 3 deletions src/plugins/data/public/ui/query_editor/_query_editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,33 @@
// overflow: auto;
}

.osdQueryEditorFooterHide {
display: none;
}

.osdQueryEditorFooter {
color: $ouiTextSubduedColor; // Apply the subdued color to all text in this class
height: 35px;

* {
color: inherit;
font-size: medium;
align-items: center;
}

#languageSelector {
height: 100%;
}
}

.osdQueryEditor__languageWrapper {
:first-child {
box-shadow: none !important;
align-items: center;
justify-content: center;
height: 40px;
border: $euiBorderThin;

#languageSelector {
height: 100%;
border-radius: 0;
}
}

Expand All @@ -42,6 +64,7 @@
.osdQueryEditor__dataSetWrapper {
.dataExplorerDSSelect {
border-bottom: $euiBorderThin !important;
max-width: 375px;

div:is([class$="--group"]) {
padding: 0 !important;
Expand Down
18 changes: 2 additions & 16 deletions src/plugins/data/public/ui/query_editor/language_selector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ describe('LanguageSelector', () => {
},
})
);
const euiComboBox = component.find(EuiCompressedComboBox);
expect(euiComboBox.prop('selectedOptions')).toEqual(
expect.arrayContaining([
{
label: 'Lucene',
},
])
);
expect(component).toMatchSnapshot();
});

it('should select DQL if language is kuery', () => {
Expand All @@ -72,13 +65,6 @@ describe('LanguageSelector', () => {
},
})
);
const euiComboBox = component.find(EuiCompressedComboBox);
expect(euiComboBox.prop('selectedOptions')).toEqual(
expect.arrayContaining([
{
label: 'DQL',
},
])
);
expect(component).toMatchSnapshot();
});
});
78 changes: 57 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 @@ -4,19 +4,22 @@
*/

import {
EuiCompressedComboBox,
EuiComboBoxOptionOption,
PopoverAnchorPosition,
EuiContextMenuPanel,
EuiPopover,
EuiButtonEmpty,
EuiContextMenuItem,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import React from 'react';
import React, { useState } from 'react';
import { getUiService } from '../../services';

interface Props {
export interface QueryLanguageSelectorProps {
language: string;
onSelectLanguage: (newLanguage: string) => void;
anchorPosition?: PopoverAnchorPosition;
appName?: string;
isFooter?: boolean;
}

const mapExternalLanguageToOptions = (language: string) => {
Expand All @@ -26,15 +29,21 @@ const mapExternalLanguageToOptions = (language: string) => {
};
};

export const QueryLanguageSelector = (props: Props) => {
export const QueryLanguageSelector = (props: QueryLanguageSelectorProps) => {
const [isPopoverOpen, setPopover] = useState(false);

const onButtonClick = () => {
setPopover(!isPopoverOpen);
};

const dqlLabel = i18n.translate('data.query.queryEditor.dqlLanguageName', {
defaultMessage: 'DQL',
});
const luceneLabel = i18n.translate('data.query.queryEditor.luceneLanguageName', {
defaultMessage: 'Lucene',
});

const languageOptions: EuiComboBoxOptionOption[] = [
const languageOptions = [
{
label: dqlLabel,
value: 'kuery',
Expand Down Expand Up @@ -68,25 +77,52 @@ export const QueryLanguageSelector = (props: Props) => {
)?.label as string) ?? languageOptions[0].label,
};

const handleLanguageChange = (newLanguage: EuiComboBoxOptionOption[]) => {
const queryLanguage = newLanguage[0].value as string;
props.onSelectLanguage(queryLanguage);
uiService.Settings.setUserQueryLanguage(queryLanguage);
const handleLanguageChange = (newLanguage: string) => {
props.onSelectLanguage(newLanguage);
uiService.Settings.setUserQueryLanguage(newLanguage);
};

uiService.Settings.setUserQueryLanguage(props.language);

const languageOptionsMenu = languageOptions.map((language) => {
return (
<EuiContextMenuItem
key={language.label}
icon={language.label === selectedLanguage.label ? 'check' : 'empty'}
onClick={() => {
setPopover(false);
handleLanguageChange(language.value);
}}
>
{language.label}
</EuiContextMenuItem>
);
});
return (
<EuiCompressedComboBox
fullWidth
className="languageSelector"
data-test-subj="languageSelector"
options={languageOptions}
selectedOptions={[selectedLanguage]}
onChange={handleLanguageChange}
singleSelection={{ asPlainText: true }}
isClearable={false}
async
/>
<EuiPopover
id="languageSelector"
button={
<EuiButtonEmpty
iconSide="right"
onClick={onButtonClick}
className={
props.isFooter ? 'osdQueryBar__languageSelectorFooter' : 'osdQueryBar__languageSelector'
}
iconType={props.isFooter ? 'arrowDown' : undefined}
>
{selectedLanguage.label}
</EuiButtonEmpty>
}
isOpen={isPopoverOpen}
closePopover={() => setPopover(false)}
panelPaddingSize="none"
anchorPosition="downLeft"
>
<EuiContextMenuPanel size="s" items={languageOptionsMenu} />
</EuiPopover>
);
};

// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default QueryLanguageSelector;
Loading

0 comments on commit 6e6ff41

Please sign in to comment.