import React , { useCallback , useContext , useMemo } from 'react' ; import { TRANSFORM_STATE } from '../../../../../../common/constants' ; import { AuthorizationContext } from '../../../../lib/authorization' ; import { TransformListAction , TransformListRow } from '../../../../common' ; import { useStopTransforms } from '../../../../hooks' ; import { isStopActionDisabled , stopActionNameText , StopActionName } from './stop_action_name' ; export type StopAction = ReturnType < typeof useStopAction > ; export const useStopAction = ( forceDisable ) => { const { canStartStopTransform } = useContext ( AuthorizationContext ) . capabilities ; const stopTransforms = useStopTransforms ( ) ; const clickHandler = useCallback ( ( i ) => stopTransforms ( [ { id : i . id , state : i . stats . state } ] ) , [ stopTransforms ] ) ; const action = useMemo ( ( ) => ( { name : ( item ) => ( < StopActionName items = { [ item ] } forceDisable = { forceDisable } / > ) , available : ( item ) => item . stats . state !== TRANSFORM_STATE . STOPPED , enabled : ( item ) => ! isStopActionDisabled ( [ item ] , canStartStopTransform , forceDisable ) , description : stopActionNameText , icon : 'stop' , type : 'icon' , onClick : clickHandler , 'data-test-subj' : 'transformActionStop' , } ) , [ canStartStopTransform , forceDisable , clickHandler ] ) ; return { action } ; } ;