mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[data.query] Add getState()
api to retrieve whole QueryState
(#132035)
This commit is contained in:
parent
968f7a9ed3
commit
f88b140f9f
22 changed files with 240 additions and 63 deletions
|
@ -20,7 +20,7 @@ import {
|
|||
Filter,
|
||||
Query,
|
||||
waitUntilNextSessionCompletes$,
|
||||
QueryState,
|
||||
GlobalQueryStateFromUrl,
|
||||
} from '../../services/data';
|
||||
import { cleanFiltersForSerialize } from '.';
|
||||
|
||||
|
@ -166,7 +166,7 @@ export const applyDashboardFilterState = ({
|
|||
* time range and refresh interval to the query service.
|
||||
*/
|
||||
if (currentDashboardState.timeRestore) {
|
||||
const globalQueryState = kbnUrlStateStorage.get<QueryState>('_g');
|
||||
const globalQueryState = kbnUrlStateStorage.get<GlobalQueryStateFromUrl>('_g');
|
||||
if (!globalQueryState?.time) {
|
||||
if (savedDashboard.timeFrom && savedDashboard.timeTo) {
|
||||
timefilterService.setTime({
|
||||
|
|
|
@ -9,7 +9,12 @@
|
|||
import type { SerializableRecord } from '@kbn/utility-types';
|
||||
import { flow } from 'lodash';
|
||||
import { type Filter } from '@kbn/es-query';
|
||||
import type { TimeRange, Query, QueryState, RefreshInterval } from '@kbn/data-plugin/public';
|
||||
import type {
|
||||
TimeRange,
|
||||
Query,
|
||||
GlobalQueryStateFromUrl,
|
||||
RefreshInterval,
|
||||
} from '@kbn/data-plugin/public';
|
||||
import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public';
|
||||
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
|
||||
import { ViewMode } from '@kbn/embeddable-plugin/public';
|
||||
|
@ -155,7 +160,7 @@ export class DashboardAppLocatorDefinition implements LocatorDefinition<Dashboar
|
|||
const { isFilterPinned } = await import('@kbn/es-query');
|
||||
|
||||
let path = `#/${hash}`;
|
||||
path = setStateToKbnUrl<QueryState>(
|
||||
path = setStateToKbnUrl<GlobalQueryStateFromUrl>(
|
||||
'_g',
|
||||
cleanEmptyKeys({
|
||||
time: params.timeRange,
|
||||
|
|
|
@ -91,6 +91,8 @@ function searchOnChange(indexPattern: IndexPattern, aggConfigs: AggConfigs) {
|
|||
|
||||
```
|
||||
|
||||
You can also retrieve a snapshot of the whole `QueryState` by using `data.query.getState()`
|
||||
|
||||
### Timefilter
|
||||
|
||||
`data.query.timefilter` is responsible for the time range filter and the auto refresh behavior settings.
|
||||
|
|
|
@ -255,6 +255,7 @@ export {
|
|||
createSavedQueryService,
|
||||
connectToQueryState,
|
||||
syncQueryStateWithUrl,
|
||||
syncGlobalQueryStateWithUrl,
|
||||
getDefaultQuery,
|
||||
FilterManager,
|
||||
TimeHistory,
|
||||
|
@ -280,6 +281,7 @@ export type {
|
|||
QueryStringContract,
|
||||
QuerySetup,
|
||||
TimefilterSetup,
|
||||
GlobalQueryStateFromUrl,
|
||||
} from './query';
|
||||
|
||||
export type { AggsStart } from './search/aggs';
|
||||
|
|
|
@ -15,3 +15,4 @@ export * from './saved_query';
|
|||
export * from './persisted_log';
|
||||
export * from './state_sync';
|
||||
export type { QueryStringContract } from './query_string';
|
||||
export type { QueryState } from './query_state';
|
||||
|
|
|
@ -21,6 +21,7 @@ const createSetupContractMock = () => {
|
|||
timefilter: timefilterServiceMock.createSetupContract(),
|
||||
queryString: queryStringManagerMock.createSetupContract(),
|
||||
state$: new Observable(),
|
||||
getState: jest.fn(),
|
||||
};
|
||||
|
||||
return setupContract;
|
||||
|
@ -33,6 +34,7 @@ const createStartContractMock = () => {
|
|||
queryString: queryStringManagerMock.createStartContract(),
|
||||
savedQueries: jest.fn() as any,
|
||||
state$: new Observable(),
|
||||
getState: jest.fn(),
|
||||
timefilter: timefilterServiceMock.createStartContract(),
|
||||
getEsQuery: jest.fn(),
|
||||
};
|
||||
|
|
91
src/plugins/data/public/query/query_service.test.ts
Normal file
91
src/plugins/data/public/query/query_service.test.ts
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { FilterStateStore } from '@kbn/es-query';
|
||||
import { FilterManager } from './filter_manager';
|
||||
import { QueryStringContract } from './query_string';
|
||||
import { getFilter } from './filter_manager/test_helpers/get_stub_filter';
|
||||
import { UI_SETTINGS } from '../../common';
|
||||
import { coreMock } from '@kbn/core/public/mocks';
|
||||
import { Storage } from '@kbn/kibana-utils-plugin/public';
|
||||
import { QueryService, QueryStart } from './query_service';
|
||||
import { StubBrowserStorage } from '@kbn/test-jest-helpers';
|
||||
import { TimefilterContract } from './timefilter';
|
||||
import { createNowProviderMock } from '../now_provider/mocks';
|
||||
|
||||
const setupMock = coreMock.createSetup();
|
||||
const startMock = coreMock.createStart();
|
||||
|
||||
setupMock.uiSettings.get.mockImplementation((key: string) => {
|
||||
switch (key) {
|
||||
case UI_SETTINGS.FILTERS_PINNED_BY_DEFAULT:
|
||||
return true;
|
||||
case UI_SETTINGS.SEARCH_QUERY_LANGUAGE:
|
||||
return 'kuery';
|
||||
case UI_SETTINGS.TIMEPICKER_TIME_DEFAULTS:
|
||||
return { from: 'now-15m', to: 'now' };
|
||||
case UI_SETTINGS.TIMEPICKER_REFRESH_INTERVAL_DEFAULTS:
|
||||
return { pause: false, value: 0 };
|
||||
default:
|
||||
throw new Error(`query_service test: not mocked uiSetting: ${key}`);
|
||||
}
|
||||
});
|
||||
|
||||
describe('query_service', () => {
|
||||
let queryServiceStart: QueryStart;
|
||||
let filterManager: FilterManager;
|
||||
let timeFilter: TimefilterContract;
|
||||
let queryStringManager: QueryStringContract;
|
||||
|
||||
beforeEach(() => {
|
||||
const queryService = new QueryService();
|
||||
queryService.setup({
|
||||
uiSettings: setupMock.uiSettings,
|
||||
storage: new Storage(new StubBrowserStorage()),
|
||||
nowProvider: createNowProviderMock(),
|
||||
});
|
||||
queryServiceStart = queryService.start({
|
||||
uiSettings: setupMock.uiSettings,
|
||||
storage: new Storage(new StubBrowserStorage()),
|
||||
http: startMock.http,
|
||||
});
|
||||
filterManager = queryServiceStart.filterManager;
|
||||
timeFilter = queryServiceStart.timefilter.timefilter;
|
||||
queryStringManager = queryServiceStart.queryString;
|
||||
});
|
||||
|
||||
test('state is initialized with state from query service', () => {
|
||||
const state = queryServiceStart.getState();
|
||||
|
||||
expect(state).toEqual({
|
||||
filters: filterManager.getFilters(),
|
||||
refreshInterval: timeFilter.getRefreshInterval(),
|
||||
time: timeFilter.getTime(),
|
||||
query: queryStringManager.getQuery(),
|
||||
});
|
||||
});
|
||||
|
||||
test('state is updated when underlying state in service updates', () => {
|
||||
const filters = [getFilter(FilterStateStore.GLOBAL_STATE, true, true, 'key1', 'value1')];
|
||||
const query = { language: 'kql', query: 'query' };
|
||||
const time = { from: new Date().toISOString(), to: new Date().toISOString() };
|
||||
const refreshInterval = { pause: false, value: 10 };
|
||||
|
||||
filterManager.setFilters(filters);
|
||||
queryStringManager.setQuery(query);
|
||||
timeFilter.setTime(time);
|
||||
timeFilter.setRefreshInterval(refreshInterval);
|
||||
|
||||
expect(queryServiceStart.getState()).toEqual({
|
||||
filters,
|
||||
refreshInterval,
|
||||
time,
|
||||
query,
|
||||
});
|
||||
});
|
||||
});
|
|
@ -15,7 +15,8 @@ import { createAddToQueryLog } from './lib';
|
|||
import { TimefilterService } from './timefilter';
|
||||
import type { TimefilterSetup } from './timefilter';
|
||||
import { createSavedQueryService } from './saved_query/saved_query_service';
|
||||
import { createQueryStateObservable } from './state_sync/create_global_query_observable';
|
||||
import { createQueryStateObservable } from './state_sync/create_query_state_observable';
|
||||
import { getQueryState } from './query_state';
|
||||
import type { QueryStringContract } from './query_string';
|
||||
import { QueryStringManager } from './query_string';
|
||||
import { getEsQueryConfig, TimeRange } from '../../common';
|
||||
|
@ -69,6 +70,7 @@ export class QueryService {
|
|||
timefilter: this.timefilter,
|
||||
queryString: this.queryStringManager,
|
||||
state$: this.state$,
|
||||
getState: () => this.getQueryState(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -82,6 +84,7 @@ export class QueryService {
|
|||
queryString: this.queryStringManager,
|
||||
savedQueries: createSavedQueryService(http),
|
||||
state$: this.state$,
|
||||
getState: () => this.getQueryState(),
|
||||
timefilter: this.timefilter,
|
||||
getEsQuery: (indexPattern: IndexPattern, timeRange?: TimeRange) => {
|
||||
const timeFilter = this.timefilter.timefilter.createFilter(indexPattern, timeRange);
|
||||
|
@ -99,6 +102,14 @@ export class QueryService {
|
|||
public stop() {
|
||||
// nothing to do here yet
|
||||
}
|
||||
|
||||
private getQueryState() {
|
||||
return getQueryState({
|
||||
timefilter: this.timefilter,
|
||||
queryString: this.queryStringManager,
|
||||
filterManager: this.filterManager,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** @public */
|
||||
|
|
40
src/plugins/data/public/query/query_state.ts
Normal file
40
src/plugins/data/public/query/query_state.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { Filter } from '@kbn/es-query';
|
||||
import type { TimefilterSetup } from './timefilter';
|
||||
import type { FilterManager } from './filter_manager';
|
||||
import type { QueryStringContract } from './query_string';
|
||||
import type { RefreshInterval, TimeRange, Query } from '../../common';
|
||||
|
||||
/**
|
||||
* All query state service state
|
||||
*/
|
||||
export interface QueryState {
|
||||
time?: TimeRange;
|
||||
refreshInterval?: RefreshInterval;
|
||||
filters?: Filter[];
|
||||
query?: Query;
|
||||
}
|
||||
|
||||
export function getQueryState({
|
||||
timefilter: { timefilter },
|
||||
filterManager,
|
||||
queryString,
|
||||
}: {
|
||||
timefilter: TimefilterSetup;
|
||||
filterManager: FilterManager;
|
||||
queryString: QueryStringContract;
|
||||
}): QueryState {
|
||||
return {
|
||||
time: timefilter.getTime(),
|
||||
refreshInterval: timefilter.getRefreshInterval(),
|
||||
filters: filterManager.getFilters(),
|
||||
query: queryString.getQuery(),
|
||||
};
|
||||
}
|
|
@ -7,16 +7,17 @@
|
|||
*/
|
||||
|
||||
import { Subscription } from 'rxjs';
|
||||
import { Filter, FilterStateStore } from '@kbn/es-query';
|
||||
import { FilterManager } from '../filter_manager';
|
||||
import { getFilter } from '../filter_manager/test_helpers/get_stub_filter';
|
||||
import { Filter, FilterStateStore, UI_SETTINGS } from '../../../common';
|
||||
import { UI_SETTINGS } from '../../../common';
|
||||
import { coreMock } from '@kbn/core/public/mocks';
|
||||
import { BaseStateContainer, createStateContainer, Storage } from '@kbn/kibana-utils-plugin/public';
|
||||
import { QueryService, QueryStart } from '../query_service';
|
||||
import { StubBrowserStorage } from '@kbn/test-jest-helpers';
|
||||
import { connectToQueryState } from './connect_to_query_state';
|
||||
import { TimefilterContract } from '../timefilter';
|
||||
import { QueryState } from './types';
|
||||
import { QueryState } from '../query_state';
|
||||
import { createNowProviderMock } from '../../now_provider/mocks';
|
||||
|
||||
const connectToQueryGlobalState = (query: QueryStart, state: BaseStateContainer<QueryState>) =>
|
||||
|
|
|
@ -9,10 +9,12 @@
|
|||
import { Subscription } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import _ from 'lodash';
|
||||
import { COMPARE_ALL_OPTIONS, compareFilters } from '@kbn/es-query';
|
||||
import { BaseStateContainer } from '@kbn/kibana-utils-plugin/public';
|
||||
import { QuerySetup, QueryStart } from '../query_service';
|
||||
import { QueryState, QueryStateChange } from './types';
|
||||
import { FilterStateStore, COMPARE_ALL_OPTIONS, compareFilters } from '../../../common';
|
||||
import { QueryState } from '../query_state';
|
||||
import { QueryStateChange } from './types';
|
||||
import { FilterStateStore } from '../../../common';
|
||||
import { validateTimeRange } from '../timefilter';
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,16 +8,16 @@
|
|||
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
import { isFilterPinned } from '@kbn/es-query';
|
||||
import { COMPARE_ALL_OPTIONS, compareFilters, isFilterPinned } from '@kbn/es-query';
|
||||
import { createStateContainer } from '@kbn/kibana-utils-plugin/public';
|
||||
import type { TimefilterSetup } from '../timefilter';
|
||||
import { FilterManager } from '../filter_manager';
|
||||
import { QueryState, QueryStateChange } from '.';
|
||||
import { compareFilters, COMPARE_ALL_OPTIONS } from '../../../common';
|
||||
import { getQueryState, QueryState } from '../query_state';
|
||||
import { QueryStateChange } from './types';
|
||||
import type { QueryStringContract } from '../query_string';
|
||||
|
||||
export function createQueryStateObservable({
|
||||
timefilter: { timefilter },
|
||||
timefilter,
|
||||
filterManager,
|
||||
queryString,
|
||||
}: {
|
||||
|
@ -25,27 +25,24 @@ export function createQueryStateObservable({
|
|||
filterManager: FilterManager;
|
||||
queryString: QueryStringContract;
|
||||
}): Observable<{ changes: QueryStateChange; state: QueryState }> {
|
||||
return new Observable((subscriber) => {
|
||||
const state = createStateContainer<QueryState>({
|
||||
time: timefilter.getTime(),
|
||||
refreshInterval: timefilter.getRefreshInterval(),
|
||||
filters: filterManager.getFilters(),
|
||||
query: queryString.getQuery(),
|
||||
});
|
||||
const state = createStateContainer<QueryState>(
|
||||
getQueryState({ timefilter, filterManager, queryString })
|
||||
);
|
||||
|
||||
return new Observable((subscriber) => {
|
||||
let currentChange: QueryStateChange = {};
|
||||
const subs: Subscription[] = [
|
||||
queryString.getUpdates$().subscribe(() => {
|
||||
currentChange.query = true;
|
||||
state.set({ ...state.get(), query: queryString.getQuery() });
|
||||
}),
|
||||
timefilter.getTimeUpdate$().subscribe(() => {
|
||||
timefilter.timefilter.getTimeUpdate$().subscribe(() => {
|
||||
currentChange.time = true;
|
||||
state.set({ ...state.get(), time: timefilter.getTime() });
|
||||
state.set({ ...state.get(), time: timefilter.timefilter.getTime() });
|
||||
}),
|
||||
timefilter.getRefreshIntervalUpdate$().subscribe(() => {
|
||||
timefilter.timefilter.getRefreshIntervalUpdate$().subscribe(() => {
|
||||
currentChange.refreshInterval = true;
|
||||
state.set({ ...state.get(), refreshInterval: timefilter.getRefreshInterval() });
|
||||
state.set({ ...state.get(), refreshInterval: timefilter.timefilter.getRefreshInterval() });
|
||||
}),
|
||||
filterManager.getUpdates$().subscribe(() => {
|
||||
currentChange.filters = true;
|
|
@ -7,5 +7,5 @@
|
|||
*/
|
||||
|
||||
export { connectToQueryState } from './connect_to_query_state';
|
||||
export { syncQueryStateWithUrl } from './sync_state_with_url';
|
||||
export type { QueryState, QueryStateChange } from './types';
|
||||
export { syncQueryStateWithUrl, syncGlobalQueryStateWithUrl } from './sync_state_with_url';
|
||||
export type { QueryStateChange, GlobalQueryStateFromUrl } from './types';
|
||||
|
|
|
@ -21,7 +21,7 @@ import { QueryService, QueryStart } from '../query_service';
|
|||
import { StubBrowserStorage } from '@kbn/test-jest-helpers';
|
||||
import { TimefilterContract } from '../timefilter';
|
||||
import { syncQueryStateWithUrl } from './sync_state_with_url';
|
||||
import { QueryState } from './types';
|
||||
import { GlobalQueryStateFromUrl } from './types';
|
||||
import { createNowProviderMock } from '../../now_provider/mocks';
|
||||
|
||||
const setupMock = coreMock.createSetup();
|
||||
|
@ -100,14 +100,14 @@ describe('sync_query_state_with_url', () => {
|
|||
test('when filters change, global filters synced to urlStorage', () => {
|
||||
const { stop } = syncQueryStateWithUrl(queryServiceStart, kbnUrlStateStorage);
|
||||
filterManager.setFilters([gF, aF]);
|
||||
expect(kbnUrlStateStorage.get<QueryState>('_g')?.filters).toHaveLength(1);
|
||||
expect(kbnUrlStateStorage.get<GlobalQueryStateFromUrl>('_g')?.filters).toHaveLength(1);
|
||||
stop();
|
||||
});
|
||||
|
||||
test('when time range changes, time synced to urlStorage', () => {
|
||||
const { stop } = syncQueryStateWithUrl(queryServiceStart, kbnUrlStateStorage);
|
||||
timefilter.setTime({ from: 'now-30m', to: 'now' });
|
||||
expect(kbnUrlStateStorage.get<QueryState>('_g')?.time).toEqual({
|
||||
expect(kbnUrlStateStorage.get<GlobalQueryStateFromUrl>('_g')?.time).toEqual({
|
||||
from: 'now-30m',
|
||||
to: 'now',
|
||||
});
|
||||
|
@ -117,7 +117,7 @@ describe('sync_query_state_with_url', () => {
|
|||
test('when refresh interval changes, refresh interval is synced to urlStorage', () => {
|
||||
const { stop } = syncQueryStateWithUrl(queryServiceStart, kbnUrlStateStorage);
|
||||
timefilter.setRefreshInterval({ pause: true, value: 100 });
|
||||
expect(kbnUrlStateStorage.get<QueryState>('_g')?.refreshInterval).toEqual({
|
||||
expect(kbnUrlStateStorage.get<GlobalQueryStateFromUrl>('_g')?.refreshInterval).toEqual({
|
||||
pause: true,
|
||||
value: 100,
|
||||
});
|
||||
|
|
|
@ -13,17 +13,17 @@ import {
|
|||
} from '@kbn/kibana-utils-plugin/public';
|
||||
import { QuerySetup, QueryStart } from '../query_service';
|
||||
import { connectToQueryState } from './connect_to_query_state';
|
||||
import { QueryState } from './types';
|
||||
import { FilterStateStore } from '../../../common';
|
||||
import { GlobalQueryStateFromUrl } from './types';
|
||||
|
||||
const GLOBAL_STATE_STORAGE_KEY = '_g';
|
||||
|
||||
/**
|
||||
* Helper to setup syncing of global data with the URL
|
||||
* Helper to sync global query state {@link GlobalQueryStateFromUrl} with the URL (`_g` query param that is preserved between apps)
|
||||
* @param QueryService: either setup or start
|
||||
* @param kbnUrlStateStorage to use for syncing
|
||||
*/
|
||||
export const syncQueryStateWithUrl = (
|
||||
export const syncGlobalQueryStateWithUrl = (
|
||||
query: Pick<QueryStart | QuerySetup, 'filterManager' | 'timefilter' | 'queryString' | 'state$'>,
|
||||
kbnUrlStateStorage: IKbnUrlStateStorage
|
||||
) => {
|
||||
|
@ -31,14 +31,15 @@ export const syncQueryStateWithUrl = (
|
|||
timefilter: { timefilter },
|
||||
filterManager,
|
||||
} = query;
|
||||
const defaultState: QueryState = {
|
||||
const defaultState: GlobalQueryStateFromUrl = {
|
||||
time: timefilter.getTime(),
|
||||
refreshInterval: timefilter.getRefreshInterval(),
|
||||
filters: filterManager.getGlobalFilters(),
|
||||
};
|
||||
|
||||
// retrieve current state from `_g` url
|
||||
const initialStateFromUrl = kbnUrlStateStorage.get<QueryState>(GLOBAL_STATE_STORAGE_KEY);
|
||||
const initialStateFromUrl =
|
||||
kbnUrlStateStorage.get<GlobalQueryStateFromUrl>(GLOBAL_STATE_STORAGE_KEY);
|
||||
|
||||
// remember whether there was info in the URL
|
||||
const hasInheritedQueryFromUrl = Boolean(
|
||||
|
@ -46,7 +47,7 @@ export const syncQueryStateWithUrl = (
|
|||
);
|
||||
|
||||
// prepare initial state, whatever was in URL takes precedences over current state in services
|
||||
const initialState: QueryState = {
|
||||
const initialState: GlobalQueryStateFromUrl = {
|
||||
...defaultState,
|
||||
...initialStateFromUrl,
|
||||
};
|
||||
|
@ -61,7 +62,7 @@ export const syncQueryStateWithUrl = (
|
|||
// if there weren't any initial state in url,
|
||||
// then put _g key into url
|
||||
if (!initialStateFromUrl) {
|
||||
kbnUrlStateStorage.set<QueryState>(GLOBAL_STATE_STORAGE_KEY, initialState, {
|
||||
kbnUrlStateStorage.set<GlobalQueryStateFromUrl>(GLOBAL_STATE_STORAGE_KEY, initialState, {
|
||||
replace: true,
|
||||
});
|
||||
}
|
||||
|
@ -92,3 +93,8 @@ export const syncQueryStateWithUrl = (
|
|||
hasInheritedQueryFromUrl,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated use {@link syncGlobalQueryStateWithUrl} instead
|
||||
*/
|
||||
export const syncQueryStateWithUrl = syncGlobalQueryStateWithUrl;
|
||||
|
|
|
@ -6,17 +6,9 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { Filter, RefreshInterval, TimeRange, Query } from '../../../common';
|
||||
|
||||
/**
|
||||
* All query state service state
|
||||
*/
|
||||
export interface QueryState {
|
||||
time?: TimeRange;
|
||||
refreshInterval?: RefreshInterval;
|
||||
filters?: Filter[];
|
||||
query?: Query;
|
||||
}
|
||||
import type { Filter } from '@kbn/es-query';
|
||||
import type { QueryState } from '../query_state';
|
||||
import { RefreshInterval, TimeRange } from '../../../common/types';
|
||||
|
||||
type QueryStateChangePartial = {
|
||||
[P in keyof QueryState]?: boolean;
|
||||
|
@ -26,3 +18,12 @@ export interface QueryStateChange extends QueryStateChangePartial {
|
|||
appFilters?: boolean; // specifies if app filters change
|
||||
globalFilters?: boolean; // specifies if global filters change
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of {@link QueryState} serialized in the `_g` portion of Url
|
||||
*/
|
||||
export interface GlobalQueryStateFromUrl {
|
||||
time?: TimeRange;
|
||||
refreshInterval?: RefreshInterval;
|
||||
filters?: Filter[];
|
||||
}
|
||||
|
|
|
@ -8,7 +8,12 @@
|
|||
|
||||
import type { SerializableRecord } from '@kbn/utility-types';
|
||||
import type { Filter } from '@kbn/es-query';
|
||||
import type { TimeRange, Query, QueryState, RefreshInterval } from '@kbn/data-plugin/public';
|
||||
import type {
|
||||
TimeRange,
|
||||
Query,
|
||||
GlobalQueryStateFromUrl,
|
||||
RefreshInterval,
|
||||
} from '@kbn/data-plugin/public';
|
||||
import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public';
|
||||
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
|
||||
import type { VIEW_MODE } from './components/view_mode_toggle';
|
||||
|
@ -126,7 +131,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition<DiscoverA
|
|||
viewMode?: string;
|
||||
hideAggregatedPreview?: boolean;
|
||||
} = {};
|
||||
const queryState: QueryState = {};
|
||||
const queryState: GlobalQueryStateFromUrl = {};
|
||||
const { isFilterPinned } = await import('@kbn/es-query');
|
||||
|
||||
if (query) appState.query = query;
|
||||
|
@ -144,7 +149,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition<DiscoverA
|
|||
if (hideAggregatedPreview) appState.hideAggregatedPreview = hideAggregatedPreview;
|
||||
|
||||
let path = `#/${savedSearchPath}`;
|
||||
path = setStateToKbnUrl<QueryState>('_g', queryState, { useHash }, path);
|
||||
path = setStateToKbnUrl<GlobalQueryStateFromUrl>('_g', queryState, { useHash }, path);
|
||||
path = setStateToKbnUrl('_a', appState, { useHash }, path);
|
||||
|
||||
if (searchSessionId) {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import { ApplicationStart } from '@kbn/core/public';
|
||||
import { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
|
||||
import { QueryState } from '@kbn/data-plugin/public';
|
||||
import { GlobalQueryStateFromUrl } from '@kbn/data-plugin/public';
|
||||
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
|
||||
import { getUISettings } from '../../services';
|
||||
import { GLOBAL_STATE_STORAGE_KEY, VISUALIZE_APP_NAME } from '../../../common/constants';
|
||||
|
@ -24,8 +24,14 @@ export const getVisualizeListItemLink = (
|
|||
path: editApp ? editUrl : `#${editUrl}`,
|
||||
});
|
||||
const useHash = getUISettings().get('state:storeInSessionStorage');
|
||||
const globalStateInUrl = kbnUrlStateStorage.get<QueryState>(GLOBAL_STATE_STORAGE_KEY) || {};
|
||||
const globalStateInUrl =
|
||||
kbnUrlStateStorage.get<GlobalQueryStateFromUrl>(GLOBAL_STATE_STORAGE_KEY) || {};
|
||||
|
||||
url = setStateToKbnUrl<QueryState>(GLOBAL_STATE_STORAGE_KEY, globalStateInUrl, { useHash }, url);
|
||||
url = setStateToKbnUrl<GlobalQueryStateFromUrl>(
|
||||
GLOBAL_STATE_STORAGE_KEY,
|
||||
globalStateInUrl,
|
||||
{ useHash },
|
||||
url
|
||||
);
|
||||
return url;
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@ import { SerializableRecord } from '@kbn/utility-types';
|
|||
import { Filter } from '@kbn/es-query';
|
||||
import { RefreshInterval, TimeRange } from '@kbn/data-plugin/common';
|
||||
import { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/common';
|
||||
import { QueryState } from '@kbn/data-plugin/public';
|
||||
import { GlobalQueryStateFromUrl } from '@kbn/data-plugin/public';
|
||||
import { Dictionary, isRisonSerializationRequired } from '../../common/util/url_state';
|
||||
import { SearchQueryLanguage } from '../types/combined_query';
|
||||
|
||||
|
@ -124,7 +124,7 @@ export class IndexDataVisualizerLocatorDefinition
|
|||
sortField?: string;
|
||||
showDistributions?: number;
|
||||
} = {};
|
||||
const queryState: QueryState = {};
|
||||
const queryState: GlobalQueryStateFromUrl = {};
|
||||
|
||||
if (query) {
|
||||
appState.searchQuery = query.searchQuery;
|
||||
|
|
|
@ -10,7 +10,12 @@
|
|||
import rison from 'rison-node';
|
||||
import type { SerializableRecord } from '@kbn/utility-types';
|
||||
import { type Filter, isFilterPinned } from '@kbn/es-query';
|
||||
import type { TimeRange, Query, QueryState, RefreshInterval } from '@kbn/data-plugin/public';
|
||||
import type {
|
||||
TimeRange,
|
||||
Query,
|
||||
GlobalQueryStateFromUrl,
|
||||
RefreshInterval,
|
||||
} from '@kbn/data-plugin/public';
|
||||
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
|
||||
import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public';
|
||||
import type { LayerDescriptor } from '../common/descriptor_types';
|
||||
|
@ -78,7 +83,7 @@ export class MapsAppLocatorDefinition implements LocatorDefinition<MapsAppLocato
|
|||
filters?: Filter[];
|
||||
vis?: unknown;
|
||||
} = {};
|
||||
const queryState: QueryState = {};
|
||||
const queryState: GlobalQueryStateFromUrl = {};
|
||||
|
||||
if (query) appState.query = query;
|
||||
if (filters && filters.length) appState.filters = filters?.filter((f) => !isFilterPinned(f));
|
||||
|
@ -87,7 +92,7 @@ export class MapsAppLocatorDefinition implements LocatorDefinition<MapsAppLocato
|
|||
if (refreshInterval) queryState.refreshInterval = refreshInterval;
|
||||
|
||||
let path = `/map#/${mapId || ''}`;
|
||||
path = setStateToKbnUrl<QueryState>('_g', queryState, { useHash }, path);
|
||||
path = setStateToKbnUrl<GlobalQueryStateFromUrl>('_g', queryState, { useHash }, path);
|
||||
path = setStateToKbnUrl('_a', appState, { useHash }, path);
|
||||
|
||||
if (initialLayers && initialLayers.length) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { QueryState } from '@kbn/data-plugin/public';
|
||||
import { GlobalQueryStateFromUrl } from '@kbn/data-plugin/public';
|
||||
import { UI_SETTINGS } from '@kbn/data-plugin/public';
|
||||
import { getUiSettings } from '../../../kibana_services';
|
||||
import { SerializedMapState } from './types';
|
||||
|
@ -15,7 +15,7 @@ export function getInitialRefreshConfig({
|
|||
globalState = {},
|
||||
}: {
|
||||
serializedMapState?: SerializedMapState;
|
||||
globalState: QueryState;
|
||||
globalState: GlobalQueryStateFromUrl;
|
||||
}) {
|
||||
const uiSettings = getUiSettings();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { QueryState } from '@kbn/data-plugin/public';
|
||||
import { GlobalQueryStateFromUrl } from '@kbn/data-plugin/public';
|
||||
import { getUiSettings } from '../../../kibana_services';
|
||||
import { SerializedMapState } from './types';
|
||||
|
||||
|
@ -14,7 +14,7 @@ export function getInitialTimeFilters({
|
|||
globalState,
|
||||
}: {
|
||||
serializedMapState?: SerializedMapState;
|
||||
globalState: QueryState;
|
||||
globalState: GlobalQueryStateFromUrl;
|
||||
}) {
|
||||
if (serializedMapState?.timeFilters) {
|
||||
return serializedMapState.timeFilters;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue