From 2caaef83d691a469a48206732ce2aed3784c2a73 Mon Sep 17 00:00:00 2001 From: Clement Brousseau Date: Fri, 20 Dec 2024 17:13:04 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20pouvoir=20supprimer=20une=20livraison?= =?UTF-8?q?=20en=20=C3=A9chec=20#588?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DatasetListTab/DatasetListTab.tsx | 7 +- .../DatasetListTab/UnfinishedUploadList.tsx | 137 +++++++++++++++--- .../datasheet/DatasheetView/DatasheetView.tsx | 25 ++++ assets/router/router.ts | 2 +- 4 files changed, 146 insertions(+), 25 deletions(-) diff --git a/assets/entrepot/pages/datasheet/DatasheetView/DatasetListTab/DatasetListTab.tsx b/assets/entrepot/pages/datasheet/DatasheetView/DatasetListTab/DatasetListTab.tsx index 1e87ed88..bbc1d128 100644 --- a/assets/entrepot/pages/datasheet/DatasheetView/DatasetListTab/DatasetListTab.tsx +++ b/assets/entrepot/pages/datasheet/DatasheetView/DatasetListTab/DatasetListTab.tsx @@ -39,7 +39,12 @@ const DatasetListTab: FC = ({ datastoreId, datasheet }) => { {unfinishedUploads && unfinishedUploads.length > 0 && (
- +
)} diff --git a/assets/entrepot/pages/datasheet/DatasheetView/DatasetListTab/UnfinishedUploadList.tsx b/assets/entrepot/pages/datasheet/DatasheetView/DatasetListTab/UnfinishedUploadList.tsx index e1ad47d0..8a0387b5 100644 --- a/assets/entrepot/pages/datasheet/DatasheetView/DatasetListTab/UnfinishedUploadList.tsx +++ b/assets/entrepot/pages/datasheet/DatasheetView/DatasetListTab/UnfinishedUploadList.tsx @@ -2,16 +2,47 @@ import { fr } from "@codegouvfr/react-dsfr"; import Button from "@codegouvfr/react-dsfr/Button"; import { FC, memo } from "react"; import { symToStr } from "tsafe/symToStr"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import RQKeys from "../../../../../modules/entrepot/RQKeys"; +import api from "../../../../api"; +import { type DatasheetDetailed } from "../../../../../@types/app"; import { routes } from "../../../../../router/router"; import { Upload } from "../../../../../@types/app"; import ReportStatusBadge from "../../../stored_data/StoredDataDetails/ReportTab/ReportStatusBadge"; +import { deleteDeliveryConfirmModal } from "../DatasheetView"; +import Wait from "../../../../../components/Utils/Wait"; +import LoadingIcon from "../../../../../components/Utils/LoadingIcon"; +import { useTranslation } from "../../../../../i18n/i18n"; type UnfinishedUploadListProps = { datastoreId: string; uploadList?: Upload[]; + nbPublications: number; + datasheet: DatasheetDetailed; }; -const UnfinishedUploadList: FC = ({ datastoreId, uploadList }) => { + +const UnfinishedUploadList: FC = ({ datastoreId, uploadList, nbPublications, datasheet }) => { + const { t } = useTranslation("DatastoreManageStorage"); + + const queryClient = useQueryClient(); + + const isLastUpload = (uploadList: Upload[]): boolean => { + return uploadList.length === 1 && nbPublications === 0; + }; + + const deleteUnfinishedUpload = useMutation({ + mutationFn: (uploadId: string) => api.upload.remove(datastoreId, uploadId), + onSuccess(uploadId) { + queryClient.setQueryData(RQKeys.datastore_datasheet(datastoreId, datasheet.name), (datasheet: { upload_list: Upload[] }) => { + return { + ...datasheet, + upload_list: datasheet.upload_list.filter((upload) => upload._id !== uploadId), + }; + }); + }, + }); + return ( <>
@@ -21,32 +52,92 @@ const UnfinishedUploadList: FC = ({ datastoreId, uplo
- {uploadList?.map((upload) => ( -
-
-
- {upload.name} - + {uploadList?.map((upload) => { + const integrationProgress = JSON.parse(upload.tags.integration_progress || "{}"); + const steps = Object.entries(integrationProgress); + const failureCase = steps.some(([, status]) => status === "failed"); + + return ( +
+
+
+ {upload.name} + {failureCase ? ( + + ) : ( + + )} +
-
-
-
- - +
+
+ {failureCase ? ( + <> + + + + ) : ( + <> + + + + )} +
+
+
+ ); + })} + {deleteUnfinishedUpload.isPending && ( + +
+
+ +
{t("storage.upload.deletion.in_progress")}
-
- ))} + + )} ); }; diff --git a/assets/entrepot/pages/datasheet/DatasheetView/DatasheetView.tsx b/assets/entrepot/pages/datasheet/DatasheetView/DatasheetView.tsx index 9272596b..c9c49522 100644 --- a/assets/entrepot/pages/datasheet/DatasheetView/DatasheetView.tsx +++ b/assets/entrepot/pages/datasheet/DatasheetView/DatasheetView.tsx @@ -31,6 +31,11 @@ const deleteDataConfirmModal = createModal({ isOpenedByDefault: false, }); +export const deleteDeliveryConfirmModal = createModal({ + id: "delete-delivery-confirm-modal", + isOpenedByDefault: false, +}); + export enum DatasheetViewActiveTabEnum { Metadata = "metadata", Dataset = "dataset", @@ -260,6 +265,26 @@ const DatasheetView: FC = ({ datastoreId, datasheetName }) = , document.body )} + {createPortal( + datasheetDeleteMutation.mutate(), + priority: "primary", + }, + ]} + > + En supprimant cette livraison, la fiche de données {datasheetName} sera supprimée. + , + document.body + )} ); diff --git a/assets/router/router.ts b/assets/router/router.ts index e897c482..1983ec44 100644 --- a/assets/router/router.ts +++ b/assets/router/router.ts @@ -147,7 +147,7 @@ const routeDefs = { uploadDataId: param.path.string, datasheetName: param.query.optional.string, }, - (p) => `${appRoot}/entrepot/${p.datastoreId}/donnees/${p.uploadDataId}/rapport` + (p) => `${appRoot}/entrepot/${p.datastoreId}/livraisons/${p.uploadDataId}/rapport` ), // Creer et publier un service WFS