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] Improves the authoring of the query and charts #186875

Merged
merged 30 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
373270a
[ES|QL] Display ESQL grid of results and make the flyout resizable
stratoula Jun 25, 2024
da2ebf7
Merge with main and resolve conflicts
stratoula Jul 16, 2024
84ec51a
some of the review comments
stratoula Jul 16, 2024
b3b5b64
Display a badge of values
stratoula Jul 16, 2024
88fa89e
Make the header sticky
stratoula Jul 16, 2024
98981f0
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 16, 2024
c9edb85
Merge branch 'main' into esql-inline-editing-grid
stratoula Jul 17, 2024
f1ae181
Open in Discover link in progress
stratoula Jul 17, 2024
d6fac74
Add Discover link
stratoula Jul 17, 2024
92fc6dc
Internationalization
stratoula Jul 17, 2024
89cb3e9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 17, 2024
8c5a287
Merge branch 'main' into esql-inline-editing-grid
stratoula Jul 17, 2024
6dcd334
Merge with main and resolve conflicts
stratoula Jul 22, 2024
e23ccd6
Adds unit tests
stratoula Jul 22, 2024
9ed274b
Open Discover link in new tab
stratoula Jul 22, 2024
d452b31
Merge branch 'main' into esql-inline-editing-grid
stratoula Jul 29, 2024
8ff2e6b
Fix typo
stratoula Jul 29, 2024
1e874dc
Adds abortController
stratoula Jul 29, 2024
9353484
Nit picks
stratoula Jul 29, 2024
40e282b
Usde promise all
stratoula Jul 29, 2024
e5dc627
Address Andrea's comments
stratoula Jul 29, 2024
5ddbcf3
Merge branch 'main' into esql-inline-editing-grid
stratoula Jul 29, 2024
73fde7c
Fix FT
stratoula Jul 29, 2024
4506321
Add min width
stratoula Jul 29, 2024
e4d050f
Revert
stratoula Jul 29, 2024
9a49502
Add min size
stratoula Jul 29, 2024
e5f0fdc
Add constants
stratoula Jul 29, 2024
b64dc30
Move to another component
stratoula Jul 29, 2024
34a6b3d
add useCallback
stratoula Jul 29, 2024
63d5a5c
Make the icon blue
stratoula Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* eslint-disable max-classes-per-file */

import { EuiFlyout } from '@elastic/eui';
import { EuiFlyout, EuiFlyoutResizable } from '@elastic/eui';
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Subject } from 'rxjs';
Expand Down Expand Up @@ -102,11 +102,26 @@ export class FlyoutService {
}
};

render(
<KibanaRenderContextProvider analytics={analytics} i18n={i18n} theme={theme}>
const getWrapper = (children: JSX.Element) => {
return options?.isResizable ? (
<EuiFlyoutResizable
{...options}
onClose={onCloseFlyout}
ref={React.createRef()}
maxWidth={Number(options?.maxWidth)}
>
{children}
</EuiFlyoutResizable>
) : (
<EuiFlyout {...options} onClose={onCloseFlyout}>
<MountWrapper mount={mount} className="kbnOverlayMountWrapper" />
{children}
</EuiFlyout>
);
};

render(
<KibanaRenderContextProvider analytics={analytics} i18n={i18n} theme={theme}>
{getWrapper(<MountWrapper mount={mount} className="kbnOverlayMountWrapper" />)}
</KibanaRenderContextProvider>,
this.targetDomElement
);
Expand Down
5 changes: 3 additions & 2 deletions packages/core/overlays/core-overlays-browser/src/flyout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { EuiFlyoutProps } from '@elastic/eui';
import type { EuiFlyoutProps, EuiFlyoutResizableProps } from '@elastic/eui';
import type { MountPoint, OverlayRef } from '@kbn/core-mount-utils-browser';

/**
Expand All @@ -28,10 +28,11 @@ export interface OverlayFlyoutStart {
/**
* @public
*/
export type OverlayFlyoutOpenOptions = Omit<EuiFlyoutProps, 'onClose'> & {
export type OverlayFlyoutOpenOptions = Omit<EuiFlyoutProps | EuiFlyoutResizableProps, 'onClose'> & {
/**
* EuiFlyout onClose handler.
* If provided the consumer is responsible for calling flyout.close() to close the flyout;
*/
onClose?: (flyout: OverlayRef) => void;
isResizable?: boolean;
};
1 change: 1 addition & 0 deletions packages/kbn-esql-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export {
getESQLQueryColumns,
getESQLQueryColumnsRaw,
getESQLResults,
formatESQLColumns,
getTimeFieldFromESQLQuery,
getStartEndParams,
hasStartEndParams,
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-esql-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
getESQLQueryColumns,
getESQLQueryColumnsRaw,
getESQLResults,
formatESQLColumns,
getStartEndParams,
hasStartEndParams,
} from './utils/run_query';
3 changes: 2 additions & 1 deletion src/plugins/esql_datagrid/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"requiredPlugins": [
"data",
"uiActions",
"fieldFormats"
"fieldFormats",
"share",
],
"requiredBundles": [
"kibanaReact",
Expand Down
15 changes: 13 additions & 2 deletions src/plugins/esql_datagrid/public/create_datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ interface ESQLDataGridProps {
dataView: DataView;
columns: DatatableColumn[];
query: AggregateQuery;
/**
* Optional parameters
*/
flyoutType?: 'overlay' | 'push';
isTableView?: boolean;
initialColumns?: DatatableColumn[];
fullHeight?: boolean;
initialRowHeight?: number;
controlColumnIds?: string[]; // default: ['openDetails', 'select']
}

const DataGridLazy = withSuspense(lazy(() => import('./data_grid')));
Expand All @@ -35,6 +41,10 @@ export const ESQLDataGrid = (props: ESQLDataGridProps) => {
return Promise.all([startServicesPromise]);
}, []);

const getWrapper = (children: JSX.Element) => {
return props.fullHeight ? <div style={{ height: 500 }}>{children}</div> : <>{children}</>;
};

const deps = value?.[0];
if (loading || !deps) return <EuiLoadingSpinner />;

Expand All @@ -45,14 +55,15 @@ export const ESQLDataGrid = (props: ESQLDataGridProps) => {
}}
>
<CellActionsProvider getTriggerCompatibleActions={deps.uiActions.getTriggerCompatibleActions}>
<div style={{ height: 500 }}>
{getWrapper(
<DataGridLazy
data={deps.data}
fieldFormats={deps.fieldFormats}
core={deps.core}
share={deps.share}
{...props}
/>
</div>
)}
</CellActionsProvider>
</KibanaContextProvider>
);
Expand Down
91 changes: 87 additions & 4 deletions src/plugins/esql_datagrid/public/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@

