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

#2840 - age display bug #2912

Merged
merged 3 commits into from
Oct 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Bulk upload form', function () {
cy.contains('VERIFIED');

// Demographics
cy.contains('41-45');
cy.contains('41 - 45');
cy.contains('Male');
cy.contains('Accountant');
cy.contains('Bangladeshi');
Expand Down
2 changes: 2 additions & 0 deletions verification/curator-service/ui/src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ function ProfileMenu(props: { user: User; version: string }): JSX.Element {
<MenuItem
onClick={() => {
dispatch(logout());
// remove previous search query from local storage
localStorage.removeItem('searchQuery');
}}
className={classes.link}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,3 @@ export const createData = (
exclusionData,
};
};

export const parseAge = (
ageStart: number | undefined,
ageEnd: number | undefined,
) => {
if (!ageStart || !ageEnd) return '';
if (ageStart === ageEnd) return ageStart?.toString() ?? '';

return `${ageStart} - ${ageEnd}`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
selectTotalCases,
selectRowsPerPage,
selectSort,
selectSearchQuery,
selectExcludeCasesDialogOpen,
selectCasesSelected,
selectDeleteCasesDialogOpen,
Expand All @@ -45,10 +44,10 @@ import Button from '@mui/material/Button';

import { nameCountry } from '../util/countryNames';
import renderDate, { renderDateRange } from '../util/date';
import { createData, labels, parseAge } from './helperFunctions';
import { createData, labels } from './helperFunctions';
import { LoaderContainer, StyledAlert } from './styled';
import { URLToSearchQuery } from '../util/searchQuery';
import { hasAnyRole } from '../util/helperFunctions';
import { hasAnyRole, parseAgeRange } from '../util/helperFunctions';
import { Helmet } from 'react-helmet';

import Pagination from './Pagination';
Expand Down Expand Up @@ -80,7 +79,6 @@ const LinelistTable = () => {
const error = useAppSelector(selectError);
const rowsPerPage = useAppSelector(selectRowsPerPage);
const sort = useAppSelector(selectSort);
const searchQuery = useAppSelector(selectSearchQuery);
const user = useAppSelector(selectUser);
const excludeCasesDialogOpen = useAppSelector(selectExcludeCasesDialogOpen);
const casesSelected = useAppSelector(selectCasesSelected);
Expand All @@ -91,6 +89,8 @@ const LinelistTable = () => {
const refetchData = useAppSelector(selectRefetchData);
const rowsAcrossPagesSelected = useAppSelector(selectRowsAcrossPages);

const searchQuery = location.search;

// Build query and fetch data
useEffect(() => {
const query =
Expand Down Expand Up @@ -130,10 +130,7 @@ const LinelistTable = () => {
parseFloat(data.location?.geometry.latitude.toFixed(4)) || 0,
parseFloat(data.location?.geometry.longitude.toFixed(4)) || 0,
data.demographics?.nationalities || '',
parseAge(
data.demographics?.ageRange?.start,
data.demographics?.ageRange?.end,
),
parseAgeRange(data.demographics?.ageRange),
data.demographics?.gender || '',
data.importedCase?.outcome ||
data.events?.find((event) => event.name === 'outcome')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ it('loads and displays case', async () => {
expect(getByText('2020-04-13')).toBeInTheDocument();
// Demographics.
expect(getByText('Non-binary/Third gender')).toBeInTheDocument();
expect(getByText('50-59')).toBeInTheDocument();
expect(getByText('50 - 59')).toBeInTheDocument();
expect(getByText('Horse breeder')).toBeInTheDocument();
expect(getByText('Swedish')).toBeInTheDocument();
expect(getByText('Asian')).toBeInTheDocument();
Expand Down
14 changes: 4 additions & 10 deletions verification/curator-service/ui/src/components/ViewCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { selectFilterBreadcrumbs } from '../redux/app/selectors';
import { selectSearchQuery } from '../redux/linelistTable/selectors';
import Chip from '@mui/material/Chip';
import { nameCountry } from './util/countryNames';
import { parseAgeRange } from './util/helperFunctions';

const styles = makeStyles((theme) => ({
errorMessage: {
Expand Down Expand Up @@ -128,15 +129,6 @@ const useStyles = makeStyles((theme) => ({
},
}));

function ageRange(range?: { start: number; end: number }): string {
if (!range) {
return '';
}
return range.start === range.end
? `${range.start}`
: `${range.start}-${range.end}`;
}

function CaseDetails(props: CaseDetailsProps): JSX.Element {
const theme = useTheme();
const showNavMenu = useMediaQuery(theme.breakpoints.up('sm'));
Expand Down Expand Up @@ -386,7 +378,9 @@ function CaseDetails(props: CaseDetailsProps): JSX.Element {
<Grid container className={classes.grid}>
<RowHeader title="Age" />
<RowContent
content={ageRange(props.c.demographics?.ageRange)}
content={parseAgeRange(
props.c.demographics?.ageRange,
)}
/>

<RowHeader title="Gender" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ export const hasAnyRole = (
}
return user?.roles?.some((r: string) => requiredRoles.includes(r));
};

export const parseAgeRange = (range?: {
start: number;
end: number;
}): string => {
if (!range) {
return '';
}
return range.start === range.end
? `${range.start}`
: `${range.start} - ${range.end}`;
};