import { i18n } from '@kbn/i18n' ; import { DiscoverStart } from '../../../../../../src/plugins/discover/public' ; import { ViewMode , IEmbeddable } from '../../../../../../src/plugins/embeddable/public' ; import { StartServicesGetter } from '../../../../../../src/plugins/kibana_utils/public' ; import { CoreStart } from '../../../../../../src/core/public' ; import { KibanaLocation } from '../../../../../../src/plugins/share/public' ; import * as shared from './shared' ; export const ACTION_EXPLORE_DATA = 'ACTION_EXPLORE_DATA' ; export interface PluginDeps { discover : Pick < DiscoverStart , 'locator' > ; } export interface CoreDeps { application : Pick < CoreStart [ 'application' ] , 'navigateToApp' | 'getUrlForApp' > ; } export interface Params { start : StartServicesGetter < PluginDeps , unknown , CoreDeps > ; } export abstract class AbstractExploreDataAction < Context extends { embeddable ? : IEmbeddable ; } > { public readonly getIconType = ( context ) : string => 'discoverApp' ; public readonly getDisplayName = ( context ) : string => i18n . translate ( 'xpack.discover.FlyoutCreateDrilldownAction.displayName' , { defaultMessage : 'Explore underlying data' , } ) ; constructor ( protected readonly params ) { } protected abstract getLocation ( context ) ; public async isCompatible ( { embeddable } ) { if ( ! embeddable ) return false ; const { core , plugins } = this . params . start ( ) ; const { capabilities } = core . application ; if ( capabilities . discover && ! capabilities . discover . show ) return false ; if ( ! plugins . discover . locator ) return false ; if ( ! shared . hasExactlyOneIndexPattern ( embeddable ) ) return false ; if ( embeddable . getInput ( ) . viewMode !== ViewMode . VIEW ) return false ; return true ; } public async execute ( context ) { if ( ! shared . hasExactlyOneIndexPattern ( context . embeddable ) ) return ; const { core } = this . params . start ( ) ; const { app , path } = await this . getLocation ( context ) ; await core . application . navigateToApp ( app , { path , } ) ; } public async getHref ( context ) { const { embeddable } = context ; if ( ! shared . hasExactlyOneIndexPattern ( embeddable ) ) { throw new Error ( `Embeddable not supported for "${ this . getDisplayName ( context ) }" action.` ) ; } const { core } = this . params . start ( ) ; const { app , path } = await this . getLocation ( context ) ; const url = await core . application . getUrlForApp ( app , { path , absolute : false } ) ; return url ; } }