Skip to content

Commit 21c1a35

Browse files
committed
UI changes
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
1 parent 6f28170 commit 21c1a35

File tree

14 files changed

+1475
-89
lines changed

14 files changed

+1475
-89
lines changed

.github/workflows/cypress_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,4 @@ jobs:
268268
269269
#### Link to results:
270270
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
271-
edit-mode: replace
271+
edit-mode: replace

changelogs/fragments/7309.yml

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

src/plugins/data/public/ui/query_editor/__snapshots__/language_selector.test.tsx.snap

Lines changed: 1097 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/data/public/ui/query_editor/_language_selector.scss

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
.languageSelector {
6-
min-width: 140px;
7-
border-bottom: $euiBorderThin !important;
5+
.osdQueryBar__languageSelector {
6+
font-size: small;
7+
}
8+
9+
.osdQueryBar__languageSelectorFooter {
10+
font-size: smaller;
11+
padding-left: 0;
12+
padding-top: 2px;
13+
color: $ouiTextSubduedColor;
814
}

src/plugins/data/public/ui/query_editor/_query_editor.scss

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,33 @@
1515
// overflow: auto;
1616
}
1717

18+
.osdQueryEditorFooterHide {
19+
display: none;
20+
}
21+
22+
.osdQueryEditorFooter {
23+
color: $ouiTextSubduedColor; // Apply the subdued color to all text in this class
24+
height: 35px;
25+
26+
* {
27+
color: inherit;
28+
font-size: medium;
29+
align-items: center;
30+
}
31+
32+
#languageSelector {
33+
height: 100%;
34+
}
35+
}
36+
1837
.osdQueryEditor__languageWrapper {
19-
:first-child {
20-
box-shadow: none !important;
38+
align-items: center;
39+
justify-content: center;
40+
height: 40px;
41+
border: $euiBorderThin;
42+
43+
#languageSelector {
2144
height: 100%;
22-
border-radius: 0;
2345
}
2446
}
2547

@@ -42,6 +64,7 @@
4264
.osdQueryEditor__dataSetWrapper {
4365
.dataExplorerDSSelect {
4466
border-bottom: $euiBorderThin !important;
67+
max-width: 375px;
4568

4669
div:is([class$="--group"]) {
4770
padding: 0 !important;

src/plugins/data/public/ui/query_editor/language_selector.test.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,7 @@ describe('LanguageSelector', () => {
5353
},
5454
})
5555
);
56-
const euiComboBox = component.find(EuiCompressedComboBox);
57-
expect(euiComboBox.prop('selectedOptions')).toEqual(
58-
expect.arrayContaining([
59-
{
60-
label: 'Lucene',
61-
},
62-
])
63-
);
56+
expect(component).toMatchSnapshot();
6457
});
6558

6659
it('should select DQL if language is kuery', () => {
@@ -72,13 +65,6 @@ describe('LanguageSelector', () => {
7265
},
7366
})
7467
);
75-
const euiComboBox = component.find(EuiCompressedComboBox);
76-
expect(euiComboBox.prop('selectedOptions')).toEqual(
77-
expect.arrayContaining([
78-
{
79-
label: 'DQL',
80-
},
81-
])
82-
);
68+
expect(component).toMatchSnapshot();
8369
});
8470
});

src/plugins/data/public/ui/query_editor/language_selector.tsx

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
*/
55

66
import {
7-
EuiCompressedComboBox,
8-
EuiComboBoxOptionOption,
97
PopoverAnchorPosition,
8+
EuiContextMenuPanel,
9+
EuiPopover,
10+
EuiButtonEmpty,
11+
EuiContextMenuItem,
1012
} from '@elastic/eui';
1113
import { i18n } from '@osd/i18n';
12-
import React from 'react';
14+
import React, { useState } from 'react';
1315
import { getUiService } from '../../services';
1416

