From dbf69a6603f22d8cfe445335fba1d235abce13b2 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:07:35 -0800 Subject: [PATCH] Re-scope sortedDates usage 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. --- .../src/components/ListResources/useDataFetch.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/static-site/src/components/ListResources/useDataFetch.ts b/static-site/src/components/ListResources/useDataFetch.ts index 54604d539..1f064fa5c 100644 --- a/static-site/src/components/ListResources/useDataFetch.ts +++ b/static-site/src/components/ListResources/useDataFetch.ts @@ -63,18 +63,12 @@ function partitionByPathogen( versioned: boolean, ) { return Object.entries(pathVersions).reduce((store: Record, [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 = { @@ -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;