Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race & Ethnicities (Playtesting Followup): Group Races by Ethnicities in Data Entry Publish Confirmation #179

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions publisher/src/components/Reports/PublishConfirmation.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
palette,
typography,
} from "@justice-counts/common/components/GlobalStyles";
import styled from "styled-components/macro";
import styled, { css } from "styled-components/macro";

import { Button } from "../DataUpload";
import {
Expand Down Expand Up @@ -190,10 +190,16 @@ export const MetricDetailWrapper = styled.div<{ isExpanded: boolean }>`
display: ${({ isExpanded }) => (isExpanded ? "block" : "none")};
`;

export const MetricSubTitleContainer = styled.div`
export const MetricSubTitleContainer = styled.div<{ secondary?: boolean }>`
${typography.sizeCSS.small}
margin-bottom: 16px;
margin-top: 16px;
${({ secondary }) =>
secondary &&
css`
color: ${palette.highlight.grey7};
margin-bottom: 8px;
`}
`;

export const Breakdown = styled.div<{ missing?: boolean }>`
Expand Down
118 changes: 95 additions & 23 deletions publisher/src/components/Reports/PublishConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { showToast } from "@justice-counts/common/components/Toast";
import {
MetricContextWithErrors,
MetricDisaggregationDimensions,
MetricDisaggregationDimensionsWithErrors,
MetricDisaggregationsWithErrors,
MetricWithErrors,
Expand All @@ -33,6 +34,7 @@ import logoImg from "../assets/jc-logo-vector.png";
import errorIcon from "../assets/status-error-icon.png";
import { DataUploadHeader } from "../DataUpload";
import { Logo, LogoContainer } from "../Header";
import { RACE_ETHNICITY_DISAGGREGATION_KEY } from "../MetricConfiguration";
import { Heading, Subheading } from "../ReviewMetrics/ReviewMetrics.styles";
import {
BreakdownErrorImg,
Expand Down Expand Up @@ -62,38 +64,108 @@ import {
VerticalLine,
} from "./PublishConfirmation.styles";

const RaceEthnicitiesGroupedByEthnicity: React.FC<{
dimensions: MetricDisaggregationDimensions[] &
MetricDisaggregationDimensionsWithErrors[];
}> = ({ dimensions }) => {
const dimensionsGroupedByEthnicity =
dimensions.reduce(
(acc, dimension) => {
if (dimension.ethnicity === "Hispanic") {
acc.Hispanic.push(dimension);
}
if (dimension.ethnicity === "Not Hispanic") {
acc["Not Hispanic"].push(dimension);
}
if (dimension.ethnicity === "Unknown Ethnicity") {
acc["Unknown Ethnicity"].push(dimension);
}
return acc;
},
{
Hispanic: [],
"Not Hispanic": [],
"Unknown Ethnicity": [],
} as { [key: string]: MetricDisaggregationDimensionsWithErrors[] }
) || {};
const dimensionsGroupedByEthnicityEntries = Object.entries(
dimensionsGroupedByEthnicity
);

return (
<>
{dimensionsGroupedByEthnicityEntries.map(
([ethnicity, groupedDimensions]) => (
<>
<MetricSubTitleContainer secondary>
{ethnicity}
</MetricSubTitleContainer>
<DisaggregationBreakdownContainer>
{groupedDimensions.map((dimension) => (
<DisaggregationBreakdown
key={dimension.key}
error={!!dimension.error}
>
<BreakdownLabelContainer>
<BreakdownLabel>{dimension.race}</BreakdownLabel>
{!!dimension.error && (
<BreakdownErrorImg src={errorIcon} alt="" />
)}
</BreakdownLabelContainer>
<BreakdownValue
missing={!dimension.value}
error={!!dimension.error}
>
{dimension.value?.toLocaleString("en-US") || "--"}
</BreakdownValue>
</DisaggregationBreakdown>
))}
</DisaggregationBreakdownContainer>
</>
)
)}
</>
);
};

const Disaggregation: React.FC<{
disaggregation: MetricDisaggregationsWithErrors;
}> = ({ disaggregation }) => {
const { display_name: displayName, dimensions } = disaggregation;

return (
<>
<MetricSubTitleContainer>{displayName}</MetricSubTitleContainer>
<DisaggregationBreakdownContainer>
{dimensions.map(
(dimension: MetricDisaggregationDimensionsWithErrors) => {
return (
<DisaggregationBreakdown
key={dimension.key}
error={!!dimension.error}
>
<BreakdownLabelContainer>
<BreakdownLabel>{dimension.label}</BreakdownLabel>
{!!dimension.error && (
<BreakdownErrorImg src={errorIcon} alt="" />
)}
</BreakdownLabelContainer>
<BreakdownValue
missing={!dimension.value}

{disaggregation.key === RACE_ETHNICITY_DISAGGREGATION_KEY ? (
<RaceEthnicitiesGroupedByEthnicity dimensions={dimensions} />
) : (
<DisaggregationBreakdownContainer>
{dimensions.map(
(dimension: MetricDisaggregationDimensionsWithErrors) => {
return (
<DisaggregationBreakdown
key={dimension.key}
error={!!dimension.error}
>
{dimension.value?.toLocaleString("en-US") || "--"}
</BreakdownValue>
</DisaggregationBreakdown>
);
}
)}
</DisaggregationBreakdownContainer>
<BreakdownLabelContainer>
<BreakdownLabel>{dimension.label}</BreakdownLabel>
{!!dimension.error && (
<BreakdownErrorImg src={errorIcon} alt="" />
)}
</BreakdownLabelContainer>
<BreakdownValue
missing={!dimension.value}
error={!!dimension.error}
>
{dimension.value?.toLocaleString("en-US") || "--"}
</BreakdownValue>
</DisaggregationBreakdown>
);
}
)}
</DisaggregationBreakdownContainer>
)}
</>
);
};
Expand Down