Skip to content

Commit 0066127

Browse files
authored
Merge pull request #901: Use showcase on splash
2 parents 3d67822 + d038264 commit 0066127

File tree

13 files changed

+192
-158
lines changed

13 files changed

+192
-158
lines changed

static-site/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ We may wish to rename this directory to avoid any doubt.
8181
* "Edit" -> "Scale Image" to 250 x 250px
8282
* "File" -> "Save Image" & use PNG
8383
3. Save the file in `./static/splash_images`
84-
4. Edit `./src/components/Cards/coreCards.js`, `./content/community-datasets.yaml` or `./src/components/Cards/narrativeCards.js` to include the card & title.
84+
4. Edit `./src/components/splash/showcase.yaml` to include the card & title.
8585
5. Edit `./src/components/Footer/index.jsx` to provide credit for the photo.
8686

8787
### Adding new team members

static-site/content/community-datasets.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ data:
2323
maintainers: E. Kinganda Lusamaki, INRB & C. Pratt
2424
date: 13 Oct 2021
2525
title: Genomic epidemiology of the 2018-21 Ebola epidemic
26-
card:
27-
img: "ebola2.png"
28-
url: "/community/inrb-drc/ebola-nord-kivu"
29-
title: "DRC Ebola (2018-19)"
30-
frontpage: true
3126
- url: https://nextstrain.org/community/narratives/ESR-NZ/GenomicsNarrativeSARSCoV2/aotearoa-border-incursions
3227
title: Real-time genomics to track COVID-19 post-elimination border incursions in Aotearoa New Zealand
3328
maintainers: Jordan Douglas, PhD, Jemma L. Geoghegan, PhD, James Hadfield, PhD, Remco Bouckaert, PhD, Matthew Storey, MSc, Xiaoyun Ren, PhD, Joep de Ligt, PhD, Nigel French, PhD, David Welch, PhD
@@ -43,11 +38,6 @@ data:
4338
maintainers: Katherine Eaton et al
4439
date: '2022-06-13'
4540
title: Yersinia Pestis (multiple datasets)
46-
card:
47-
img: "yersinia.png"
48-
url: "/community/ktmeaton/yersinia-pestis/maximum-likelihood/all?m=div"
49-
title: "Yersinia pestis"
50-
frontpage: true
5141
- url: https://nextstrain.org/community/pestdisplace/CMDAFRICA
5242
maintainers: PestDisPlace
5343
date: 07 Sep 2019

static-site/src/components/Cards/coreCards.js

-14
This file was deleted.

static-site/src/components/Cards/nCoVCards.js

-14
This file was deleted.

static-site/src/components/Cards/narrativeCards.js

-14
This file was deleted.

static-site/src/components/ListResources/index.tsx

+85-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
import React, { useState, useRef, useEffect } from 'react';
1+
import React, { useState, useRef, useEffect, useCallback, createContext, useContext } from 'react';
22
import styled from 'styled-components';
33
import Select, { MultiValue } from 'react-select';
4-
import ScrollableAnchor from '../../../vendored/react-scrollable-anchor/index';
4+
import ScrollableAnchor, { goToAnchor } from '../../../vendored/react-scrollable-anchor/index';
55
import {Tooltip} from 'react-tooltip-v5';
6-
import { useFilterOptions } from './useFilterOptions';
6+
import { createFilterOption, useFilterOptions } from './useFilterOptions';
77
import { useSortAndFilter } from "./useSortAndFilter";
88
import { useDataFetch } from "./useDataFetch";
99
import {Spinner} from '../Spinner/Spinner';
1010
import { ResourceGroup } from './ResourceGroup';
1111
import { ErrorContainer } from "../../pages/404";
1212
import { TooltipWrapper } from "./IndividualResource";
1313
import {ResourceModal, SetModalResourceContext} from "./Modal";
14-
import { Showcase, useShowcaseCards} from "./Showcase";
15-
import { Card, FilterOption, Group, GroupDisplayNames, QuickLink, Resource } from './types';
14+
import { CardImgWrapper, CardInner, CardOuter, CardTitle, Showcase } from "../Showcase";
15+
import { FilterCard, FilterOption, Group, GroupDisplayNames, QuickLink, Resource } from './types';
1616

