Skip to content

Commit

Permalink
Add Other textbox to race breakdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nasaownsky committed Oct 17, 2024
1 parent 6ed810d commit 8387bba
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,11 @@ export const ContextLabel = styled.div`
color: ${palette.highlight.grey8};
margin-bottom: 16px;
`;

export const InputWrapper = styled.div`
margin-bottom: 16px;
textarea {
height: 100px;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
CheckboxOption,
CheckboxOptions,
} from "@justice-counts/common/components/CheckboxOptions";
import { NewInput } from "@justice-counts/common/components/Input";
import {
RadioButton,
RadioButtonsWrapper,
Expand Down Expand Up @@ -144,6 +145,9 @@ function RaceEthnicitiesModalForm({
return "NO_ETHNICITY_HISPANIC_NOT_SPECIFIED";
};

const [isOtherChecked, setOtherChecked] = useState(false);
const [otherDescription, setOtherDescription] = useState("");

const handleUpdateRacesDimensions = () => {
if (!systemSearchParam || !metricSearchParam) return;
const currentState = determineCurrentState();
Expand All @@ -160,7 +164,8 @@ function RaceEthnicitiesModalForm({
currentState,
raceEthnicityGridStates,
systemSearchParam,
metricSearchParam
metricSearchParam,
otherDescription
);
saveMetricSettings(updatedDimensions, agencyId);
};
Expand Down Expand Up @@ -207,9 +212,25 @@ function RaceEthnicitiesModalForm({
capture for race?
</Styled.ToggleSwitchesListHeader>
<Styled.CheckboxWrapper>
{isOtherChecked && (
<Styled.InputWrapper>
<NewInput
type="text"
label=""
placeholder={`If the listed categories do not adequately describe this breakdown, please describe additional definition/clarification of the "Other" selection.`}
value={otherDescription}
multiline
onChange={(e) => setOtherDescription(e.target.value)}
fullWidth
/>
</Styled.InputWrapper>
)}
<CheckboxOptions
options={raceEthnicityOptions}
onChange={({ key, checked }) => {
if (key === "Other") {
setOtherChecked(!checked);
}
setRacesStatusObject({
...racesStatusObject,
[key]: !checked,
Expand Down
2 changes: 2 additions & 0 deletions publisher/src/components/MetricsConfiguration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type Dimensions = {
enabled?: boolean | null;
label?: string;
description?: string;
other_description?: string;
key?: string;
race?: Races;
ethnicity?: Ethnicities;
Expand All @@ -101,6 +102,7 @@ export type UpdatedDimension = {
enabled: boolean;
race: Races;
ethnicity: Ethnicities;
other_description?: string;
};

export type UpdatedDisaggregation = {
Expand Down
12 changes: 11 additions & 1 deletion publisher/src/stores/MetricConfigStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,8 @@ class MetricConfigStore {
state: StateKeys,
gridStates: RaceEthnicitiesGridStates,
system: AgencySystem,
metricKey: string
metricKey: string,
otherDescription?: string
): UpdatedDisaggregation => {
const ethnicitiesByRace = this.getEthnicitiesByRace(system, metricKey);

Expand Down Expand Up @@ -1192,6 +1193,15 @@ class MetricConfigStore {
raceEthnicitiesDimensions &&
(Object.values(raceEthnicitiesDimensions) as UpdatedDimension[]);

if (otherDescription) {
const otherDimension = dimensions.find(
(dimension) => dimension.race === "Other" && dimension.enabled
);
if (otherDimension) {
otherDimension.other_description = otherDescription;
}
}

/** Return an object w/ all dimensions in the desired backend data structure for saving purposes */
return {
key: metricKey,
Expand Down

0 comments on commit 8387bba

Please sign in to comment.