From 5114e6dab2db994e581150740e274d7cc54bf2ac Mon Sep 17 00:00:00 2001 From: Simen Fivelstad Smaaberg <66635118+simensma-fresh@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:25:09 -0700 Subject: [PATCH] [MDS-6148] Fixed invalid date / missing create_user in spatial file bundle upload table (#3231) MDS-6148 Fixed invalid date / missing create_user in spatial file bundle upload table --- .../spatial/AddSpatialDocumentsModal.tsx | 2 +- .../spatial/SpatialDocumentTable.tsx | 21 +++++++++++++++++-- .../AddSpatialDocumentsModal.spec.tsx.snap | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/services/common/src/components/documents/spatial/AddSpatialDocumentsModal.tsx b/services/common/src/components/documents/spatial/AddSpatialDocumentsModal.tsx index 170d181aa1..b7af6d28c3 100644 --- a/services/common/src/components/documents/spatial/AddSpatialDocumentsModal.tsx +++ b/services/common/src/components/documents/spatial/AddSpatialDocumentsModal.tsx @@ -165,7 +165,7 @@ const AddSpatialDocumentsModal: FC = ({ onRemoveFile={handleRemoveFile} component={RenderFileUpload} maxFileSize="400MB" - label="Upload shapefiles" + label="Upload Spatial File" abbrevLabel listedFileTypes={["spatial"]} required diff --git a/services/common/src/components/documents/spatial/SpatialDocumentTable.tsx b/services/common/src/components/documents/spatial/SpatialDocumentTable.tsx index 1831cfcdbd..9f409d08ce 100644 --- a/services/common/src/components/documents/spatial/SpatialDocumentTable.tsx +++ b/services/common/src/components/documents/spatial/SpatialDocumentTable.tsx @@ -1,5 +1,5 @@ import React, { FC, useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { GenericDocTableProps } from "@mds/common/interfaces/document/documentTableProps.interface"; import CoreTable from "../../common/CoreTable"; import { uploadDateColumn, uploadedByColumn } from "../DocumentColumns"; @@ -16,6 +16,8 @@ import { groupSpatialBundles } from "@mds/common/redux/slices/spatialDataSlice"; import { downloadFileFromDocumentManager } from "@mds/common/redux/utils/actionlessNetworkCalls"; import { ISpatialBundle } from "@mds/common/interfaces/document/spatialBundle.interface"; import { IMineDocument } from "@mds/common/interfaces"; +import { getFormattedUserName } from "@mds/common/redux/selectors/authenticationSelectors"; +import moment from "moment"; interface SpatialDocumentTableProps extends GenericDocTableProps { documents: IMineDocument[]; @@ -26,9 +28,24 @@ const SpatialDocumentTable: FC = ({ documents, catego const dispatch = useDispatch(); const [isCompressionModalVisible, setIsCompressionModalVisible] = useState(false); const [spatialBundles, setSpatialBundles] = useState([]); + const username = useSelector(getFormattedUserName); const handleGetSpatialBundles = async () => { - const newSpatialBundles = groupSpatialBundles(documents); + // Provide default upload_date / create_user for new documents so they don't show + // up as emtpy columns in the table + const docs = documents.map((doc) => { + if (doc.mine_document_guid) { + return doc; + } + + return { + ...doc, + upload_date: doc.upload_date ?? moment().toISOString(), + create_user: doc.create_user ?? username, + }; + }); + + const newSpatialBundles = groupSpatialBundles(docs); setSpatialBundles(newSpatialBundles); }; diff --git a/services/common/src/components/documents/spatial/__snapshots__/AddSpatialDocumentsModal.spec.tsx.snap b/services/common/src/components/documents/spatial/__snapshots__/AddSpatialDocumentsModal.spec.tsx.snap index d5a6e2274e..7027e14b2f 100644 --- a/services/common/src/components/documents/spatial/__snapshots__/AddSpatialDocumentsModal.spec.tsx.snap +++ b/services/common/src/components/documents/spatial/__snapshots__/AddSpatialDocumentsModal.spec.tsx.snap @@ -159,7 +159,7 @@ exports[`AddSpatialDocumentsModal renders properly 1`] = ` title="" > - Upload shapefiles + Upload Spatial File