-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port <ListResources> types file to App Router style [#1066]
* segregate types and functions * update formatting
- Loading branch information
Showing
1 changed file
with
74 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,110 @@ | ||
import { InternalError } from "../ErrorBoundary"; | ||
import { Tile } from "../ExpandableTiles/types" | ||
import { InternalError } from "../error-boundary"; | ||
import { GenericTileBase } from "../expandable-tiles/types"; | ||
|
||
export interface FilterOption { | ||
value: string | ||
label: string | ||
value: string; | ||
label: string; | ||
} | ||
|
||
export type SortMethod = "lastUpdated" | "alphabetical"; | ||
|
||
export interface Group { | ||
groupName: string | ||
nResources: number | ||
nVersions: number | undefined | ||
lastUpdated: string | undefined | ||
resources: Resource[] | ||
groupUrl?: string | ||
groupDisplayName?: string | ||
groupName: string; | ||
nResources: number; | ||
nVersions: number | undefined; | ||
lastUpdated: string | undefined; | ||
resources: Resource[]; | ||
groupUrl?: string; | ||
groupDisplayName?: string; | ||
} | ||
|
||
export interface VersionedGroup extends Group { | ||
nVersions: number | ||
lastUpdated: string | ||
} | ||
|
||
export function convertVersionedGroup(group: Group): VersionedGroup { | ||
if (group.nVersions !== undefined && | ||
group.lastUpdated !== undefined) { | ||
return { | ||
...group, | ||
nVersions: group.nVersions, | ||
lastUpdated: group.lastUpdated, | ||
} | ||
} | ||
throw new InternalError("Group is not versioned."); | ||
nVersions: number; | ||
lastUpdated: string; | ||
} | ||
|
||
export interface Resource { | ||
name: string | ||
displayName?: ResourceDisplayName | ||
groupName: string | ||
nameParts: string[] | ||
sortingName: string | ||
url: string | ||
lastUpdated?: string // date | ||
firstUpdated?: string // date | ||
dates?: string[] | ||
nVersions?: number | ||
updateCadence?: UpdateCadence | ||
name: string; | ||
displayName?: ResourceDisplayName; | ||
groupName: string; | ||
nameParts: string[]; | ||
sortingName: string; | ||
url: string; | ||
lastUpdated?: string; // date | ||
firstUpdated?: string; // date | ||
dates?: string[]; | ||
nVersions?: number; | ||
updateCadence?: UpdateCadence; | ||
} | ||
|
||
export interface DisplayNamedResource extends Resource { | ||
displayName: ResourceDisplayName | ||
displayName: ResourceDisplayName; | ||
} | ||
|
||
export interface VersionedResource extends Resource { | ||
lastUpdated: string // date | ||
firstUpdated: string // date | ||
dates: string[] | ||
nVersions: number | ||
updateCadence: UpdateCadence | ||
} | ||
|
||
export function convertVersionedResource(resource: Resource): VersionedResource { | ||
if (resource.lastUpdated !== undefined && | ||
resource.firstUpdated !== undefined && | ||
resource.dates !== undefined && | ||
resource.nVersions !== undefined && | ||
resource.updateCadence !== undefined) { | ||
return { | ||
...resource, | ||
lastUpdated: resource.lastUpdated, | ||
firstUpdated: resource.firstUpdated, | ||
dates: resource.dates, | ||
nVersions: resource.nVersions, | ||
updateCadence: resource.updateCadence | ||
} | ||
} | ||
throw new InternalError("Resource is not versioned."); | ||
lastUpdated: string; // date | ||
firstUpdated: string; // date | ||
dates: string[]; | ||
nVersions: number; | ||
updateCadence: UpdateCadence; | ||
} | ||
|
||
export interface ResourceDisplayName { | ||
hovered: string | ||
default: string | ||
hovered: string; | ||
default: string; | ||
} | ||
|
||
export interface ResourceListingInfo { | ||
pathPrefix: string | ||
pathVersions: Record<string, string[]> | ||
pathPrefix: string; | ||
pathVersions: Record<string, string[]>; | ||
} | ||
|
||
export interface UpdateCadence { | ||
summary: string | ||
description: string | ||
summary: string; | ||
description: string; | ||
} | ||
|
||
// See coreTiles in static-site/content/resource-listing.yaml | ||
export interface FilterTile extends Tile { | ||
filters: string[] | ||
export interface FilterTile extends GenericTileBase { | ||
filters: string[]; | ||
} | ||
|
||
// See coreQuickLinks in static-site/content/resource-listing.yaml | ||
export interface QuickLink { | ||
name: string | ||
display: string | ||
groupName?: string | ||
name: string; | ||
display: string; | ||
groupName?: string; | ||
} | ||
|
||
export function convertVersionedGroup(group: Group): VersionedGroup { | ||
if (group.nVersions !== undefined && group.lastUpdated !== undefined) { | ||
return { | ||
...group, | ||
nVersions: group.nVersions, | ||
lastUpdated: group.lastUpdated, | ||
}; | ||
} | ||
throw new InternalError("Group is not versioned."); | ||
} | ||
|
||
export function convertVersionedResource( | ||
resource: Resource, | ||
): VersionedResource { | ||
if ( | ||
resource.lastUpdated !== undefined && | ||
resource.firstUpdated !== undefined && | ||
resource.dates !== undefined && | ||
resource.nVersions !== undefined && | ||
resource.updateCadence !== undefined | ||
) { | ||
return { | ||
...resource, | ||
lastUpdated: resource.lastUpdated, | ||
firstUpdated: resource.firstUpdated, | ||
dates: resource.dates, | ||
nVersions: resource.nVersions, | ||
updateCadence: resource.updateCadence, | ||
}; | ||
} | ||
throw new InternalError("Resource is not versioned."); | ||
} |