Skip to content

Commit 5217996

Browse files
committed
feat: 🎸 improve getUrl() method of explore data action
1 parent 302702f commit 5217996

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

‎x-pack/plugins/discover_enhanced/public/actions/explore_data/explore_data_context_menu_action.ts‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import { Action } from '../../../../../../src/plugins/ui_actions/public';
88
import { EmbeddableContext } from '../../../../../../src/plugins/embeddable/public';
9-
import { VisualizeEmbeddableContract } from '../../../../../../src/plugins/visualizations/public';
9+
import { DiscoverUrlGeneratorState } from '../../../../../../src/plugins/discover/public';
10+
import { isTimeRange, isQuery, isFilters } from '../../../../../../src/plugins/data/public';
1011
import { KibanaURL } from './kibana_url';
1112
import * as shared from './shared';
1213
import { AbstractExploreDataAction } from './abstract_explore_data_action';
@@ -25,24 +26,29 @@ export class ExploreDataContextMenuAction extends AbstractExploreDataAction<Embe
2526

2627
public readonly order = 200;
2728

28-
protected async getUrl(embeddable: VisualizeEmbeddableContract): Promise<KibanaURL> {
29+
protected readonly getUrl = async (context: EmbeddableContext): Promise<KibanaURL> => {
2930
const { plugins } = this.params.start();
3031
const { urlGenerator } = plugins.discover;
3132

3233
if (!urlGenerator) {
3334
throw new Error('Discover URL generator not available.');
3435
}
3536

36-
const { timeRange, query, filters } = embeddable.getInput();
37-
const indexPatternId = shared.getIndexPattern(embeddable);
37+
const { embeddable } = context;
38+
const state: DiscoverUrlGeneratorState = {};
3839

39-
const path = await urlGenerator.createUrl({
40-
indexPatternId,
41-
filters,
42-
query,
43-
timeRange,
44-
});
40+
if (embeddable) {
41+
state.indexPatternId = shared.getIndexPattern(embeddable) || undefined;
42+
43+
const input = embeddable.getInput();
44+
45+
if (isTimeRange(input.timeRange) && !state.timeRange) state.timeRange = input.timeRange;
46+
if (isQuery(input.query)) state.query = input.query;
47+
if (isFilters(input.filters)) state.filters = [...input.filters, ...(state.filters || [])];
48+
}
49+
50+
const path = await urlGenerator.createUrl(state);
4551

4652
return new KibanaURL(path);
47-
}
53+
};
4854
}

0 commit comments

Comments
 (0)