Skip to content

Commit 6e29416

Browse files
committed
Add an explicit org IDs list
1 parent 4a5e5f6 commit 6e29416

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@acm-uiuc/js-shared",
3-
"version": "3.3.0",
3+
"version": "3.3.1",
44
"description": "ACM UIUC Shared JS code",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

src/orgs.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ export enum OrgType {
55
MISC = "misc",
66
}
77

8+
// IDs are the source of truth
9+
export const AllOrganizationIdList = [
10+
"A01",
11+
"S01", "S02", "S03", "S04", "S05", "S06", "S07", "S08", "S09",
12+
"S10", "S11", "S12", "S13", "S14", "S15", "S16", "S17", "S18",
13+
"C01", "C02", "C03", "C04", "C05", "C06", "C07", "C08",
14+
] as const;
15+
16+
export type OrganizationId = (typeof AllOrganizationIdList)[number];
17+
818
export type Organization = {
9-
name: string
10-
type: OrgType
11-
shortcode: string
12-
color: string
13-
}
19+
name: string;
20+
type: OrgType;
21+
shortcode: string;
22+
color: string;
23+
};
1424

15-
export const Organizations = {
25+
// This MUST have an entry for every ID (compile error if missing)
26+
export const Organizations: { readonly [K in OrganizationId]: Organization } = {
1627
"A01": { name: "ACM", type: OrgType.MAIN, shortcode: "acm", color: "#4577f8" },
1728
"S01": { name: "SIGPwny", type: OrgType.SIG, shortcode: "sigpwny", color: "#33cc55" },
1829
"S02": { name: "SIGCHI", type: OrgType.SIG, shortcode: "sigchi", color: "#EEAE48" },
@@ -32,20 +43,17 @@ export const Organizations = {
3243
"S16": { name: "SIGARCH", type: OrgType.SIG, shortcode: "sigarch", color: "#155CD0" },
3344
"S17": { name: "SIGRobotics", type: OrgType.SIG, shortcode: "sigrobotics", color: "#B0B0B0" },
3445
"S18": { name: "SIGtricity", type: OrgType.SIG, shortcode: "sigtricity", color: "#4577f8" },
35-
3646
"C01": { name: "Infrastructure Committee", type: OrgType.COMMITTEE, shortcode: "infra", color: "#4577f8" },
3747
"C02": { name: "Social Committee", type: OrgType.COMMITTEE, shortcode: "social", color: "#4577f8" },
3848
"C03": { name: "Mentorship Committee", type: OrgType.COMMITTEE, shortcode: "mentorship", color: "#4577f8" },
3949
"C04": { name: "Academic Committee", type: OrgType.COMMITTEE, shortcode: "academic", color: "#4577f8" },
4050
"C05": { name: "Corporate Committee", type: OrgType.COMMITTEE, shortcode: "corporate", color: "#4577f8" },
4151
"C06": { name: "Marketing Committee", type: OrgType.COMMITTEE, shortcode: "marketing", color: "#4577f8" },
42-
4352
"C07": { name: "Reflections | Projections", type: OrgType.COMMITTEE, shortcode: "reflproj", color: "#4577f8" },
4453
"C08": { name: "HackIllinois", type: OrgType.COMMITTEE, shortcode: "hackillinois", color: "#4577f8" },
45-
} as const satisfies Record<string, Organization>;
54+
};
4655

47-
// Derived types from the const object
48-
export type OrganizationId = keyof typeof Organizations;
56+
// Derived types
4957
export type OrganizationName = (typeof Organizations)[OrganizationId]["name"];
5058

5159
// Reverse lookup type and value
@@ -57,6 +65,8 @@ export const OrganizationsByName = Object.fromEntries(
5765
Object.entries(Organizations).map(([id, org]) => [org.name, id])
5866
) as OrganizationsByNameType;
5967

68+
export const AllOrganizationNameList = AllOrganizationIdList.map(id => Organizations[id].name) as OrganizationName[];
69+
6070
// Helper to get ID from name (typed return)
6171
export function getOrgIdByName<N extends OrganizationName>(name: N): OrganizationsByNameType[N] {
6272
return OrganizationsByName[name];
@@ -75,10 +85,12 @@ export function isValidOrgName(name: string): name is OrganizationName {
7585
return name in OrganizationsByName;
7686
}
7787

78-
export function getOrgsByType(type: OrgType): Array<Organization & { id: OrganizationId }> {
79-
return (Object.entries(Organizations) as Array<[OrganizationId, Organization]>)
80-
.filter(([_, org]) => org.type === type)
81-
.map(([id, org]) => ({ ...org, id }));
88+
export function isValidOrgId(id: string): id is OrganizationId {
89+
return id in Organizations;
8290
}
8391

84-
export const AllOrganizationNameList: OrganizationName[] = Object.values(Organizations).map(x => x.name);
92+
export function getOrgsByType(type: OrgType): Array<Organization & { id: OrganizationId }> {
93+
return AllOrganizationIdList
94+
.filter(id => Organizations[id].type === type)
95+
.map(id => ({ ...Organizations[id], id }));
96+
}

0 commit comments

Comments
 (0)