From 475deb11a4a83d5d4d675a167183426899c47919 Mon Sep 17 00:00:00 2001 From: Raff Viglianti Date: Mon, 4 Nov 2024 16:37:53 -0500 Subject: [PATCH] getting facets from airtable --- gatsby-config.ts | 4 ++-- gatsby-node.ts | 12 +++++++++--- src/pages/search.tsx | 43 ++++++++++++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/gatsby-config.ts b/gatsby-config.ts index 0abd6d8fd..dd109c2ed 100644 --- a/gatsby-config.ts +++ b/gatsby-config.ts @@ -59,8 +59,8 @@ const config: GatsbyConfig = { { baseId, tableName: `Metadata Dictionary NEW`, - tableView: `SCD Fields - Public Portal (Revised)`, - queryName: `ScdMetadataFields`, + tableView: `SCD Fields - Public Facets`, + queryName: `ScdFacets`, separateNodeType: true }, ] diff --git a/gatsby-node.ts b/gatsby-node.ts index dc50cd61e..19b2f4159 100644 --- a/gatsby-node.ts +++ b/gatsby-node.ts @@ -26,10 +26,10 @@ async function makeCollectionPages({createPage, graphql}: IMakePages) { collection_holder_name collection_title collection_description - collection_extent + extent collectionFormats content_types - collection_finding_aid_url + finding_aid_url collection_holder_country collection_holder_state collection_holder_city @@ -38,7 +38,13 @@ async function makeCollectionPages({createPage, graphql}: IMakePages) { languages collection_notes collection_usage_statement - collection_website_url + website_url + record_type + collection_holder_category + collection_content_category + physical_formats + creators + subjects } } } diff --git a/src/pages/search.tsx b/src/pages/search.tsx index fce432bf5..9e1f1091b 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -1,6 +1,5 @@ import * as React from "react" import { graphql, Link, type HeadFC, type PageProps } from "gatsby" -import { FieldsMap } from "../fieldsMap" import Layout from "../components/Layout" import Button from "../components/Button" import Pagination from "../components/Pagination" @@ -19,8 +18,8 @@ const Results = ({results, start}: ResultProps) => (
{results.map((r, i) => { const d = r.data! - d.collection_finding_aid_url - 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}` + 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

@@ -43,11 +42,11 @@ const Results = ({results, start}: ResultProps) => ( Format: {d.collectionFormats} } - {d.collection_extent && + {d.extent && Extent: - {d.collection_extent} + {d.extent} } - {d.collection_finding_aid_url && + {d.finding_aid_url && Online finding aid: View on {new URL(faURL).hostname} } @@ -79,13 +78,13 @@ const SearchPage: React.FC = ({data}) => { const [sortOrder, setSortOrder] = React.useState("asc"); const [facets, setFacets] = React.useState([]); - const facetFields = new Map([ - ["Content type", "content_types"], - ["Format", "collectionFormats"], - ["Repository/Collector", "collection_holder_name"], - ["Country (Location)", "collection_holder_country"], - ["State (Location)", "collection_holder_state"] - ]) + const facetsFromAirTable = (data as Queries.qSearchPageQuery).allAirtableScdFacets.nodes || [] + + const facetData = facetsFromAirTable.map(f => + [f.data!.scd_field_label_revised, f.data!.Fields!.replace('-', '_')] as [string, string] + ) + + const facetFields = new Map(facetData) // apply facets const facetedResults = facets.length > 0 ? results.filter(r => { @@ -338,12 +337,26 @@ export const query = graphql` collection_description collection_holder_name collection_title - collection_extent + extent collectionFormats content_types - collection_finding_aid_url + finding_aid_url collection_holder_country collection_holder_state + record_type + collection_holder_category + collection_content_category + physical_formats + creators + subjects + } + } + } + allAirtableScdFacets { + nodes { + data { + scd_field_label_revised + Fields } } }