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

[Discover] In-table search #206454

Merged
merged 105 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
9a50e4c
[Discover] Initial implementation
jughosta Jan 13, 2025
1b17280
[Discover] Some updates
jughosta Jan 13, 2025
6907398
[Discover] Calculate matches count
jughosta Jan 14, 2025
bb3385c
[Discover] Add scrolling to a visible row
jughosta Jan 14, 2025
1c1a015
[Discover] Change the approach
jughosta Jan 15, 2025
949d18c
[Discover] Improve highlight inserts
jughosta Jan 15, 2025
a0ddc31
[Discover] Rename
jughosta Jan 15, 2025
f7286db
[Discover] Add highlights for the next active match
jughosta Jan 15, 2025
27559ec
[Discover] Exclude Summary column for now completely
jughosta Jan 15, 2025
dadb590
[Discover] Support Summary column too
jughosta Jan 15, 2025
2520df7
[Discover] Add debounce for the input
jughosta Jan 15, 2025
40ca7ab
[Discover] Revert some redundant changes
jughosta Jan 15, 2025
9b3b390
[Discover] Add navigation between pages
jughosta Jan 15, 2025
ee62e43
[Discover] Improve search input
jughosta Jan 15, 2025
52c9716
[Discover] Update data structure
jughosta Jan 15, 2025
d9a2a5f
[Discover] Support shift+enter
jughosta Jan 15, 2025
b432336
[Discover] Skip converting html to string
jughosta Jan 15, 2025
0e97a27
[Discover] More updates
jughosta Jan 15, 2025
b749d4f
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 15, 2025
ec80ce4
[Discover] Reorganize code
jughosta Jan 16, 2025
bdc9644
Merge remote-tracking branch 'origin/192360-in-table-search' into 192…
jughosta Jan 16, 2025
85c2ba8
[Discover] Fix the context issue
jughosta Jan 16, 2025
bb9110f
[Discover] Reorganize the code
jughosta Jan 16, 2025
286fbec
[Discover] Allow to circle though matches endlessly
jughosta Jan 16, 2025
e181a0b
[Discover] Update styles
jughosta Jan 16, 2025
2d9337e
[Discover] Update search input interactions
jughosta Jan 16, 2025
5361661
[Discover] Opt-in in table search. Fix rendering.
jughosta Jan 16, 2025
3eed799
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 16, 2025
5180cd5
[Discover] Handle errors during rendering
jughosta Jan 16, 2025
b467488
Merge remote-tracking branch 'origin/192360-in-table-search' into 192…
jughosta Jan 16, 2025
4e5c1d0
[Discover] Better search in Summary column
jughosta Jan 16, 2025
9e16b41
[Discover] Update types
jughosta Jan 16, 2025
5db514e
[Discover] Enable for ES|QL grid too
jughosta Jan 16, 2025
7737aa6
[Discover] Override Cmd+f
jughosta Jan 16, 2025
72f409f
[Discover] Better escaping for regexp
jughosta Jan 17, 2025
1ede72e
[Discover] Makes the matches count aggregation faster
jughosta Jan 17, 2025
b383650
[Discover] Update input styles
jughosta Jan 17, 2025
ac700ff
[Discover] Return the focus to the button
jughosta Jan 17, 2025
7f5609f
[Discover] Refactor the solution to account for any parent contexts
jughosta Jan 17, 2025
3a05a53
[Discover] Revert some changes
jughosta Jan 17, 2025
890d1c8
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 17, 2025
405e545
Merge branch 'main' into 192360-in-table-search
jughosta Jan 18, 2025
e5ca868
[Discover] Update tests
jughosta Jan 18, 2025
339f586
Merge remote-tracking branch 'origin/192360-in-table-search' into 192…
jughosta Jan 18, 2025
aa07743
[Discover] Simplify
jughosta Jan 18, 2025
fb5f063
[Discover] Refocus the input if it's already present
jughosta Jan 20, 2025
a85e318
[Discover] Split contexts and improve styles
jughosta Jan 20, 2025
f98aae2
[Discover] Update tests
jughosta Jan 20, 2025
e755f66
[Discover] Add support for Timeline toolbar
jughosta Jan 20, 2025
2bb5bd0
[Discover] Fix styles
jughosta Jan 20, 2025
a8234df
[Discover] Update code style
jughosta Jan 20, 2025
70e45c5
[Discover] Use cellContext instead of table context. Refactor the hook.
jughosta Jan 20, 2025
938ba08
[Discover] Change back to a callback
jughosta Jan 20, 2025
96ae264
[Discover] Update tests
jughosta Jan 20, 2025
ffb4ca1
[Discover] Some updates
jughosta Jan 21, 2025
d3d207b
[Discover] Change back to updating grid first
jughosta Jan 21, 2025
2cb0c29
[Discover] Avoid blocking the main thread
jughosta Jan 21, 2025
bd84a44
[Discover] Reset styles when term changes
jughosta Jan 21, 2025
17d1b74
[Discover] Add a timeout
jughosta Jan 21, 2025
f91ab48
[Discover] Update types
jughosta Jan 21, 2025
2f81527
[Discover] Restore interactions
jughosta Jan 21, 2025
d4743a5
[Discover] Add a comment
jughosta Jan 21, 2025
03785a3
[Discover] Rerun the in-table search when visible columns change
jughosta Jan 21, 2025
b627d4c
Merge branch 'main' into 192360-in-table-search
jughosta Jan 22, 2025
d1ed376
[Discover] Remove scss
jughosta Jan 22, 2025
815b9d9
[Discover] Try another align param
jughosta Jan 22, 2025
7b11780
[Discover] Add a slight animation for the active cell
jughosta Jan 22, 2025
7d6f9a7
[Discover] Replace the animation with a cell border
jughosta Jan 22, 2025
8dee0be
[Discover] Process rows in chunks of 10 at the time
jughosta Jan 22, 2025
55ee25c
[Discover] Create a high level hook
jughosta Jan 22, 2025
ccb006c
[Discover] Move to a separate package
jughosta Jan 22, 2025
b796e6c
[Discover] Simplify
jughosta Jan 22, 2025
647a851
[Discover] Update defaults
jughosta Jan 22, 2025
d8f0363
[Discover] Clean up
jughosta Jan 22, 2025
2c56de0
[Discover] Enable in-table search for Lens table
jughosta Jan 22, 2025
7335218
Revert "[Discover] Enable in-table search for Lens table"
jughosta Jan 22, 2025
619167d
[Discover] Update readme
jughosta Jan 22, 2025
b2a9a93
Merge branch 'main' into 192360-in-table-search
jughosta Jan 23, 2025
e099632
[Discover] Use an increasing speed for rows processing. Allow to meas…
jughosta Jan 23, 2025
9990531
[Discover] Update styles
jughosta Jan 24, 2025
9921927
[Discover] Better reference management
jughosta Jan 24, 2025
3022865
[Discover] Reorganize the code before adding tests
jughosta Jan 24, 2025
0e8def0
[Discover] Switch to a wrapper for renderCellValue
jughosta Jan 24, 2025
bd03809
Merge branch 'main' into 192360-in-table-search
jughosta Jan 24, 2025
d0c9216
Merge branch 'main' into 192360-in-table-search
jughosta Jan 27, 2025
8614fdd
[Discover] Add unit tests for InTableSearchHighlightsWrapper
jughosta Jan 27, 2025
9a2e0a8
[Discover] Add more unit tests
jughosta Jan 27, 2025
c41387c
[Discover] Add functional tests
jughosta Jan 27, 2025
81e317a
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Jan 27, 2025
b63a819
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 27, 2025
850e686
[Discover] Fix refs
jughosta Jan 27, 2025
d990b2f
Merge remote-tracking branch 'origin/192360-in-table-search' into 192…
jughosta Jan 27, 2025
2ae25b0
Update src/platform/packages/shared/kbn-data-grid-in-table-search/src…
jughosta Jan 28, 2025
b5ad104
Update src/platform/packages/shared/kbn-data-grid-in-table-search/src…
jughosta Jan 28, 2025
062c4fe
Update src/platform/packages/shared/kbn-data-grid-in-table-search/src…
jughosta Jan 28, 2025
e19d763
Merge branch 'main' into 192360-in-table-search
jughosta Jan 28, 2025
c84e7b7
[Discover] Fix test snapshots
jughosta Jan 28, 2025
60f8fd9
[Discover] Fix flaky test
jughosta Jan 28, 2025
f24fbf0
Merge branch 'main' into 192360-in-table-search
jughosta Jan 28, 2025
2ec6cc0
Merge branch 'main' into 192360-in-table-search
jughosta Jan 28, 2025
179a6fd
[Discover] Add more tests
jughosta Jan 29, 2025
665122f
Merge remote-tracking branch 'origin/192360-in-table-search' into 192…
jughosta Jan 29, 2025
90673c8
[Discover] Update tests
jughosta Jan 29, 2025
860eff7
Merge branch 'main' into 192360-in-table-search
jughosta Jan 29, 2025
ad91ee5
Merge branch 'main' into 192360-in-table-search
jughosta Jan 29, 2025
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ src/platform/packages/shared/kbn-content-management-utils @elastic/kibana-data-d
src/platform/packages/shared/kbn-crypto @elastic/kibana-security
src/platform/packages/shared/kbn-crypto-browser @elastic/kibana-core
src/platform/packages/shared/kbn-custom-icons @elastic/obs-ux-logs-team
src/platform/packages/shared/kbn-data-grid-in-table-search @elastic/kibana-data-discovery
src/platform/packages/shared/kbn-data-service @elastic/kibana-visualizations @elastic/kibana-data-discovery
src/platform/packages/shared/kbn-data-view-utils @elastic/kibana-data-discovery
src/platform/packages/shared/kbn-datemath @elastic/kibana-data-discovery
Expand Down
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"unifiedFieldList": "src/platform/packages/shared/kbn-unified-field-list",
"unifiedHistogram": "src/platform/plugins/shared/unified_histogram",
"unifiedDataTable": "src/platform/packages/shared/kbn-unified-data-table",
"dataGridInTableSearch": "src/platform/packages/shared/kbn-data-grid-in-table-search",
"unsavedChangesBadge": "src/platform/packages/private/kbn-unsaved-changes-badge",
"unsavedChangesPrompt": "src/platform/packages/shared/kbn-unsaved-changes-prompt",
"managedContentBadge": "src/platform/packages/private/kbn-managed-content-badge",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@
"@kbn/dashboard-enhanced-plugin": "link:x-pack/platform/plugins/shared/dashboard_enhanced",
"@kbn/dashboard-plugin": "link:src/platform/plugins/shared/dashboard",
"@kbn/data-forge": "link:x-pack/platform/packages/shared/kbn-data-forge",
"@kbn/data-grid-in-table-search": "link:src/platform/packages/shared/kbn-data-grid-in-table-search",
"@kbn/data-plugin": "link:src/platform/plugins/shared/data",
"@kbn/data-quality-plugin": "link:x-pack/platform/plugins/shared/data_quality",
"@kbn/data-search-plugin": "link:test/plugin_functional/plugins/data_search",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# @kbn/data-grid-in-table-search