import React, { useState, useCallback, useMemo } from 'react';
import { zipObject } from 'lodash';
import { UnifiedDataTable, DataLoadingState, type SortOrder } from '@kbn/unified-data-table';
import {
UnifiedDataTable,
DataLoadingState,
type SortOrder,
renderCustomToolbar,
} from '@kbn/unified-data-table';
import { i18n } from '@kbn/i18n';
import { EuiLink, EuiText, EuiIcon } from '@elastic/eui';
import { css } from '@emotion/react';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import type { ESQLRow } from '@kbn/es-types';
import type { DatatableColumn, DatatableColumnMeta } from '@kbn/expressions-plugin/common';
import type { SharePluginStart } from '@kbn/share-plugin/public';
import type { AggregateQuery } from '@kbn/es-query';
import type { DataTableRecord } from '@kbn/discover-utils/types';
import type { DataView } from '@kbn/data-views-plugin/common';
Expand All @@ -24,13 +33,16 @@ interface ESQLDataGridProps {
core: CoreStart;
data: DataPublicPluginStart;
fieldFormats: FieldFormatsStart;
share?: SharePluginStart;
rows: ESQLRow[];
dataView: DataView;
columns: DatatableColumn[];
query: AggregateQuery;
flyoutType?: 'overlay' | 'push';
isTableView?: boolean;
initialColumns?: DatatableColumn[];
initialRowHeight?: number;
controlColumnIds?: string[];
}
type DataTableColumnsMeta = Record<
string,
Expand All @@ -41,13 +53,19 @@ type DataTableColumnsMeta = Record<
>;

const sortOrder: SortOrder[] = [];
const DEFAULT_INITIAL_ROW_HEIGHT = 5;
const DEFAULT_ROWS_PER_PAGE = 10;
const ROWS_PER_PAGE_OPTIONS = [10, 25];

