import React , { FC } from 'react' ; import { i18n } from '@kbn/i18n' ; import { EuiToolTip } from '@elastic/eui' ; import { TransformState , TRANSFORM_STATE } from '../../../../../../common/constants' ; import { createCapabilityFailureMessage } from '../../../../lib/authorization' ; import { TransformListRow } from '../../../../common' ; export const deleteActionNameText = i18n . translate ( 'xpack.transform.transformList.deleteActionNameText' , { defaultMessage : 'Delete' , } ) ; const transformCanNotBeDeleted = ( i ) => ! ( [ TRANSFORM_STATE . STOPPED , TRANSFORM_STATE . FAILED ] as TransformState [ ] ) . includes ( i . stats . state ) ; export const isDeleteActionDisabled = ( items , forceDisable ) => { const disabled = items . some ( transformCanNotBeDeleted ) ; return forceDisable === true || disabled ; } ; export interface DeleteActionNameProps { canDeleteTransform : boolean ; disabled : boolean ; isBulkAction : boolean ; } export const DeleteActionName = ( { canDeleteTransform , disabled , isBulkAction , } ) => { const bulkDeleteButtonDisabledText = i18n . translate ( 'xpack.transform.transformList.deleteBulkActionDisabledToolTipContent' , { defaultMessage : 'One or more selected transforms must be stopped in order to be deleted.' , } ) ; const deleteButtonDisabledText = i18n . translate ( 'xpack.transform.transformList.deleteActionDisabledToolTipContent' , { defaultMessage : 'Stop the transform in order to delete it.' , } ) ; if ( disabled || ! canDeleteTransform ) { let content ; if ( disabled ) { content = isBulkAction ? bulkDeleteButtonDisabledText : deleteButtonDisabledText ; } else { content = createCapabilityFailureMessage ( 'canDeleteTransform' ) ; } return ( < EuiToolTip position = "top" content = { content } > < > { deleteActionNameText } < /> < /EuiToolTip>); } return < > { deleteActionNameText } < />; } ;