Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
fd399ce
[Discover] Allow to change current sample size and save it with a sav…
jughosta May 10, 2023
6fdae5c
[Discover] Search embaddable supports a custom sample size
jughosta May 10, 2023
fcb469b
Merge remote-tracking branch 'upstream/main' into onweek-configurable…
jughosta May 11, 2023
5ca785c
[Discover] Update test
jughosta May 11, 2023
8d80dbe
[Discover] Fix context page
jughosta May 11, 2023
8150dd7
[Discover] Disable in SQL mode
jughosta May 11, 2023
517cd51
[Discover] Fix redundant state updates
jughosta May 11, 2023
e39f191
[Discover] Fix the max value
jughosta May 11, 2023
b25b974
[Discover] Discard old value
jughosta May 11, 2023
469a3ac
Merge branch 'main' into onweek-configurable-sample-size
jughosta May 11, 2023
1fbf4eb
[Discover] Fix the default case
jughosta May 15, 2023
f070a1c
Merge branch 'main' into onweek-configurable-sample-size
jughosta May 15, 2023
f5b6ae7
Merge remote-tracking branch 'upstream/main' into onweek-configurable…
jughosta May 22, 2023
96572bb
[Discover] Update UI
jughosta May 22, 2023
05a72b7
[Discover] Update icon
jughosta May 22, 2023
2095b0c
Merge remote-tracking branch 'upstream/main' into onweek-configurable…
jughosta Jun 8, 2023
ba2297d
[Discover] Fix tests
jughosta Jun 8, 2023
0755a37
Merge branch 'main' into onweek-configurable-sample-size
jughosta Jun 8, 2023
d05a506
Merge branch 'main' into onweek-configurable-sample-size
jughosta Jun 8, 2023
cedb282
Merge remote-tracking branch 'upstream/main' into onweek-configurable…
jughosta Aug 9, 2023
d468443
[Discover] Fix reading from saved search SO
jughosta Aug 9, 2023
5bbe61e
[Discover] Update search hash
jughosta Aug 9, 2023
44c3da0
[Discover] Add tests
jughosta Aug 9, 2023
19e60ff
[Discover] Fix tests
jughosta Aug 9, 2023
b18c5d9
Merge remote-tracking branch 'upstream/main' into onweek-configurable…
jughosta Sep 28, 2023
8f2679e
[Discover] Use new Eui props
jughosta Sep 28, 2023
8b6cee9
[Discover] Update version
jughosta Sep 28, 2023
fbf56b3
Merge branch 'main' into onweek-configurable-sample-size
jughosta Oct 2, 2023
3b1650b
[Discover] Update tests
jughosta Oct 2, 2023
54a3449
Merge remote-tracking branch 'upstream/main' into onweek-configurable…
jughosta Oct 5, 2023
e2a9d30
[Discover] Update scheme version
jughosta Oct 5, 2023
4f55005
[Discover] Update UI
jughosta Oct 5, 2023
e1bcb2a
[Discover] Fix props
jughosta Oct 5, 2023
7a31208
[Discover] Add jest tests
jughosta Oct 5, 2023
60baf90
[Discover] Update search SO hash
jughosta Oct 6, 2023
40ba04c
Merge branch 'main' into onweek-configurable-sample-size
jughosta Oct 6, 2023
7194e6b
[Discover] Extend tests suite
jughosta Oct 6, 2023
79712df
[Discover] Add functional tests
jughosta Oct 6, 2023
6866eb4
[Discover] Update code style
jughosta Oct 6, 2023
a636a95
[Discover] Fix messaging for legacy table embeddable
jughosta Oct 6, 2023
b58bff1
Merge branch 'main' into onweek-configurable-sample-size
jughosta Oct 9, 2023
7feb2ae
[Discover] Switch back to EuiRange
jughosta Oct 9, 2023
9d38df8
Merge branch 'main' into onweek-configurable-sample-size
jughosta Oct 13, 2023
9766615
[Discover] Limit fetched sample by settings and 10_000
jughosta Oct 13, 2023
b398fdd
[Discover] Add tests
jughosta Oct 13, 2023
d6c17ad
[Discover] Fix tests
jughosta Oct 13, 2023
cc1fbc0
Merge branch 'main' into onweek-configurable-sample-size
jughosta Oct 13, 2023
1bbb2e6
Merge branch 'main' into onweek-configurable-sample-size
jughosta Oct 16, 2023
c25f598
Merge branch 'main' into onweek-configurable-sample-size
jughosta Oct 17, 2023
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 @@ -10,6 +10,7 @@ import { ReactWrapper } from 'enzyme';
import {
EuiButton,
EuiCopy,
EuiDataGrid,
EuiDataGridCellValueElementProps,
EuiDataGridCustomBodyProps,
} from '@elastic/eui';
Expand Down Expand Up @@ -52,7 +53,7 @@ function getProps(): UnifiedDataTableProps {
onSetColumns: jest.fn(),
onSort: jest.fn(),
rows: esHitsMock.map((hit) => buildDataTableRecord(hit, dataViewMock)),
sampleSize: 30,
sampleSizeState: 30,
searchDescription: '',
searchTitle: '',
setExpandedDoc: jest.fn(),
Expand Down Expand Up @@ -301,6 +302,74 @@ describe('UnifiedDataTable', () => {
});
});

describe('display settings', () => {
it('should include additional display settings if onUpdateSampleSize is provided', async () => {
const component = await getComponent({
...getProps(),
sampleSizeState: 150,
onUpdateSampleSize: jest.fn(),
onUpdateRowHeight: jest.fn(),
});

expect(component.find(EuiDataGrid).prop('toolbarVisibility')).toMatchInlineSnapshot(`
Object {
"additionalControls": <React.Fragment />,
"showColumnSelector": false,
"showDisplaySelector": Object {
"additionalDisplaySettings": <UnifiedDataTableAdditionalDisplaySettings
onChangeSampleSize={[MockFunction]}
sampleSize={150}
/>,
"allowDensity": false,
"allowResetButton": false,
"allowRowHeight": true,
},
"showFullScreenSelector": true,
"showSortSelector": true,
}
`);
});

it('should not include additional display settings if onUpdateSampleSize is not provided', async () => {
const component = await getComponent({
...getProps(),
sampleSizeState: 200,
onUpdateRowHeight: jest.fn(),
});

expect(component.find(EuiDataGrid).prop('toolbarVisibility')).toMatchInlineSnapshot(`
Object {
"additionalControls": <React.Fragment />,
"showColumnSelector": false,
"showDisplaySelector": Object {
"allowDensity": false,
"allowRowHeight": true,
},
"showFullScreenSelector": true,
"showSortSelector": true,
}
`);
});

it('should hide display settings if no handlers provided', async () => {
const component = await getComponent({
...getProps(),
onUpdateRowHeight: undefined,
onUpdateSampleSize: undefined,
});

expect(component.find(EuiDataGrid).prop('toolbarVisibility')).toMatchInlineSnapshot(`
Object {
"additionalControls": <React.Fragment />,
"showColumnSelector": false,
"showDisplaySelector": undefined,
"showFullScreenSelector": true,
"showSortSelector": true,
}
`);
});
});