1717
interface ListResourcesProps extends ListResourcesResponsiveProps {
1818
elWidth: number
1919
}
2020

21-
export const LIST_ANCHOR = "list";
21+
const LIST_ANCHOR = "list";
22+
23+
const SetSelectedFilterOptions = createContext<React.Dispatch<React.SetStateAction<readonly FilterOption[]>> | null>(null);
2224

2325
/**
2426
* A React component to fetch data and display the available resources,
@@ -67,7 +69,13 @@ function ListResources({
6769
return (
6870
<ListResourcesContainer>
6971

70-
<Showcase cards={showcaseCards} setSelectedFilterOptions={setSelectedFilterOptions}/>
72+
<Byline>
73+
Showcase resources: click to filter the resources to a pathogen
74+
</Byline>
75+
76+
<SetSelectedFilterOptions.Provider value={setSelectedFilterOptions}>
77+
<Showcase cards={showcaseCards} CardComponent={FilterShowcaseTile} />
78+
</SetSelectedFilterOptions.Provider>
7179

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

@@ -107,7 +115,7 @@ interface ListResourcesResponsiveProps {
107115
/** Should the group name itself be a url? (which we let the server redirect) */
108116
defaultGroupLinks: boolean
109117
groupDisplayNames: GroupDisplayNames
110-
showcase: Card[]
118+
showcase: FilterCard[]
111119
}
112120

113121
/**
@@ -222,4 +230,72 @@ const SortContainer = styled.div`
222230
margin-left: 20px;
223231
margin-right: 5px;
224232
}
225-
`
233+
`
234+
235+
const Byline = styled.div`
236+
font-size: 1.6rem;
237+
border-top: 1px rgb(230, 230, 230) solid;
238+
`
239+
240+
241+
/*** SHOWCASE ***/
242+
243+
244+
interface FilterShowcaseTileProps {
245+
card: FilterCard
246+
}
247+
248+
249+
const FilterShowcaseTile = ({ card }: FilterShowcaseTileProps) => {
250+
const setSelectedFilterOptions = useContext(SetSelectedFilterOptions);
251+
252+
if (!setSelectedFilterOptions) {
253+
throw new Error("Usage of this component requires the SetSelectedFilterOptions context to be set.")
254+
}
255+
256+
const filter = useCallback(
257+
() => {
258+
setSelectedFilterOptions(card.filters.map(createFilterOption));
259+
goToAnchor(LIST_ANCHOR);
260+
},
261+
[setSelectedFilterOptions, card]
262+
)
263+
264+
return (
265+
<CardOuter>
266+
<CardInner>
267+
<div onClick={filter}>
268+
<CardTitle $squashed>
269+
{card.name}
270+
</CardTitle>
271+
<CardImgWrapper filename={card.img}/>
272+
</div>
273+
</CardInner>
274+
</CardOuter>
275+
)
276+
}
277+
278+
279+
/**
280+
* Given a set of user-defined cards, restrict them to the set of cards for
281+
* which the filters are valid given the resources known to the resource listing
282+
* UI
283+
*/
284+
const useShowcaseCards = (cards?: FilterCard[], groups?: Group[]) => {
285+
const [restrictedCards, setRestrictedCards] = useState<FilterCard[]>([]);
286+
useEffect(() => {
287+
if (!cards || !groups) return;
288+
const words = groups.reduce((words, group) => {
289+
for (const resource of group.resources) {
290+
for (const word of resource.nameParts) {
291+
words.add(word);
292+
}
293+
}
294+
return words;
295+
}, new Set<string>());
296+
setRestrictedCards(cards.filter((card) => {
297+
return card.filters.every((word) => words.has(word))
298+
}));
299+
}, [cards, groups]);
300+
return restrictedCards;
301+
}

static-site/src/components/ListResources/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Card } from "../Showcase/types"
2+
13
export interface FilterOption {
24
value: string
35
label: string
@@ -45,9 +47,7 @@ export interface UpdateCadence {
4547
}
4648

4749
// See coreShowcase in static-site/content/resource-listing.yaml
48-
export interface Card {
49-
name: string
50-
img: string
50+
export interface FilterCard extends Card {
5151
filters: string[]
5252
}
5353

0 commit comments

Comments
 (0)