Skip to content

Commit

Permalink
Re-scope sortedDates usage
Browse files Browse the repository at this point in the history
sortedDates is not used if the resource is not versioned. The premature
null check in the case of unversioned resources resulted in an error on
the groups page, which does not use versioned resources.
  • Loading branch information
victorlin committed Dec 9, 2024
1 parent ea0c570 commit dbf69a6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions static-site/src/components/ListResources/useDataFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,12 @@ function partitionByPathogen(
versioned: boolean,
) {
return Object.entries(pathVersions).reduce((store: Record<string, Resource[]>, [name, dates]) => {
const sortedDates = [...dates].sort();

const nameParts = name.split('/');

if (nameParts[0] === undefined) {
throw new InternalError(`Name is not properly formatted: '${name}'`);
}

if (sortedDates[0] === undefined) {
throw new InternalError("Resource does not have any dates.");
}

const groupName = nameParts[0];

const resourceDetails: Resource = {
Expand All @@ -85,6 +79,11 @@ function partitionByPathogen(
url: `/${pathPrefix}${name}`,
};
if (versioned) {
const sortedDates = [...dates].sort();
if (sortedDates[0] === undefined) {
throw new InternalError("Resource does not have any dates.");
}

resourceDetails.lastUpdated = sortedDates.at(-1);
resourceDetails.firstUpdated = sortedDates[0];
resourceDetails.dates = sortedDates;
Expand Down

0 comments on commit dbf69a6

Please sign in to comment.