-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OnWeek][Discover] Allow to change current sample size and save it wi…
…th a saved search (#157269) - Closes #94140 - #11758 - #4060 - #3220 - #23307 - Closes #131130 ## Summary This PR allows to change current sample size right from Discover page, no need to modify the global default value. Saved search panels on Dashboard will also use the saved value to fetch only the requested sample size. This customisation was requested by many customers as it will allow to load Dashboards faster. Current range for the slider: from 10 to 1000 (with a step 10). <img width="400" alt="Screenshot 2023-10-09 at 11 10 52" src="https://github.com/elastic/kibana/assets/1415710/74e2e4ad-9929-4a44-8d85-c2baafccbaa6"> ### Checklist - [x] 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) - [x] [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 - [x] 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)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- Loading branch information
Showing
47 changed files
with
964 additions
and
148 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
111 changes: 111 additions & 0 deletions
111
...ges/kbn-unified-data-table/src/components/data_table_additional_display_settings.test.tsx
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,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(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.