import React from 'react' ; import { i18n } from '@osd/i18n' ; import { EuiBadge } from '@elastic/eui' ; import { IEmbeddable , ViewMode , isReferenceOrValueEmbeddable , isErrorEmbeddable , } from '../../embeddable_plugin' ; import { ActionByType , IncompatibleActionError } from '../../ui_actions_plugin' ; import { reactToUiComponent } from '../../../../opensearch_dashboards_react/public' ; export const ACTION_LIBRARY_NOTIFICATION = 'ACTION_LIBRARY_NOTIFICATION' ; export interface LibraryNotificationActionContext { embeddable : IEmbeddable ; } export class LibraryNotificationAction implements ActionByType < typeof ACTION_LIBRARY_NOTIFICATION > { public readonly id = ACTION_LIBRARY_NOTIFICATION ; public readonly type = ACTION_LIBRARY_NOTIFICATION ; public readonly order = 1 ; private displayName = i18n . translate ( 'dashboard.panel.LibraryNotification' , { defaultMessage : 'Library' , } ) ; private icon = 'folderCheck' ; public readonly MenuItem = reactToUiComponent ( ( ) => ( < EuiBadge data - test - subj = { `embeddablePanelNotification-${ this . id }` } iconType = { this . icon } key = { this . id } style = { { marginTop : '2px' , marginRight : '4px' } } color = "hollow" > { this . displayName } < /EuiBadge>)); 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 getDisplayNameTooltip = ( { embeddable } ) => { if ( ! embeddable . getRoot ( ) || ! embeddable . getRoot ( ) . isContainer ) { throw new IncompatibleActionError ( ) ; } return i18n . translate ( 'dashboard.panel.libraryNotification.toolTip' , { defaultMessage : 'This panel is linked to a Library item. Editing the panel might affect other dashboards.' , } ) ; } ; public isCompatible = async ( { embeddable } ) => { return ( ! isErrorEmbeddable ( embeddable ) && embeddable . getRoot ( ) . isContainer && embeddable . getInput ( ) ?. viewMode !== ViewMode . VIEW && isReferenceOrValueEmbeddable ( embeddable ) && embeddable . inputIsRefType ( embeddable . getInput ( ) ) ) ; } ; public execute = async ( ) => { } ; }