This package allows to extend `EuiDataGrid` with in-table search.

If you are already using `UnifiedDataTable` component, you can enable in-table search simply by passing `enableInTableSearch` prop to it.

```tsx
<UnifiedDataTable
enableInTableSearch={true}
// ... other props
/>
```

If you are using `EuiDataGrid` directly, you can enable in-table search by importing this package and following these steps:

1. include `useDataGridInTableSearch` hook in your component
2. pass `inTableSearchControl` to `EuiDataGrid` inside `additionalControls.right` prop or `renderCustomToolbar`
3. pass `inTableSearchCss` to the grid container element as `css` prop
4. update your `cellContext` prop with `cellContextWithInTableSearchSupport`
5. update your `renderCellValue` prop with `renderCellValueWithInTableSearchSupport`.

```tsx
import { useDataGridInTableSearch } from '@kbn/data-grid-in-table-search';

// ...

const dataGridRef = useRef<EuiDataGridRefProps>(null);
const [dataGridWrapper, setDataGridWrapper] = useState<HTMLElement | null>(null);

// ...

const { inTableSearchTermCss, inTableSearchControl, cellContextWithInTableSearchSupport, renderCellValueWithInTableSearchSupport } =
useDataGridInTableSearch({
dataGridWrapper,
dataGridRef,
visibleColumns,
rows,
cellContext,
renderCellValue,
pagination,
});

const toolbarVisibility: EuiDataGridProps['toolbarVisibility'] = useMemo(
() => ({
additionalControls: inTableSearchControl ? { right: inTableSearchControl } : false,
// ...
}),
[inTableSearchControl]
);

// ...
<div ref={(node) => setDataGridWrapper(node)} css={inTableSearchCss}>
<EuiDataGrid
ref={dataGridRef}
toolbarVisibility={toolbarVisibility}
renderCellValue={renderCellValueWithInTableSearchSupport}
cellContext={cellContextWithInTableSearchSupport}
pagination={pagination}
// ... other props
/>
</div>
```