const DataGrid: React.FC<ESQLDataGridProps> = (props) => {
const [expandedDoc, setExpandedDoc] = useState<DataTableRecord | undefined>(undefined);
const [activeColumns, setActiveColumns] = useState<string[]>(
(props.initialColumns || (props.isTableView ? props.columns : [])).map((c) => c.name)
);
const [rowHeight, setRowHeight] = useState<number>(5);
const [rowHeight, setRowHeight] = useState<number>(
props.initialRowHeight ?? DEFAULT_INITIAL_ROW_HEIGHT
);
const [rowsPerPage, setRowsPerPage] = useState(DEFAULT_ROWS_PER_PAGE);

const onSetColumns = useCallback((columns) => {
setActiveColumns(columns);
Expand Down Expand Up @@ -123,9 +141,70 @@ const DataGrid: React.FC<ESQLDataGridProps> = (props) => {
props.fieldFormats,
]);

const discoverLocator = useMemo(() => {
return props.share?.url.locators.get('DISCOVER_APP_LOCATOR');
}, [props.share?.url.locators]);

const renderToolbar = useCallback(
(customToolbarProps) => {
const discoverLink = discoverLocator?.getRedirectUrl({
dataViewSpec: props.dataView.toSpec(),
timeRange: props.data.query.timefilter.timefilter.getTime(),
query: props.query,
columns: activeColumns,
});
return renderCustomToolbar({
...customToolbarProps,
toolbarProps: {
...customToolbarProps.toolbarProps,
hasRoomForGridControls: true,
},
gridProps: {
additionalControls: (
<EuiLink
href={discoverLink}
target="_blank"
color="primary"
css={css`
display: flex;
align-items: center;
`}
external={false}
>
<EuiIcon
type="discoverApp"
size="s"
css={css`
margin-right: 4px;
`}
/>
<EuiText size="xs">
{i18n.translate('esqlDataGrid.openInDiscoverLabel', {
defaultMessage: 'Open in Discover',
})}
</EuiText>
</EuiLink>
),
},
});
},
[
activeColumns,
discoverLocator,
props.data.query.timefilter.timefilter,
props.dataView,
props.query,
]
);

return (
<UnifiedDataTable
columns={activeColumns}
css={css`
.unifiedDataTableToolbar {
padding: 4px 0px;
}
`}
rows={rows}
columnsMeta={columnsMeta}
services={services}
Expand All @@ -134,8 +213,10 @@ const DataGrid: React.FC<ESQLDataGridProps> = (props) => {
loadingState={DataLoadingState.loaded}
dataView={props.dataView}
sampleSizeState={rows.length}
rowsPerPageState={10}
rowsPerPageState={rowsPerPage}
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS}
onSetColumns={onSetColumns}
onUpdateRowsPerPage={setRowsPerPage}
expandedDoc={expandedDoc}
setExpandedDoc={setExpandedDoc}
showTimeCol
Expand All @@ -146,9 +227,11 @@ const DataGrid: React.FC<ESQLDataGridProps> = (props) => {
maxDocFieldsDisplayed={100}
renderDocumentView={renderDocumentView}
showFullScreenButton={false}
configRowHeight={5}
configRowHeight={DEFAULT_INITIAL_ROW_HEIGHT}
rowHeightState={rowHeight}
onUpdateRowHeight={setRowHeight}
controlColumnIds={props.controlColumnIds}
renderCustomToolbar={discoverLocator ? renderToolbar : undefined}
/>
);
};
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/esql_datagrid/public/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { CoreStart } from '@kbn/core/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';

export let core: CoreStart;

Expand All @@ -19,6 +20,7 @@ interface ServiceDeps {
data: DataPublicPluginStart;
uiActions: UiActionsStart;
fieldFormats: FieldFormatsStart;
share?: SharePluginStart;
}

const servicesReady$ = new BehaviorSubject<ServiceDeps | undefined>(undefined);
Expand All @@ -38,13 +40,15 @@ export const setKibanaServices = (
kibanaCore: CoreStart,
data: DataPublicPluginStart,
uiActions: UiActionsStart,
fieldFormats: FieldFormatsStart
fieldFormats: FieldFormatsStart,
share?: SharePluginStart
) => {
core = kibanaCore;
servicesReady$.next({
core,
data,
uiActions,
fieldFormats,
share,
});
};
9 changes: 7 additions & 2 deletions src/plugins/esql_datagrid/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ import type { Plugin, CoreStart, CoreSetup } from '@kbn/core/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';
import { setKibanaServices } from './kibana_services';

interface ESQLDataGridPluginStart {
data: DataPublicPluginStart;
uiActions: UiActionsStart;
fieldFormats: FieldFormatsStart;
share?: SharePluginStart;
}
export class ESQLDataGridPlugin implements Plugin<{}, void> {
public setup(_: CoreSetup, {}: {}) {
return {};
}

public start(core: CoreStart, { data, uiActions, fieldFormats }: ESQLDataGridPluginStart): void {
setKibanaServices(core, data, uiActions, fieldFormats);
public start(
core: CoreStart,
{ data, uiActions, fieldFormats, share }: ESQLDataGridPluginStart
): void {
setKibanaServices(core, data, uiActions, fieldFormats, share);
}

public stop() {}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/esql_datagrid/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@kbn/unified-doc-viewer-plugin",
"@kbn/core-notifications-browser",
"@kbn/shared-ux-utility",
"@kbn/share-plugin",
"@kbn/i18n",
],
"exclude": [
"target/**/*",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/lens/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"embeddable",
"fieldFormats",
"charts",
"esqlDataGrid",
"esql",
],
"extraPublicDirs": [
Expand Down
Loading