From 761c23d224b501f7d33752cccf30e831005b217d Mon Sep 17 00:00:00 2001 From: Jake Rosenberg Date: Tue, 10 Dec 2024 12:59:39 -0600 Subject: [PATCH] sort pulication requests in descending date order (#1014) Co-authored-by: Shayan Khan --- .../DataFilesPublicationRequestModal.jsx | 16 +++++- .../DescriptionList/DescriptionList.jsx | 53 +++++++++++++------ 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/client/src/components/DataFiles/DataFilesModals/DataFilesPublicationRequestModal.jsx b/client/src/components/DataFiles/DataFilesModals/DataFilesPublicationRequestModal.jsx index 979b5f65b..87e8e97f4 100644 --- a/client/src/components/DataFiles/DataFilesModals/DataFilesPublicationRequestModal.jsx +++ b/client/src/components/DataFiles/DataFilesModals/DataFilesPublicationRequestModal.jsx @@ -13,10 +13,23 @@ const DataFilesPublicationRequestModal = () => { const { publicationRequests } = useSelector((state) => state.files.modalProps.publicationRequest) || []; + const compareFn = (req1, req2) => { + // sort more recent requests first + const date1 = new Date(req1.created_at); + const date2 = new Date(req2.created_at); + if (date1 < date2) { + return 1; + } + if (date1 > date2) { + return -1; + } + return 0; + }; + useEffect(() => { const data = {}; - publicationRequests?.forEach((request, index) => { + publicationRequests?.sort(compareFn).forEach((request, index) => { const publicationRequestDataObj = { Status: request.status, Reviewers: request.reviewers.reduce((acc, reviewer, index) => { @@ -27,6 +40,7 @@ const DataFilesPublicationRequestModal = () => { ); }, ''), Submitted: formatDateTime(new Date(request.created_at)), + _order: index, }; const heading = `Publication Request ${index + 1}`; diff --git a/client/src/components/_common/DescriptionList/DescriptionList.jsx b/client/src/components/_common/DescriptionList/DescriptionList.jsx index 86dc7a039..0cf30f56d 100644 --- a/client/src/components/_common/DescriptionList/DescriptionList.jsx +++ b/client/src/components/_common/DescriptionList/DescriptionList.jsx @@ -33,26 +33,45 @@ const DescriptionList = ({ className, data, density, direction }) => { shouldTruncateValues ? 'value-truncated' : '' }`; + const compareFn = (entry1, entry2) => { + const [, val1] = entry1; + const [, val2] = entry2; + if ((val1._order ?? 0) < (val2._order ?? 0)) { + return -1; + } + if ((val1._order ?? 0) > (val2._order ?? 0)) { + return 1; + } + return 0; + }; + return (
- {Object.entries(data).map(([key, value]) => ( - -
- {key} -
- {Array.isArray(value) ? ( - value.map((val) => ( -
- {val} + {Object.entries(data) + .sort(compareFn) + .filter(([key, _]) => !key.startsWith('_')) + .map(([key, value]) => ( + +
+ {key} +
+ {Array.isArray(value) ? ( + value.map((val) => ( +
+ {val} +
+ )) + ) : ( +
+ {value}
- )) - ) : ( -
- {value} -
- )} -
- ))} + )} + + ))}
); };