import React from 'react' ; import { Action , IncompatibleActionError } from '../../services/ui_actions' ; import { CoreStart } from '../../../../../core/public' ; import { KibanaThemeProvider , reactToUiComponent } from '../../services/kibana_react' ; import { IEmbeddable , ViewMode , isReferenceOrValueEmbeddable , isErrorEmbeddable , } from '../../services/embeddable' ; import { UnlinkFromLibraryAction } from '.' ; import { LibraryNotificationPopover } from './library_notification_popover' ; import { dashboardLibraryNotification } from '../../dashboard_strings' ; export const ACTION_LIBRARY_NOTIFICATION = 'ACTION_LIBRARY_NOTIFICATION' ; export interface LibraryNotificationActionContext { embeddable : IEmbeddable ; } export class LibraryNotificationAction implements Action < LibraryNotificationActionContext > { public readonly id = ACTION_LIBRARY_NOTIFICATION ; public readonly type = ACTION_LIBRARY_NOTIFICATION ; public readonly order = 1 ; constructor ( private theme , private unlinkAction ) { } private displayName = dashboardLibraryNotification . getDisplayName ( ) ; private icon = 'folderCheck' ; private LibraryNotification : React . FC < { context : LibraryNotificationActionContext ; } > = ( { context , } ) => { const { embeddable } = context ; return ( < KibanaThemeProvider theme$ = { this . theme . theme$ } > < LibraryNotificationPopover unlinkAction = { this . unlinkAction } displayName = { this . displayName } context = { context } icon = { this . getIconType ( { embeddable } ) } id = { this . id } / > < /KibanaThemeProvider>); } ; public readonly MenuItem = reactToUiComponent ( this . LibraryNotification ) ; public getDisplayName ( { embeddable } ) { if ( ! embeddable . getRoot ( ) || ! embeddable . getRoot ( ) . isContainer ) { throw new IncompatibleActionError ( ) ; } return this . displayName ; } public getIconType ( { embeddable } ) { if ( ! embeddable . getRoot ( ) || ! embeddable . getRoot ( ) . isContainer ) { throw new IncompatibleActionError ( ) ; } return this . icon ; } public isCompatible = async ( { embeddable } ) => { return ( ! isErrorEmbeddable ( embeddable ) && embeddable . getRoot ( ) . isContainer && embeddable . getInput ( ) ?. viewMode !== ViewMode . VIEW && isReferenceOrValueEmbeddable ( embeddable ) && embeddable . inputIsRefType ( embeddable . getInput ( ) ) ) ; } ; public execute = async ( ) => { } ; }