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 12, 2024
1 parent a76391e commit 28fc179
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 36 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.lastUpdated ? `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 !== undefined && `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 @@ -75,11 +75,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}/>
{ typeof groups !== "undefined" && groups[0]?.lastUpdated !== "" && (
<SortOptions sortMethod={sortMethod} changeSortMethod={changeSortMethod}/>
) || (
<HugeSpacer/>
)}

<SetModalResourceContext.Provider value={setModalResource}>
<ScrollableAnchor id={LIST_ANCHOR}>
Expand Down
3 changes: 0 additions & 3 deletions static-site/src/components/ListResources/useDataFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ function partitionByPathogen(pathVersions: PathVersions, pathPrefix: string, ver
return Object.entries(pathVersions).reduce((store: Partitions, [name, dates]) => {
const sortedDates = [...dates].sort();

// do nothing if resource has no dates
if (sortedDates.length < 1) return store

const nameParts = name.split('/');
// split() will always return at least 1 string
const groupName = nameParts[0]!;
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 sourceUrl = "/charon/getAvailable?prefix=/groups/";
async function parseResourceListingCallback(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
sourceUrl={sourceUrl}
resourceType="dataset"
versioned={false}
parseResourceListingCallback={parseResourceListingCallback}/>

<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 28fc179

Please sign in to comment.