import React , { useCallback , useContext , useMemo } from 'react' ; import { AuthorizationContext } from '../../../../lib/authorization' ; import { TransformListAction , TransformListRow } from '../../../../common' ; import { crateAlertRuleActionNameText , CreateAlertRuleActionName , } from './create_alert_rule_action_name' ; import { useAlertRuleFlyout } from '../../../../../alerting/transform_alerting_flyout' ; import { isContinuousTransform } from '../../../../../../common/types/transform' ; export type CreateAlertRuleAction = ReturnType < typeof useCreateAlertRuleAction > ; export const useCreateAlertRuleAction = ( forceDisable ) => { const { canCreateTransformAlerts } = useContext ( AuthorizationContext ) . capabilities ; const { setCreateAlertRule } = useAlertRuleFlyout ( ) ; const clickHandler = useCallback ( ( item ) => { setCreateAlertRule ( item . id ) ; } , [ setCreateAlertRule ] ) ; const action = useMemo ( ( ) => ( { name : ( item ) => ( < CreateAlertRuleActionName disabled = { ! canCreateTransformAlerts } / > ) , available : ( item ) => isContinuousTransform ( item . config ) , enabled : ( ) => canCreateTransformAlerts && ! forceDisable , description : crateAlertRuleActionNameText , type : 'icon' , icon : 'bell' , onClick : clickHandler , 'data-test-subj' : 'transformActionCreateAlertRule' , } ) , [ canCreateTransformAlerts , forceDisable , clickHandler ] ) ; return { action } ; } ;