From 2a08b35cd59b967c1a059b32dc1b3219db4c2f29 Mon Sep 17 00:00:00 2001 From: Davis McPhee Date: Mon, 30 Oct 2023 17:36:32 -0300 Subject: [PATCH 1/2] [Discover] Revert data table row height to 3 by default (#169724) ## Summary This PR reverts the changes from #164218 that updated the default Discover grid row height to "auto", and changes it back to "3". ### Checklist - [ ] 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 - [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 - [ ] 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) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) (cherry picked from commit 788d30239640e4f549eaeedebad766072de45a05) --- packages/kbn-unified-data-table/src/constants.ts | 2 +- .../src/hooks/use_row_heights_options.test.tsx | 14 +++++++++----- src/plugins/discover/server/ui_settings.ts | 2 +- .../apps/discover/group2/_data_grid_row_height.ts | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/kbn-unified-data-table/src/constants.ts b/packages/kbn-unified-data-table/src/constants.ts index f648f09f558f3..c4c236c828fc1 100644 --- a/packages/kbn-unified-data-table/src/constants.ts +++ b/packages/kbn-unified-data-table/src/constants.ts @@ -20,7 +20,7 @@ export const ROWS_PER_PAGE_OPTIONS = [10, 25, 50, DEFAULT_ROWS_PER_PAGE, 250, 50 export const ROWS_HEIGHT_OPTIONS = { auto: -1, single: 0, - default: -1, + default: 3, }; export const defaultRowLineHeight = '1.6em'; export const defaultMonacoEditorWidth = 370; diff --git a/packages/kbn-unified-data-table/src/hooks/use_row_heights_options.test.tsx b/packages/kbn-unified-data-table/src/hooks/use_row_heights_options.test.tsx index 1ef0d9c70d139..2da08c178720a 100644 --- a/packages/kbn-unified-data-table/src/hooks/use_row_heights_options.test.tsx +++ b/packages/kbn-unified-data-table/src/hooks/use_row_heights_options.test.tsx @@ -11,6 +11,8 @@ import { Storage } from '@kbn/kibana-utils-plugin/public'; import { LocalStorageMock } from '../../__mocks__/local_storage_mock'; import { useRowHeightsOptions } from './use_row_heights_options'; +const CONFIG_ROW_HEIGHT = 3; + describe('useRowHeightsOptions', () => { test('should apply rowHeight from savedSearch', () => { const { result } = renderHook(() => { @@ -30,7 +32,7 @@ describe('useRowHeightsOptions', () => { storage: new LocalStorageMock({ ['discover:dataGridRowHeight']: { previousRowHeight: 5, - previousConfigRowHeight: -1, + previousConfigRowHeight: 3, }, }) as unknown as Storage, consumer: 'discover', @@ -50,7 +52,7 @@ describe('useRowHeightsOptions', () => { }); expect(result.current.defaultHeight).toEqual({ - lineCount: 3, + lineCount: CONFIG_ROW_HEIGHT, }); }); @@ -59,8 +61,8 @@ describe('useRowHeightsOptions', () => { return useRowHeightsOptions({ storage: new LocalStorageMock({ ['discover:dataGridRowHeight']: { - previousRowHeight: 5, - // different from uiSettings (config), now user changed it to -1, but prev was 4 + previousRowHeight: 4, + // different from uiSettings (config), now user changed it to 3, but prev was 4 previousConfigRowHeight: 4, }, }) as unknown as Storage, @@ -68,6 +70,8 @@ describe('useRowHeightsOptions', () => { }); }); - expect(result.current.defaultHeight).toEqual('auto'); + expect(result.current.defaultHeight).toEqual({ + lineCount: CONFIG_ROW_HEIGHT, + }); }); }); diff --git a/src/plugins/discover/server/ui_settings.ts b/src/plugins/discover/server/ui_settings.ts index bc5ad09d260c4..d6bbbd0eed9f0 100644 --- a/src/plugins/discover/server/ui_settings.ts +++ b/src/plugins/discover/server/ui_settings.ts @@ -287,7 +287,7 @@ export const getUiSettings: (docLinks: DocLinksServiceSetup) => Record { await dataGrid.clickGridSettings(); - expect(await dataGrid.getCurrentRowHeightValue()).to.be('Auto fit'); + expect(await dataGrid.getCurrentRowHeightValue()).to.be('Custom'); await dataGrid.changeRowHeightValue('Single'); From 1bf8b3cb6cc6609e9325de3bdfcde3e9b597d643 Mon Sep 17 00:00:00 2001 From: Davis McPhee Date: Tue, 31 Oct 2023 00:00:42 -0300 Subject: [PATCH 2/2] Fix Unified Data Table reset to default button when default is a number, and update functional tests --- .../src/hooks/use_row_heights_options.ts | 2 ++ .../apps/discover/group2/_data_grid_row_height.ts | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/kbn-unified-data-table/src/hooks/use_row_heights_options.ts b/packages/kbn-unified-data-table/src/hooks/use_row_heights_options.ts index 55eaa17c2c2ea..3df1a31aaa9d3 100644 --- a/packages/kbn-unified-data-table/src/hooks/use_row_heights_options.ts +++ b/packages/kbn-unified-data-table/src/hooks/use_row_heights_options.ts @@ -34,6 +34,8 @@ const serializeRowHeight = (rowHeight?: EuiDataGridRowHeightOption): number => { return ROWS_HEIGHT_OPTIONS.auto; } else if (typeof rowHeight === 'object' && rowHeight.lineCount) { return rowHeight.lineCount; // custom + } else if (typeof rowHeight === 'number') { + return rowHeight; } return ROWS_HEIGHT_OPTIONS.single; diff --git a/test/functional/apps/discover/group2/_data_grid_row_height.ts b/test/functional/apps/discover/group2/_data_grid_row_height.ts index 0cdfc16cb3536..109c35e25a24c 100644 --- a/test/functional/apps/discover/group2/_data_grid_row_height.ts +++ b/test/functional/apps/discover/group2/_data_grid_row_height.ts @@ -61,18 +61,18 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await dataGrid.resetRowHeightValue(); - expect(await dataGrid.getCurrentRowHeightValue()).to.be('Auto fit'); + expect(await dataGrid.getCurrentRowHeightValue()).to.be('Custom'); - await dataGrid.changeRowHeightValue('Custom'); + await dataGrid.changeRowHeightValue('Auto fit'); await dataGrid.resetRowHeightValue(); - expect(await dataGrid.getCurrentRowHeightValue()).to.be('Auto fit'); + expect(await dataGrid.getCurrentRowHeightValue()).to.be('Custom'); }); it('should persist the selection after reloading the page', async () => { await dataGrid.clickGridSettings(); - expect(await dataGrid.getCurrentRowHeightValue()).to.be('Auto fit'); + expect(await dataGrid.getCurrentRowHeightValue()).to.be('Custom'); await dataGrid.changeRowHeightValue('Single');