import React from 'react' ; import { usePolicyListContext } from '../policy_list_context' ; import { IndexTemplatesFlyout } from '../../../components/index_templates_flyout' ; import { ConfirmDelete } from './confirm_delete' ; import { AddPolicyToTemplateConfirmModal } from './add_policy_to_template_confirm_modal' ; interface Props { updatePolicies : ( ) => void ; } export const ListActionHandler = ( { updatePolicies } ) => { const { listAction , setListAction } = usePolicyListContext ( ) ; if ( listAction ?. actionType === 'viewIndexTemplates' ) { return ( < IndexTemplatesFlyout policyName = { listAction . selectedPolicy . name } indexTemplates = { listAction . selectedPolicy . indexTemplates ?? [ ] } close = { ( ) => { setListAction ( null ) ; } } />); } if ( listAction ?. actionType === 'deletePolicy' ) { return ( < ConfirmDelete policyToDelete = { listAction . selectedPolicy } callback = { ( ) => { updatePolicies ( ) ; setListAction ( null ) ; } } onCancel = { ( ) => { setListAction ( null ) ; } } />); } if ( listAction ?. actionType === 'addIndexTemplate' ) { return ( < AddPolicyToTemplateConfirmModal policy = { listAction . selectedPolicy } onSuccess = { ( indexTemplate ) => { listAction ! . selectedPolicy . indexTemplates = [ ... ( listAction ! . selectedPolicy . indexTemplates || [ ] ) , indexTemplate , ] ; setListAction ( null ) ; } } onCancel = { ( ) => setListAction ( null ) } />); } return null ; } ;