-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,001 additions
and
307 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
84 changes: 84 additions & 0 deletions
84
spotlight-client/src/RacialDisparitiesNarrativePage/BarChartPair.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,84 @@ | ||
// Recidiviz - a data platform for criminal justice reform | ||
// Copyright (C) 2021 Recidiviz, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// ============================================================================= | ||
|
||
import useBreakpoint from "@w11r/use-breakpoint"; | ||
import { rem } from "polished"; | ||
import React, { useState } from "react"; | ||
import styled from "styled-components/macro"; | ||
import { ItemToHighlight, ProportionalBar } from "../charts"; | ||
import { DemographicCategoryRecords } from "../contentModels/types"; | ||
import VizControls, { VizControlsProps } from "../VizControls"; | ||
|
||
const CHART_HEIGHT = 165; | ||
|
||
const CHART_HEIGHT_MOBILE = 100; | ||
|
||
const Wrapper = styled.div` | ||
padding: ${rem(48)} 0; | ||
`; | ||
|
||
const Spacer = styled.div` | ||
height: ${rem(24)}; | ||
`; | ||
|
||
type BarChartPairProps = { | ||
data: DemographicCategoryRecords[]; | ||
download: () => void; | ||
filters: VizControlsProps["filters"]; | ||
methodology: string; | ||
}; | ||
|
||
export default function BarChartPair({ | ||
data, | ||
download, | ||
filters, | ||
methodology, | ||
}: BarChartPairProps): React.ReactElement { | ||
const [highlightedCategory, setHighlightedCategory] = useState< | ||
ItemToHighlight | undefined | ||
>(); | ||
|
||
const chartHeight = useBreakpoint(CHART_HEIGHT, [ | ||
"mobile-", | ||
CHART_HEIGHT_MOBILE, | ||
]); | ||
|
||
return ( | ||
<Wrapper> | ||
<VizControls | ||
filters={filters} | ||
methodology={methodology} | ||
download={download} | ||
/> | ||
<ProportionalBar | ||
data={data[0].records} | ||
title={data[0].label} | ||
height={chartHeight} | ||
highlighted={highlightedCategory} | ||
showLegend={false} | ||
/> | ||
<Spacer /> | ||
<ProportionalBar | ||
data={data[1].records} | ||
title={data[1].label} | ||
height={chartHeight} | ||
highlighted={highlightedCategory} | ||
setHighlighted={setHighlightedCategory} | ||
/> | ||
</Wrapper> | ||
); | ||
} |
78 changes: 78 additions & 0 deletions
78
spotlight-client/src/RacialDisparitiesNarrativePage/RaceOrEthnicityFilterSelect.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,78 @@ | ||
// Recidiviz - a data platform for criminal justice reform | ||
// Copyright (C) 2021 Recidiviz, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// ============================================================================= | ||
|
||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import React from "react"; | ||
import RacialDisparitiesNarrative from "../contentModels/RacialDisparitiesNarrative"; | ||
import contentFixture from "../contentModels/__fixtures__/tenant_content_exhaustive"; | ||
import { reactImmediately } from "../testUtils"; | ||
import RaceOrEthnicityFilterSelect from "./RaceOrEthnicityFilterSelect"; | ||
|
||
const expectedOptions = [ | ||
{ id: "AMERICAN_INDIAN_ALASKAN_NATIVE", label: "Native American" }, | ||
{ id: "BLACK", label: "Black" }, | ||
{ id: "HISPANIC", label: "Hispanic" }, | ||
{ id: "WHITE", label: "White" }, | ||
{ id: "OTHER", label: "Other" }, | ||
]; | ||
|
||
let narrative: RacialDisparitiesNarrative; | ||
|
||
beforeEach(() => { | ||
narrative = RacialDisparitiesNarrative.build({ | ||
tenantId: "US_ND", | ||
content: contentFixture.racialDisparitiesNarrative, | ||
}); | ||
|
||
render(<RaceOrEthnicityFilterSelect narrative={narrative} />); | ||
}); | ||
|
||
test("has expected options", () => { | ||
const menuButton = screen.getByRole("button", { | ||
name: "Race or Ethnicity Black", | ||
}); | ||
fireEvent.click(menuButton); | ||
|
||
const options = screen.getAllByRole("option"); | ||
|
||
expect(options.length).toBe(expectedOptions.length); | ||
|
||
options.forEach((option, index) => | ||
expect(option).toHaveTextContent(expectedOptions[index].label) | ||
); | ||
}); | ||
|
||
test("changes demographic filter", () => { | ||
const menuButton = screen.getByRole("button", { | ||
name: "Race or Ethnicity Black", | ||
}); | ||
|
||
expectedOptions.forEach((expectedOption) => { | ||
// open the menu | ||
fireEvent.click(menuButton); | ||
|
||
const option = screen.getByRole("option", { name: expectedOption.label }); | ||
fireEvent.click(option); | ||
|
||
reactImmediately(() => { | ||
expect(narrative.selectedCategory).toBe(expectedOption.id); | ||
expect(menuButton).toHaveTextContent(expectedOption.label); | ||
}); | ||
}); | ||
|
||
expect.hasAssertions(); | ||
}); |
59 changes: 59 additions & 0 deletions
59
spotlight-client/src/RacialDisparitiesNarrativePage/RaceOrEthnicityFilterSelect.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,59 @@ | ||
// Recidiviz - a data platform for criminal justice reform | ||
// Copyright (C) 2021 Recidiviz, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// ============================================================================= | ||
|
||
import { action } from "mobx"; | ||
import { observer } from "mobx-react-lite"; | ||
import React from "react"; | ||
import RacialDisparitiesNarrative from "../contentModels/RacialDisparitiesNarrative"; | ||
import { | ||
getDemographicCategories, | ||
getDemographicViewLabel, | ||
RaceIdentifier, | ||
} from "../demographics"; | ||
import { Dropdown } from "../UiLibrary"; | ||
|
||
const DROPDOWN_OPTIONS = getDemographicCategories( | ||
"raceOrEthnicity" | ||
).map(({ identifier, label }) => ({ label, id: identifier })); | ||
|
||
type RaceOrEthnicityFilterSelectProps = { | ||
narrative: RacialDisparitiesNarrative; | ||
}; | ||
|
||
const RaceOrEthnicityFilterSelect: React.FC<RaceOrEthnicityFilterSelectProps> = ({ | ||
narrative, | ||
}) => { | ||
const onChange = action( | ||
"change race/ethnicity filter", | ||
(newFilter: string) => { | ||
// safe assertion because this is the id type in our options array | ||
// eslint-disable-next-line no-param-reassign | ||
narrative.selectedCategory = newFilter as RaceIdentifier; | ||
} | ||
); | ||
|
||
return ( | ||
<Dropdown | ||
label={getDemographicViewLabel("raceOrEthnicity")} | ||
onChange={onChange} | ||
options={DROPDOWN_OPTIONS} | ||
selectedId={narrative.selectedCategory} | ||
/> | ||
); | ||
}; | ||
|
||
export default observer(RaceOrEthnicityFilterSelect); |
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
Oops, something went wrong.