Skip to content

Commit

Permalink
Replace Datasets DatasetSelect component on groups page with ListReso…
Browse files Browse the repository at this point in the history
…urces [#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
  • Loading branch information
genehack committed Jun 7, 2024
1 parent 9c86ad1 commit ed27afb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,14 @@ export const IndividualResource = ({resource, isMobile}: IndividualResourceProps
)
}

const description = resource.nVersions ? `Last known update on ${resource.lastUpdated}` : "";

return (
<Container ref={ref}>

<FlexRow>

<TooltipWrapper description={`Last known update on ${resource.lastUpdated}`}>
<TooltipWrapper description={description}>
<ResourceLinkWrapper onShiftClick={() => setModalResource(resource)}>
<Name displayName={resource.displayName} href={resource.url} topOfColumn={topOfColumn}/>
</ResourceLinkWrapper>
Expand Down
2 changes: 1 addition & 1 deletion static-site/src/components/ListResources/ResourceGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ResourceGroupHeader = ({group, isMobile, setCollapsed, collapsible, isColl
<TooltipWrapper description={`The most recently updated datasets in this group were last updated on ${group.lastUpdated}` +
'<br/>(however there may have been a more recent update since we indexed the data)'}>
<span>
{`Most recent snapshot: ${group.lastUpdated}`}
{group.lastUpdated !== "" && `Most recent snapshot: ${group.lastUpdated}`}
</span>
</TooltipWrapper>
)}
Expand Down
10 changes: 8 additions & 2 deletions static-site/src/components/ListResources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ function ListResources({
return (
<ListResourcesContainer>

<Showcase cards={showcaseCards} setSelectedFilterOptions={setSelectedFilterOptions}/>
{ showcaseCards.length > 0 && (
<Showcase cards={showcaseCards} setSelectedFilterOptions={setSelectedFilterOptions}/>
)}

<Filter options={availableFilterOptions} selectedFilterOptions={selectedFilterOptions} setSelectedFilterOptions={setSelectedFilterOptions}/>

<SortOptions sortMethod={sortMethod} changeSortMethod={changeSortMethod}/>
{ groups[0].lastUpdated !== "" && (
<SortOptions sortMethod={sortMethod} changeSortMethod={changeSortMethod}/>
) || (
<HugeSpacer/>
)}

<SetModalResourceContext.Provider value={setModalResource}>
<ScrollableAnchor id={LIST_ANCHOR}>
Expand Down
65 changes: 36 additions & 29 deletions static-site/src/pages/groups.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -92,31 +108,22 @@ class GroupsPage extends React.Component {
<GroupCards squashed/>
<HugeSpacer />

<ScrollableAnchor id={'datasets'}>
<splashStyles.H2>Available Datasets</splashStyles.H2>
</ScrollableAnchor>
<FlexCenter>
<splashStyles.CenteredFocusParagraph>
{`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.`}
</splashStyles.CenteredFocusParagraph>
</FlexCenter>
<HugeSpacer />
{this.state.dataLoaded && (
<DatasetSelect
datasets={this.state.datasets}
columns={datasetColumns({isNarrative: false})}
/>
)}
<ListResources
sourceId={sourceId}
resourceType="dataset"
versioned={false}
parserCallBackFxn={parserCallBackFxn}/>

<HugeSpacer />

<ScrollableAnchor id={'narratives'}>
<splashStyles.H2>Available Narratives</splashStyles.H2>
</ScrollableAnchor>

{this.state.dataLoaded && (
<DatasetSelect
datasets={this.state.narratives}
columns={datasetColumns({isNarrative: true})}
/>
columns={datasetColumns}/>
)}
{ this.state.errorFetchingData && <DataFetchErrorParagraph />}

Expand Down

0 comments on commit ed27afb

Please sign in to comment.