Skip to content

Commit 2e1318e

Browse files
Split CT into three groups (#315)
1 parent a7804bc commit 2e1318e

File tree

6 files changed

+63
-7
lines changed

6 files changed

+63
-7
lines changed

packages/ct/data/city-stats.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"percentage": "26%",
55
"population": "121,054",
66
"reforms": "adopted",
7-
"url": "https://parkingreform.org/mandates-map/city_detail/Hartford_CT.html"
7+
"url": "https://parkingreform.org/mandates-map/city_detail/Hartford_CT.html",
8+
"group": "Group 1"
89
},
910
"new-haven": {
1011
"name": "New Haven",
1112
"percentage": "34%",
1213
"population": "134,023",
1314
"reforms": "adopted",
14-
"url": "https://parkingreform.org/mandates-map/city_detail/NewHaven_CT.html"
15+
"url": "https://parkingreform.org/mandates-map/city_detail/NewHaven_CT.html",
16+
"group": "Group 2"
1517
}
1618
}
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
1-
import { DropdownGroup } from "@prn-parking-lots/shared/src/js/city-ui/dropdownUtils";
1+
import {
2+
DropdownChoiceId,
3+
DropdownGroup,
4+
} from "@prn-parking-lots/shared/src/js/city-ui/dropdownUtils";
25
import type { CityStatsCollection } from "@prn-parking-lots/shared/src/js/model/types";
36

47
import type { CityStats } from "./types";
58

69
export default function createDropdownGroups(
710
data: CityStatsCollection<CityStats>,
811
): DropdownGroup[] {
12+
const group1: DropdownChoiceId[] = [];
13+
const group2: DropdownChoiceId[] = [];
14+
const group3: DropdownChoiceId[] = [];
15+
Object.entries(data).forEach(([id, { name, group }]) => {
16+
switch (group) {
17+
case "Group 1":
18+
group1.push({ name, id });
19+
break;
20+
case "Group 2":
21+
group2.push({ name, id });
22+
break;
23+
case "Group 3":
24+
group3.push({ name, id });
25+
break;
26+
default:
27+
throw new Error(`Unrecognized group '${group}' for ${id}`);
28+
}
29+
});
930
return [
1031
{
1132
label: "Group 1",
12-
cities: Object.entries(data).map(([id, { name }]) => ({ id, name })),
33+
cities: group1,
34+
},
35+
{
36+
label: "Group 2",
37+
cities: group2,
38+
},
39+
{
40+
label: "Group 3",
41+
cities: group3,
1342
},
1443
];
1544
}

packages/ct/src/js/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import type { CommonCityStats } from "@prn-parking-lots/shared/src/js/model/types";
22

3-
export type CityStats = CommonCityStats;
3+
export type CityStats = CommonCityStats & { group: string };

packages/ct/tests/dropdownGroups.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,39 @@ test("createDropdownGroups", () => {
1313
city1: {
1414
...common,
1515
name: "City 1",
16+
group: "Group 1",
1617
},
1718
city2: {
1819
...common,
1920
name: "City 2",
21+
group: "Group 2",
22+
},
23+
city3: {
24+
...common,
25+
name: "City 3",
26+
group: "Group 3",
27+
},
28+
city4: {
29+
...common,
30+
name: "City 4",
31+
group: "Group 1",
2032
},
2133
};
2234
expect(createDropdownGroups(input)).toEqual([
2335
{
2436
label: "Group 1",
2537
cities: [
2638
{ id: "city1", name: "City 1" },
27-
{ id: "city2", name: "City 2" },
39+
{ id: "city4", name: "City 4" },
2840
],
2941
},
42+
{
43+
label: "Group 2",
44+
cities: [{ id: "city2", name: "City 2" }],
45+
},
46+
{
47+
label: "Group 3",
48+
cities: [{ id: "city3", name: "City 3" }],
49+
},
3050
]);
3151
});

packages/ct/tests/scorecard.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ test.describe("formatScorecard", () => {
1212
population: "42,412",
1313
reforms: "adopted",
1414
url: "https://parkingreform.org",
15+
group: "",
1516
});
1617
expect(listEntries).toEqual([
1718
"42,412 city residents",
@@ -26,6 +27,7 @@ test.describe("formatScorecard", () => {
2627
population: "42,412",
2728
reforms: null,
2829
url: null,
30+
group: "",
2931
});
3032
expect(listEntries).toEqual(["42,412 city residents"]);
3133
});

packages/scripts/src/add-city.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ async function addScoreCard(
2323
};
2424
let newEntry;
2525
if (pkg === "ct") {
26-
newEntry = { ...common };
26+
newEntry = {
27+
...common,
28+
group: "FILL ME IN, either 'Group 1', 'Group 2', or 'Group 3'",
29+
};
2730
} else {
2831
newEntry = {
2932
...common,

0 commit comments

Comments
 (0)