An example of how to use this package can be found in `kbn-data-grid-in-table-search/__mocks__/data_grid_example.tsx`
or in `kbn-unified-data-table` package.






Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export {
useDataGridInTableSearch,
type UseDataGridInTableSearchProps,
type UseDataGridInTableSearchReturn,
} from './src';

export {
BUTTON_TEST_SUBJ,
COUNTER_TEST_SUBJ,
BUTTON_PREV_TEST_SUBJ,
BUTTON_NEXT_TEST_SUBJ,
INPUT_TEST_SUBJ,
HIGHLIGHT_CLASS_NAME,
} from './src/constants';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../../../..',
roots: ['<rootDir>/src/platform/packages/shared/kbn-data-grid-in-table-search'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "shared-browser",
"id": "@kbn/data-grid-in-table-search",
"owner": "@elastic/kibana-data-discovery",
"group": "platform",
"visibility": "shared"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/data-grid-in-table-search",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0",
"sideEffects": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const generateMockData = (rowsCount: number, columnsCount: number) => {
const testData: string[][] = [];

Array.from({ length: rowsCount }).forEach((_, i) => {
const row: string[] = [];
Array.from({ length: columnsCount }).forEach((__, j) => {
row.push(`cell-in-row-${i}-col-${j}`);
});
testData.push(row);
});

return testData;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React, { useMemo, useRef, useState } from 'react';
import { EuiDataGrid, EuiDataGridProps, EuiDataGridRefProps } from '@elastic/eui';
import { generateMockData } from './data';
import { getRenderCellValueMock } from './render_cell_value_mock';
import { useDataGridInTableSearch } from '../use_data_grid_in_table_search';

export interface DataGridWithInTableSearchExampleProps {
rowsCount: number;
columnsCount: number;
pageSize: number | null;
}

export const DataGridWithInTableSearchExample: React.FC<DataGridWithInTableSearchExampleProps> = ({
rowsCount,
columnsCount,
pageSize,
}) => {
const dataGridRef = useRef<EuiDataGridRefProps>(null);
const [dataGridWrapper, setDataGridWrapper] = useState<HTMLElement | null>(null);

const sampleData = useMemo(
() => generateMockData(rowsCount, columnsCount),
[rowsCount, columnsCount]
);
const columns = useMemo(
() => Array.from({ length: columnsCount }, (_, i) => ({ id: `column-${i}` })),
[columnsCount]
);

const [visibleColumns, setVisibleColumns] = useState(columns.map(({ id }) => id));

const renderCellValue = useMemo(() => getRenderCellValueMock(sampleData), [sampleData]);

const isPaginationEnabled = typeof pageSize === 'number';
const [pageIndex, setPageIndex] = useState(0);
const pagination = useMemo(() => {
return isPaginationEnabled
? {
onChangePage: setPageIndex,
onChangeItemsPerPage: () => {},
pageIndex,
pageSize,
}
: undefined;
}, [isPaginationEnabled, setPageIndex, pageSize, pageIndex]);

const {
inTableSearchTermCss,
inTableSearchControl,
cellContextWithInTableSearchSupport,
renderCellValueWithInTableSearchSupport,
} = useDataGridInTableSearch({
dataGridWrapper,
dataGridRef,
visibleColumns,
rows: sampleData,
cellContext: undefined,
renderCellValue,
pagination,
});

const toolbarVisibility: EuiDataGridProps['toolbarVisibility'] = useMemo(
() => ({
additionalControls: inTableSearchControl ? { right: inTableSearchControl } : false,
}),
[inTableSearchControl]
);

return (
<div ref={(node) => setDataGridWrapper(node)} css={inTableSearchTermCss}>
<EuiDataGrid
ref={dataGridRef}
aria-label="Data grid with in-table search"
columns={columns}
columnVisibility={{ visibleColumns, setVisibleColumns }}
toolbarVisibility={toolbarVisibility}
rowCount={rowsCount}
pagination={pagination}
cellContext={cellContextWithInTableSearchSupport}
renderCellValue={renderCellValueWithInTableSearchSupport}
width={800}
height={200}
/>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { generateMockData } from './data';
export { getRenderCellValueMock } from './render_cell_value_mock';
export { DataGridWithInTableSearchExample } from './data_grid_example';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import type { EuiDataGridCellValueElementProps } from '@elastic/eui';

export function getRenderCellValueMock(testData: string[][]) {
return function OriginalRenderCellValue({
colIndex,
rowIndex,
}: EuiDataGridCellValueElementProps) {
const cellValue = testData[rowIndex][colIndex];

if (!cellValue) {
throw new Error('Testing unexpected errors');
}

return <div>{cellValue}</div>;
};
}
Loading