Skip to content

Commit

Permalink
Fix age display bug, closes #2840
Browse files Browse the repository at this point in the history
* Modified age parsing function
* Fixed other found bug: when user had filters set and refreshed
  the page there was a race condition on two queries to the DB one
  with the filters and one without. Because of that sometimes the results
  were filtered and sometimes not. This is now also fixed.
  • Loading branch information
maciej-zarzeczny committed Oct 18, 2022
1 parent 604344f commit 8b23708
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
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}`;
};

0 comments on commit 8b23708

Please sign in to comment.