66
77import { Action } from '../../../../../../src/plugins/ui_actions/public' ;
88import { 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' ;
1011import { KibanaURL } from './kibana_url' ;
1112import * as shared from './shared' ;
1213import { 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