forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES|QL] Render a Discover-like table in the assistant instead of a Le…
…ns chart (elastic#184106) ## Summary This PR does 2 things: - Creates a new plugin that is a wrapper of the unified datatable and is only for rendering as a table ES|QL results. The UnifiedDatatable package is good but the consumers need to know all the properties to understand how to use it and the necessity of displaying in a table the results of an ES|QL query comes a lot lately. This plugin has only 3 required properties (rows, columns, query) which make it very easy for the consumers to use it. It also integrates the Row Viewer flyout - It changes the implementation of the obs ai assistant to render a Discover like table instead of a Lens table. The Discover-like table is much better on rendering a table with thousands of columns and is going to be much more helpful for our users. The same plugin can be used later for the inline ediitng flyout too in a dashboard if we want to also display the results of an ES|QL query. Some screenshots of the new possibilities in the assistant: - I can see the results of an ES|QL query in a visualization ![meow](https://github.com/elastic/kibana/assets/17003240/27f77ca3-633b-45f2-b935-42c62c184a04) - I can render my results as a Document view <img width="880" alt="image" src="https://github.com/elastic/kibana/assets/17003240/e8034e10-325d-4d9e-b8a5-34d01b0dbd9d"> <img width="1095" alt="image" src="https://github.com/elastic/kibana/assets/17003240/c8236e65-96aa-4fcb-b7c3-835e2a5665bd"> <img width="955" alt="image" src="https://github.com/elastic/kibana/assets/17003240/78b1d664-6863-42bf-a337-659143b7683d"> ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
eaed27c
commit 5860259
Showing
30 changed files
with
1,066 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"prefix": "esqlDataGrid", | ||
"paths": { | ||
"esqlDataGrid": "." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# @kbn/esql-datagrid | ||
|
||
Contains a Discover-like table specifically for ES|QL queries: | ||
- You have to run the esql query on your application, this is just a UI component | ||
- You pass the columns and rows of the _query response to the table | ||
- The table operates in both Document view and table view mode, define this with the `isTableView` property | ||
- The table offers a built in Row Viewer flyout | ||
- The table offers a rows comparison mode, exactly as Discover | ||
|
||
--- | ||
|
||
### Properties | ||
* rows: ESQLRow[], is the array of values returned by the _query api | ||
* columns: DatatableColumn[], is the array of columns in a kibana compatible format. You can sue the `formatESQLColumns` helper function from the `@kbn/esql-utils` package | ||
* query: AggregateQuery, the ES|QL query in the format of | ||
```json | ||
{ | ||
esql: <queryString> | ||
} | ||
``` | ||
* flyoutType?: "overlay" | "push", defines the type of flyout for the Row Viewer | ||
* isTableView?: boolean, defines if the table will render as a Document Viewer or a Table View | ||
|
||
|
||
### How to use it | ||
```tsx | ||
import { getIndexPatternFromESQLQuery, getESQLAdHocDataview, formatESQLColumns } from '@kbn/esql-utils'; | ||
import { ESQLDataGrid } from '@kbn/esql-datagrid/public'; | ||
|
||
/** | ||
Run the _query api to get the datatable with the ES|QL query you want. | ||
This will return a response with columns and values | ||
**/ | ||
|
||
const indexPattern = getIndexPatternFromESQLQuery(query); | ||
const adHocDataView = getESQLAdHocDataview(indexPattern, dataViewService); | ||
const formattedColumns = formatESQLColumns(columns); | ||
|
||
<ESQLDataGrid | ||
rows={values} | ||
columns={formattedColumns} | ||
dataView={adHocDataView} | ||
query={{ esql: query }} | ||
flyoutType="overlay" | ||
isTableView | ||
/> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/src/plugins/esql_datagrid'], | ||
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/esql_datagrid', | ||
coverageReporters: ['text', 'html'], | ||
collectCoverageFrom: [ | ||
'<rootDir>/src/plugins/esql_datagrid/{common,public,server}/**/*.{js,ts,tsx}', | ||
], | ||
setupFiles: ['jest-canvas-mock'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"type": "plugin", | ||
"id": "@kbn/esql-datagrid", | ||
"owner": "@elastic/kibana-esql", | ||
"plugin": { | ||
"id": "esqlDataGrid", | ||
"server": false, | ||
"browser": true, | ||
"requiredPlugins": [ | ||
"data", | ||
"uiActions", | ||
"fieldFormats" | ||
], | ||
"requiredBundles": [ | ||
"kibanaReact", | ||
"kibanaUtils", | ||
"dataViews", | ||
"unifiedDocViewer" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@kbn/esql-datagrid", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import React, { lazy } from 'react'; | ||
import { EuiLoadingSpinner } from '@elastic/eui'; | ||
import type { ESQLRow } from '@kbn/es-types'; | ||
import type { AggregateQuery } from '@kbn/es-query'; | ||
import { withSuspense } from '@kbn/shared-ux-utility'; | ||
import useAsync from 'react-use/lib/useAsync'; | ||
import type { DataView } from '@kbn/data-views-plugin/common'; | ||
import type { DatatableColumn } from '@kbn/expressions-plugin/common'; | ||
import { CellActionsProvider } from '@kbn/cell-actions'; | ||
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public'; | ||
import { untilPluginStartServicesReady } from './kibana_services'; | ||
|
||
interface ESQLDataGridProps { | ||
rows: ESQLRow[]; | ||
dataView: DataView; | ||
columns: DatatableColumn[]; | ||
query: AggregateQuery; | ||
flyoutType?: 'overlay' | 'push'; | ||
isTableView?: boolean; | ||
} | ||
|
||
const DataGridLazy = withSuspense(lazy(() => import('./data_grid'))); | ||
|
||
export const ESQLDataGrid = (props: ESQLDataGridProps) => { | ||
const { loading, value } = useAsync(() => { | ||
const startServicesPromise = untilPluginStartServicesReady(); | ||
return Promise.all([startServicesPromise]); | ||
}, []); | ||
|
||
const deps = value?.[0]; | ||
if (loading || !deps) return <EuiLoadingSpinner />; | ||
|
||
return ( | ||
<KibanaContextProvider | ||
services={{ | ||
...deps, | ||
}} | ||
> | ||
<CellActionsProvider getTriggerCompatibleActions={deps.uiActions.getTriggerCompatibleActions}> | ||
<div style={{ height: 500 }}> | ||
<DataGridLazy | ||
data={deps.data} | ||
fieldFormats={deps.fieldFormats} | ||
core={deps.core} | ||
{...props} | ||
/> | ||
</div> | ||
</CellActionsProvider> | ||
</KibanaContextProvider> | ||
); | ||
}; |
Oops, something went wrong.