Skip to content

Commit

Permalink
fix: corrections et amélioration de la mise à jour des statuts #588
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrousseau1 committed Jan 14, 2025
1 parent 0ca3acc commit 8ebdfc8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,19 @@ const DatasheetUploadIntegrationDialog: FC<DatasheetUploadIntegrationDialogProps
buttons={[
{
children: "Consulter la fiche de données",
linkProps: routes.datastore_datasheet_view({
datastoreId,
datasheetName: uploadQuery.data?.tags.datasheet_name,
activeTab: DatasheetViewActiveTabEnum.Dataset,
}).link,
onClick: () => {
uploadQuery.data?.tags.datasheet_name &&
(queryClient.refetchQueries({
queryKey: RQKeys.datastore_datasheet(datastoreId, uploadQuery.data?.tags.datasheet_name),
}),
routes
.datastore_datasheet_view({
datastoreId,
datasheetName: uploadQuery.data?.tags.datasheet_name,
activeTab: DatasheetViewActiveTabEnum.Dataset,
})
.push());
},
},
]}
inlineLayoutWhen="always"
Expand All @@ -211,11 +219,19 @@ const DatasheetUploadIntegrationDialog: FC<DatasheetUploadIntegrationDialogProps
buttons={[
{
children: "Consulter la fiche de données",
linkProps: routes.datastore_datasheet_view({
datastoreId,
datasheetName: uploadQuery.data?.tags.datasheet_name,
activeTab: DatasheetViewActiveTabEnum.Dataset,
}).link,
onClick: () => {
uploadQuery.data?.tags.datasheet_name &&
(queryClient.refetchQueries({
queryKey: RQKeys.datastore_datasheet(datastoreId, uploadQuery.data?.tags.datasheet_name),
}),
routes
.datastore_datasheet_view({
datastoreId,
datasheetName: uploadQuery.data?.tags.datasheet_name,
activeTab: DatasheetViewActiveTabEnum.Dataset,
})
.push());
},
},
]}
inlineLayoutWhen="always"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { fr } from "@codegouvfr/react-dsfr";
import Button from "@codegouvfr/react-dsfr/Button";
import { FC, memo, useMemo } from "react";
import { symToStr } from "tsafe/symToStr";
import { useQuery } from "@tanstack/react-query";

import api from "../../../../api";
import RQKeys from "../../../../../modules/entrepot/RQKeys";
import { Upload } from "../../../../../@types/app";
import { CartesApiException } from "../../../../../modules/jsonFetch";
import { type DatasheetDetailed } from "../../../../../@types/app";
import { routes } from "../../../../../router/router";
import PyramidVectorList from "./PyramidVectorList/PyramidVectorList";
Expand All @@ -22,14 +17,9 @@ type DataListTabProps = {

const DatasetListTab: FC<DataListTabProps> = ({ datastoreId, datasheet }) => {
// TODO : il y en aura d'autres types de données aussi (pyramid vector, raster, etc)
const uploadListQuery = useQuery<Upload[], CartesApiException>({
queryKey: RQKeys.datastore_upload_list(datastoreId),
queryFn: ({ signal }) => api.upload.getList(datastoreId, undefined, { signal }),
staleTime: 60000,
});
// liste des uploads/livraisons dont l'intégration en base de données n'a pas réussi ou n'a pas terminé
const unfinishedUploads = useMemo(() => {
return uploadListQuery.data?.filter((upload) => {
return datasheet.upload_list?.filter((upload) => {
if (upload.tags.datasheet_name !== datasheet.name) {
return false;
}
Expand All @@ -39,7 +29,7 @@ const DatasetListTab: FC<DataListTabProps> = ({ datastoreId, datasheet }) => {
const integrationProgress = JSON.parse(upload.tags.integration_progress);
return ["waiting"].includes(Object.values(integrationProgress)?.[2] as string);
});
}, [uploadListQuery.data, datasheet.name]);
}, [datasheet]);

const nbPublications =
(datasheet.vector_db_list?.length || 0) + (datasheet.pyramid_vector_list?.length || 0) + (datasheet.pyramid_raster_list?.length || 0);
Expand All @@ -54,7 +44,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} nbPublications={nbPublications} />
<UnfinishedUploadList
datastoreId={datastoreId}
uploadList={unfinishedUploads}
nbPublications={nbPublications}
datasheetName={datasheet.name}
/>
</div>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { fr } from "@codegouvfr/react-dsfr";
import Button from "@codegouvfr/react-dsfr/Button";
import { FC, memo, useState } from "react";
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 { routes } from "../../../../../router/router";
import { Upload } from "../../../../../@types/app";
import { type DatasheetDetailed, Upload } from "../../../../../@types/app";
import ReportStatusBadge from "../../../data_details/ReportTab/ReportStatusBadge";
import { deleteUploadConfirmModal } from "../DatasheetView/DatasheetView";
import Wait from "../../../../../components/Utils/Wait";
Expand All @@ -18,9 +18,10 @@ type UnfinishedUploadListProps = {
datastoreId: string;
uploadList?: Upload[];
nbPublications: number;
datasheetName: string;
};

const UnfinishedUploadList: FC<UnfinishedUploadListProps> = ({ datastoreId, uploadList, nbPublications }) => {
const UnfinishedUploadList: FC<UnfinishedUploadListProps> = ({ datastoreId, uploadList, nbPublications, datasheetName }) => {
const { t } = useTranslation("DatastoreManageStorage");

const queryClient = useQueryClient();
Expand All @@ -29,19 +30,16 @@ const UnfinishedUploadList: FC<UnfinishedUploadListProps> = ({ datastoreId, uplo
return uploadList.length === 1 && nbPublications === 0;
};

const [currentUploadId, setCurrentUploadId] = useState<string | undefined>();

const deleteUnfinishedUpload = useMutation({
mutationFn: (uploadId: string) => api.upload.remove(datastoreId, uploadId),
onSuccess() {
queryClient.setQueryData(RQKeys.datastore_upload_list(datastoreId), (uploadsList: Upload[]) => {
return uploadsList.filter((annexe) => annexe._id !== currentUploadId);
onSuccess(uploadId) {
queryClient.setQueryData(RQKeys.datastore_datasheet(datastoreId, datasheetName), (datasheet: DatasheetDetailed) => {
return {
...datasheet,
upload_list: datasheet.upload_list?.filter((upload) => upload._id !== uploadId) ?? [],
};
});

setCurrentUploadId(undefined);
},
onError() {
setCurrentUploadId(undefined);
queryClient.refetchQueries({ queryKey: RQKeys.datastore_datasheet(datastoreId, datasheetName) });
},
});

Expand Down Expand Up @@ -105,7 +103,6 @@ const UnfinishedUploadList: FC<UnfinishedUploadListProps> = ({ datastoreId, uplo
iconId="fr-icon-delete-fill"
priority="secondary"
onClick={() => {
setCurrentUploadId(upload._id);
if (isLastUpload(uploadList)) {
deleteUploadConfirmModal.open();
} else {
Expand Down

0 comments on commit 8ebdfc8

Please sign in to comment.