generated from NYCPlanning/ae-remix-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Export data button to each district project list Add modal that links to download for selected or all district data closes #44
- Loading branch information
1 parent
6a43630
commit b853bb5
Showing
12 changed files
with
237 additions
and
12 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
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,49 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { ExportDataModal } from "./ExportDataModal"; | ||
import { act } from "react"; | ||
|
||
describe("Export Data Modal", () => { | ||
const geography = "Community District MN05"; | ||
const fileName = "community_district_manhattan_05.csv"; | ||
|
||
it("should have a button to open the modal", async () => { | ||
render(<ExportDataModal geography={geography} fileName={fileName} />); | ||
|
||
expect(screen.queryByText(/Data Export/)).not.toBeInTheDocument(); | ||
await act(() => fireEvent.click(screen.getByText(/Export Data/))); | ||
expect(screen.getByText(/Data Export/)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should show the current district", async () => { | ||
render(<ExportDataModal geography={geography} fileName={fileName} />); | ||
|
||
await act(() => fireEvent.click(screen.getByText(/Export Data/))); | ||
expect(screen.getByText(geography)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should have a button to download the files", async () => { | ||
render(<ExportDataModal geography={geography} fileName={fileName} />); | ||
|
||
await act(() => fireEvent.click(screen.getByText(/Export Data/))); | ||
expect( | ||
screen.getByRole("link", { | ||
name: "Export Data", | ||
}), | ||
).toHaveAttribute("href", expect.stringContaining(fileName)); | ||
}); | ||
|
||
it("should let user choose whether to download all districts", async () => { | ||
render(<ExportDataModal geography={geography} fileName={fileName} />); | ||
|
||
await act(() => fireEvent.click(screen.getByText(/Export Data/))); | ||
await act(() => fireEvent.click(screen.getByText(/Include all districts/))); | ||
expect( | ||
screen.getByRole("link", { | ||
name: "Export Data", | ||
}), | ||
).toHaveAttribute( | ||
"href", | ||
expect.stringContaining("projects_in_geographies.zip"), | ||
); | ||
}); | ||
}); |
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,103 @@ | ||
import { | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
Button, | ||
Text, | ||
Switch, | ||
Heading, | ||
FormControl, | ||
FormLabel, | ||
Box, | ||
} from "@nycplanning/streetscape"; | ||
|
||
import { useState } from "react"; | ||
import { LinkBtn } from "./LinkBtn"; | ||
|
||
export interface ExportDataModalProps { | ||
geography: string; | ||
fileName: string; | ||
} | ||
|
||
export function ExportDataModal({ geography, fileName }: ExportDataModalProps) { | ||
const [allDistricts, setAllDistricts] = useState(false); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const onOpen = () => setIsOpen(true); | ||
const onClose = () => setIsOpen(false); | ||
|
||
return ( | ||
<> | ||
<Button size="xs" onClick={onOpen}> | ||
Export Data | ||
</Button> | ||
<Modal onClose={onClose} isOpen={isOpen}> | ||
<ModalOverlay /> | ||
<ModalContent | ||
height={"min-content"} | ||
width={{ base: "100vw", md: "400px" }} | ||
> | ||
<Box | ||
fontWeight={"bold"} | ||
borderBottom={"1px"} | ||
borderColor={"gray.200"} | ||
borderStyle={"solid"} | ||
margin={"1rem"} | ||
> | ||
<ModalHeader padding={"0.5rem"}>Data Export</ModalHeader> | ||
<ModalCloseButton /> | ||
</Box> | ||
<ModalBody> | ||
<Box marginBottom={"1rem"}> | ||
<Heading | ||
as={"h2"} | ||
fontWeight={"bold"} | ||
fontSize={"xs"} | ||
color={"primary.600"} | ||
textTransform={"uppercase"} | ||
> | ||
Geography | ||
</Heading> | ||
<Text>{geography}</Text> | ||
</Box> | ||
<Box> | ||
<FormControl> | ||
<FormLabel htmlFor="export-all-districts"> | ||
<Heading | ||
as={"h2"} | ||
fontWeight={"bold"} | ||
fontSize={"xs"} | ||
color={"primary.600"} | ||
textTransform={"uppercase"} | ||
> | ||
Include all districts? | ||
</Heading> | ||
</FormLabel> | ||
<Switch | ||
id="export-all-districts" | ||
isChecked={allDistricts} | ||
onChange={() => | ||
setAllDistricts((allDistricts) => !allDistricts) | ||
} | ||
/> | ||
</FormControl> | ||
</Box> | ||
</ModalBody> | ||
<ModalFooter> | ||
<LinkBtn | ||
isExternal | ||
href={`${import.meta.env.VITE_CPDB_DATA_URL}/${allDistricts ? "projects_in_geographies.zip" : fileName}`} | ||
width={"full"} | ||
textAlign={"center"} | ||
> | ||
Export Data | ||
</LinkBtn> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
} |
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,16 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { LinkBtn } from "./LinkBtn"; | ||
|
||
describe("LinkBtn", () => { | ||
it("should link to url while displaying text", () => { | ||
const testUrl = "test.com"; | ||
const testText = "Test Text"; | ||
render(<LinkBtn href={testUrl}>{testText}</LinkBtn>); | ||
screen.debug(); | ||
expect( | ||
screen.getByRole("link", { | ||
name: "Test Text", | ||
}), | ||
).toHaveAttribute("href", testUrl); | ||
}); | ||
}); |
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,44 @@ | ||
import { Link, LinkProps } from "@nycplanning/streetscape"; | ||
|
||
export type LinkBtnProps = LinkProps; | ||
export function LinkBtn(props: LinkBtnProps) { | ||
return ( | ||
<Link | ||
borderRadius={"base"} | ||
paddingX={6} | ||
paddingY={3} | ||
backgroundColor={"primary.600"} | ||
color={"white"} | ||
boxShadow="0 1.5 1.5 0 rgba(35, 78, 82, 0.08)" | ||
minH={11} | ||
minW={11} | ||
fontSize={"sm"} | ||
_disabled={{ | ||
backgroundColor: "primary.500", | ||
color: "white", | ||
opacity: 0.64, | ||
pointerEvents: "none", | ||
}} | ||
_hover={{ | ||
backgroundColor: "brand.50", | ||
border: "1px solid", | ||
borderColor: "brand.800", | ||
boxShadow: "0 1 1.5 0 rgba(217, 107, 39, 0.18)", | ||
color: "gray.700", | ||
fontWeight: "medium", | ||
}} | ||
_active={{ | ||
backgroundColor: "primary.500", | ||
border: "none", | ||
boxShadow: | ||
"0px 4px 4px 0px rgba(0, 0, 0, 0.08) inset, 0px -4px 4px 0px rgba(0, 0, 0, 0.08) inset, 4px 0px 4px 0px rgba(0, 0, 0, 0.08) inset, -4px 0px 4px 0px rgba(0, 0, 0, 0.08) inset;", | ||
color: "white", | ||
fontWeight: "medium", | ||
textDecorationLine: "underline", | ||
}} | ||
{...props} | ||
> | ||
{props.children} | ||
</Link> | ||
); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
VITE_ZONING_API_URL=http://localhost:3000 | ||
VITE_CPDB_DATA_URL= |