Skip to content

Commit

Permalink
sort pulication requests in descending date order (#1014)
Browse files Browse the repository at this point in the history
Co-authored-by: Shayan Khan <[email protected]>
  • Loading branch information
jarosenb and shayanaijaz authored Dec 10, 2024
1 parent 7787b4a commit 761c23d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -27,6 +40,7 @@ const DataFilesPublicationRequestModal = () => {
);
}, ''),
Submitted: formatDateTime(new Date(request.created_at)),
_order: index,
};

const heading = `Publication Request ${index + 1}`;
Expand Down
53 changes: 36 additions & 17 deletions client/src/components/_common/DescriptionList/DescriptionList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<dl className={`${className} ${containerStyleNames}`} data-testid="list">
{Object.entries(data).map(([key, value]) => (
<React.Fragment key={key}>
<dt className={styles.key} data-testid="key">
{key}
</dt>
{Array.isArray(value) ? (
value.map((val) => (
<dd className={valueClassName} data-testid="value" key={uuidv4()}>
{val}
{Object.entries(data)
.sort(compareFn)
.filter(([key, _]) => !key.startsWith('_'))
.map(([key, value]) => (
<React.Fragment key={key}>
<dt className={styles.key} data-testid="key">
{key}
</dt>
{Array.isArray(value) ? (
value.map((val) => (
<dd
className={valueClassName}
data-testid="value"
key={uuidv4()}
>
{val}
</dd>
))
) : (
<dd className={valueClassName} data-testid="value">
{value}
</dd>
))
) : (
<dd className={valueClassName} data-testid="value">
{value}
</dd>
)}
</React.Fragment>
))}
)}
</React.Fragment>
))}
</dl>
);
};
Expand Down

0 comments on commit 761c23d

Please sign in to comment.