From 504f3a9e4d1d706b05f15cc6a584c0c82be74fc2 Mon Sep 17 00:00:00 2001 From: Raff Viglianti Date: Tue, 5 Nov 2024 15:51:59 -0500 Subject: [PATCH] new fields --- gatsby-config.ts | 7 +++ gatsby-node.ts | 47 ++++++++++------ src/pages/search.tsx | 62 ++++++++++++--------- src/templates/collection.tsx | 105 +++++++++++++++++++++++++---------- 4 files changed, 147 insertions(+), 74 deletions(-) diff --git a/gatsby-config.ts b/gatsby-config.ts index dd109c2ed..bb1f25834 100644 --- a/gatsby-config.ts +++ b/gatsby-config.ts @@ -63,6 +63,13 @@ const config: GatsbyConfig = { queryName: `ScdFacets`, separateNodeType: true }, + { + baseId, + tableName: `Metadata Dictionary NEW`, + tableView: `SCD Fields - Public Portal (Revised)`, + queryName: `ScdFields`, + separateNodeType: true + }, ] } } diff --git a/gatsby-node.ts b/gatsby-node.ts index 19b2f4159..432409976 100644 --- a/gatsby-node.ts +++ b/gatsby-node.ts @@ -23,35 +23,45 @@ async function makeCollectionPages({createPage, graphql}: IMakePages) { data { collection_id scd_publish_status - collection_holder_name + record_type + collection_content_category collection_title collection_description - extent - collectionFormats + collection_holder_category + collection_holder_name + collection_holder_city + collection_holder_state + collection_holder_country content_types + dates + extent + historical_relevance + subjects + creators + physical_formats + access_statement finding_aid_url - collection_holder_country - collection_holder_state - collection_holder_city collection_catalog_url - inventory_description + supporting_documentation languages - collection_notes - collection_usage_statement - website_url - record_type - collection_holder_category - collection_content_category - physical_formats - creators - subjects + inventory_description + } + } + } + allAirtableScdFields { + nodes { + data { + Fields + scd_field_label_revised } } } } `) - const {nodes} = (results.data as Queries.qCollectionsQuery).allAirtableScdItems; + const r = results.data as Queries.qCollectionsQuery; + const {nodes} = r.allAirtableScdItems; + const fields = r.allAirtableScdFields.nodes; for (const node of nodes) { const collection = node.data @@ -59,7 +69,8 @@ async function makeCollectionPages({createPage, graphql}: IMakePages) { path: `/collections/${collection?.collection_id}/`, component: path.resolve(`./src/templates/collection.tsx`), context: { - ...collection + collection: {...collection}, + fields } }) } diff --git a/src/pages/search.tsx b/src/pages/search.tsx index 9e1f1091b..56822bf6b 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -8,19 +8,27 @@ import FacetAccordion from "../components/FacetAccordion" interface ResultProps { results: Queries.qSearchPageQuery["allAirtableScdItems"]["nodes"] + fieldLabels: Queries.qSearchPageQuery["allAirtableScdFields"]["nodes"] start: number } type PerPageValues = 10 | 20 | 50 | 100 type SortValues = "asc" | "desc" -const Results = ({results, start}: ResultProps) => ( -
+const Results = ({results, fieldLabels, start}: ResultProps) => { + const getLabel = (label: string) => { + const f = fieldLabels.find(field => field.data!.Fields!.replace(/-/g, "_") === label) + if (f) { + return f.data!.scd_field_label_revised + } + return label + } + + return (
{results.map((r, i) => { const d = r.data! d.finding_aid_url const faURL = d.finding_aid_url && d.finding_aid_url?.startsWith("http") ? d.finding_aid_url : `http://${d.finding_aid_url}` - const ctypes = d.content_types || [] return

