Skip to content

Commit

Permalink
[Discover] Include column width in shared links (elastic#172405)
Browse files Browse the repository at this point in the history
## Summary

Resolves elastic#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>
(cherry picked from commit d79f191)
  • Loading branch information
lukasolson committed Dec 19, 2023
1 parent 49f8243 commit 9017eb3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
9 changes: 7 additions & 2 deletions src/plugins/discover/common/locator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')))"`
);
});

Expand Down
9 changes: 9 additions & 0 deletions src/plugins/discover/common/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -70,6 +71,11 @@ export interface DiscoverAppLocatorParams extends SerializableRecord {
*/
columns?: string[];

/**
* Data Grid related state
*/
grid?: DiscoverGridSettings;

/**
* Used interval of the histogram
*/
Expand Down Expand Up @@ -139,6 +145,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition<DiscoverA
timeRange,
searchSessionId,
columns,
grid,
savedQuery,
sort,
interval,
Expand All @@ -154,6 +161,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition<DiscoverA
filters?: Filter[];
index?: string;
columns?: string[];
grid?: DiscoverGridSettings;
interval?: string;
sort?: string[][];
savedQuery?: string;
Expand All @@ -169,6 +177,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition<DiscoverA
if (indexPatternId) appState.index = indexPatternId;
if (dataViewId) appState.index = dataViewId;
if (columns) appState.columns = columns;
if (grid) appState.grid = grid;
if (savedQuery) appState.savedQuery = savedQuery;
if (sort) appState.sort = sort;
if (interval) appState.interval = interval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,11 @@ export const getTopNavLinks = ({
const { timefilter } = services.data.query.timefilter;
const timeRange = timefilter.getTime();
const refreshInterval = timefilter.getRefreshInterval();
const { grid, ...otherState } = appState;
const filters = services.filterManager.getFilters();

// Share -> Get links -> Snapshot
const params: DiscoverAppLocatorParams = {
...otherState,
...appState,
...(savedSearch.id ? { savedSearchId: savedSearch.id } : {}),
...(dataView?.isPersisted()
? { dataViewId: dataView?.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -94,7 +94,7 @@ export interface DiscoverAppState {
/**
* Data Grid related state
*/
grid?: UnifiedDataTableSettings;
grid?: DiscoverGridSettings;
/**
* Hide chart
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,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,
Expand Down
13 changes: 5 additions & 8 deletions src/plugins/saved_search/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, DiscoverGridSettingsColumn>;
}

export interface DiscoverGridSettingsColumn {
export interface DiscoverGridSettingsColumn extends SerializableRecord {
width?: number;
}

Expand All @@ -25,9 +26,7 @@ export interface SavedSearchAttributes {
sort: Array<[string, string]>;
columns: string[];
description: string;
grid: {
columns?: Record<string, DiscoverGridSettingsColumn>;
};
grid: DiscoverGridSettings;
hideChart: boolean;
isTextBasedQuery: boolean;
usesAdHocDataView?: boolean;
Expand Down Expand Up @@ -59,9 +58,7 @@ export interface SavedSearch {
columns?: string[];
description?: string;
tags?: string[] | undefined;
grid?: {
columns?: Record<string, DiscoverGridSettingsColumn>;
};
grid?: DiscoverGridSettings;
hideChart?: boolean;
viewMode?: VIEW_MODE;
hideAggregatedPreview?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/saved_search/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@kbn/discover-utils",
"@kbn/logging",
"@kbn/core-plugins-server",
"@kbn/utility-types",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit 9017eb3

Please sign in to comment.