Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update usage of TypeScript #920

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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