Skip to content

Commit

Permalink
[8.12] [Discover] Include column width in shared links (#172405) (#17…
Browse files Browse the repository at this point in the history
…3658)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Discover] Include column width in shared links
(#172405)](#172405)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Lukas
Olson","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-12-19T15:28:17Z","message":"[Discover]
Include column width in shared links (#172405)\n\n##
Summary\r\n\r\nResolves
https://github.com/elastic/kibana/issues/170577.\r\n\r\nIncludes the
`grid` properties (which include specified column widths)\r\nin the
shareable links generated from Discover.\r\n\r\n### Checklist\r\n\r\n- [
] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
Release note\r\n\r\nDiscover sharing links now preserve customized
column widths.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"d79f191b4e12a1ae7634c1a1f5e676aeec499b93","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","v8.12.0","v8.13.0"],"number":172405,"url":"https://github.com/elastic/kibana/pull/172405","mergeCommit":{"message":"[Discover]
Include column width in shared links (#172405)\n\n##
Summary\r\n\r\nResolves
https://github.com/elastic/kibana/issues/170577.\r\n\r\nIncludes the
`grid` properties (which include specified column widths)\r\nin the
shareable links generated from Discover.\r\n\r\n### Checklist\r\n\r\n- [
] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
Release note\r\n\r\nDiscover sharing links now preserve customized
column widths.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"d79f191b4e12a1ae7634c1a1f5e676aeec499b93"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/172405","number":172405,"mergeCommit":{"message":"[Discover]
Include column width in shared links (#172405)\n\n##
Summary\r\n\r\nResolves
https://github.com/elastic/kibana/issues/170577.\r\n\r\nIncludes the
`grid` properties (which include specified column widths)\r\nin the
shareable links generated from Discover.\r\n\r\n### Checklist\r\n\r\n- [
] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
Release note\r\n\r\nDiscover sharing links now preserve customized
column widths.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"d79f191b4e12a1ae7634c1a1f5e676aeec499b93"}}]}]
BACKPORT-->

Co-authored-by: Lukas Olson <[email protected]>
  • Loading branch information
kibanamachine and lukasolson authored Jan 2, 2024
1 parent 2adb22d commit fdd0dc4
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 fdd0dc4

Please sign in to comment.