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

:typo: Add cell in profile table in pt entity page #3828

Merged
merged 1 commit into from
Oct 25, 2023
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
28 changes: 28 additions & 0 deletions src/components/OutcomesAgeCells/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { IArrangerResultsTree } from '@ferlab/ui/core/graphql/types';
import { IParticipantOutcomes } from 'graphql/participants/models';

import { TABLE_EMPTY_PLACE_HOLDER } from 'common/constants';
import AgeCell from 'components/AgeCell';
import { isNumber } from 'utils/helper';

interface OwnProps {
outcomes?: IArrangerResultsTree<IParticipantOutcomes>;
}

const OutcomesAgeCells = ({ outcomes }: OwnProps) => {
const outcomeAges: number[] =
outcomes?.hits?.edges.map((x) => x.node?.age_at_event_days?.value).filter((x) => isNumber(x)) ||
[];
return (
<>
{outcomeAges.length > 0
? outcomeAges.map((age: number, index: number) => (
<AgeCell key={`${index}-${age}`} ageInDays={age} />
))
: { TABLE_EMPTY_PLACE_HOLDER }}
</>
);
};

export default OutcomesAgeCells;
4 changes: 4 additions & 0 deletions src/graphql/participants/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export const GET_PARTICIPANT_ENTITY = gql`
edges {
node {
vital_status
age_at_event_days {
value
units
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@ const en = {
trio: 'Trio',
trio_plus: ' Trio+',
trisomy: 'T21: "Trisomy 21"',
age_at_outcome_tooltip: 'Age at Vital Status',
},
study: {
count: '{count, plural, =0 {Study} =1 {Study} other {Studies}}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ import {
import { mapStudyToPedcBioportal } from 'views/Studies/utils/helper';

import { TABLE_EMPTY_PLACE_HOLDER } from 'common/constants';
import AgeCell from 'components/AgeCell';
import OutcomesAgeCells from 'components/OutcomesAgeCells';
import { ReportType } from 'services/api/reports/models';
import { SetType } from 'services/api/savedSet/models';
import { fetchReport, fetchTsvReport } from 'store/report/thunks';
import { useUser } from 'store/user';
import { updateUserConfig } from 'store/user/thunks';
import { formatQuerySortList, isNumber, scrollToTop } from 'utils/helper';
import { formatQuerySortList, scrollToTop } from 'utils/helper';
import { goToParticipantEntityPage, STATIC_ROUTES } from 'utils/routes';
import { getProTableDictionary } from 'utils/translation';

Expand Down Expand Up @@ -423,16 +423,9 @@ const defaultColumns: ProColumnType[] = [
sorter: {
multiple: 1,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ve extracted this code into a re-usable component.

render: (outcomes: IArrangerResultsTree<IParticipantOutcomes>) => {
const outcomeAges = outcomes?.hits?.edges
.map((x) => x.node?.age_at_event_days?.value)
.filter((x) => isNumber(x));
return outcomeAges.length > 0
? outcomeAges.map((age: number, index: number) => (
<AgeCell key={`${index}-${age}`} ageInDays={age} />
))
: TABLE_EMPTY_PLACE_HOLDER;
},
render: (outcomes: IArrangerResultsTree<IParticipantOutcomes>) => (
<OutcomesAgeCells outcomes={outcomes} />
),
},
];

Expand Down
24 changes: 23 additions & 1 deletion src/views/ParticipantEntity/utils/getProfileItems.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import intl from 'react-intl-universal';
import { IEntityDescriptionsItem } from '@ferlab/ui/core/pages/EntityPage';
import { Tag } from 'antd';
import { Tag, Tooltip } from 'antd';
import { IParticipantEntity, Sex } from 'graphql/participants/models';
import { capitalize } from 'lodash';

import { TABLE_EMPTY_PLACE_HOLDER } from 'common/constants';
import OutcomesAgeCells from 'components/OutcomesAgeCells';

const getVitalStatus = (participant?: IParticipantEntity) => {
const vitalStatuses = new Set();
Expand All @@ -18,6 +20,18 @@ const getVitalStatus = (participant?: IParticipantEntity) => {
return vitalStatuses.size ? vitalStatuses : TABLE_EMPTY_PLACE_HOLDER;
};

const getAgeAtVitalStatus = (participant?: IParticipantEntity) => {
const vitalStatuses = new Set();
participant?.outcomes?.hits?.edges?.forEach((o) => {
const vitalStatus = o.node.age_at_event_days.value;
if (vitalStatus) {
vitalStatuses.add(vitalStatus);
}
});

return vitalStatuses.size ? vitalStatuses : TABLE_EMPTY_PLACE_HOLDER;
};

const getProfileItems = (participant?: IParticipantEntity): IEntityDescriptionsItem[] => [
{
label: intl.get('entities.participant.race'),
Expand Down Expand Up @@ -47,6 +61,14 @@ const getProfileItems = (participant?: IParticipantEntity): IEntityDescriptionsI
label: intl.get('entities.participant.vital_status'),
value: getVitalStatus(participant),
},
{
label: (
<Tooltip title={intl.get('entities.participant.age_at_outcome_tooltip')}>
{intl.get('entities.participant.age')}
</Tooltip>
),
value: <OutcomesAgeCells outcomes={participant?.outcomes} />,
},
];

export default getProfileItems;
Loading