From 0b9b4a3313f0c931a29bb669da1827a415ae06c4 Mon Sep 17 00:00:00 2001 From: Colin Slater Date: Fri, 6 Dec 2024 00:22:22 -0300 Subject: [PATCH] Sort per-plot-type page by dataId. --- app/plot/[repo]/[collection]/[plotName]/page.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/plot/[repo]/[collection]/[plotName]/page.js b/app/plot/[repo]/[collection]/[plotName]/page.js index e825437..32bf9f4 100644 --- a/app/plot/[repo]/[collection]/[plotName]/page.js +++ b/app/plot/[repo]/[collection]/[plotName]/page.js @@ -29,10 +29,23 @@ export default async function Collection({params, searchParams}) { const collectionData = await GetSummary(repo, collection) - const plotEntries = findPlotEntries(collectionData, plotName) + const dataIdSortFunc = (a, b) => { + const dataIdA = JSON.parse(a.dataId) + const dataIdB = JSON.parse(b.dataId) + if('tract' in dataIdA && 'tract' in dataIdB) { + return dataIdA.tract - dataIdB.tract + } else if('visit' in dataIdA && 'visit' in dataIdB) { + return dataIdA.visit - dataIdB.visit + } else if('band' in dataIdA && 'band' in dataIdB) { + const bandsOrder = ['u', 'g', 'r', 'i', 'z', 'y'] + return bandsOrder.indexOf(dataIdA.band) - bandsOrder.indexOf(dataIdB.band) + } + return 0 + } + + const plotEntries = findPlotEntries(collectionData, plotName).sort(dataIdSortFunc) const encodeDataId = (id) => { - /* return encodeURIComponent(JSON.stringify(JSON.parse(id.trim()))) */ return encodeURIComponent(id.trim()) }