import { get, isEmpty, set } from 'lodash'; import { $log } from 'ngimport'; import React from 'react'; import { Modal } from 'react-bootstrap'; import type { Application } from '../../../../application'; import type { IPipeline } from '../../../../domain'; import { ModalClose } from '../../../../modal'; import type { IModalComponentProps } from '../../../../presentation'; import { ReactInjector } from '../../../../reactShims'; import { PipelineConfigService } from '../../services/PipelineConfigService'; export interface IDeletePipelineModalProps extends IModalComponentProps { application: Application; pipeline: IPipeline; } export function DeletePipelineModal(props: IDeletePipelineModalProps) { const [errorMessage, setErrorMessage] = React.useState(null); const [deleteError, setDeleteError] = React.useState(false); const [deleting, setDeleting] = React.useState(false); const { application, closeModal, dismissModal, pipeline } = props; function deletePipeline() { setDeleting(true); PipelineConfigService.deletePipeline(application.name, pipeline, pipeline.name).then( () => { const idsToUpdatedIndices = {}; const isPipelineStrategy = pipeline.strategy === true; const data = isPipelineStrategy ? application.strategyConfigs.data : application.pipelineConfigs.data; data.splice( data.findIndex((p: any) => p.id === pipeline.id), 1, ); data.forEach((p: IPipeline, index: number) => { if (p.index !== index) { p.index = index; set(idsToUpdatedIndices, p.id, index); } }); if (!isEmpty(idsToUpdatedIndices)) { PipelineConfigService.reorderPipelines(application.name, idsToUpdatedIndices, isPipelineStrategy); } ReactInjector.$state.go('^.executions', null, { location: 'replace' }); closeModal(); }, (response) => { $log.warn(response); setDeleting(false); setDeleteError(true); setErrorMessage(get(response, 'data.message', 'No message provided')); }, ); } return ( <> {}}> Really Delete {pipeline.strategy === true ? 'Strategy' : 'Pipeline'}? {deleteError && (

Could not delete {pipeline.strategy === true ? 'strategy' : 'pipeline'}.

Reason: {errorMessage}

{ e.preventDefault(); setDeleteError(false); }} > [dismiss]

)}

Are you sure you want to delete the {pipeline.strategy === true ? 'strategy: ' : 'pipeline: '} {pipeline.name}?

); }