-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize setting up groups in dropdown (#306)
<img width="260" alt="Screenshot 2025-01-11 at 11 00 25 AM" src="https://github.com/user-attachments/assets/2502abcb-2c2d-45a9-bd1a-f8f9ac713c89" />
- Loading branch information
1 parent
f9756fd
commit d84640d
Showing
10 changed files
with
149 additions
and
63 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { DropdownGroup } from "@prn-parking-lots/shared/src/js/city-ui/dropdownUtils"; | ||
import { CityStatsCollection } from "@prn-parking-lots/shared/src/js/model/types"; | ||
|
||
export default function createDropdownGroups( | ||
data: CityStatsCollection, | ||
): DropdownGroup[] { | ||
return [ | ||
{ | ||
label: "Group 1", | ||
cities: Object.entries(data).map(([id, { name }]) => ({ id, name })), | ||
}, | ||
]; | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
DropdownGroup, | ||
DropdownChoiceId, | ||
} from "@prn-parking-lots/shared/src/js/city-ui/dropdownUtils"; | ||
import { CityStatsCollection } from "@prn-parking-lots/shared/src/js/model/types"; | ||
|
||
export default function createDropdownGroups( | ||
data: CityStatsCollection, | ||
): DropdownGroup[] { | ||
const official: DropdownChoiceId[] = []; | ||
const community: DropdownChoiceId[] = []; | ||
Object.entries(data).forEach(([id, { name, contribution }]) => { | ||
if (contribution) { | ||
community.push({ id, name }); | ||
} else { | ||
official.push({ id, name }); | ||
} | ||
}); | ||
return [ | ||
{ | ||
label: "Official maps", | ||
cities: official, | ||
}, | ||
{ | ||
label: "Community maps", | ||
cities: community, | ||
}, | ||
]; | ||
} |
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import createDropdownGroups from "../src/js/dropdownGroups"; | ||
|
||
test("createDropdownGroups", () => { | ||
const common = { | ||
percentage: "", | ||
cityType: "", | ||
population: "", | ||
urbanizedAreaPopulation: "", | ||
parkingScore: null, | ||
reforms: "", | ||
url: "", | ||
}; | ||
const input = { | ||
"city1-ny": { | ||
...common, | ||
name: "City 1, NY", | ||
}, | ||
"city2-ny": { | ||
...common, | ||
name: "City 2, NY", | ||
contribution: "some-email@web.com", | ||
}, | ||
}; | ||
expect(createDropdownGroups(input)).toEqual([ | ||
{ | ||
label: "Official maps", | ||
cities: [{ id: "city1-ny", name: "City 1, NY" }], | ||
}, | ||
{ | ||
label: "Community maps", | ||
cities: [{ id: "city2-ny", name: "City 2, NY" }], | ||
}, | ||
]); | ||
}); |
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
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
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
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