From e143c16b29d1ffbd1f86ceae7d63a5a816dbee02 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:26:12 -0700 Subject: [PATCH 1/4] Replace Partitions interface with Record The Partitions intermediate did not convey anything more than what can be conveyed by a Record. --- static-site/src/components/ListResources/useDataFetch.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/static-site/src/components/ListResources/useDataFetch.ts b/static-site/src/components/ListResources/useDataFetch.ts index b5eccdfb3..14624ea14 100644 --- a/static-site/src/components/ListResources/useDataFetch.ts +++ b/static-site/src/components/ListResources/useDataFetch.ts @@ -51,18 +51,13 @@ export function useDataFetch( } -interface Partitions { - [name: string]: Resource[] -} - - /** * Groups the provided array of pathVersions into an object with keys * representing group names (pathogen names) and values which are arrays of * resource objects. */ function partitionByPathogen(pathVersions: PathVersions, pathPrefix: string, versioned: boolean) { - return Object.entries(pathVersions).reduce((store: Partitions, [name, dates]) => { + return Object.entries(pathVersions).reduce((store: Record, [name, dates]) => { const sortedDates = [...dates].sort(); const nameParts = name.split('/'); @@ -96,7 +91,7 @@ function partitionByPathogen(pathVersions: PathVersions, pathPrefix: string, ver * Turn the provided partitions (an object mapping groupName to an array of resources) * into an array of groups. */ -function groupsFrom(partitions: Partitions, pathPrefix: string, defaultGroupLinks: boolean, groupDisplayNames: GroupDisplayNames) { +function groupsFrom(partitions: Record, pathPrefix: string, defaultGroupLinks: boolean, groupDisplayNames: GroupDisplayNames) { return Object.entries(partitions).map(([groupName, resources]) => { const groupInfo: Group = { groupName: groupName, From e3adbbc787de4243e5311557ddf71f58c41b782f Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:28:19 -0700 Subject: [PATCH 2/4] Replace GroupDisplayNames interface with Record The GroupDisplayNames intermediate did not convey anything more than what can be conveyed by a Record. --- static-site/src/components/ListResources/index.tsx | 6 ++++-- static-site/src/components/ListResources/types.ts | 7 ------- static-site/src/components/ListResources/useDataFetch.ts | 6 +++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/static-site/src/components/ListResources/index.tsx b/static-site/src/components/ListResources/index.tsx index 5632abdca..5dfb04380 100644 --- a/static-site/src/components/ListResources/index.tsx +++ b/static-site/src/components/ListResources/index.tsx @@ -12,7 +12,7 @@ import { ErrorContainer } from "../../pages/404"; import { TooltipWrapper } from "./IndividualResource"; import {ResourceModal, SetModalResourceContext} from "./Modal"; import { CardImgWrapper, CardInner, CardOuter, CardTitle, Showcase } from "../Showcase"; -import { FilterCard, FilterOption, Group, GroupDisplayNames, QuickLink, Resource, ResourceListingInfo } from './types'; +import { FilterCard, FilterOption, Group, QuickLink, Resource, ResourceListingInfo } from './types'; import { HugeSpacer } from "../../layouts/generalComponents"; interface ListResourcesProps extends ListResourcesResponsiveProps { @@ -128,7 +128,9 @@ interface ListResourcesResponsiveProps { /** Should the group name itself be a url? (which we let the server redirect) */ defaultGroupLinks: boolean - groupDisplayNames: GroupDisplayNames + + /** Mapping from group name -> display name */ + groupDisplayNames: Record showcase: FilterCard[] resourceListingCallback: () => Promise; } diff --git a/static-site/src/components/ListResources/types.ts b/static-site/src/components/ListResources/types.ts index 5f0e1cbdc..483a8739a 100644 --- a/static-site/src/components/ListResources/types.ts +++ b/static-site/src/components/ListResources/types.ts @@ -39,13 +39,6 @@ export interface ResourceListingInfo { pathVersions: PathVersions } -/** - * Mapping from group name -> display name - */ -export interface GroupDisplayNames { - [name: string]: string -} - export interface UpdateCadence { summary: string description: string diff --git a/static-site/src/components/ListResources/useDataFetch.ts b/static-site/src/components/ListResources/useDataFetch.ts index 14624ea14..b01b4b9e9 100644 --- a/static-site/src/components/ListResources/useDataFetch.ts +++ b/static-site/src/components/ListResources/useDataFetch.ts @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react'; -import { Group, GroupDisplayNames, PathVersions, Resource, ResourceListingInfo } from './types'; +import { Group, PathVersions, Resource, ResourceListingInfo } from './types'; /** @@ -21,7 +21,7 @@ import { Group, GroupDisplayNames, PathVersions, Resource, ResourceListingInfo } export function useDataFetch( versioned: boolean, defaultGroupLinks: boolean, - groupDisplayNames: GroupDisplayNames, + groupDisplayNames: Record, resourceListingCallback: () => Promise, ) : {groups: Group[] | undefined, dataFetchError: boolean} { const [groups, setGroups] = useState(); @@ -91,7 +91,7 @@ function partitionByPathogen(pathVersions: PathVersions, pathPrefix: string, ver * Turn the provided partitions (an object mapping groupName to an array of resources) * into an array of groups. */ -function groupsFrom(partitions: Record, pathPrefix: string, defaultGroupLinks: boolean, groupDisplayNames: GroupDisplayNames) { +function groupsFrom(partitions: Record, pathPrefix: string, defaultGroupLinks: boolean, groupDisplayNames: Record) { return Object.entries(partitions).map(([groupName, resources]) => { const groupInfo: Group = { groupName: groupName, From dbdca0be99594007800fc5c135f1d7f3f7d5491e Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:33:33 -0700 Subject: [PATCH 3/4] Replace PathVersions interface with Record The PathVersions intermediate did not convey anything more than what can be conveyed by a Record. --- static-site/src/components/ListResources/types.ts | 6 +----- static-site/src/components/ListResources/useDataFetch.ts | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/static-site/src/components/ListResources/types.ts b/static-site/src/components/ListResources/types.ts index 483a8739a..0b933fab1 100644 --- a/static-site/src/components/ListResources/types.ts +++ b/static-site/src/components/ListResources/types.ts @@ -36,7 +36,7 @@ export interface ResourceDisplayName { export interface ResourceListingInfo { pathPrefix: string - pathVersions: PathVersions + pathVersions: Record } export interface UpdateCadence { @@ -55,7 +55,3 @@ export interface QuickLink { display: string groupName?: string } - -export interface PathVersions { - [name: string]: string[] // versions -} diff --git a/static-site/src/components/ListResources/useDataFetch.ts b/static-site/src/components/ListResources/useDataFetch.ts index b01b4b9e9..d8c0e7bb2 100644 --- a/static-site/src/components/ListResources/useDataFetch.ts +++ b/static-site/src/components/ListResources/useDataFetch.ts @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react'; -import { Group, PathVersions, Resource, ResourceListingInfo } from './types'; +import { Group, Resource, ResourceListingInfo } from './types'; /** @@ -52,11 +52,11 @@ export function useDataFetch( /** - * Groups the provided array of pathVersions into an object with keys + * Groups the provided array mapping from path to dates into an object with keys * representing group names (pathogen names) and values which are arrays of * resource objects. */ -function partitionByPathogen(pathVersions: PathVersions, pathPrefix: string, versioned: boolean) { +function partitionByPathogen(pathVersions: Record, pathPrefix: string, versioned: boolean) { return Object.entries(pathVersions).reduce((store: Record, [name, dates]) => { const sortedDates = [...dates].sort(); From d4144d503f724e61ac55976d16186328fd19222d Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:38:26 -0700 Subject: [PATCH 4/4] Inline FilterShowcaseTile prop typing There is only one prop so it can be represented in the function signature without much clutter. --- static-site/src/components/ListResources/index.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/static-site/src/components/ListResources/index.tsx b/static-site/src/components/ListResources/index.tsx index 5dfb04380..10a2765b7 100644 --- a/static-site/src/components/ListResources/index.tsx +++ b/static-site/src/components/ListResources/index.tsx @@ -257,13 +257,7 @@ const Byline = styled.div` /*** SHOWCASE ***/ - -interface FilterShowcaseTileProps { - card: FilterCard -} - - -const FilterShowcaseTile = ({ card }: FilterShowcaseTileProps) => { +const FilterShowcaseTile = ({ card }: { card: FilterCard }) => { const setSelectedFilterOptions = useContext(SetSelectedFilterOptions); if (!setSelectedFilterOptions) {