From d79f191b4e12a1ae7634c1a1f5e676aeec499b93 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 19 Dec 2023 08:28:17 -0700 Subject: [PATCH] [Discover] Include column width in shared links (#172405) ## Summary Resolves https://github.com/elastic/kibana/issues/170577. Includes the `grid` properties (which include specified column widths) in the shareable links generated from Discover. ### 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 - [ ] [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) ### Release note Discover sharing links now preserve customized column widths. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- src/plugins/discover/common/locator.test.ts | 9 +++++++-- src/plugins/discover/common/locator.ts | 9 +++++++++ .../main/components/top_nav/get_top_nav_links.tsx | 3 +-- .../main/services/discover_app_state_container.ts | 4 ++-- .../application/main/services/discover_state.ts | 1 + src/plugins/saved_search/common/types.ts | 13 +++++-------- src/plugins/saved_search/tsconfig.json | 1 + 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/plugins/discover/common/locator.test.ts b/src/plugins/discover/common/locator.test.ts index 80bc4ceebed2b..93da54ad365e9 100644 --- a/src/plugins/discover/common/locator.test.ts +++ b/src/plugins/discover/common/locator.test.ts @@ -218,17 +218,22 @@ describe('Discover url generator', () => { expect(path).toContain('__test__'); }); - test('can specify columns, interval, sort and savedQuery', async () => { + test('can specify columns, grid, interval, sort and savedQuery', async () => { const { locator } = await setup(); const { path } = await locator.getLocation({ columns: ['_source'], + grid: { + columns: { + _source: { width: 150 }, + }, + }, interval: 'auto', sort: [['timestamp, asc']] as string[][] & SerializableRecord, savedQuery: '__savedQueryId__', }); expect(path).toMatchInlineSnapshot( - `"#/?_a=(columns:!(_source),interval:auto,savedQuery:__savedQueryId__,sort:!(!('timestamp,%20asc')))"` + `"#/?_a=(columns:!(_source),grid:(columns:(_source:(width:150))),interval:auto,savedQuery:__savedQueryId__,sort:!(!('timestamp,%20asc')))"` ); }); diff --git a/src/plugins/discover/common/locator.ts b/src/plugins/discover/common/locator.ts index 70e60f55b5fb1..9be9947e743dd 100644 --- a/src/plugins/discover/common/locator.ts +++ b/src/plugins/discover/common/locator.ts @@ -10,6 +10,7 @@ import type { SerializableRecord } from '@kbn/utility-types'; import type { Filter, TimeRange, Query, AggregateQuery } from '@kbn/es-query'; import type { GlobalQueryStateFromUrl, RefreshInterval } from '@kbn/data-plugin/public'; import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public'; +import type { DiscoverGridSettings } from '@kbn/saved-search-plugin/common'; import { DataViewSpec } from '@kbn/data-views-plugin/common'; import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/common'; import { VIEW_MODE } from './constants'; @@ -70,6 +71,11 @@ export interface DiscoverAppLocatorParams extends SerializableRecord { */ columns?: string[]; + /** + * Data Grid related state + */ + grid?: DiscoverGridSettings; + /** * Used interval of the histogram */ @@ -139,6 +145,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition Get links -> Snapshot const params: DiscoverAppLocatorParams = { - ...otherState, + ...appState, ...(savedSearch.id ? { savedSearchId: savedSearch.id } : {}), ...(dataView?.isPersisted() ? { dataViewId: dataView?.id } diff --git a/src/plugins/discover/public/application/main/services/discover_app_state_container.ts b/src/plugins/discover/public/application/main/services/discover_app_state_container.ts index facf8e26fb851..e1614bf796391 100644 --- a/src/plugins/discover/public/application/main/services/discover_app_state_container.ts +++ b/src/plugins/discover/public/application/main/services/discover_app_state_container.ts @@ -24,7 +24,7 @@ import { SavedSearch, VIEW_MODE } from '@kbn/saved-search-plugin/public'; import { IKbnUrlStateStorage, ISyncStateRef, syncState } from '@kbn/kibana-utils-plugin/public'; import { isEqual } from 'lodash'; import { connectToQueryState, syncGlobalQueryStateWithUrl } from '@kbn/data-plugin/public'; -import type { UnifiedDataTableSettings } from '@kbn/unified-data-table'; +import type { DiscoverGridSettings } from '@kbn/saved-search-plugin/common'; import type { DiscoverServices } from '../../../build_services'; import { addLog } from '../../../utils/add_log'; import { cleanupUrlState } from '../utils/cleanup_url_state'; @@ -94,7 +94,7 @@ export interface DiscoverAppState { /** * Data Grid related state */ - grid?: UnifiedDataTableSettings; + grid?: DiscoverGridSettings; /** * Hide chart */ diff --git a/src/plugins/discover/public/application/main/services/discover_state.ts b/src/plugins/discover/public/application/main/services/discover_state.ts index 1dc58643ebdc0..8994afb8a5f96 100644 --- a/src/plugins/discover/public/application/main/services/discover_state.ts +++ b/src/plugins/discover/public/application/main/services/discover_state.ts @@ -570,6 +570,7 @@ function createUrlGeneratorState({ : data.query.timefilter.timefilter.getTime(), searchSessionId: shouldRestoreSearchSession ? data.search.session.getSessionId() : undefined, columns: appState.columns, + grid: appState.grid, sort: appState.sort, savedQuery: appState.savedQuery, interval: appState.interval, diff --git a/src/plugins/saved_search/common/types.ts b/src/plugins/saved_search/common/types.ts index c47548aebd8d4..acb98d26a0d14 100644 --- a/src/plugins/saved_search/common/types.ts +++ b/src/plugins/saved_search/common/types.ts @@ -9,13 +9,14 @@ import type { ISearchSource, RefreshInterval, TimeRange } from '@kbn/data-plugin/common'; import type { SavedObjectReference } from '@kbn/core-saved-objects-server'; import type { SavedObjectsResolveResponse } from '@kbn/core/server'; +import type { SerializableRecord } from '@kbn/utility-types'; import { VIEW_MODE } from '.'; -export interface DiscoverGridSettings { +export interface DiscoverGridSettings extends SerializableRecord { columns?: Record; } -export interface DiscoverGridSettingsColumn { +export interface DiscoverGridSettingsColumn extends SerializableRecord { width?: number; } @@ -25,9 +26,7 @@ export interface SavedSearchAttributes { sort: Array<[string, string]>; columns: string[]; description: string; - grid: { - columns?: Record; - }; + grid: DiscoverGridSettings; hideChart: boolean; isTextBasedQuery: boolean; usesAdHocDataView?: boolean; @@ -59,9 +58,7 @@ export interface SavedSearch { columns?: string[]; description?: string; tags?: string[] | undefined; - grid?: { - columns?: Record; - }; + grid?: DiscoverGridSettings; hideChart?: boolean; viewMode?: VIEW_MODE; hideAggregatedPreview?: boolean; diff --git a/src/plugins/saved_search/tsconfig.json b/src/plugins/saved_search/tsconfig.json index 7ed2cb4e82119..b1aa1679469ee 100644 --- a/src/plugins/saved_search/tsconfig.json +++ b/src/plugins/saved_search/tsconfig.json @@ -31,6 +31,7 @@ "@kbn/discover-utils", "@kbn/logging", "@kbn/core-plugins-server", + "@kbn/utility-types", ], "exclude": [ "target/**/*",