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.
Capital Projects in Community District
Implement the panel to show capital projects in a community district closes #15
- Loading branch information
1 parent
a1e78cf
commit 6d2e6ab
Showing
5 changed files
with
176 additions
and
48 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/components/CapitalProjectsList/CapitalProjectsPanel.test.tsx
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,17 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { CapitalProjectsPanel } from "./CapitalProjectsPanel"; | ||
|
||
describe("CapitalProjectsPanel", () => { | ||
it("should contain a project list", () => { | ||
render( | ||
<CapitalProjectsPanel | ||
capitalProjects={[]} | ||
agencies={[]} | ||
district="Community District" | ||
> | ||
<></> | ||
</CapitalProjectsPanel>, | ||
); | ||
expect(screen.getByText(/Mapped Capital Projects/)).toBeVisible(); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
app/components/CapitalProjectsList/CapitalProjectsPanel.tsx
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,38 @@ | ||
import { Hide, Show } from "@nycplanning/streetscape"; | ||
import { | ||
CapitalProjectsAccordionPanel, | ||
CapitalProjectsAccordionPanelProps, | ||
} from "./CapitalProjectsAccordionPanel"; | ||
import { | ||
CapitalProjectsDrawer, | ||
CapitalProjectsDrawerProps, | ||
} from "./CapitalProjectsDrawer"; | ||
|
||
export interface CapitalProjectsPanelProps | ||
extends CapitalProjectsAccordionPanelProps, | ||
CapitalProjectsDrawerProps {} | ||
|
||
export function CapitalProjectsPanel(props: CapitalProjectsPanelProps) { | ||
return ( | ||
<> | ||
<Show above="sm"> | ||
<CapitalProjectsAccordionPanel | ||
capitalProjects={props.capitalProjects} | ||
agencies={props.agencies} | ||
district={props.district} | ||
> | ||
{props.children} | ||
</CapitalProjectsAccordionPanel> | ||
</Show> | ||
<Hide above="sm"> | ||
<CapitalProjectsDrawer | ||
capitalProjects={props.capitalProjects} | ||
agencies={props.agencies} | ||
district={props.district} | ||
> | ||
{props.children} | ||
</CapitalProjectsDrawer> | ||
</Hide> | ||
</> | ||
); | ||
} |
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,3 +1,4 @@ | ||
export { CapitalProjectsAccordionPanel } from "./CapitalProjectsAccordionPanel"; | ||
export { CapitalProjectsList } from "./CapitalProjectsList"; | ||
export { CapitalProjectsListItem } from "./CapitalProjectsListItem"; | ||
export { CapitalProjectsPanel } from "./CapitalProjectsPanel"; |
87 changes: 86 additions & 1 deletion
87
app/routes/boroughs.$boroughId.community-districts.$communityDistrictId.capital-projects.tsx
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,3 +1,88 @@ | ||
import { Flex } from "@nycplanning/streetscape"; | ||
import { json, LoaderFunctionArgs } from "@remix-run/node"; | ||
import { useLoaderData } from "@remix-run/react"; | ||
import { CapitalProjectsPanel } from "~/components/CapitalProjectsList"; | ||
import { Pagination } from "~/components/Pagination"; | ||
import { | ||
findAgencies, | ||
findBoroughs, | ||
findCapitalProjectsByBoroughIdCommunityDistrictId, | ||
} from "~/gen"; | ||
|
||
export async function loader({ request, params }: LoaderFunctionArgs) { | ||
const url = new URL(request.url); | ||
const itemsPerPage = 7; | ||
const pageParam = url.searchParams.get("page"); | ||
const page = pageParam === null ? 1 : parseInt(pageParam); | ||
|
||
const { boroughId, communityDistrictId } = params; | ||
if ( | ||
boroughId === undefined || | ||
communityDistrictId === undefined || | ||
isNaN(page) | ||
) { | ||
throw json("Bad request", { status: 400 }); | ||
} | ||
|
||
const offset = (page - 1) * itemsPerPage; | ||
const projectsByCommunityDistrictPromise = | ||
findCapitalProjectsByBoroughIdCommunityDistrictId( | ||
boroughId, | ||
communityDistrictId, | ||
{ | ||
limit: itemsPerPage, | ||
offset: offset, | ||
}, | ||
{ | ||
baseURL: `${import.meta.env.VITE_ZONING_API_URL}/api`, | ||
}, | ||
); | ||
|
||
const agenciesPromise = findAgencies({ | ||
baseURL: `${import.meta.env.VITE_ZONING_API_URL}/api`, | ||
}); | ||
const boroughsPromise = findBoroughs({ | ||
baseURL: `${import.meta.env.VITE_ZONING_API_URL}/api`, | ||
}); | ||
const [agenciesResponse, boroughsResponse, capitalProjectsResponse] = | ||
await Promise.all([ | ||
agenciesPromise, | ||
boroughsPromise, | ||
projectsByCommunityDistrictPromise, | ||
]); | ||
const boroughAbbr = boroughsResponse.boroughs.find( | ||
(borough) => borough.id === boroughId, | ||
)?.abbr; | ||
return { | ||
capitalProjectsResponse, | ||
agencies: agenciesResponse.agencies, | ||
boroughAbbr, | ||
communityDistrictId, | ||
}; | ||
} | ||
|
||
export default function CapitalProjectsByBoroughIdCommunityDistrictId() { | ||
return <></>; | ||
const { | ||
capitalProjectsResponse: { total: capitalProjectsTotal, capitalProjects }, | ||
agencies, | ||
boroughAbbr, | ||
communityDistrictId, | ||
} = useLoaderData<typeof loader>(); | ||
|
||
return ( | ||
<CapitalProjectsPanel | ||
capitalProjects={capitalProjects} | ||
agencies={agencies} | ||
district={`Community District ${boroughAbbr}${communityDistrictId}`} | ||
> | ||
<Flex | ||
paddingTop={4} | ||
alignItems="center" | ||
justifyContent={"space-between"} | ||
marginTop={"auto"} | ||
> | ||
<Pagination total={capitalProjectsTotal} /> | ||
</Flex> | ||
</CapitalProjectsPanel> | ||
); | ||
} |
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