Skip to content

Commit

Permalink
Support new Connecticut city IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Jan 11, 2025
1 parent 6660500 commit 10cf08f
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 79 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@playwright/test": "^1.49.1",
"@types/geojson": "^7946.0.15",
"@types/leaflet": "^1.9.16",
"@types/lodash-es": "^4.17.12",
"@types/node": "^22.10.5",
"@typescript-eslint/eslint-plugin": "^8.19.1",
"eslint": "^8.37.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/ct/data/city-boundaries.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
"type": "Feature",
"properties": {
"id": "hartford-ct"
"id": "hartford"
},
"geometry": {
"type": "Polygon",
Expand Down Expand Up @@ -171,7 +171,7 @@
{
"type": "Feature",
"properties": {
"id": "new-haven-ct"
"id": "new-haven"
},
"geometry": {
"type": "Polygon",
Expand Down
12 changes: 6 additions & 6 deletions packages/ct/data/city-stats.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"hartford-ct": {
"name": "Hartford, CT",
"hartford": {
"name": "Hartford",
"percentage": "26%",
"cityType": "core",
"population": "121,054",
"urbanizedAreaPopulation": "977,158",
"parkingScore": "53",
"reforms": "implemented",
"reforms": "adopted",
"url": "https://parkingreform.org/mandates-map/city_detail/Hartford_CT.html"
},
"new-haven-ct": {
"name": "New Haven, CT",
"new-haven": {
"name": "New Haven",
"percentage": "34%",
"cityType": "principal",
"population": "134,023",
"urbanizedAreaPopulation": "561,456",
"parkingScore": null,
"reforms": "implemented",
"reforms": "adopted",
"url": "https://parkingreform.org/mandates-map/city_detail/NewHaven_CT.html"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "Feature",
"properties": {
"id": "hartford-ct"
"id": "hartford"
},
"geometry": {
"type": "MultiPolygon",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "Feature",
"properties": {
"id": "new-haven-ct"
"id": "new-haven"
},
"geometry": {
"type": "MultiPolygon",
Expand Down
2 changes: 1 addition & 1 deletion packages/ct/src/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export default async function initApp(): Promise<void> {
boundaries: CITY_BOUNDARIES_GEOJSON,
parkingLots: PARKING_LOT_GEOJSON_MODULES,
},
initialCity: "hartford-ct",
initialCity: "hartford",
});
}
4 changes: 2 additions & 2 deletions packages/primary/data/city-boundaries.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -9868,7 +9868,7 @@
{
"type": "Feature",
"properties": {
"id": "st.-louis-mo"
"id": "st-louis-mo"
},
"geometry": {
"type": "Polygon",
Expand Down Expand Up @@ -9969,7 +9969,7 @@
{
"type": "Feature",
"properties": {
"id": "st.-petersburg-fl"
"id": "st-petersburg-fl"
},
"geometry": {
"type": "Polygon",
Expand Down
4 changes: 2 additions & 2 deletions packages/primary/data/city-stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@
"reforms": "implemented",
"url": "https://parkingreform.org/mandates-map/city_detail/Seattle_WA.html"
},
"st.-louis-mo": {
"st-louis-mo": {
"name": "St. Louis, MO",
"percentage": "27%",
"cityType": "core",
Expand All @@ -940,7 +940,7 @@
"reforms": "implemented",
"url": "https://parkingreform.org/mandates-map/city_detail/St.Louis_MO.html"
},
"st.-petersburg-fl": {
"st-petersburg-fl": {
"name": "St. Petersburg, FL",
"percentage": "28%",
"cityType": "principal",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "Feature",
"properties": {
"id": "st.-louis-mo"
"id": "st-louis-mo"
},
"geometry": {
"type": "MultiPolygon",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "Feature",
"properties": {
"id": "st.-petersburg-fl"
"id": "st-petersburg-fl"
},
"geometry": {
"type": "MultiPolygon",
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"@fortawesome/free-regular-svg-icons": "^6.7.2",
"@fortawesome/free-solid-svg-icons": "^6.7.2",
"choices.js": "^10.2.0",
"leaflet": "~1.9.3"
"leaflet": "~1.9.3",
"lodash-es": "^4.17.21"
},
"devDependencies": {}
}
13 changes: 7 additions & 6 deletions packages/shared/src/js/cityId.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import { kebabCase } from "lodash-es";

import type { CityId } from "./types";

/**
* Extract the city ID from the URL's `#`, if present.
*/
export function extractCityIdFromUrl(windowUrl: string): string | null {
return windowUrl.indexOf("#parking-reform-map=") === -1
? null
: windowUrl.split("#")[1].split("=")[1].toLowerCase();
if (windowUrl.indexOf("#parking-reform-map=") === -1) return null;
return windowUrl.split("#")[1].split("=")[1].toLowerCase().replace(".", "");
}

/**
* Parse the geojson's `Name` property into the city ID.
*
* @param jsonCityName: the `Name` property from JSON, e.g. `"My City, AZ"`
* @return: the city ID, e.g. `st.-louis-mo`.
* @return: the city ID, e.g. `st-louis-mo`.
*/
export function parseCityIdFromJson(jsonCityName: string): string {
return jsonCityName.toLowerCase().replace(/ /g, "-").replace(/,/g, "");
return kebabCase(jsonCityName);
}

/**
* Determine what URL to use to share the current city.
*
* @param windowUrl: the current page's URL
* @param cityId: e.g. `st.-louis-mo`
* @param cityId: e.g. `st-louis-mo`
* @return: the URL to share
*/
export function determineShareUrl(windowUrl: string, cityId: CityId): string {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type {
GeoJsonProperties,
} from "geojson";

/// The slugified ID, e.g. `st.-louis-mo` or `hartford`.
/// The slugified ID, e.g. `st-louis-mo` or `hartford`.
/// (The state code is missing for state-specific maps like CT.)
export type CityId = string; // e.g. `st.-louis-mo`
export type CityId = string;

export interface CityStats {
name: string;
Expand Down
9 changes: 9 additions & 0 deletions packages/shared/tests/cityId.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ test.describe("extractCityIdFromUrl()", () => {
"https://parking.org#parking-reform-map=CITY-OF-SHOUP",
),
).toEqual("city-of-shoup");
expect(
extractCityIdFromUrl("https://parking.org#parking-reform-map=st.-louis"),
).toEqual("st-louis");
});
});

Expand All @@ -41,7 +44,13 @@ test("parseCityIdFromJson() extracts the city", () => {
expect(parseCityIdFromJson("Saint Shoup Village, AZ")).toEqual(
"saint-shoup-village-az",
);
expect(parseCityIdFromJson("St. Shoup Village, AZ")).toEqual(
"st-shoup-village-az",
);
expect(parseCityIdFromJson("No state")).toEqual("no-state");
expect(parseCityIdFromJson("Hartford - rail station")).toEqual(
"hartford-rail-station",
);
});

test.describe("determineShareUrl()", () => {
Expand Down
Loading

0 comments on commit 10cf08f

Please sign in to comment.