-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/DEVSU-2244-cd8t-percentile-visibilit…
…y-toggle
- Loading branch information
Showing
11 changed files
with
279 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.variant-edit-dialog { | ||
&__form-control { | ||
min-width: 160px; | ||
margin: 0 0 16px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import React, { | ||
useState, useEffect, useContext, useCallback, | ||
} from 'react'; | ||
import { | ||
Dialog, | ||
DialogTitle, | ||
DialogContent, | ||
DialogActions, | ||
Button, | ||
} from '@mui/material'; | ||
|
||
import api from '@/services/api'; | ||
import AsyncButton from '@/components/AsyncButton'; | ||
|
||
import ConfirmContext from '@/context/ConfirmContext'; | ||
import ReportContext from '@/context/ReportContext'; | ||
import snackbar from '@/services/SnackbarUtils'; | ||
import useConfirmDialog from '@/hooks/useConfirmDialog'; | ||
import { | ||
CopyNumberType, SmallMutationType, StructuralVariantType, ExpOutliersType, | ||
} from '@/common'; | ||
import { GeneVariantType } from '@/views/ReportView/components/GenomicSummary/types'; | ||
|
||
import './index.scss'; | ||
|
||
type VariantEditDialogProps = { | ||
editData: SmallMutationType | CopyNumberType | StructuralVariantType | ExpOutliersType; | ||
variantType: string; | ||
isOpen: boolean; | ||
onClose: (newData?: SmallMutationType | CopyNumberType | StructuralVariantType | ExpOutliersType) => void; | ||
showErrorSnackbar: (message: string) => void; | ||
}; | ||
|
||
const VariantEditDialog = ({ | ||
editData, | ||
variantType, | ||
isOpen = false, | ||
onClose, | ||
showErrorSnackbar, | ||
}: VariantEditDialogProps): JSX.Element => { | ||
const { showConfirmDialog } = useConfirmDialog(); | ||
const { report } = useContext(ReportContext); | ||
const { isSigned } = useContext(ConfirmContext); | ||
const [variant, setVariant] = useState(''); | ||
const [variants, setVariants] = useState<GeneVariantType[]>(); | ||
const [isApiCalling, setIsApiCalling] = useState(false); | ||
|
||
useEffect(() => { | ||
if (editData) { | ||
let newVariant; | ||
switch (variantType) { | ||
case 'snv': | ||
newVariant = `${editData?.gene.name}:${editData?.proteinChange}`; | ||
setVariant(newVariant); | ||
break; | ||
case 'cnv': | ||
newVariant = `${editData?.gene.name} (${editData?.cnvState})`; | ||
setVariant(newVariant); | ||
break; | ||
case 'sv': | ||
newVariant = `${editData?.displayName}`; | ||
setVariant(newVariant); | ||
break; | ||
case 'exp': | ||
newVariant = `${editData?.gene.name} (${editData?.expressionState})`; | ||
setVariant(newVariant); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
}, [editData, variantType]); | ||
|
||
useEffect(() => { | ||
async function fetchVariants() { | ||
const variantsResp = api.get(`/reports/${report.ident}/summary/genomic-alterations-identified`).request(); | ||
if (variantsResp) { | ||
setVariants(await variantsResp); | ||
} | ||
} | ||
|
||
fetchVariants(); | ||
}, [report.ident]); | ||
|
||
const availableVariants = variants?.map(({ geneVariant }) => geneVariant); | ||
|
||
const handleSubmit = useCallback(async () => { | ||
if (!availableVariants.includes(variant)) { | ||
setIsApiCalling(true); | ||
const req = api.post(`/reports/${report.ident}/summary/genomic-alterations-identified`, { geneVariant: variant }); | ||
try { | ||
if (isSigned) { | ||
showConfirmDialog(req); | ||
setIsApiCalling(false); | ||
} else { | ||
await req.request(); | ||
onClose({ ...editData }); | ||
snackbar.success('Variant added to key alterations.'); | ||
} | ||
} catch (err) { | ||
showErrorSnackbar(`Error updating key alterations: ${err.message}`); | ||
onClose(); | ||
} finally { | ||
setIsApiCalling(false); | ||
} | ||
} else { | ||
snackbar.error('Variant already in key alterations.'); | ||
onClose(); | ||
} | ||
}, [availableVariants, variant, report.ident, isSigned, showConfirmDialog, onClose, editData, showErrorSnackbar]); | ||
|
||
const handleClose = useCallback(() => { | ||
onClose(); | ||
}, [onClose]); | ||
|
||
return ( | ||
<Dialog open={isOpen} maxWidth="sm" fullWidth className="variant-edit-dialog"> | ||
<DialogTitle>Key Alterations Edit</DialogTitle> | ||
<DialogContent> | ||
<div className="variant-edit-dialog__body"> | ||
<p> | ||
Variant: | ||
{' '} | ||
{variant} | ||
</p> | ||
</div> | ||
<DialogActions className="variant-edit-dialog__actions"> | ||
<AsyncButton isLoading={isApiCalling} color="secondary" onClick={handleSubmit} component="label"> | ||
Add to Summary | ||
</AsyncButton> | ||
<Button onClick={handleClose}> | ||
Cancel | ||
</Button> | ||
</DialogActions> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default VariantEditDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.