mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
make locator async (#125112)
This commit is contained in:
parent
8b5293bd6a
commit
227e4d1c63
2 changed files with 73 additions and 57 deletions
|
@ -6,21 +6,12 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { SerializableRecord, Serializable } from '@kbn/utility-types';
|
||||
import { omitBy } from 'lodash';
|
||||
import type { ParsedQuery } from 'query-string';
|
||||
import { stringify } from 'query-string';
|
||||
import rison from 'rison-node';
|
||||
import { Filter, isFilterPinned } from '@kbn/es-query';
|
||||
import type { SerializableRecord } from '@kbn/utility-types';
|
||||
import { Filter } from '@kbn/es-query';
|
||||
import type { Query, RefreshInterval, TimeRange } from 'src/plugins/data/common';
|
||||
import type { LocatorDefinition, LocatorPublic } from 'src/plugins/share/common';
|
||||
import { url } from '../../kibana_utils/common';
|
||||
import { GLOBAL_STATE_STORAGE_KEY, STATE_STORAGE_KEY, VisualizeConstants } from './constants';
|
||||
import type { SavedVisState } from './types';
|
||||
|
||||
const removeEmptyKeys = (o: Record<string, Serializable>): Record<string, Serializable> =>
|
||||
omitBy(o, (v) => v == null);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
export type VisualizeLocatorParams = {
|
||||
/**
|
||||
|
@ -83,51 +74,8 @@ export const VISUALIZE_APP_LOCATOR = 'VISUALIZE_APP_LOCATOR';
|
|||
export class VisualizeLocatorDefinition implements LocatorDefinition<VisualizeLocatorParams> {
|
||||
id = VISUALIZE_APP_LOCATOR;
|
||||
|
||||
public async getLocation({
|
||||
visId,
|
||||
timeRange,
|
||||
filters,
|
||||
refreshInterval,
|
||||
linked,
|
||||
uiState,
|
||||
query,
|
||||
vis,
|
||||
savedSearchId,
|
||||
indexPattern,
|
||||
}: VisualizeLocatorParams) {
|
||||
let path = visId
|
||||
? `#${VisualizeConstants.EDIT_PATH}/${visId}`
|
||||
: `#${VisualizeConstants.CREATE_PATH}`;
|
||||
|
||||
const urlState: ParsedQuery = {
|
||||
[GLOBAL_STATE_STORAGE_KEY]: rison.encode(
|
||||
removeEmptyKeys({
|
||||
time: timeRange,
|
||||
filters: filters?.filter((f) => isFilterPinned(f)),
|
||||
refreshInterval,
|
||||
})
|
||||
),
|
||||
[STATE_STORAGE_KEY]: rison.encode(
|
||||
removeEmptyKeys({
|
||||
linked,
|
||||
filters: filters?.filter((f) => !isFilterPinned(f)),
|
||||
uiState,
|
||||
query,
|
||||
vis,
|
||||
})
|
||||
),
|
||||
};
|
||||
|
||||
path += `?${stringify(url.encodeQuery(urlState), { encode: false, sort: false })}`;
|
||||
|
||||
const otherParams = stringify({ type: vis?.type, savedSearchId, indexPattern });
|
||||
|
||||
if (otherParams) path += `&${otherParams}`;
|
||||
|
||||
return {
|
||||
app: VisualizeConstants.APP_ID,
|
||||
path,
|
||||
state: {},
|
||||
};
|
||||
public async getLocation(params: VisualizeLocatorParams) {
|
||||
const { getLocation } = await import('./locator_location');
|
||||
return getLocation(params);
|
||||
}
|
||||
}
|
||||
|
|
68
src/plugins/visualizations/common/locator_location.ts
Normal file
68
src/plugins/visualizations/common/locator_location.ts
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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 { Serializable } from '@kbn/utility-types';
|
||||
import { omitBy } from 'lodash';
|
||||
import type { ParsedQuery } from 'query-string';
|
||||
import { stringify } from 'query-string';
|
||||
import rison from 'rison-node';
|
||||
import { isFilterPinned } from '@kbn/es-query';
|
||||
import { url } from '../../kibana_utils/common';
|
||||
import { GLOBAL_STATE_STORAGE_KEY, STATE_STORAGE_KEY, VisualizeConstants } from './constants';
|
||||
import type { VisualizeLocatorParams } from './locator';
|
||||
|
||||
const removeEmptyKeys = (o: Record<string, Serializable>): Record<string, Serializable> =>
|
||||
omitBy(o, (v) => v == null);
|
||||
|
||||
export async function getLocation({
|
||||
visId,
|
||||
timeRange,
|
||||
filters,
|
||||
refreshInterval,
|
||||
linked,
|
||||
uiState,
|
||||
query,
|
||||
vis,
|
||||
savedSearchId,
|
||||
indexPattern,
|
||||
}: VisualizeLocatorParams) {
|
||||
let path = visId
|
||||
? `#${VisualizeConstants.EDIT_PATH}/${visId}`
|
||||
: `#${VisualizeConstants.CREATE_PATH}`;
|
||||
|
||||
const urlState: ParsedQuery = {
|
||||
[GLOBAL_STATE_STORAGE_KEY]: rison.encode(
|
||||
removeEmptyKeys({
|
||||
time: timeRange,
|
||||
filters: filters?.filter((f) => isFilterPinned(f)),
|
||||
refreshInterval,
|
||||
})
|
||||
),
|
||||
[STATE_STORAGE_KEY]: rison.encode(
|
||||
removeEmptyKeys({
|
||||
linked,
|
||||
filters: filters?.filter((f) => !isFilterPinned(f)),
|
||||
uiState,
|
||||
query,
|
||||
vis,
|
||||
})
|
||||
),
|
||||
};
|
||||
|
||||
path += `?${stringify(url.encodeQuery(urlState), { encode: false, sort: false })}`;
|
||||
|
||||
const otherParams = stringify({ type: vis?.type, savedSearchId, indexPattern });
|
||||
|
||||
if (otherParams) path += `&${otherParams}`;
|
||||
|
||||
return {
|
||||
app: VisualizeConstants.APP_ID,
|
||||
path,
|
||||
state: {},
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue