Skip to content

Commit eda91f8

Browse files
committed
bugfix: better logic on tumourSummary edit dialog
- some cleanup on dead code - rename tumoursummaryedit callback variable signatures to more accurately reflect data being returned no-ticket
1 parent 6baafac commit eda91f8

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

app/components/TumourSummaryEdit/index.tsx

+38-22
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,26 @@ const TumourSummaryEdit = ({
137137

138138
if (reportDirty && newReportData) {
139139
apiCalls.push(api.put(`/reports/${report.ident}`, newReportData, {}));
140-
} else {
141-
apiCalls.push({ request: () => null });
142140
}
143141

144142
if (mutationBurdenDirty && newMutationBurdenData) {
145143
if (mutationBurden?.ident) {
146144
apiCalls.push(api.put(`/reports/${report.ident}/mutation-burden/${mutationBurden.ident}`, newMutationBurdenData, {}));
147145
} else {
148-
apiCalls.push(api.post(`/reports/${report.ident}/mutation-burden`, newMutationBurdenData, {}));
146+
apiCalls.push(api.post(
147+
`/reports/${report.ident}/mutation-burden`,
148+
{ ...newMutationBurdenData, role: 'primary' },
149+
{},
150+
));
149151
}
150-
} else {
151-
apiCalls.push({ request: () => null });
152152
}
153153

154-
if (tmburMutDirty && newTmburMutData && tmburMutBur?.ident) {
155-
apiCalls.push(api.put(`/reports/${report.ident}/tmbur-mutation-burden`, newTmburMutData, {}));
156-
} else {
157-
apiCalls.push({ request: () => null });
154+
if (tmburMutDirty && newTmburMutData) {
155+
if (tmburMutBur?.ident) {
156+
apiCalls.push(api.put(`/reports/${report.ident}/tmbur-mutation-burden`, newTmburMutData, {}));
157+
} else {
158+
apiCalls.push(api.post(`/reports/${report.ident}/tmbur-mutation-burden`, newTmburMutData, {}));
159+
}
158160
}
159161

160162
callSet = new ApiCallSet(apiCalls);
@@ -164,19 +166,33 @@ const TumourSummaryEdit = ({
164166
setIsApiCalling(false);
165167
} else {
166168
try {
167-
const resp = await callSet.request();
168-
const tmburMutResp = resp.pop();
169-
const primaryBurdenResp = resp.pop();
170-
const reportResp = resp.pop();
169+
await callSet.request();
170+
171+
let microbialResp = null;
172+
let tmburMutResp = null;
173+
let mutationBurdenResp = null;
174+
let reportResp = null;
171175

172176
// Too complicated between delete/update/new, might as well grab updated micb species for report again
173-
const microbialResp = await api.get(`/reports/${report.ident}/summary/microbial`).request();
177+
if (microbialDirty) {
178+
microbialResp = await api.get(`/reports/${report.ident}/summary/microbial`).request();
179+
}
180+
if (tmburMutDirty) {
181+
tmburMutResp = await api.get(`/reports/${report.ident}/tmbur-mutation-burden`).request();
182+
}
183+
if (mutationBurdenDirty) {
184+
mutationBurdenResp = await api.get(`/reports/${report.ident}/mutation-burden/`).request();
185+
}
186+
if (reportDirty) {
187+
reportResp = await api.get(`/reports/${report.ident}`).request();
188+
}
189+
174190
snackbar.success('Successfully updated Tumour Summary');
175191
onClose(
176192
true,
177193
microbialDirty ? microbialResp : null,
178194
reportDirty ? reportResp : null,
179-
mutationBurdenDirty ? primaryBurdenResp : null,
195+
mutationBurdenDirty ? mutationBurdenResp.find((mb) => mb.role === 'primary') : null,
180196
tmburMutDirty ? tmburMutResp : null,
181197
);
182198
} catch (callSetError) {
@@ -324,12 +340,12 @@ const TumourSummaryEdit = ({
324340
}, [handleClicked, handleDelete, handleKeyDown, newMicrobialData]);
325341

326342
const mutBurDataSection = useMemo(() => {
327-
if (newMutationBurdenData) {
343+
if (reportType === 'genomic') {
328344
return (
329345
<TextField
330346
className="tumour-dialog__text-field"
331347
label="Mutation Burden (Mut/Mb)"
332-
value={newMutationBurdenData.totalMutationsPerMb}
348+
value={newMutationBurdenData?.totalMutationsPerMb ?? 0}
333349
name="totalMutationsPerMb"
334350
onChange={handleMutationBurdenChange}
335351
variant="outlined"
@@ -339,16 +355,16 @@ const TumourSummaryEdit = ({
339355
);
340356
}
341357
return null;
342-
}, [newMutationBurdenData, handleMutationBurdenChange]);
358+
}, [newMutationBurdenData?.totalMutationsPerMb, reportType, handleMutationBurdenChange]);
343359

344360
const tmburMutBurSection = useMemo(() => {
345-
if (newTmburMutData) {
361+
if (reportType === 'rapid') {
346362
return (
347363
<>
348364
<TextField
349365
className="tumour-dialog__text-field"
350366
label="genomeSnvTmb"
351-
value={newTmburMutData.genomeSnvTmb}
367+
value={newTmburMutData?.genomeSnvTmb ?? 0}
352368
name="genomeSnvTmb"
353369
onChange={handleTmburChange}
354370
variant="outlined"
@@ -358,7 +374,7 @@ const TumourSummaryEdit = ({
358374
<TextField
359375
className="tumour-dialog__text-field"
360376
label="genomeIndelTmb"
361-
value={newTmburMutData.genomeIndelTmb}
377+
value={newTmburMutData?.genomeIndelTmb ?? 0}
362378
name="genomeIndelTmb"
363379
onChange={handleTmburChange}
364380
variant="outlined"
@@ -369,7 +385,7 @@ const TumourSummaryEdit = ({
369385
);
370386
}
371387
return null;
372-
}, [newTmburMutData, handleTmburChange]);
388+
}, [reportType, newTmburMutData?.genomeSnvTmb, newTmburMutData?.genomeIndelTmb, handleTmburChange]);
373389

374390
return (
375391
<Dialog open={isOpen}>

app/hooks/useConfirmDialog.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import AlertDialog from '@/components/AlertDialog';
22
import ReportContext from '@/context/ReportContext';
3-
import api from '@/services/api';
43
import React, { useCallback, useContext } from 'react';
54
import ReactDOM from 'react-dom';
65
import snackbar from '@/services/SnackbarUtils';

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,12 @@ const GenomicSummary = ({
444444
isSaved: boolean,
445445
newMicrobialData: MicrobialType[],
446446
newReportData: ReportType,
447-
newMutationBurdenData: MutationBurdenType,
447+
newPrimaryBurdenData: MutationBurdenType,
448448
newTmBurMutBurData: TmburType,
449449
) => {
450450
setShowTumourSummaryEdit(false);
451451

452-
if (!isSaved || (!newMicrobialData && !newReportData && !newMutationBurdenData && !newTmBurMutBurData)) {
452+
if (!isSaved || (!newMicrobialData && !newReportData && !newPrimaryBurdenData && !newTmBurMutBurData)) {
453453
return;
454454
}
455455

@@ -461,8 +461,8 @@ const GenomicSummary = ({
461461
setReport(newReportData);
462462
}
463463

464-
if (newMutationBurdenData) {
465-
setPrimaryBurden(newMutationBurdenData);
464+
if (newPrimaryBurdenData) {
465+
setPrimaryBurden(newPrimaryBurdenData);
466466
}
467467

468468
if (newTmBurMutBurData) {

0 commit comments

Comments
 (0)