Skip to content

Commit 426f6f2

Browse files
committed
Move ProjectGrid state into URL
1 parent f4b26ce commit 426f6f2

File tree

7 files changed

+145
-94
lines changed

7 files changed

+145
-94
lines changed

db/python/layers/web.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ async def get_project_summary(
193193
seen_seq_types: set[str] = set(cram_number_by_seq_type.keys()).union(
194194
set(seq_number_by_seq_type.keys())
195195
)
196-
seq_number_by_seq_type_and_batch: dict[str, dict[str, int]] = defaultdict(dict)
196+
seq_number_by_seq_type_and_batch: dict[str, dict[str, str]] = defaultdict(dict)
197197
for stat in assay_batch_stats:
198198
# batch, sequencing_type,
199-
seq_number_by_seq_type_and_batch[stat.batch][stat.sequencing_type] = len(
200-
stat.sequencing_group_ids
199+
seq_number_by_seq_type_and_batch[stat.batch][stat.sequencing_type] = str(
200+
len(stat.sequencing_group_ids)
201201
)
202202

203203
seen_batches = set(a.batch for a in assay_batch_stats)
204204

205-
sequence_stats: dict[str, dict[str, int]] = {}
205+
sequence_stats: dict[str, dict[str, str]] = {}
206206
cram_seqr_stats = {}
207207

208208
for seq in seen_seq_types:
@@ -215,7 +215,7 @@ async def get_project_summary(
215215
for batch in seen_batches:
216216
batch_display = batch or '<no-batch>'
217217
sequence_stats[batch_display] = {
218-
seq: seq_number_by_seq_type_and_batch[batch].get(seq, 0)
218+
seq: seq_number_by_seq_type_and_batch[batch].get(seq, '0')
219219
for seq in seen_seq_types
220220
}
221221

@@ -225,8 +225,7 @@ async def get_project_summary(
225225
total_participants=total_participants,
226226
total_assays=total_assays,
227227
total_sequencing_groups=total_sequencing_groups,
228-
# TODO: fix this
229-
batch_sequencing_group_stats={},
228+
batch_sequencing_group_stats=sequence_stats,
230229
cram_seqr_stats=cram_seqr_stats,
231230
seqr_links=seqr_links,
232231
seqr_sync_types=seqr_sync_types,

models/models/participant.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ def to_external(self):
6868
reported_gender=self.reported_gender,
6969
karyotype=self.karyotype,
7070
meta=self.meta,
71-
samples=[s.to_external() for s in self.samples],
72-
families=[f.to_external() for f in self.families],
71+
samples=[
72+
s.to_external() for s in self.samples # pylint:disable=not-an-iterable
73+
],
74+
families=[
75+
f.to_external() for f in self.families # pylint:disable=not-an-iterable
76+
],
7377
)
7478

7579

@@ -103,7 +107,7 @@ class Participant(SMBase):
103107

104108
id: int
105109
project: ProjectId
106-
external_id: str = None
110+
external_id: str
107111
reported_sex: int | None = None
108112
reported_gender: str | None = None
109113
karyotype: str | None = None

models/models/sample.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import json
22

3-
from pydantic import Field
4-
53
from models.base import OpenApiGenNoneType, SMBase, parse_sql_bool
64
from models.models.assay import Assay, AssayInternal, AssayUpsert, AssayUpsertInternal
75
from models.models.sequencing_group import (
@@ -66,7 +64,7 @@ class NestedSampleInternal(SMBase):
6664
active: bool | None
6765
created_date: str | None
6866

69-
sequencing_groups: list[NestedSequencingGroupInternal] = Field(default_factory=list)
67+
sequencing_groups: list[NestedSequencingGroupInternal]
7068
non_sequencing_assays: list[AssayInternal]
7169

7270
def to_external(self):

models/models/sequencing_group.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ def to_external(self):
103103
platform=self.platform,
104104
meta=self.meta,
105105
external_ids=self.external_ids or {},
106-
assays=[a.to_external() for a in self.assays],
106+
assays=[
107+
a.to_external() for a in self.assays # pylint:disable=not-an-iterable
108+
],
107109
)
108110

109111

test/test_web.py

+19-20
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ async def test_project_summary_single_entry(self):
243243
await self.partl.upsert_participants(participants=[get_test_participant()])
244244

245245
result = await self.webl.get_project_summary()
246-
self.assertEqual(SINGLE_PARTICIPANT_SUMMARY_RESULT, result)
246+
self.assertDataclassEqual(SINGLE_PARTICIPANT_SUMMARY_RESULT, result)
247247

248248
@run_as_sync
249249
async def test_project_summary_to_external(self):
@@ -256,52 +256,51 @@ async def test_project_summary_to_external(self):
256256
SINGLE_PARTICIPANT_SUMMARY_RESULT.to_external(),
257257
summary.to_external(),
258258
)
259-
nested_participants = await self.webl.query_participants(
259+
internal_participants = await self.webl.query_participants(
260260
ParticipantFilter(), limit=None
261261
)
262262

263-
result = ProjectParticipantGridResponse.from_params(
264-
participants=nested_participants,
263+
ex_result = ProjectParticipantGridResponse.from_params(
264+
participants=internal_participants,
265265
total_results=1,
266266
)
267267

268-
# ex_result = result.to_external(links=None)
269-
assert isinstance(nested_participants[0].samples, list)
270-
self.assertIsInstance(nested_participants[0].samples[0].id, int)
271-
self.assertIsInstance(result.participants[0].samples[0].id, str)
268+
assert isinstance(internal_participants[0].samples, list)
269+
self.assertIsInstance(internal_participants[0].samples[0].id, int)
270+
self.assertIsInstance(ex_result.participants[0].samples[0].id, str)
272271
self.assertEqual(
273-
result.participants[0].samples[0].id,
274-
sample_id_transform_to_raw(result.participants[0].samples[0].id),
272+
sample_id_transform_to_raw(ex_result.participants[0].samples[0].id),
273+
internal_participants[0].samples[0].id,
275274
)
276275

277-
assert isinstance(nested_participants[0].samples[0].sequencing_groups, list)
278-
assert isinstance(result.participants[0].samples[0].sequencing_groups, list)
276+
assert isinstance(internal_participants[0].samples[0].sequencing_groups, list)
277+
assert isinstance(ex_result.participants[0].samples[0].sequencing_groups, list)
279278

280279
self.assertIsInstance(
281-
nested_participants[0].samples[0].sequencing_groups[0].id, int
280+
internal_participants[0].samples[0].sequencing_groups[0].id, int
282281
)
283282
self.assertIsInstance(
284-
result.participants[0].samples[0].sequencing_groups[0].id, str
283+
ex_result.participants[0].samples[0].sequencing_groups[0].id, str
285284
)
286285
self.assertEqual(
287-
result.participants[0].samples[0].sequencing_groups[0].id,
288286
sequencing_group_id_transform_to_raw(
289-
result.participants[0].samples[0].sequencing_groups[0].id
287+
ex_result.participants[0].samples[0].sequencing_groups[0].id
290288
),
289+
internal_participants[0].samples[0].sequencing_groups[0].id,
291290
)
292291

293292
assert isinstance(
294-
nested_participants[0].samples[0].sequencing_groups[0].assays, list
293+
internal_participants[0].samples[0].sequencing_groups[0].assays, list
295294
)
296295
assert isinstance(
297-
result.participants[0].samples[0].sequencing_groups[0].assays, list
296+
ex_result.participants[0].samples[0].sequencing_groups[0].assays, list
298297
)
299298
self.assertIsInstance(
300-
nested_participants[0].samples[0].sequencing_groups[0].assays[0],
299+
internal_participants[0].samples[0].sequencing_groups[0].assays[0],
301300
AssayInternal,
302301
)
303302
self.assertIsInstance(
304-
result.participants[0].samples[0].sequencing_groups[0].assays[0], Assay
303+
ex_result.participants[0].samples[0].sequencing_groups[0].assays[0], Assay
305304
)
306305

307306
@run_as_sync

web/src/pages/project/ProjectGrid.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const ProjectGridFilterRow: React.FC<{
143143
}> = ({ headerGroups, filterValues, updateFilters }) => {
144144
return (
145145
// <SUITable.Header>
146-
<React.Fragment>
146+
<tr>
147147
{headerGroups.flatMap((hg) =>
148148
hg.fields
149149
.filter((f) => f.isVisible)
@@ -188,7 +188,7 @@ const ProjectGridFilterRow: React.FC<{
188188
)
189189
})
190190
)}
191-
</React.Fragment>
191+
</tr>
192192
// </SUITable.Header>
193193
)
194194
}

0 commit comments

Comments
 (0)