Skip to content

Commit

Permalink
feat: pouvoir supprimer une livraison en échec #588
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrousseau1 committed Dec 20, 2024
1 parent e23c6c4 commit 2caaef8
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ const DatasetListTab: FC<DataListTabProps> = ({ datastoreId, datasheet }) => {
{unfinishedUploads && unfinishedUploads.length > 0 && (
<div className={fr.cx("fr-grid-row", "fr-grid-row--center", "fr-grid-row--middle")}>
<div className={fr.cx("fr-col")}>
<UnfinishedUploadList datastoreId={datastoreId} uploadList={unfinishedUploads} />
<UnfinishedUploadList
datastoreId={datastoreId}
uploadList={unfinishedUploads}
nbPublications={datasheet.nb_publications}
datasheet={datasheet}
/>
</div>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnfinishedUploadListProps> = ({ datastoreId, uploadList }) => {

const UnfinishedUploadList: FC<UnfinishedUploadListProps> = ({ 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 (
<>
<div className={fr.cx("fr-grid-row")}>
Expand All @@ -21,32 +52,92 @@ const UnfinishedUploadList: FC<UnfinishedUploadListProps> = ({ datastoreId, uplo
</h5>
</div>

{uploadList?.map((upload) => (
<div key={upload._id} className={fr.cx("fr-grid-row", "fr-grid-row--middle", "fr-mt-2v")}>
<div className={fr.cx("fr-col")}>
<div className={fr.cx("fr-grid-row", "fr-grid-row--middle")}>
{upload.name}
<ReportStatusBadge status="FAILURE" className={fr.cx("fr-ml-2w")} />
{uploadList?.map((upload) => {
const integrationProgress = JSON.parse(upload.tags.integration_progress || "{}");
const steps = Object.entries(integrationProgress);
const failureCase = steps.some(([, status]) => status === "failed");

return (
<div key={upload._id} className={fr.cx("fr-grid-row", "fr-grid-row--middle", "fr-mt-2v")}>
<div className={fr.cx("fr-col")}>
<div className={fr.cx("fr-grid-row", "fr-grid-row--middle")}>
{upload.name}
{failureCase ? (
<ReportStatusBadge status="FAILURE" className={fr.cx("fr-ml-2w")} />
) : (
<ReportStatusBadge status="WAITING" className={fr.cx("fr-ml-2w")} />
)}
</div>
</div>
</div>

<div className={fr.cx("fr-col")}>
<div className={fr.cx("fr-grid-row", "fr-grid-row--right", "fr-grid-row--middle")}>
<Button
className={fr.cx("fr-mr-2w")}
linkProps={
routes.datastore_delivery_details({ datastoreId, uploadDataId: upload._id, datasheetName: upload.tags.datasheet_name }).link
}
>
{"Voir le rapport"}
</Button>
<Button iconId="fr-icon-delete-fill" priority="secondary">
{"Supprimer"}
</Button>
<div className={fr.cx("fr-col")}>
<div className={fr.cx("fr-grid-row", "fr-grid-row--right", "fr-grid-row--middle")}>
{failureCase ? (
<>
<Button
className={fr.cx("fr-mr-2w")}
linkProps={
routes.datastore_delivery_details({
datastoreId,
uploadDataId: upload._id,
datasheetName: upload.tags.datasheet_name,
}).link
}
>
{"Voir le rapport"}
</Button>
<Button
iconId="fr-icon-delete-fill"
priority="secondary"
onClick={() => {
if (isLastUpload(uploadList)) {
deleteDeliveryConfirmModal.open();
} else {
deleteUnfinishedUpload.mutate(upload._id);
}
}}
>
{"Supprimer"}
</Button>
</>
) : (
<>
<Button
className={fr.cx("fr-mr-2w")}
linkProps={routes.datastore_datasheet_upload_integration({ datastoreId, uploadId: upload._id }).link}
>
{"Reprendre l'intégration"}
</Button>
<Button
iconId="fr-icon-delete-fill"
priority="secondary"
onClick={() => {
if (isLastUpload(uploadList)) {
deleteDeliveryConfirmModal.open();
} else {
deleteUnfinishedUpload.mutate(upload._id);
}
}}
>
{"Supprimer"}
</Button>
</>
)}
</div>
</div>
</div>
);
})}
{deleteUnfinishedUpload.isPending && (
<Wait>
<div className={fr.cx("fr-container")}>
<div className={fr.cx("fr-grid-row", "fr-grid-row--middle")}>
<LoadingIcon className={fr.cx("fr-mr-2v")} />
<h6 className={fr.cx("fr-m-0")}>{t("storage.upload.deletion.in_progress")}</h6>
</div>
</div>
</div>
))}
</Wait>
)}
</>
);
};
Expand Down
25 changes: 25 additions & 0 deletions assets/entrepot/pages/datasheet/DatasheetView/DatasheetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -260,6 +265,26 @@ const DatasheetView: FC<DatasheetViewProps> = ({ datastoreId, datasheetName }) =
</deleteDataConfirmModal.Component>,
document.body
)}
{createPortal(
<deleteDeliveryConfirmModal.Component
title={`Voulez-vous supprimer la fiche de données ${datasheetName} ?`}
buttons={[
{
children: tCommon("no"),
doClosesModal: true,
priority: "secondary",
},
{
children: tCommon("yes"),
onClick: () => datasheetDeleteMutation.mutate(),
priority: "primary",
},
]}
>
<strong>En supprimant cette livraison, la fiche de données {datasheetName} sera supprimée.</strong>
</deleteDeliveryConfirmModal.Component>,
document.body
)}
</>
</DatastoreLayout>
);
Expand Down
2 changes: 1 addition & 1 deletion assets/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2caaef8

Please sign in to comment.