{start + i}. {d.collection_title} @@ -28,39 +36,33 @@ const Results = ({results, start}: ResultProps) => ( {d.collection_description && - + } {d.scd_publish_status !== "collection-owner-title-description-only" && <> - {ctypes.length > 0 && - - - - - } - {d.collectionFormats && - - + {d.physical_formats && + + } {d.extent && - + } {d.finding_aid_url && - + } } - +
Description:{getLabel('collection_description')}: {d.collection_description}
Content type{ctypes.length > 1 ? 's': ''}:{ctypes.join("; ")}
Format:{d.collectionFormats}
{getLabel('physical_formats')}:{d.physical_formats}
Extent:{getLabel('extent')}: {d.extent}
Online finding aid:{getLabel('finding_aid_url')}: View on {new URL(faURL).hostname}
Repository/Collector:{getLabel('collection_holder_name')}: {d.collection_holder_name}

}) } -
-) +
) +} interface Facet { cat: string, val: string @@ -79,9 +81,10 @@ const SearchPage: React.FC = ({data}) => { const [facets, setFacets] = React.useState([]); const facetsFromAirTable = (data as Queries.qSearchPageQuery).allAirtableScdFacets.nodes || [] + const fieldsFromAirTable = (data as Queries.qSearchPageQuery).allAirtableScdFields.nodes || [] const facetData = facetsFromAirTable.map(f => - [f.data!.scd_field_label_revised, f.data!.Fields!.replace('-', '_')] as [string, string] + [f.data!.scd_field_label_revised, f.data!.Fields!.replace(/-/g, '_')] as [string, string] ) const facetFields = new Map(facetData) @@ -314,7 +317,7 @@ const SearchPage: React.FC = ({data}) => { ]} /> - + @@ -334,19 +337,18 @@ export const query = graphql` data { collection_id scd_publish_status + collection_title collection_description collection_holder_name - collection_title extent - collectionFormats - content_types + physical_formats finding_aid_url - collection_holder_country - collection_holder_state + record_type + collection_holder_state collection_holder_category collection_content_category - physical_formats + content_types creators subjects } @@ -360,6 +362,14 @@ export const query = graphql` } } } + allAirtableScdFields { + nodes { + data { + scd_field_label_revised + Fields + } + } + } } ` diff --git a/src/templates/collection.tsx b/src/templates/collection.tsx index f03078a58..4f916a33c 100644 --- a/src/templates/collection.tsx +++ b/src/templates/collection.tsx @@ -3,12 +3,25 @@ import { Link, type HeadFC, type PageProps } from "gatsby" import Layout from "../components/Layout" const Collection: React.FC = ({pageContext}) => { - const data = pageContext as Queries.qCollectionsQuery["allAirtableScdItems"]["nodes"][0]["data"] - const d = data! - const faURL = d.collection_finding_aid_url && d.collection_finding_aid_url.startsWith("http") ? d.collection_finding_aid_url : `http://${d.collection_finding_aid_url}` + const context = pageContext as { + collection: Queries.qCollectionsQuery["allAirtableScdItems"]["nodes"][0]["data"] + fields: Queries.qCollectionsQuery["allAirtableScdFields"]["nodes"] + } + + const getLabel = (label: string) => { + const f = context.fields.find(field => field.data!.Fields!.replace(/-/g, "_") === label) + if (f) { + return f.data!.scd_field_label_revised + } + return label + } + + const d = context.collection! + const faURL = d.finding_aid_url && d.finding_aid_url.startsWith("http") ? d.finding_aid_url : `http://${d.finding_aid_url}` const catURL = d.collection_catalog_url && d.collection_catalog_url.startsWith("http") ? d.collection_catalog_url : `http://${d.collection_catalog_url}` - const webURL = d.collection_website_url && d.collection_website_url.startsWith("http") ? d.collection_website_url : `http://${d.collection_website_url}` const ctypes = d.content_types || [] + const subjects = d.subjects || [] + const formats = d.physical_formats || [] const langs = d.languages || [] const loc = [] d.collection_holder_city ? loc.push(d.collection_holder_city) : false; @@ -27,47 +40,81 @@ const Collection: React.FC = ({pageContext}) => { {d.collection_description && - + } { // additional fields for public entries. d.scd_publish_status !== "collection-owner-title-description-only" && <> + {d.record_type && + + + } + {ctypes.length > 0 && - + - {d.collectionFormats && - - + } + {d.collection_content_category && + + } - {d.collection_extent && - - + {d.collection_holder_category && + + } - {langs.length > 0 && + {d.extent && + + + } + {d.dates && + + + } + {d.historical_relevance && + + + } + {subjects.length > 0 && - - + + } - {d.collection_notes && + {d.creators && + + + } + {formats.length > 0 && + + + } + {langs.length > 0 && - - + + } - {d.collection_finding_aid_url && - + {d.finding_aid_url && + } + {d.supporting_documentation && + + + + + } + {d.inventory_description && + + + + + } {d.collection_catalog_url && } - {d.collection_website_url && - - - } } @@ -80,12 +127,10 @@ const Collection: React.FC = ({pageContext}) => { - {d.collection_usage_statement && - - - - - } + {d.access_statement && + + + } }
Description:{getLabel("collection_description")}: {d.collection_description}
{getLabel("record_type")}:{d.record_type}
Content type{ctypes.length > 1 ? 's': ''}:{getLabel("content_types")}: {ctypes.join("; ")}
Format:{d.collectionFormats}
{getLabel("collection_content_category")}:{d.collection_content_category}
Extent:{d.collection_extent}
{getLabel("collection_holder_category")}:{d.collection_holder_category}
{getLabel("extent")}:{d.extent}
{getLabel("dates")}:{d.dates}
{getLabel("historical_relevance")}:{d.historical_relevance}
Language{langs.length > 1 ? 's': ''}:{langs.join("; ")}{getLabel("subjects")}:{subjects.join("; ")}
{getLabel("creators")}:{d.creators}
{getLabel("physical_formats")}:{formats}
Additional notes:{d.collection_notes}{getLabel("languages")}:{langs.join("; ")}
Online finding aid:
{getLabel("finding_aid_url")}: 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}
Collection website:View on {new URL(webURL).hostname}
Location: {loc.join(", ")}
Usage statement:{d.collection_usage_statement}
{getLabel("access_statement")}:{d.access_statement}