import React from 'react' ; import { EuiTableActionsColumnType } from '@elastic/eui' ; import { checkPermission } from '../../../../../capabilities/check_capabilities' ; import { DeleteJobCheckModal } from '../../../../../components/delete_job_check_modal' ; import { useCloneAction } from '../action_clone' ; import { useDeleteAction , DeleteActionModal } from '../action_delete' ; import { isEditActionFlyoutVisible , useEditAction , EditActionFlyout } from '../action_edit' ; import { useStartAction , StartActionModal } from '../action_start' ; import { useStopAction , StopActionModal } from '../action_stop' ; import { useViewAction } from '../action_view' ; import { useMapAction } from '../action_map' ; import { DataFrameAnalyticsListRow } from './common' ; import { useRefreshAnalyticsList } from '../../../../common/analytics' ; export const useActions = ( isManagementTable ) : { actions : EuiTableActionsColumnType < DataFrameAnalyticsListRow > [ 'actions' ] ; modals : JSX . Element | null ; } => { const canCreateDataFrameAnalytics = checkPermission ( 'canCreateDataFrameAnalytics' ) ; const canDeleteDataFrameAnalytics = checkPermission ( 'canDeleteDataFrameAnalytics' ) ; const canStartStopDataFrameAnalytics = checkPermission ( 'canStartStopDataFrameAnalytics' ) ; const viewAction = useViewAction ( ) ; const mapAction = useMapAction ( ) ; const cloneAction = useCloneAction ( canCreateDataFrameAnalytics ) ; const deleteAction = useDeleteAction ( canDeleteDataFrameAnalytics ) ; const editAction = useEditAction ( canStartStopDataFrameAnalytics ) ; const startAction = useStartAction ( canStartStopDataFrameAnalytics ) ; const stopAction = useStopAction ( canStartStopDataFrameAnalytics ) ; const { refresh } = useRefreshAnalyticsList ( ) ; let modals = null ; const actions = [ viewAction . action , mapAction . action , ] ; if ( isManagementTable === false ) { modals = ( < > { startAction . isModalVisible && < StartActionModal { ... startAction } / > } { stopAction . isModalVisible && < StopActionModal { ... stopAction } / > } { deleteAction . isDeleteJobCheckModalVisible && deleteAction ?. item ?. config && ( < DeleteJobCheckModal onCloseCallback = { deleteAction . closeDeleteJobCheckModal } canDeleteCallback = { ( ) => { deleteAction . openModal ( deleteAction . item ! ) ; deleteAction . closeDeleteJobCheckModal ( ) ; } } refreshJobsCallback = { refresh } jobType = { deleteAction . jobType } jobIds = { [ deleteAction . item . config . id ] } / > ) } { deleteAction . isModalVisible && < DeleteActionModal { ... deleteAction } / > } { isEditActionFlyoutVisible ( editAction ) && < EditActionFlyout { ... editAction } / > } < />); actions . push ( ... [ startAction . action , stopAction . action , editAction . action , cloneAction . action , deleteAction . action , ] ) ; } return { actions , modals } ; } ;