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

[ES|QL] Edits query in the dashboard #169911

Merged
merged 64 commits into from Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
ace30ca
[ES|QL] Edits query in the dashboard
stratoula Oct 2, 2023
d9fcad7
Merge branch 'main' into esql-edit-query
stratoula Oct 2, 2023
4cd63b5
Merge branch 'main' into esql-edit-query
stratoula Oct 3, 2023
c17b3ae
Update embeddable on query change
stratoula Oct 3, 2023
d8d55f4
Fix jest test
stratoula Oct 3, 2023
dd1a25e
Add suggestions panel
stratoula Oct 3, 2023
930b5cc
Merge branch 'main' into esql-edit-query
stratoula Oct 4, 2023
f66bd28
Fix css styling for suggestions
stratoula Oct 4, 2023
ba61858
Merge branch 'main' into esql-edit-query
stratoula Oct 5, 2023
ccbc1f9
Fix datectTimestamp
stratoula Oct 6, 2023
20b8a34
Merge branch 'main' into esql-edit-query
stratoula Oct 9, 2023
e3be4b8
Render errors and more fixed
stratoula Oct 9, 2023
7f76223
Fixes bug with adhoc dataviews
stratoula Oct 9, 2023
2dacfa2
Reports the query correctly on the Discover histogram
stratoula Oct 10, 2023
d5cbf6b
Making life easier
stratoula Oct 11, 2023
1303d49
Fix jest test
stratoula Oct 11, 2023
d28c88c
Merge branch 'main' into esql-edit-query
stratoula Oct 11, 2023
07f3623
Fix editor's responsiveness
stratoula Oct 11, 2023
6f80179
Merge branch 'main' into esql-edit-query
stratoula Oct 12, 2023
43dff03
Fixes problem when Lens doesn't have a suggestion to render
stratoula Oct 13, 2023
c225c24
Merge branch 'main' into esql-edit-query
stratoula Oct 13, 2023
c539720
Merge branch 'main' into esql-edit-query
stratoula Oct 16, 2023
7abc547
Merge branch 'main' into esql-edit-query
stratoula Oct 17, 2023
208fdc8
Fix drop
stratoula Oct 17, 2023
6500f70
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Oct 17, 2023
70520f2
Resizable button
stratoula Oct 17, 2023
6de94c5
Merge with main and resolve conflicts
stratoula Oct 18, 2023
c4cb206
Adds a callout
stratoula Oct 18, 2023
223cfe1
Merge branch 'main' into esql-edit-query
stratoula Oct 19, 2023
0dba296
Fix
stratoula Oct 19, 2023
5bdc856
Unit tests for thye editor
stratoula Oct 19, 2023
b67a2a1
Inline editing flyout tests
stratoula Oct 19, 2023
5ff6e41
Fix check
stratoula Oct 19, 2023
410fc23
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Oct 19, 2023
591645a
Merge branch 'main' into esql-edit-query
stratoula Oct 23, 2023
c7fb320
Adds unit tests in datasource
stratoula Oct 23, 2023
a85b67c
Adds more tests
stratoula Oct 23, 2023
649288e
Merge branch 'main' into esql-edit-query
stratoula Oct 23, 2023
2498098
Add FTs
stratoula Oct 24, 2023
86d4d37
Merge branch 'main' into esql-edit-query
stratoula Oct 24, 2023
e531cb1
[ES|QL] Design changes for the inline editing flyout
stratoula Oct 26, 2023
1442b67
Fix scrolling
stratoula Oct 27, 2023
556d000
Fix FT
stratoula Oct 27, 2023
eae933b
Scrollable suggestions
stratoula Oct 27, 2023
bde5f51
Add warnings note
stratoula Oct 27, 2023
e9604a0
Improve error message
stratoula Oct 27, 2023
f840111
Last changes
stratoula Oct 27, 2023
6eba6de
Merge branch 'main' into edit-query-design-changes
kibanamachine Oct 27, 2023
8135f07
Merge branch 'main' into edit-query-design-changes
stratoula Nov 1, 2023
7fb6a83
Merge with main, resolve conflicts and write unit tests
stratoula Nov 5, 2023
8f3bbfc
Merge with main and resolve conflicts
stratoula Nov 12, 2023
25b28b6
Improves the variable name
stratoula Nov 14, 2023
afa6282
Merge branch 'main' into edit-query-design-changes
stratoula Nov 14, 2023
2dcc0a2
Merge branch 'main' into edit-query-design-changes
stratoula Nov 15, 2023
466c911
Fix
stratoula Nov 15, 2023
d94f1a4
Address PR comment for histogram
stratoula Nov 16, 2023
7f15c78
Address flyout design comments
stratoula Nov 16, 2023
f98811c
Fix checks
stratoula Nov 16, 2023
25e9fcf
ESQL editor design comments
stratoula Nov 16, 2023
2d09bd1
Accordion desiugn changes
stratoula Nov 16, 2023
1525d7b
Suggestions comments
stratoula Nov 16, 2023
63f1f3c
Merge branch 'main' into edit-query-design-changes
stratoula Nov 23, 2023
e229aa3
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 23, 2023
6c8f8d7
Address PR comments
stratoula Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
114 changes: 87 additions & 27 deletions packages/kbn-text-based-editor/src/editor_footer.tsx
Expand Up @@ -19,6 +19,8 @@ import {
EuiPopoverTitle,
EuiDescriptionList,
EuiDescriptionListDescription,
EuiButton,
useEuiTheme,
} from '@elastic/eui';
import { Interpolation, Theme, css } from '@emotion/react';
import { css as classNameCss } from '@emotion/css';
Expand Down Expand Up @@ -60,12 +62,14 @@ export function ErrorsWarningsPopover({
type,
setIsPopoverOpen,
onErrorClick,
isSpaceReduced,
}: {
isPopoverOpen: boolean;
items: MonacoError[];
type: 'error' | 'warning';
setIsPopoverOpen: (flag: boolean) => void;
onErrorClick: (error: MonacoError) => void;
isSpaceReduced?: boolean;
}) {
const strings = getConstsByType(type, items.length);
return (
Expand All @@ -90,7 +94,7 @@ export function ErrorsWarningsPopover({
setIsPopoverOpen(!isPopoverOpen);
}}
>
<p>{strings.message}</p>
<p>{isSpaceReduced ? items.length : strings.message}</p>
</EuiText>
}
ownFocus={false}
Expand Down Expand Up @@ -151,8 +155,11 @@ interface EditorFooterProps {
warning?: MonacoError[];
detectTimestamp: boolean;
onErrorClick: (error: MonacoError) => void;
refreshErrors: () => void;
runQuery: () => void;
hideRunQueryText?: boolean;
disableSubmitAction?: boolean;
editorIsInline?: boolean;
isSpaceReduced?: boolean;
}

export const EditorFooter = memo(function EditorFooter({
Expand All @@ -162,10 +169,15 @@ export const EditorFooter = memo(function EditorFooter({
warning,
detectTimestamp,
onErrorClick,
refreshErrors,
runQuery,
hideRunQueryText,
disableSubmitAction,
editorIsInline,
isSpaceReduced,
}: EditorFooterProps) {
const { euiTheme } = useEuiTheme();
const [isPopoverOpen, setIsPopoverOpen] = useState(false);

return (
<EuiFlexGroup
gutterSize="s"
Expand All @@ -176,24 +188,6 @@ export const EditorFooter = memo(function EditorFooter({
>
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="s" responsive={false} alignItems="center">
{errors && errors.length > 0 && (
<ErrorsWarningsPopover
isPopoverOpen={isPopoverOpen}
items={errors}
type="error"
setIsPopoverOpen={setIsPopoverOpen}
onErrorClick={onErrorClick}
/>
)}
{warning && warning.length > 0 && (
<ErrorsWarningsPopover
isPopoverOpen={isPopoverOpen}
items={warning}
type="warning"
setIsPopoverOpen={setIsPopoverOpen}
onErrorClick={onErrorClick}
/>
)}
<EuiFlexItem grow={false} style={{ marginRight: '8px' }}>
<EuiText size="xs" color="subdued" data-test-subj="TextBasedLangEditor-footer-lines">
<p>
Expand All @@ -206,30 +200,49 @@ export const EditorFooter = memo(function EditorFooter({
</EuiFlexItem>
<EuiFlexItem grow={false} style={{ marginRight: '16px' }}>
<EuiFlexGroup gutterSize="xs" responsive={false} alignItems="center">
<EuiFlexItem grow={false}>
<EuiIcon type="calendar" color="subdued" size="s" />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="xs" color="subdued" data-test-subj="TextBasedLangEditor-date-info">
<p>
{detectTimestamp
{isSpaceReduced
? '@timestamp'
: detectTimestamp
? i18n.translate(
'textBasedEditor.query.textBasedLanguagesEditor.timestampDetected',
{
defaultMessage: '@timestamp detected',
defaultMessage: '@timestamp found',
}
)
: i18n.translate(
'textBasedEditor.query.textBasedLanguagesEditor.timestampNotDetected',
{
defaultMessage: '@timestamp not detected',
defaultMessage: '@timestamp not found',
}
)}
</p>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
{errors && errors.length > 0 && (
<ErrorsWarningsPopover
isPopoverOpen={isPopoverOpen}
items={errors}
type="error"
setIsPopoverOpen={setIsPopoverOpen}
onErrorClick={onErrorClick}
isSpaceReduced={isSpaceReduced}
/>
)}
{warning && warning.length > 0 && (
<ErrorsWarningsPopover
isPopoverOpen={isPopoverOpen}
items={warning}
type="warning"
setIsPopoverOpen={setIsPopoverOpen}
onErrorClick={onErrorClick}
isSpaceReduced={isSpaceReduced}
/>
)}
</EuiFlexGroup>
</EuiFlexItem>
{!hideRunQueryText && (
Expand All @@ -255,6 +268,53 @@ export const EditorFooter = memo(function EditorFooter({
</EuiFlexGroup>
</EuiFlexItem>
)}
{Boolean(editorIsInline) && (
<EuiFlexItem grow={false}>
<EuiButton
color="text"
size="s"
fill
onClick={runQuery}
isDisabled={Boolean(disableSubmitAction)}
data-test-subj="TextBasedLangEditor-run-query-button"
minWidth={isSpaceReduced ? false : undefined}
>
<EuiFlexGroup
gutterSize="xs"
responsive={false}
alignItems="center"
justifyContent="spaceBetween"
>
<EuiFlexItem grow={false}>
{isSpaceReduced
? i18n.translate('textBasedEditor.query.textBasedLanguagesEditor.run', {
defaultMessage: 'Run',
})
: i18n.translate('textBasedEditor.query.textBasedLanguagesEditor.runQuery', {
defaultMessage: 'Run query',
})}
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText
size="xs"
css={css`
border: 1px solid
${Boolean(disableSubmitAction)
? euiTheme.colors.disabled
: euiTheme.colors.emptyShade};
padding: 0 ${euiTheme.size.xs};
font-size: ${euiTheme.size.s};
margin-left: ${euiTheme.size.xs};
border-radius: ${euiTheme.size.xs};
`}
>
{COMMAND_KEY}⏎
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiButton>
</EuiFlexItem>
)}
</EuiFlexGroup>
);
});
4 changes: 3 additions & 1 deletion packages/kbn-text-based-editor/src/resizable_button.tsx
Expand Up @@ -13,11 +13,13 @@ import { css } from '@emotion/react';
export function ResizableButton({
onMouseDownResizeHandler,
onKeyDownResizeHandler,
editorIsInline,
}: {
onMouseDownResizeHandler: (
mouseDownEvent: React.MouseEvent<HTMLButtonElement, MouseEvent> | React.TouchEvent
) => void;
onKeyDownResizeHandler: (keyDownEvernt: React.KeyboardEvent) => void;
editorIsInline?: boolean;
}) {
return (
<EuiResizableButton
Expand All @@ -26,7 +28,7 @@ export function ResizableButton({
onKeyDown={onKeyDownResizeHandler}
onTouchStart={onMouseDownResizeHandler}
css={css`
position: absolute;
position: ${editorIsInline ? 'relative' : 'absolute'};
bottom: 0;
left: 0;
right: 0;
Expand Down
Expand Up @@ -20,7 +20,8 @@ export const textBasedLanguagedEditorStyles = (
hasErrors: boolean,
hasWarning: boolean,
isCodeEditorExpandedFocused: boolean,
hasReference: boolean
hasReference: boolean,
editorIsInline: boolean
) => {
let position = isCompactFocused ? ('absolute' as 'absolute') : ('relative' as 'relative'); // cast string to type 'relative' | 'absolute'
if (isCodeEditorExpanded) {
Expand All @@ -33,6 +34,8 @@ export const textBasedLanguagedEditorStyles = (
zIndex: isCompactFocused ? 4 : 0,
height: `${editorHeight}px`,
border: isCompactFocused ? euiTheme.border.thin : 'none',
borderLeft: editorIsInline || !isCompactFocused ? 'none' : euiTheme.border.thin,
borderRight: editorIsInline || !isCompactFocused ? 'none' : euiTheme.border.thin,
borderTopLeftRadius: isCodeEditorExpanded ? 0 : '6px',
borderBottom: isCodeEditorExpanded
? 'none'
Expand Down Expand Up @@ -66,6 +69,8 @@ export const textBasedLanguagedEditorStyles = (
},
bottomContainer: {
border: euiTheme.border.thin,
borderLeft: editorIsInline ? 'none' : euiTheme.border.thin,
borderRight: editorIsInline ? 'none' : euiTheme.border.thin,
borderTop:
isCodeEditorExpanded && !isCodeEditorExpandedFocused
? hasErrors
Expand All @@ -75,29 +80,29 @@ export const textBasedLanguagedEditorStyles = (
backgroundColor: euiTheme.colors.lightestShade,
paddingLeft: euiTheme.size.base,
paddingRight: euiTheme.size.base,
paddingTop: euiTheme.size.xs,
paddingBottom: euiTheme.size.xs,
paddingTop: editorIsInline ? '7px' : euiTheme.size.xs,
paddingBottom: editorIsInline ? '7px' : euiTheme.size.xs,
stratoula marked this conversation as resolved.
Show resolved Hide resolved
width: 'calc(100% + 2px)',
position: 'relative' as 'relative', // cast string to type 'relative',
marginTop: 0,
marginLeft: 0,
marginBottom: 0,
borderBottomLeftRadius: '6px',
borderBottomRightRadius: '6px',
borderBottomLeftRadius: editorIsInline ? 0 : '6px',
borderBottomRightRadius: editorIsInline ? 0 : '6px',
stratoula marked this conversation as resolved.
Show resolved Hide resolved
},
topContainer: {
border: euiTheme.border.thin,
borderTopLeftRadius: '6px',
borderTopRightRadius: '6px',
border: editorIsInline ? 'none' : euiTheme.border.thin,
borderTopLeftRadius: editorIsInline ? 0 : '6px',
borderTopRightRadius: editorIsInline ? 0 : '6px',
stratoula marked this conversation as resolved.
Show resolved Hide resolved
backgroundColor: euiTheme.colors.lightestShade,
paddingLeft: euiTheme.size.base,
paddingRight: euiTheme.size.base,
paddingTop: euiTheme.size.xs,
paddingBottom: euiTheme.size.xs,
paddingTop: editorIsInline ? euiTheme.size.s : euiTheme.size.xs,
paddingBottom: editorIsInline ? euiTheme.size.s : euiTheme.size.xs,
width: 'calc(100% + 2px)',
position: 'relative' as 'relative', // cast string to type 'relative',
marginLeft: 0,
marginTop: euiTheme.size.s,
marginTop: editorIsInline ? 0 : euiTheme.size.s,
},
dragResizeContainer: {
width: '100%',
Expand Down
Expand Up @@ -84,7 +84,7 @@ describe('TextBasedLanguagesEditor', () => {
});
});

it('should render the date info with no @timestamp detected', async () => {
it('should render the date info with no @timestamp found', async () => {
const newProps = {
...props,
isCodeEditorExpanded: true,
Expand All @@ -93,11 +93,11 @@ describe('TextBasedLanguagesEditor', () => {
const component = mount(renderTextBasedLanguagesEditorComponent({ ...newProps }));
expect(
component.find('[data-test-subj="TextBasedLangEditor-date-info"]').at(0).text()
).toStrictEqual('@timestamp not detected');
).toStrictEqual('@timestamp not found');
});
});

it('should render the date info with @timestamp detected if detectTimestamp is true', async () => {
it('should render the date info with @timestamp found if detectTimestamp is true', async () => {
const newProps = {
...props,
isCodeEditorExpanded: true,
Expand All @@ -107,7 +107,7 @@ describe('TextBasedLanguagesEditor', () => {
const component = mount(renderTextBasedLanguagesEditorComponent({ ...newProps }));
expect(
component.find('[data-test-subj="TextBasedLangEditor-date-info"]').at(0).text()
).toStrictEqual('@timestamp detected');
).toStrictEqual('@timestamp found');
});
});

Expand Down Expand Up @@ -265,4 +265,24 @@ describe('TextBasedLanguagesEditor', () => {
expect(component.find('[data-test-subj="TextBasedLangEditor-run-query"]').length).toBe(0);
});
});

it('should render correctly if editorIsInline prop is set to true', async () => {
const onTextLangQuerySubmit = jest.fn();
const newProps = {
...props,
isCodeEditorExpanded: true,
hideRunQueryText: true,
editorIsInline: true,
onTextLangQuerySubmit,
};
await act(async () => {
const component = mount(renderTextBasedLanguagesEditorComponent({ ...newProps }));
expect(component.find('[data-test-subj="TextBasedLangEditor-run-query"]').length).toBe(0);
expect(
component.find('[data-test-subj="TextBasedLangEditor-run-query-button"]').length
).not.toBe(1);
findTestSubject(component, 'TextBasedLangEditor-run-query-button').simulate('click');
expect(onTextLangQuerySubmit).toHaveBeenCalled();
});
});
});