@@ -19,19 +19,21 @@ import useConfirmDialog from '@/hooks/useConfirmDialog';
19
19
20
20
import './index.scss' ;
21
21
import { ReportType } from '@/context/ReportContext' ;
22
- import { MicrobialType , MutationBurdenType , TmburType } from '@/common' ;
22
+ import { ImmuneType , MicrobialType , MutationBurdenType , TmburType } from '@/common' ;
23
23
import snackbar from '@/services/SnackbarUtils' ;
24
24
25
25
type TumourSummaryEditProps = {
26
26
microbial : MicrobialType [ ] ;
27
27
report : ReportType ;
28
+ tCellCd8 : ImmuneType ;
28
29
mutationBurden : MutationBurdenType ;
29
- tmburMutBur ? : TmburType ;
30
+ tmburMutBur : TmburType ;
30
31
isOpen : boolean ;
31
32
onClose : (
32
33
isSaved : boolean ,
33
34
newMicrobialData ?: MicrobialType [ ] ,
34
35
newReportData ?: ReportType ,
36
+ newTCellCd8Data ?: ImmuneType ,
35
37
newMutationBurdenData ?: MutationBurdenType ,
36
38
newTmBurMutBurData ?: TmburType ,
37
39
) => void ;
@@ -43,6 +45,7 @@ const TumourSummaryEdit = ({
43
45
report : {
44
46
template : { name : reportType } ,
45
47
} ,
48
+ tCellCd8,
46
49
mutationBurden,
47
50
tmburMutBur,
48
51
isOpen,
@@ -53,10 +56,12 @@ const TumourSummaryEdit = ({
53
56
54
57
const [ newMicrobialData , setNewMicrobialData ] = useState ( cloneDeep ( microbial ) ) ;
55
58
const [ newReportData , setNewReportData ] = useState < Partial < ReportType > > ( null ) ;
59
+ const [ newTCellCd8Data , setNewTCellCd8Data ] = useState < Partial < ImmuneType > > ( null ) ;
56
60
const [ newMutationBurdenData , setNewMutationBurdenData ] = useState < Partial < MutationBurdenType > > ( null ) ;
57
61
const [ newTmburMutData , setNewTmburMutData ] = useState < Partial < TmburType > > ( null ) ;
58
62
const [ microbialDirty , setMicrobialDirty ] = useState ( false ) ;
59
63
const [ reportDirty , setReportDirty ] = useState ( false ) ;
64
+ const [ tCellCd8Dirty , setTCellCd8Dirty ] = useState ( false ) ;
60
65
const [ mutationBurdenDirty , setMutationBurdenDirty ] = useState ( false ) ;
61
66
const [ tmburMutDirty , setTmburMutDirty ] = useState ( false ) ;
62
67
const [ isApiCalling , setIsApiCalling ] = useState ( false ) ;
@@ -71,6 +76,15 @@ const TumourSummaryEdit = ({
71
76
}
72
77
} , [ report ] ) ;
73
78
79
+ useEffect ( ( ) => {
80
+ if ( tCellCd8 ) {
81
+ setNewTCellCd8Data ( {
82
+ score : tCellCd8 . score ,
83
+ percentile : tCellCd8 . percentile ,
84
+ } ) ;
85
+ }
86
+ } , [ tCellCd8 ] ) ;
87
+
74
88
useEffect ( ( ) => {
75
89
if ( mutationBurden ) {
76
90
setNewMutationBurdenData ( {
@@ -97,6 +111,12 @@ const TumourSummaryEdit = ({
97
111
setReportDirty ( true ) ;
98
112
} , [ ] ) ;
99
113
114
+ const handleTCellCd8Change = useCallback ( ( event : React . ChangeEvent < HTMLInputElement > ) => {
115
+ const { target : { value, name } } = event ;
116
+ setNewTCellCd8Data ( ( prevVal ) => ( { ...prevVal , [ name ] : value } ) ) ;
117
+ setTCellCd8Dirty ( true ) ;
118
+ } , [ ] ) ;
119
+
100
120
const handleMutationBurdenChange = useCallback ( ( event : React . ChangeEvent < HTMLInputElement > ) => {
101
121
const { target : { value, name } } = event ;
102
122
setNewMutationBurdenData ( ( prevVal ) => ( { ...prevVal , [ name ] : value } ) ) ;
@@ -144,6 +164,16 @@ const TumourSummaryEdit = ({
144
164
apiCalls . push ( { request : ( ) => null } ) ;
145
165
}
146
166
167
+ if ( tCellCd8Dirty && newTCellCd8Data ) {
168
+ if ( tCellCd8 ?. ident ) {
169
+ apiCalls . push ( api . put ( `/reports/${ report . ident } /immune-cell-types/${ tCellCd8 . ident } ` , newTCellCd8Data , { } ) ) ;
170
+ } else {
171
+ apiCalls . push ( api . post ( `/reports/${ report . ident } /immune-cell-types` , { ...newTCellCd8Data , cellType : 'T cells CD8' } , { } ) ) ;
172
+ }
173
+ } else {
174
+ apiCalls . push ( { request : ( ) => null } ) ;
175
+ }
176
+
147
177
if ( mutationBurdenDirty && newMutationBurdenData ) {
148
178
if ( mutationBurden ?. ident ) {
149
179
apiCalls . push ( api . put ( `/reports/${ report . ident } /mutation-burden/${ mutationBurden . ident } ` , newMutationBurdenData , { } ) ) ;
@@ -168,19 +198,37 @@ const TumourSummaryEdit = ({
168
198
setIsApiCalling ( false ) ;
169
199
} else {
170
200
try {
171
- const resp = await callSet . request ( ) ;
172
- const tmburMutResp = resp . pop ( ) ;
173
- const primaryBurdenResp = resp . pop ( ) ;
174
- const reportResp = resp . pop ( ) ;
201
+ await callSet . request ( ) ;
202
+
203
+ let microbialResp = null ;
204
+ let immuneResp = null ;
205
+ let tmburMutResp = null ;
206
+ let mutationBurdenResp = null ;
207
+ let reportResp = null ;
208
+
209
+ if ( microbialDirty ) {
210
+ microbialResp = await api . get ( `/reports/${ report . ident } /summary/microbial` ) . request ( ) ;
211
+ }
212
+ if ( tCellCd8Dirty ) {
213
+ immuneResp = await api . get ( `/reports/${ report . ident } /immune-cell-types` ) . request ( ) ;
214
+ }
215
+ if ( tmburMutDirty ) {
216
+ tmburMutResp = await api . get ( `/reports/${ report . ident } /tmbur-mutation-burden` ) . request ( ) ;
217
+ }
218
+ if ( mutationBurdenDirty ) {
219
+ mutationBurdenResp = await api . get ( `/reports/${ report . ident } /mutation-burden` ) . request ( ) ;
220
+ }
221
+ if ( reportDirty ) {
222
+ reportResp = await api . get ( `/reports/${ report . ident } ` ) . request ( ) ;
223
+ }
175
224
176
- // Too complicated between delete/update/new, might as well grab updated micb species for report again
177
- const microbialResp = await api . get ( `/reports/${ report . ident } /summary/microbial` ) . request ( ) ;
178
225
snackbar . success ( 'Successfully updated Tumour Summary' ) ;
179
226
onClose (
180
227
true ,
181
228
microbialDirty ? microbialResp : null ,
229
+ tCellCd8Dirty ? immuneResp . find ( ( { cellType} ) => cellType === 'T cells CD8' ) : null ,
182
230
reportDirty ? reportResp : null ,
183
- mutationBurdenDirty ? primaryBurdenResp : null ,
231
+ mutationBurdenDirty ? mutationBurdenResp . find ( ( mb ) => mb . role === 'primary' ) : null ,
184
232
tmburMutDirty ? tmburMutResp : null ,
185
233
) ;
186
234
} catch ( callSetError ) {
@@ -198,6 +246,8 @@ const TumourSummaryEdit = ({
198
246
microbialDirty ,
199
247
reportDirty ,
200
248
newReportData ,
249
+ tCellCd8Dirty ,
250
+ newTCellCd8Data ,
201
251
mutationBurdenDirty ,
202
252
newMutationBurdenData ,
203
253
tmburMutDirty ,
@@ -206,6 +256,7 @@ const TumourSummaryEdit = ({
206
256
newMicrobialData ,
207
257
microbial ,
208
258
report ?. ident ,
259
+ tCellCd8 ?. ident ,
209
260
mutationBurden ?. ident ,
210
261
tmburMutBur ?. ident ,
211
262
showConfirmDialog ,
@@ -327,13 +378,40 @@ const TumourSummaryEdit = ({
327
378
return null ;
328
379
} , [ handleClicked , handleDelete , handleKeyDown , newMicrobialData ] ) ;
329
380
381
+ const tCellCd8DataSection = useMemo ( ( ) => {
382
+ return (
383
+ < >
384
+ < TextField
385
+ className = "tumour-dialog__text-field"
386
+ label = "CD8+ T Cell Score"
387
+ value = { newTCellCd8Data ?. score ?? 0 }
388
+ name = "score"
389
+ onChange = { handleTCellCd8Change }
390
+ variant = "outlined"
391
+ fullWidth
392
+ type = "number"
393
+ />
394
+ < TextField
395
+ className = "tumour-dialog__text-field"
396
+ label = "CD8+ T Cell Percentile"
397
+ value = { newTCellCd8Data ?. percentile ?? 0 }
398
+ name = "percentile"
399
+ onChange = { handleTCellCd8Change }
400
+ variant = "outlined"
401
+ fullWidth
402
+ type = "number"
403
+ />
404
+ </ >
405
+ )
406
+ } , [ newTCellCd8Data , handleTCellCd8Change ] )
407
+
330
408
const mutBurDataSection = useMemo ( ( ) => {
331
409
return (
332
410
< >
333
411
< TextField
334
412
className = "tumour-dialog__text-field"
335
413
label = "Mutation Burden (Mut/Mb)"
336
- value = { newMutationBurdenData ?. totalMutationsPerMb ?? null }
414
+ value = { newMutationBurdenData ?. totalMutationsPerMb ?? 0 }
337
415
name = "totalMutationsPerMb"
338
416
onChange = { handleMutationBurdenChange }
339
417
variant = "outlined"
@@ -343,7 +421,7 @@ const TumourSummaryEdit = ({
343
421
< TextField
344
422
className = "tumour-dialog__text-field"
345
423
label = "SV Burden (POG average)"
346
- value = { newMutationBurdenData ?. qualitySvCount ?? null }
424
+ value = { newMutationBurdenData ?. qualitySvCount ?? 0 }
347
425
name = "qualitySvCount"
348
426
onChange = { handleMutationBurdenChange }
349
427
variant = "outlined"
@@ -353,7 +431,7 @@ const TumourSummaryEdit = ({
353
431
< TextField
354
432
className = "tumour-dialog__text-field"
355
433
label = "SV Burden (Percentile)"
356
- value = { newMutationBurdenData ?. qualitySvPercentile ?? null }
434
+ value = { newMutationBurdenData ?. qualitySvPercentile ?? 0 }
357
435
name = "qualitySvPercentile"
358
436
onChange = { handleMutationBurdenChange }
359
437
variant = "outlined"
@@ -370,7 +448,7 @@ const TumourSummaryEdit = ({
370
448
< TextField
371
449
className = "tumour-dialog__text-field"
372
450
label = "genomeSnvTmb"
373
- value = { newTmburMutData ?. genomeSnvTmb ?? null }
451
+ value = { newTmburMutData ?. genomeSnvTmb ?? 0 }
374
452
name = "genomeSnvTmb"
375
453
onChange = { handleTmburChange }
376
454
variant = "outlined"
@@ -380,7 +458,7 @@ const TumourSummaryEdit = ({
380
458
< TextField
381
459
className = "tumour-dialog__text-field"
382
460
label = "genomeIndelTmb"
383
- value = { newTmburMutData ?. genomeIndelTmb ?? null }
461
+ value = { newTmburMutData ?. genomeIndelTmb ?? 0 }
384
462
name = "genomeIndelTmb"
385
463
onChange = { handleTmburChange }
386
464
variant = "outlined"
@@ -399,6 +477,7 @@ const TumourSummaryEdit = ({
399
477
< DialogContent className = "tumour-dialog__content" >
400
478
{ reportDataSection }
401
479
{ micbDataSection }
480
+ { tCellCd8DataSection }
402
481
{ mutBurDataSection }
403
482
{ tmburMutBurSection }
404
483
</ DialogContent >
0 commit comments