From fe719fb88948b5851cb2cd252c81014470cb9cd9 Mon Sep 17 00:00:00 2001 From: Raff Viglianti Date: Wed, 6 Nov 2024 15:32:48 -0500 Subject: [PATCH] fixes in pagination and display/order of fields --- src/pages/search.tsx | 21 ++++--- src/templates/collection.tsx | 119 +++++++++++------------------------ 2 files changed, 48 insertions(+), 92 deletions(-) diff --git a/src/pages/search.tsx b/src/pages/search.tsx index 56822bf6b..8fafa05a4 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -37,25 +37,25 @@ const Results = ({results, fieldLabels, start}: ResultProps) => { {d.collection_description && {getLabel('collection_description')}: - {d.collection_description} + {d.collection_description} } {d.scd_publish_status !== "collection-owner-title-description-only" && <> - {d.physical_formats && + {(d.physical_formats || []).length > 0 && {getLabel('physical_formats')}: - {d.physical_formats} + {d.physical_formats?.join("; ")} } {d.extent && {getLabel('extent')}: - {d.extent} + {d.extent} } {d.finding_aid_url && {getLabel('finding_aid_url')}: - View on {new URL(faURL).hostname} + View on {new URL(faURL).hostname} } } {getLabel('collection_holder_name')}: - {d.collection_holder_name} + {d.collection_holder_name} @@ -73,10 +73,6 @@ const SearchPage: React.FC = ({data}) => { const results = (data as Queries.qSearchPageQuery).allAirtableScdItems.nodes const [currentPage, setCurrentPage] = React.useState(1) const [resultsPerPage, setResultsPerPage] = React.useState(20) - const startIndex = (currentPage - 1) * resultsPerPage - const endIndex = startIndex + resultsPerPage - const totalPages = Math.ceil(results.length / resultsPerPage) - const [sortOrder, setSortOrder] = React.useState("asc"); const [facets, setFacets] = React.useState([]); @@ -110,6 +106,11 @@ const SearchPage: React.FC = ({data}) => { return b.data!.collection_title!.localeCompare(a.data!.collection_title!) } }) + + const totalPages = Math.ceil(facetedResults.length / resultsPerPage) + const startIndex = (currentPage - 1) * resultsPerPage + const endIndex = Math.min(startIndex + resultsPerPage, facetedResults.length) + const paginatedResults = facetedResults.slice(startIndex, endIndex) // Update component with existing query parameters on load diff --git a/src/templates/collection.tsx b/src/templates/collection.tsx index 4f916a33c..bd5e41b29 100644 --- a/src/templates/collection.tsx +++ b/src/templates/collection.tsx @@ -23,11 +23,22 @@ const Collection: React.FC = ({pageContext}) => { const subjects = d.subjects || [] const formats = d.physical_formats || [] const langs = d.languages || [] + const contentCats = d.collection_content_category || [] + const holderCats = d.collection_holder_category || [] + const invDesc = d.inventory_description || [] + const creators = d.creators || [] const loc = [] d.collection_holder_city ? loc.push(d.collection_holder_city) : false; d.collection_holder_state ? loc.push(d.collection_holder_state) : false; d.collection_holder_country ? loc.push(d.collection_holder_country) : false; + const Field = ({label, value}: {label: string, value: string}) => { + return + {getLabel(label)}: + {value} + + } + return (
@@ -39,98 +50,42 @@ const Collection: React.FC = ({pageContext}) => {

« Back to search

- {d.collection_description && - - - } { // additional fields for public entries. d.scd_publish_status !== "collection-owner-title-description-only" && <> - {d.record_type && - - - } - {ctypes.length > 0 && + {d.record_type && } + {contentCats.length > 0 && } + } + {d.collection_description && } + { // additional fields for public entries. + d.scd_publish_status !== "collection-owner-title-description-only" && <> + {holderCats && } + } + + { // additional fields for public entries. + d.scd_publish_status !== "collection-owner-title-description-only" && <> - - + + - } - {d.collection_content_category && - - - } - {d.collection_holder_category && - - - } - {d.extent && - - - } - {d.dates && - - - } - {d.historical_relevance && - - - } - {subjects.length > 0 && - - - - - } - {d.creators && - - - } - {formats.length > 0 && - - - } - {langs.length > 0 && - - - - - } + {ctypes.length > 0 && } + {d.dates && } + {d.extent && } + {d.historical_relevance && } + {subjects.length > 0 && } + {creators.length > 0 && } + {formats.length > 0 && } + {d.access_statement && } {d.finding_aid_url && - + } - {d.supporting_documentation && - - - - - } - {d.inventory_description && - - - - - } {d.collection_catalog_url && - - } - - } - - - - - { // additional fields for public entries. - d.scd_publish_status !== "collection-owner-title-description-only" && <> - - - - - {d.access_statement && - - + } + {d.supporting_documentation && } + {langs.length > 0 && } + {invDesc.length > 0 && } }
{getLabel("collection_description")}:{d.collection_description}
{getLabel("record_type")}:{d.record_type}
{getLabel("content_types")}:{ctypes.join("; ")}Location:{loc.join(", ")}
{getLabel("collection_content_category")}:{d.collection_content_category}
{getLabel("collection_holder_category")}:{d.collection_holder_category}
{getLabel("extent")}:{d.extent}
{getLabel("dates")}:{d.dates}
{getLabel("historical_relevance")}:{d.historical_relevance}
{getLabel("subjects")}:{subjects.join("; ")}
{getLabel("creators")}:{d.creators}
{getLabel("physical_formats")}:{formats}
{getLabel("languages")}:{langs.join("; ")}
{getLabel("finding_aid_url")}:View on {new URL(faURL).hostname}View on {new URL(faURL).hostname}
{getLabel("supporting_documentation")}:{d.supporting_documentation}
{getLabel("inventory_description")}:{d.inventory_description}
Online catalog:View on {new URL(catURL).hostname}
Repository/Collector:{d.collection_holder_name}
Location:{loc.join(", ")}
{getLabel("access_statement")}:{d.access_statement}View on {new URL(catURL).hostname}