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

Austenem/CAT-873 add donor age messaging #3548

Merged
merged 10 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions CHANGELOG-add-donor-age-messaging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add messaging where donors with ages > 89 are displayed on search and detail pages.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import Stack from '@mui/material/Stack';

import { StyledTableContainer, HeaderCell } from 'js/shared-styles/tables';
import IconTooltipCell from 'js/shared-styles/tables/IconTooltipCell';
import DonorAgeTooltip from 'js/shared-styles/tooltips/DonorAgeTooltip';
import { defaultColumns } from '../MetadataSection/columns';

interface MetadataTableRow {
Expand All @@ -32,7 +34,13 @@ function MetadataTable({ tableRows = [] as MetadataTableRow[], columns = default
{tableRows.map((row) => (
<TableRow key={row.key}>
<IconTooltipCell tooltipTitle={row?.description}>{row.key}</IconTooltipCell>
<TableCell>{row.value}</TableCell>
<TableCell>
<Stack direction="row">
{row.value}
{row.key === 'age_value' ||
(row.key === 'donor.age_value' && <DonorAgeTooltip donorAge={row.value} />)}
austenem marked this conversation as resolved.
Show resolved Hide resolved
</Stack>
</TableCell>
</TableRow>
))}
</TableBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useFlaskDataContext } from 'js/components/Contexts';
import { Entity, isDataset, isDonor, isPublication, isSample } from 'js/components/types';
import EntityIcon from 'js/shared-styles/icons/EntityIcon';
import { SampleCategoryIcon } from 'js/shared-styles/icons';
import DonorAgeTooltip from 'js/shared-styles/tooltips/DonorAgeTooltip';
import { getDonorMetadata, getOriginSampleAndMappedOrgan } from '../../utils';
import EntityHeaderItem from '../EntityHeaderItem';

Expand Down Expand Up @@ -72,7 +73,10 @@ function DonorItems({ data: { entity } }: EntityHeaderItemsProps) {
{race && <Typography>{race}</Typography>}
{age_unit && age_value && (
<Typography>
{age_value} {age_unit}
<Stack direction="row" justifyContent="center">
{age_value} {age_unit}
<DonorAgeTooltip donorAge={age_value} />
</Stack>
</Typography>
)}
<Divider orientation="vertical" flexItem />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';

import Stack from '@mui/system/Stack';
import Tile from 'js/shared-styles/tiles/Tile';
import EntityTileThumbnail from 'js/components/entity-tile/EntityTileThumbnail';
import { getOriginSamplesOrgan } from 'js/helpers/functions';
import { EntityWithType, isDataset, isDonor, isSample } from 'js/components/types';
import DonorAgeTooltip from 'js/shared-styles/tooltips/DonorAgeTooltip';
import { Flex, StyledDiv, BodyWrapper } from './style';

const thumbnailDimension = 80;
Expand Down Expand Up @@ -33,7 +35,10 @@ function EntityTileBody({ entity_type, id, entityData, invertColors }: EntityTil
<Tile.Text>{entityData.mapped_metadata?.sex}</Tile.Text>
<Tile.Divider invertColors={invertColors} />
<Tile.Text>
{entityData.mapped_metadata?.age_value} {entityData.mapped_metadata?.age_unit}
<Stack direction="row">
austenem marked this conversation as resolved.
Show resolved Hide resolved
{entityData.mapped_metadata?.age_value} {entityData.mapped_metadata?.age_unit}
<DonorAgeTooltip donorAge={entityData.mapped_metadata?.age_value} />
</Stack>
</Tile.Text>
</Flex>
<Tile.Text>{(entityData.mapped_metadata?.race ?? []).join(', ')}</Tile.Text>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import React from 'react';
import Stack from '@mui/material/Stack';
import { get } from 'js/helpers/nodash';
import DonorAgeTooltip from 'js/shared-styles/tooltips/DonorAgeTooltip';

const donorMetadataPath = 'mapped_metadata';
const sampleMetdataPath = 'metadata';
Expand Down Expand Up @@ -48,6 +51,14 @@ function getByPath(hitSource, field) {
}

if (Array.isArray(fieldValue)) {
if (field?.id === 'mapped_metadata.age_value') {
return (
<Stack direction="row">
{fieldValue.join(' / ')}
<DonorAgeTooltip donorAge={fieldValue.join(' / ')} />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be able to be converted with Number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the fieldValue array only contains one element - but it might be a bit safer to take only the first element of fieldValue.

</Stack>
);
}
return fieldValue.join(' / ');
}

Expand Down
2 changes: 1 addition & 1 deletion context/app/static/js/components/searchPage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function makeDonorMetadataFilters(isDonor) {
const labelPrefix = isDonor ? '' : 'Donor ';
return [
listFilter(`${pathPrefix}mapped_metadata.sex`, `${labelPrefix}Sex`),
rangeFilter(`${pathPrefix}mapped_metadata.${ageField}`, `${labelPrefix}Age`, 0, 100),
rangeFilter(`${pathPrefix}mapped_metadata.${ageField}`, `${labelPrefix}Age`, 0, 90),
listFilter(`${pathPrefix}mapped_metadata.race`, `${labelPrefix}Race`),
rangeFilter(`${pathPrefix}mapped_metadata.${bmiField}`, `${labelPrefix}BMI`, 0, 50),
];
Expand Down
4 changes: 2 additions & 2 deletions context/app/static/js/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ export interface Entity {
mapped_data_types?: string[];
mapped_data_access_level: 'Public' | 'Protected' | 'Consortium';
status: string;
mapped_metadata: Record<string, unknown>;
mapped_metadata?: Record<string, unknown>;
[key: string]: unknown;
}

export type PartialEntity = Partial<Entity> & Pick<Entity, 'entity_type' | 'uuid' | 'hubmap_id'>;

export interface Donor extends Entity {
entity_type: 'Donor';
mapped_metadata: Partial<{
mapped_metadata?: Partial<{
sex: string;
age_unit: string;
age_value: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';

import { SecondaryBackgroundTooltip } from 'js/shared-styles/tooltips';
import { StyledStack, StyledInfoIcon } from 'js/shared-styles/tooltips/DonorAgeTooltip/style';

const DONOR_AGE_TEXT = 'For donors older than 89, the metadata will indicate an age of 90.';

interface DonorAgeTooltipProps {
donorAge?: string;
}

function DonorAgeTooltip({ donorAge }: DonorAgeTooltipProps) {
if (!donorAge || Number(donorAge) <= 89) {
return null;
}

return (
<SecondaryBackgroundTooltip title={DONOR_AGE_TEXT}>
<StyledStack>
<StyledInfoIcon />
</StyledStack>
</SecondaryBackgroundTooltip>
);
}
export default DonorAgeTooltip;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import DonorAgeTooltip from './DonorAgeTooltip';

export default DonorAgeTooltip;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Stack } from '@mui/material';
import { styled } from '@mui/material/styles';
import { InfoIcon } from 'js/shared-styles/icons';

const StyledStack = styled(Stack)(({ theme }) => ({
marginLeft: theme.spacing(0.5),
justifyContent: 'center',
}));

const StyledInfoIcon = styled(InfoIcon)(({ theme }) => ({
color: theme.palette.primary.main,
fontSize: '0.75rem',
}));

export { StyledStack, StyledInfoIcon };
Loading