Skip to content

Commit 414995c

Browse files
Merge pull request #418 from bcgsc/feat/DEVSU-2213-CD8T-score-editable
Feat/DEVSU-2213-cd8t-score-editable
2 parents a4d2681 + cdbe7d8 commit 414995c

File tree

3 files changed

+89
-12
lines changed

3 files changed

+89
-12
lines changed

app/components/TumourSummaryEdit/index.tsx

+72-7
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@ import useConfirmDialog from '@/hooks/useConfirmDialog';
1919

2020
import './index.scss';
2121
import { ReportType } from '@/context/ReportContext';
22-
import { MicrobialType, MutationBurdenType, TmburType } from '@/common';
22+
import {
23+
ImmuneType, MicrobialType, MutationBurdenType, TmburType,
24+
} from '@/common';
2325
import snackbar from '@/services/SnackbarUtils';
2426

2527
type TumourSummaryEditProps = {
2628
microbial: MicrobialType[];
2729
report: ReportType;
30+
tCellCd8: ImmuneType;
2831
mutationBurden: MutationBurdenType;
29-
tmburMutBur?: TmburType;
32+
tmburMutBur: TmburType;
3033
isOpen: boolean;
3134
onClose: (
3235
isSaved: boolean,
3336
newMicrobialData?: MicrobialType[],
3437
newReportData?: ReportType,
38+
newTCellCd8Data?: ImmuneType,
3539
newMutationBurdenData?: MutationBurdenType,
3640
newTmBurMutBurData?: TmburType,
3741
) => void;
@@ -43,6 +47,7 @@ const TumourSummaryEdit = ({
4347
report: {
4448
template: { name: reportType },
4549
},
50+
tCellCd8,
4651
mutationBurden,
4752
tmburMutBur,
4853
isOpen,
@@ -53,10 +58,12 @@ const TumourSummaryEdit = ({
5358

5459
const [newMicrobialData, setNewMicrobialData] = useState(cloneDeep(microbial));
5560
const [newReportData, setNewReportData] = useState<Partial<ReportType>>(null);
61+
const [newTCellCd8Data, setNewTCellCd8Data] = useState<Partial<ImmuneType>>(null);
5662
const [newMutationBurdenData, setNewMutationBurdenData] = useState<Partial<MutationBurdenType>>(null);
5763
const [newTmburMutData, setNewTmburMutData] = useState<Partial<TmburType>>(null);
5864
const [microbialDirty, setMicrobialDirty] = useState(false);
5965
const [reportDirty, setReportDirty] = useState(false);
66+
const [tCellCd8Dirty, setTCellCd8Dirty] = useState(false);
6067
const [mutationBurdenDirty, setMutationBurdenDirty] = useState(false);
6168
const [tmburMutDirty, setTmburMutDirty] = useState(false);
6269
const [isApiCalling, setIsApiCalling] = useState(false);
@@ -71,6 +78,15 @@ const TumourSummaryEdit = ({
7178
}
7279
}, [report]);
7380

81+
useEffect(() => {
82+
if (tCellCd8) {
83+
setNewTCellCd8Data({
84+
score: tCellCd8.score,
85+
percentile: tCellCd8.percentile,
86+
});
87+
}
88+
}, [tCellCd8]);
89+
7490
useEffect(() => {
7591
if (mutationBurden) {
7692
setNewMutationBurdenData({
@@ -97,6 +113,12 @@ const TumourSummaryEdit = ({
97113
setReportDirty(true);
98114
}, []);
99115

116+
const handleTCellCd8Change = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
117+
const { target: { value, name } } = event;
118+
setNewTCellCd8Data((prevVal) => ({ ...prevVal, [name]: value }));
119+
setTCellCd8Dirty(true);
120+
}, []);
121+
100122
const handleMutationBurdenChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
101123
const { target: { value, name } } = event;
102124
setNewMutationBurdenData((prevVal) => ({ ...prevVal, [name]: value }));
@@ -142,6 +164,16 @@ const TumourSummaryEdit = ({
142164
apiCalls.push(api.put(`/reports/${report.ident}`, newReportData, {}));
143165
}
144166

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+
145177
if (mutationBurdenDirty && newMutationBurdenData) {
146178
if (mutationBurden?.ident) {
147179
apiCalls.push(api.put(`/reports/${report.ident}/mutation-burden/${mutationBurden.ident}`, newMutationBurdenData, {}));
@@ -172,19 +204,22 @@ const TumourSummaryEdit = ({
172204
await callSet.request();
173205

174206
let microbialResp = null;
207+
let immuneResp = null;
175208
let tmburMutResp = null;
176209
let mutationBurdenResp = null;
177210
let reportResp = null;
178211

179-
// Too complicated between delete/update/new, might as well grab updated micb species for report again
180212
if (microbialDirty) {
181213
microbialResp = await api.get(`/reports/${report.ident}/summary/microbial`).request();
182214
}
215+
if (tCellCd8Dirty) {
216+
immuneResp = await api.get(`/reports/${report.ident}/immune-cell-types`).request();
217+
}
183218
if (tmburMutDirty) {
184219
tmburMutResp = await api.get(`/reports/${report.ident}/tmbur-mutation-burden`).request();
185220
}
186221
if (mutationBurdenDirty) {
187-
mutationBurdenResp = await api.get(`/reports/${report.ident}/mutation-burden/`).request();
222+
mutationBurdenResp = await api.get(`/reports/${report.ident}/mutation-burden`).request();
188223
}
189224
if (reportDirty) {
190225
reportResp = await api.get(`/reports/${report.ident}`).request();
@@ -195,6 +230,7 @@ const TumourSummaryEdit = ({
195230
true,
196231
microbialDirty ? microbialResp : null,
197232
reportDirty ? reportResp : null,
233+
tCellCd8Dirty ? immuneResp.find(({ cellType }) => cellType === 'T cells CD8') : null,
198234
mutationBurdenDirty ? mutationBurdenResp.find((mb) => mb.role === 'primary') : null,
199235
tmburMutDirty ? tmburMutResp : null,
200236
);
@@ -213,6 +249,8 @@ const TumourSummaryEdit = ({
213249
microbialDirty,
214250
reportDirty,
215251
newReportData,
252+
tCellCd8Dirty,
253+
newTCellCd8Data,
216254
mutationBurdenDirty,
217255
newMutationBurdenData,
218256
tmburMutDirty,
@@ -221,6 +259,7 @@ const TumourSummaryEdit = ({
221259
newMicrobialData,
222260
microbial,
223261
report?.ident,
262+
tCellCd8?.ident,
224263
mutationBurden?.ident,
225264
tmburMutBur?.ident,
226265
showConfirmDialog,
@@ -342,6 +381,31 @@ const TumourSummaryEdit = ({
342381
return null;
343382
}, [handleClicked, handleDelete, handleKeyDown, newMicrobialData]);
344383

384+
const tCellCd8DataSection = useMemo(() => (
385+
<>
386+
<TextField
387+
className="tumour-dialog__text-field"
388+
label="CD8+ T Cell Score"
389+
value={newTCellCd8Data?.score ?? null}
390+
name="score"
391+
onChange={handleTCellCd8Change}
392+
variant="outlined"
393+
fullWidth
394+
type="number"
395+
/>
396+
<TextField
397+
className="tumour-dialog__text-field"
398+
label="CD8+ T Cell Percentile"
399+
value={newTCellCd8Data?.percentile ?? null}
400+
name="percentile"
401+
onChange={handleTCellCd8Change}
402+
variant="outlined"
403+
fullWidth
404+
type="number"
405+
/>
406+
</>
407+
), [newTCellCd8Data, handleTCellCd8Change]);
408+
345409
const mutBurDataSection = useMemo(() => (
346410
<>
347411
<TextField
@@ -377,7 +441,7 @@ const TumourSummaryEdit = ({
377441
</>
378442
), [newMutationBurdenData, handleMutationBurdenChange]);
379443

380-
const tmburMutBurSection = useMemo(() => {
444+
const tmburMutBurSection = useMemo(() => (
381445
<>
382446
<TextField
383447
className="tumour-dialog__text-field"
@@ -399,8 +463,8 @@ const TumourSummaryEdit = ({
399463
fullWidth
400464
type="number"
401465
/>
402-
</>;
403-
}, [newTmburMutData?.genomeSnvTmb, newTmburMutData?.genomeIndelTmb, handleTmburChange]);
466+
</>
467+
), [newTmburMutData?.genomeSnvTmb, newTmburMutData?.genomeIndelTmb, handleTmburChange]);
404468

405469
return (
406470
<Dialog open={isOpen}>
@@ -410,6 +474,7 @@ const TumourSummaryEdit = ({
410474
<DialogContent className="tumour-dialog__content">
411475
{reportDataSection}
412476
{micbDataSection}
477+
{tCellCd8DataSection}
413478
{mutBurDataSection}
414479
{tmburMutBurSection}
415480
</DialogContent>

app/views/ReportView/components/GenomicSummary/index.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,13 @@ const GenomicSummary = ({
445445
isSaved: boolean,
446446
newMicrobialData: MicrobialType[],
447447
newReportData: ReportType,
448-
newPrimaryBurdenData: MutationBurdenType,
448+
newTCellCd8Data: ImmuneType,
449+
newMutationBurdenData: MutationBurdenType,
449450
newTmBurMutBurData: TmburType,
450451
) => {
451452
setShowTumourSummaryEdit(false);
452453

453-
if (!isSaved || (!newMicrobialData && !newReportData && !newPrimaryBurdenData && !newTmBurMutBurData)) {
454+
if (!isSaved || (!newMicrobialData && !newReportData && !newTCellCd8Data && !newMutationBurdenData && !newTmBurMutBurData)) {
454455
return;
455456
}
456457

@@ -462,8 +463,12 @@ const GenomicSummary = ({
462463
setReport(newReportData);
463464
}
464465

465-
if (newPrimaryBurdenData) {
466-
setPrimaryBurden(newPrimaryBurdenData);
466+
if (newTCellCd8Data) {
467+
setTCellCd8(newTCellCd8Data)
468+
}
469+
470+
if (newMutationBurdenData) {
471+
setPrimaryBurden(newMutationBurdenData);
467472
}
468473

469474
if (newTmBurMutBurData) {
@@ -559,6 +564,7 @@ const GenomicSummary = ({
559564
<TumourSummaryEdit
560565
microbial={microbial}
561566
report={report}
567+
tCellCd8={tCellCd8}
562568
mutationBurden={primaryBurden}
563569
tmburMutBur={tmburMutBur}
564570
isOpen={showTumourSummaryEdit}

app/views/ReportView/components/RapidSummary/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,13 @@ const RapidSummary = ({
443443
isSaved,
444444
newMicrobialData,
445445
newReportData,
446+
newTCellCd8Data: ImmuneType,
446447
newMutationBurdenData: MutationBurdenType,
447448
newTmBurMutBurData,
448449
) => {
449450
setShowTumourSummaryEdit(false);
450451

451-
if (!isSaved || (!newMicrobialData && !newReportData && !newMutationBurdenData && !newTmBurMutBurData)) {
452+
if (!isSaved || (!newMicrobialData && !newReportData && !newTCellCd8Data && !newMutationBurdenData && !newTmBurMutBurData)) {
452453
return;
453454
}
454455

@@ -460,6 +461,10 @@ const RapidSummary = ({
460461
setReport(newReportData);
461462
}
462463

464+
if (newTCellCd8Data) {
465+
setTCellCd8(newTCellCd8Data)
466+
}
467+
463468
if (newMutationBurdenData) {
464469
setPrimaryBurden(newMutationBurdenData);
465470
}
@@ -484,6 +489,7 @@ const RapidSummary = ({
484489
<TumourSummaryEdit
485490
microbial={microbial}
486491
report={report}
492+
tCellCd8={tCellCd8}
487493
mutationBurden={primaryBurden}
488494
tmburMutBur={tmburMutBur}
489495
isOpen={showTumourSummaryEdit}

0 commit comments

Comments
 (0)