15-
interface Props {
17+
export interface QueryLanguageSelectorProps {
1618
language: string;
1719
onSelectLanguage: (newLanguage: string) => void;
1820
anchorPosition?: PopoverAnchorPosition;
1921
appName?: string;
22+
isFooter?: boolean;
2023
}
2124

2225
const mapExternalLanguageToOptions = (language: string) => {
@@ -26,15 +29,21 @@ const mapExternalLanguageToOptions = (language: string) => {
2629
};
2730
};
2831

29-
export const QueryLanguageSelector = (props: Props) => {
32+
export const QueryLanguageSelector = (props: QueryLanguageSelectorProps) => {
33+
const [isPopoverOpen, setPopover] = useState(false);
34+
35+
const onButtonClick = () => {
36+
setPopover(!isPopoverOpen);
37+
};
38+
3039
const dqlLabel = i18n.translate('data.query.queryEditor.dqlLanguageName', {
3140
defaultMessage: 'DQL',
3241
});
3342
const luceneLabel = i18n.translate('data.query.queryEditor.luceneLanguageName', {
3443
defaultMessage: 'Lucene',
3544
});
3645

37-
const languageOptions: EuiComboBoxOptionOption[] = [
46+
const languageOptions = [
3847
{
3948
label: dqlLabel,
4049
value: 'kuery',
@@ -68,25 +77,52 @@ export const QueryLanguageSelector = (props: Props) => {
6877
)?.label as string) ?? languageOptions[0].label,
6978
};
7079

71-
const handleLanguageChange = (newLanguage: EuiComboBoxOptionOption[]) => {
72-
const queryLanguage = newLanguage[0].value as string;
73-
props.onSelectLanguage(queryLanguage);
74-
uiService.Settings.setUserQueryLanguage(queryLanguage);
80+
const handleLanguageChange = (newLanguage: string) => {
81+
props.onSelectLanguage(newLanguage);
82+
uiService.Settings.setUserQueryLanguage(newLanguage);
7583
};
7684

7785
uiService.Settings.setUserQueryLanguage(props.language);
7886

87+
const languageOptionsMenu = languageOptions.map((language) => {
88+
return (
89+
<EuiContextMenuItem
90+
key={language.label}
91+
icon={language.label === selectedLanguage.label ? 'check' : 'empty'}
92+
onClick={() => {
93+
setPopover(false);
94+
handleLanguageChange(language.value);
95+
}}
96+
>
97+
{language.label}
98+
</EuiContextMenuItem>
99+
);
100+
});
79101
return (
80-
<EuiCompressedComboBox
81-
fullWidth
82-
className="languageSelector"
83-
data-test-subj="languageSelector"
84-
options={languageOptions}
85-
selectedOptions={[selectedLanguage]}
86-
onChange={handleLanguageChange}
87-
singleSelection={{ asPlainText: true }}
88-
isClearable={false}
89-
async
90-
/>
102+
<EuiPopover
103+
id="languageSelector"
104+
button={
105+
<EuiButtonEmpty
106+
iconSide="right"
107+
onClick={onButtonClick}
108+
className={
109+
props.isFooter ? 'osdQueryBar__languageSelectorFooter' : 'osdQueryBar__languageSelector'
110+
}
111+
iconType={props.isFooter ? 'arrowDown' : undefined}
112+
>
113+
{selectedLanguage.label}
114+
</EuiButtonEmpty>
115+
}
116+
isOpen={isPopoverOpen}
117+
closePopover={() => setPopover(false)}
118+
panelPaddingSize="none"
119+
anchorPosition="downLeft"
120+
>
121+
<EuiContextMenuPanel size="s" items={languageOptionsMenu} />
122+
</EuiPopover>
91123
);
92124
};
125+
126+
// Needed for React.lazy
127+
// eslint-disable-next-line import/no-default-export
128+
export default QueryLanguageSelector;

0 commit comments

Comments
 (0)