Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/WC-166 Sort publication requests by descending date #1014

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading