Skip to content

Commit

Permalink
Hotfix for external IDs on the Project Grid (#824)
Browse files Browse the repository at this point in the history
* Format external_ids on project grid

* Fix external id key

* Fix tests

* Let linter do it's thang

---------

Co-authored-by: Michael Franklin <[email protected]>
  • Loading branch information
illusional and illusional authored Jun 13, 2024
1 parent c748513 commit 71dddbe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions db/python/layers/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ async def get_project_summary(
has_reported_gender = any(p.reported_gender for p in pmodels)
has_karyotype = any(p.karyotype for p in pmodels)

participant_keys = [('external_id', 'Participant ID')]
participant_keys = [('external_ids', 'Participant ID')]

if has_reported_sex:
participant_keys.append(('reported_sex', 'Reported sex'))
Expand All @@ -518,7 +518,7 @@ async def get_project_summary(
participant_keys.extend(('meta.' + k, k) for k in participant_meta_keys)
sample_keys: list[tuple[str, str]] = [
('id', 'Sample ID'),
('external_id', 'External Sample ID'),
('external_ids', 'External Sample ID'),
('created_date', 'Created date'),
] + [('meta.' + k, k) for k in sample_meta_keys]

Expand Down
16 changes: 8 additions & 8 deletions test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def get_test_participant_2():
},
batch_sequencing_group_stats={'M001': {'genome': '1'}},
participants=[],
participant_keys=[('external_id', 'Participant ID')],
participant_keys=[('external_ids', 'Participant ID')],
sample_keys=[
('id', 'Sample ID'),
('external_id', 'External Sample ID'),
('external_ids', 'External Sample ID'),
('created_date', 'Created date'),
],
sequencing_group_keys=[
Expand Down Expand Up @@ -349,10 +349,10 @@ async def test_project_summary_multiple_participants(self):
},
batch_sequencing_group_stats={'M001': {'genome': '2'}},
participants=[], # data_to_class(expected_data_list),
participant_keys=[('external_id', 'Participant ID')],
participant_keys=[('external_ids', 'Participant ID')],
sample_keys=[
('id', 'Sample ID'),
('external_id', 'External Sample ID'),
('external_ids', 'External Sample ID'),
('created_date', 'Created date'),
],
sequencing_group_keys=[
Expand Down Expand Up @@ -402,10 +402,10 @@ async def test_project_summary_multiple_participants_and_filter(self):
},
batch_sequencing_group_stats={'M001': {'genome': '2'}},
participants=[], # data_to_class(expected_data_list_filtered),
participant_keys=[('external_id', 'Participant ID')],
participant_keys=[('external_ids', 'Participant ID')],
sample_keys=[
('id', 'Sample ID'),
('external_id', 'External Sample ID'),
('external_ids', 'External Sample ID'),
('created_date', 'Created date'),
],
sequencing_group_keys=[
Expand Down Expand Up @@ -478,10 +478,10 @@ async def test_field_with_space(self):
},
batch_sequencing_group_stats={'M001': {'genome': '2'}},
participants=[],
participant_keys=[('external_id', 'Participant ID')],
participant_keys=[('external_ids', 'Participant ID')],
sample_keys=[
('id', 'Sample ID'),
('external_id', 'External Sample ID'),
('external_ids', 'External Sample ID'),
('created_date', 'Created date'),
],
sequencing_group_keys=[
Expand Down
20 changes: 14 additions & 6 deletions web/src/pages/project/ProjectGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ interface ProjectGridProps {
}) => void
}

const formatExternalIds = (ids: Record<string, string>) => {
return Object.entries(ids)
.map(([k, v]) => (k.length === 0 ? sanitiseValue(v) : `${k}: ${v}`))
.join(', ')
}

const ProjectGrid: React.FunctionComponent<ProjectGridProps> = ({
summary,
projectName,
Expand Down Expand Up @@ -300,9 +306,7 @@ const ProjectGrid: React.FunctionComponent<ProjectGridProps> = ({
// const border = '1px solid'
// debugger
return (
<SUITable.Row
key={`${p.external_id}-${s.id}-${sg.id}-${assay.id}`}
>
<SUITable.Row key={`${p.id}-${s.id}-${sg.id}-${assay.id}`}>
{isFirstOfGroup && (
<SUITable.Cell
style={{
Expand Down Expand Up @@ -343,7 +347,9 @@ const ProjectGrid: React.FunctionComponent<ProjectGridProps> = ({
key={`${p.id}participant.${k}`}
rowSpan={participantRowSpan}
>
{sanitiseValue(_.get(p, k))}
{k === 'external_ids'
? formatExternalIds(p.external_ids)
: sanitiseValue(_.get(p, k))}
</SUITable.Cell>
))}
{sgidx === 0 &&
Expand All @@ -364,12 +370,14 @@ const ProjectGrid: React.FunctionComponent<ProjectGridProps> = ({
key={`${s.id}sample.${k}`}
rowSpan={samplesRowSpan}
>
{k === 'external_id' || k === 'id' ? (
{k === 'external_ids' || k === 'id' ? (
<SampleLink
id={s.id}
projectName={projectName}
>
{sanitiseValue(_.get(s, k))}
{k === 'external_ids'
? formatExternalIds(s.external_ids)
: sanitiseValue(s.id)}
</SampleLink>
) : (
sanitiseValue(_.get(s, k))
Expand Down

0 comments on commit 71dddbe

Please sign in to comment.