Skip to content

Commit

Permalink
Merge pull request #920: Update usage of TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Jun 17, 2024
2 parents 3bcad1d + d4144d5 commit cfdeac1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
14 changes: 5 additions & 9 deletions static-site/src/components/ListResources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<string, string>
showcase: FilterCard[]
resourceListingCallback: () => Promise<ResourceListingInfo>;
}
Expand Down Expand Up @@ -255,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) {
Expand Down
13 changes: 1 addition & 12 deletions static-site/src/components/ListResources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ export interface ResourceDisplayName {

export interface ResourceListingInfo {
pathPrefix: string
pathVersions: PathVersions
}

/**
* Mapping from group name -> display name
*/
export interface GroupDisplayNames {
[name: string]: string
pathVersions: Record<string, string[]>
}

export interface UpdateCadence {
Expand All @@ -62,7 +55,3 @@ export interface QuickLink {
display: string
groupName?: string
}

export interface PathVersions {
[name: string]: string[] // versions
}
17 changes: 6 additions & 11 deletions static-site/src/components/ListResources/useDataFetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { Group, GroupDisplayNames, PathVersions, Resource, ResourceListingInfo } from './types';
import { Group, Resource, ResourceListingInfo } from './types';


/**
Expand All @@ -21,7 +21,7 @@ import { Group, GroupDisplayNames, PathVersions, Resource, ResourceListingInfo }
export function useDataFetch(
versioned: boolean,
defaultGroupLinks: boolean,
groupDisplayNames: GroupDisplayNames,
groupDisplayNames: Record<string, string>,
resourceListingCallback: () => Promise<ResourceListingInfo>,
) : {groups: Group[] | undefined, dataFetchError: boolean} {
const [groups, setGroups] = useState<Group[]>();
Expand Down Expand Up @@ -51,18 +51,13 @@ export function useDataFetch(
}


interface Partitions {
[name: string]: Resource[]
}


/**
* 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) {
return Object.entries(pathVersions).reduce((store: Partitions, [name, dates]) => {
function partitionByPathogen(pathVersions: Record<string, string[]>, pathPrefix: string, versioned: boolean) {
return Object.entries(pathVersions).reduce((store: Record<string, Resource[]>, [name, dates]) => {
const sortedDates = [...dates].sort();

const nameParts = name.split('/');
Expand Down Expand Up @@ -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<string, Resource[]>, pathPrefix: string, defaultGroupLinks: boolean, groupDisplayNames: Record<string, string>) {
return Object.entries(partitions).map(([groupName, resources]) => {
const groupInfo: Group = {
groupName: groupName,
Expand Down

0 comments on commit cfdeac1

Please sign in to comment.