describe('externalControlColumns', () => {
it('should render external leading control columns', async () => {
const component = await getComponent({
Expand Down
55 changes: 39 additions & 16 deletions packages/kbn-unified-data-table/src/components/data_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
EuiDataGridControlColumn,
EuiDataGridCustomBodyProps,
EuiDataGridCellValueElementProps,
EuiDataGridToolBarVisibilityDisplaySelectorOptions,
EuiDataGridStyle,
} from '@elastic/eui';
import type { DataView } from '@kbn/data-views-plugin/public';
Expand Down Expand Up @@ -63,6 +64,7 @@ import {
toolbarVisibility as toolbarVisibilityDefaults,
} from '../constants';
import { UnifiedDataTableFooter } from './data_table_footer';
import { UnifiedDataTableAdditionalDisplaySettings } from './data_table_additional_display_settings';

export type SortOrder = [string, string];

Expand Down Expand Up @@ -137,10 +139,6 @@ export interface UnifiedDataTableProps {
* Array of documents provided by Elasticsearch
*/
rows?: DataTableRecord[];
/**
* The max size of the documents returned by Elasticsearch
*/
sampleSize: number;
/**
* Function to set the expanded document, which is displayed in a flyout
*/
Expand Down Expand Up @@ -205,6 +203,18 @@ export interface UnifiedDataTableProps {
* Update rows per page state
*/
onUpdateRowsPerPage?: (rowsPerPage: number) => void;
/**
* Configuration option to limit sample size slider
*/
maxAllowedSampleSize?: number;
/**
* The max size of the documents returned by Elasticsearch
*/
sampleSizeState: number;
/**
* Update rows per page state
*/
onUpdateSampleSize?: (sampleSize: number) => void;
/**
* Callback to execute on edit runtime field
*/
Expand Down Expand Up @@ -328,7 +338,6 @@ export const UnifiedDataTable = ({
onSetColumns,
onSort,
rows,
sampleSize,
searchDescription,
searchTitle,
settings,
Expand All @@ -342,6 +351,9 @@ export const UnifiedDataTable = ({
className,
rowHeightState,
onUpdateRowHeight,
maxAllowedSampleSize,
sampleSizeState,
onUpdateSampleSize,
isPlainRecord = false,
rowsPerPageState,
onUpdateRowsPerPage,
Expand Down Expand Up @@ -715,16 +727,27 @@ export const UnifiedDataTable = ({
[usedSelectedDocs, isFilterActive, rows, externalAdditionalControls]
);

const showDisplaySelector = useMemo(
() =>
!!onUpdateRowHeight
? {
allowDensity: false,
allowRowHeight: true,
}
: undefined,
[onUpdateRowHeight]
);
const showDisplaySelector = useMemo(() => {
const options: EuiDataGridToolBarVisibilityDisplaySelectorOptions = {};

if (onUpdateRowHeight) {
options.allowDensity = false;
options.allowRowHeight = true;
}

if (onUpdateSampleSize) {
options.allowResetButton = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we set this to false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davismcphee Since we have issues with the button #131130 and now we introduce additional settings which are not handled by eui code, we better hide the button. Originally suggested by @kertal

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it did not work as expected, and introducing new settings, wouldn't make it better, so I suggested to remove it (not having a good way to handle it, at least back in the days)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense to remove it for now if it wasn't working as intended. Might be worth figuring out if we can fix it and add it back in later though. It would be convenient to be able to reset the sample size back to the saved search default after changing it on a dashboard and saving, which persists the updated value with the dashboard.

options.additionalDisplaySettings = (
<UnifiedDataTableAdditionalDisplaySettings
maxAllowedSampleSize={maxAllowedSampleSize}
sampleSize={sampleSizeState}
onChangeSampleSize={onUpdateSampleSize}
/>
);
}

return Object.keys(options).length ? options : undefined;
}, [maxAllowedSampleSize, sampleSizeState, onUpdateRowHeight, onUpdateSampleSize]);

const inMemory = useMemo(() => {
return isPlainRecord && columns.length
Expand Down Expand Up @@ -837,7 +860,7 @@ export const UnifiedDataTable = ({
<UnifiedDataTableFooter
isLoadingMore={loadingState === DataLoadingState.loadingMore}
rowCount={rowCount}
sampleSize={sampleSize}
sampleSize={sampleSizeState}
pageCount={pageCount}
pageIndex={paginationObj?.pageIndex}
totalHits={totalHits}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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 from 'react';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { act } from 'react-dom/test-utils';
import { findTestSubject } from '@elastic/eui/lib/test';
import { UnifiedDataTableAdditionalDisplaySettings } from './data_table_additional_display_settings';
import lodash from 'lodash';

jest.spyOn(lodash, 'debounce').mockImplementation((fn: any) => fn);

describe('UnifiedDataTableAdditionalDisplaySettings', function () {
describe('sampleSize', function () {
it('should work correctly', async () => {
const onChangeSampleSizeMock = jest.fn();

const component = mountWithIntl(
<UnifiedDataTableAdditionalDisplaySettings
sampleSize={10}
onChangeSampleSize={onChangeSampleSizeMock}
/>
);
const input = findTestSubject(component, 'unifiedDataTableSampleSizeInput').last();
expect(input.prop('value')).toBe(10);

await act(async () => {
input.simulate('change', {
target: {
value: 100,
},
});
});

expect(onChangeSampleSizeMock).toHaveBeenCalledWith(100);

await new Promise((resolve) => setTimeout(resolve, 0));
component.update();

expect(
findTestSubject(component, 'unifiedDataTableSampleSizeInput').last().prop('value')
).toBe(100);
});

it('should not execute the callback for an invalid input', async () => {
const invalidValue = 600;
const onChangeSampleSizeMock = jest.fn();

const component = mountWithIntl(
<UnifiedDataTableAdditionalDisplaySettings
maxAllowedSampleSize={500}
sampleSize={50}
onChangeSampleSize={onChangeSampleSizeMock}
/>
);
const input = findTestSubject(component, 'unifiedDataTableSampleSizeInput').last();
expect(input.prop('value')).toBe(50);

await act(async () => {
input.simulate('change', {
target: {
value: invalidValue,
},
});
});

await new Promise((resolve) => setTimeout(resolve, 0));
component.update();

expect(
findTestSubject(component, 'unifiedDataTableSampleSizeInput').last().prop('value')
).toBe(invalidValue);

expect(onChangeSampleSizeMock).not.toHaveBeenCalled();
});

it('should render value changes correctly', async () => {
const onChangeSampleSizeMock = jest.fn();

const component = mountWithIntl(
<UnifiedDataTableAdditionalDisplaySettings
sampleSize={200}
onChangeSampleSize={onChangeSampleSizeMock}
/>
);

expect(
findTestSubject(component, 'unifiedDataTableSampleSizeInput').last().prop('value')
).toBe(200);

component.setProps({
sampleSize: 500,
onChangeSampleSize: onChangeSampleSizeMock,
});

await new Promise((resolve) => setTimeout(resolve, 0));
component.update();

expect(
findTestSubject(component, 'unifiedDataTableSampleSizeInput').last().prop('value')
).toBe(500);

expect(onChangeSampleSizeMock).not.toHaveBeenCalled();
});
});
});
Loading