From ed27afbb3e36586f3af2ba08cfa88eb3b1c7e677 Mon Sep 17 00:00:00 2001 From: John SJ Anderson Date: Thu, 6 Jun 2024 15:20:30 -0700 Subject: [PATCH] Replace Datasets DatasetSelect component on groups page with ListResources [#870] * conditionalize display of "List known update" in IndividualResource TooltipWrapper * conditionalize display of "Most recent snapshot" in ResourceGroup * conditionalize use of Showcase in ListResources based on length of showcaseCards prop * conditionalize use of SortOptions in ListResources based on initial group lacking a lastUpdated field * extend groups page with custom useDataFetch callback to hit charon/getAvailableResources endpoint --- .../ListResources/IndividualResource.tsx | 4 +- .../ListResources/ResourceGroup.tsx | 2 +- .../src/components/ListResources/index.tsx | 10 ++- static-site/src/pages/groups.jsx | 65 ++++++++++--------- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/static-site/src/components/ListResources/IndividualResource.tsx b/static-site/src/components/ListResources/IndividualResource.tsx index 3e7d276ae..22579e746 100644 --- a/static-site/src/components/ListResources/IndividualResource.tsx +++ b/static-site/src/components/ListResources/IndividualResource.tsx @@ -158,12 +158,14 @@ export const IndividualResource = ({resource, isMobile}: IndividualResourceProps ) } + const description = resource.nVersions ? `Last known update on ${resource.lastUpdated}` : ""; + return ( - + setModalResource(resource)}> diff --git a/static-site/src/components/ListResources/ResourceGroup.tsx b/static-site/src/components/ListResources/ResourceGroup.tsx index 82a244ae6..175e7e3aa 100644 --- a/static-site/src/components/ListResources/ResourceGroup.tsx +++ b/static-site/src/components/ListResources/ResourceGroup.tsx @@ -49,7 +49,7 @@ const ResourceGroupHeader = ({group, isMobile, setCollapsed, collapsible, isColl (however there may have been a more recent update since we indexed the data)'}> - {`Most recent snapshot: ${group.lastUpdated}`} + {group.lastUpdated !== "" && `Most recent snapshot: ${group.lastUpdated}`} )} diff --git a/static-site/src/components/ListResources/index.tsx b/static-site/src/components/ListResources/index.tsx index c8a0da78b..0409ad680 100644 --- a/static-site/src/components/ListResources/index.tsx +++ b/static-site/src/components/ListResources/index.tsx @@ -76,11 +76,17 @@ function ListResources({ return ( - + { showcaseCards.length > 0 && ( + + )} - + { groups[0].lastUpdated !== "" && ( + + ) || ( + + )} diff --git a/static-site/src/pages/groups.jsx b/static-site/src/pages/groups.jsx index 1db066d54..3810b2e5c 100644 --- a/static-site/src/pages/groups.jsx +++ b/static-site/src/pages/groups.jsx @@ -4,23 +4,39 @@ import { SmallSpacer, HugeSpacer, FlexCenter } from "../layouts/generalComponent import * as splashStyles from "../components/splash/styles"; import { fetchAndParseJSON } from "../util/datasetsHelpers"; import DatasetSelect from "../components/Datasets/dataset-select"; +import ListResources from "../components/ListResources/index"; import { GroupCards } from "../components/splash/groupCards"; import GenericPage from "../layouts/generic-page"; import { UserContext } from "../layouts/userDataWrapper"; import { DataFetchErrorParagraph } from "../components/splash/errorMessages"; import { groupsTitle, GroupsAbstract } from "../../data/SiteConfig"; -const datasetColumns = ({isNarrative}) => [ - { - name: isNarrative ? "Narrative" : "Dataset", - value: (d) => d.request.replace("/groups/", "").replace(/\//g, " / "), - url: (d) => d.url - }, - { - name: "Group Name", - value: (d) => d.request.split("/")[2], - url: (d) => `/groups/${d.request.split("/")[2]}` - } +const sourceId = "charon/groups"; +async function parserCallBackFxn(response) { + const datasets = (await response.json()).datasets; + + // Use "" instead of fake date because downstream components can + // conditionalize display choices based on `== ""` or `!== ""` + const pathVersions = Object.assign( + ...datasets.map((ds) => ({ + [ds.request.replace(/^\/groups\//, "")]: [""] + })), + ); + + return { pathPrefix: "groups/", pathVersions }; +} + +const datasetColumns = [ + { + name: "Narrative", + value: (d) => d.request.replace("/groups/", "").replace(/\//g, " / "), + url: (d) => d.url, + }, + { + name: "Group Name", + value: (d) => d.request.split("/")[2], + url: (d) => `/groups/${d.request.split("/")[2]}`, + }, ]; const GroupListingInfo = () => { @@ -92,31 +108,22 @@ class GroupsPage extends React.Component { - - Available Datasets - - - - {`Note that this listing is refreshed every ~6 hours. - To see a current listing, visit the page for that group by clicking on that group's tile, above.`} - - - - {this.state.dataLoaded && ( - - )} + + + Available Narratives + {this.state.dataLoaded && ( + columns={datasetColumns}/> )} { this.state.errorFetchingData && }