Skip to content

Commit d9e08a3

Browse files
committed
Task 412 Add Selected Location Section to Results Panel
- added section to results panel for CD, CCD, and borough filter selections - added and updated (other failing) tests - code review changes and updates
1 parent 25ab8b2 commit d9e08a3

File tree

4 files changed

+316
-28
lines changed

4 files changed

+316
-28
lines changed

app/components/ClearFilter/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { Button } from "@nycplanning/streetscape";
2+
import type { Property } from "csstype";
23

34
export interface ClearFilterBtnProps {
45
onClear: () => void;
56
buttonLabel?: string;
7+
textAlign?: Property.TextAlign;
8+
verticalAlign?: string;
69
}
710

811
export function ClearFilterBtn({
912
onClear,
1013
buttonLabel = "Reset Selections",
14+
textAlign = "left",
15+
verticalAlign = "initial",
1116
}: ClearFilterBtnProps) {
1217
const handleClear = () => {
1318
try {
@@ -26,11 +31,12 @@ export function ClearFilterBtn({
2631
variant="tertiarty"
2732
textDecoration={"underline"}
2833
color={"primary.600"}
29-
textAlign={"left"}
34+
textAlign={textAlign}
3035
role={"button"}
3136
minHeight={"unset"}
3237
marginY={3}
3338
padding={0}
39+
verticalAlign={verticalAlign}
3440
>
3541
{buttonLabel}
3642
</Button>
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import { Box, CloseIcon, Flex, Heading, Tag } from "@nycplanning/streetscape";
2+
import { useLoaderData } from "react-router";
3+
import { useUpdateSearchParams } from "~/utils/utils";
4+
import { loader } from "~/layouts/ResultsPanel";
5+
import { ClearFilterBtn } from "./ClearFilter";
6+
7+
export function SelectedLocations() {
8+
const {
9+
boroughsResponse: { boroughs },
10+
} = useLoaderData<typeof loader>();
11+
12+
const [searchParams, updateSearchParams] = useUpdateSearchParams();
13+
const boundaryType = searchParams.get("boundaryType");
14+
const boroughId = searchParams.get("boroughId");
15+
const boundaryId = searchParams.get("boundaryId");
16+
17+
const boroughIds = searchParams.get("boroughIds");
18+
19+
const tagLabel = (() => {
20+
if (boundaryType === "ccd" && boundaryId !== null) {
21+
return (
22+
<>
23+
<span style={{ fontWeight: "bold" }}>City Council</span>
24+
<span style={{ paddingRight: "2px" }}>{` | ${boundaryId}`}</span>
25+
</>
26+
);
27+
}
28+
29+
const borough = boroughs.find((b) => b.id === (boroughId ?? boroughIds));
30+
31+
if (!borough) return null;
32+
33+
if (boundaryType === "cd" && boundaryId !== null) {
34+
return (
35+
<>
36+
<span style={{ fontWeight: "bold" }}>{borough.title}</span>
37+
<span style={{ paddingRight: "2px" }}>{` | CD ${boundaryId}`}</span>
38+
</>
39+
);
40+
}
41+
42+
if (boundaryType === "borough") {
43+
return <span style={{ fontWeight: "bold" }}>{borough.title}</span>;
44+
}
45+
46+
return null;
47+
})();
48+
49+
const clearSelections = () => {
50+
updateSearchParams({
51+
boundaryType: null,
52+
boroughId: null,
53+
boundaryId: null,
54+
boroughIds: null,
55+
});
56+
};
57+
58+
const clearTag = () => {
59+
if (boundaryType === "ccd") {
60+
updateSearchParams({
61+
boundaryType: null,
62+
boundaryId: null,
63+
boroughId: null,
64+
});
65+
} else if (boundaryType === "cd") {
66+
updateSearchParams({
67+
boundaryType: null,
68+
boroughId: null,
69+
boundaryId: null,
70+
});
71+
} else if (boundaryType === "borough") {
72+
updateSearchParams({
73+
boundaryType: null,
74+
boroughIds: null,
75+
});
76+
}
77+
};
78+
79+
return (
80+
<Flex
81+
direction="column"
82+
gap={"10px"}
83+
border={"1px solid"}
84+
borderColor={"gray.300"}
85+
borderRadius={"12px"}
86+
background={"gray.50"}
87+
padding={4}
88+
height={"82px"}
89+
>
90+
<Flex
91+
className="title-section"
92+
alignItems={"flex-start"}
93+
justify={"space-between"}
94+
height={"20px"}
95+
>
96+
<Box alignSelf={"center"}>
97+
<Heading fontSize={"xs"} fontWeight={"bold"}>
98+
SELECTED LOCATION
99+
</Heading>
100+
</Box>
101+
<Box alignSelf={"center"}>
102+
<ClearFilterBtn
103+
textAlign={"right"}
104+
verticalAlign={"text-bottom"}
105+
onClear={clearSelections}
106+
buttonLabel="Clear"
107+
></ClearFilterBtn>
108+
</Box>
109+
</Flex>
110+
111+
<Flex
112+
justifyContent={"flex-start"}
113+
alignItems={"center"}
114+
height={"20px"}
115+
padding={"2px 4px"}
116+
className={"tag-container"}
117+
>
118+
{tagLabel !== null && (
119+
<Tag
120+
display={"flex"}
121+
justifyContent={"space-between"}
122+
alignItems={"center"}
123+
gap={"4px"}
124+
fontSize={"11px"}
125+
borderRadius={"4px"}
126+
background={"primary.100"}
127+
color={"teal.700"}
128+
>
129+
<Box className={"tag-information"}>{tagLabel}</Box>
130+
<Box>
131+
<CloseIcon
132+
color={"teal.700"}
133+
width={"8px"}
134+
height={"8px"}
135+
onClick={clearTag}
136+
aria-label={"closeIcon"}
137+
sx={{
138+
cursor: "pointer",
139+
}}
140+
/>
141+
</Box>
142+
</Tag>
143+
)}
144+
</Flex>
145+
</Flex>
146+
);
147+
}

0 commit comments

Comments
 (0)