Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.12] [Discover] Include column width in shared links (#172405) #173658

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading