From 73017f05496a4d583f82b3cce499c5c64d00647e Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 17 Jun 2024 17:28:28 -0400 Subject: [PATCH 1/4] Store feature in sequence feature detail model --- .../SequenceFeatureDetails.tsx | 104 ++++++++++-------- .../dialogs/SequenceDialog.tsx | 5 +- .../dialogs/SequenceTypeSelector.tsx | 23 +--- .../SequenceFeatureDetails/model.ts | 78 +++++++++++-- .../seqtypes/CDNASequence.tsx | 10 +- .../seqtypes/CDSSequence.tsx | 4 +- .../seqtypes/GenomicSequence.tsx | 8 +- .../seqtypes/ProteinSequence.tsx | 4 +- .../seqtypes/SequenceDisplay.tsx | 12 +- .../SequenceFeatureDetails/util.ts | 10 +- 10 files changed, 155 insertions(+), 103 deletions(-) diff --git a/packages/core/BaseFeatureWidget/SequenceFeatureDetails/SequenceFeatureDetails.tsx b/packages/core/BaseFeatureWidget/SequenceFeatureDetails/SequenceFeatureDetails.tsx index 92aa113138..171874c53d 100644 --- a/packages/core/BaseFeatureWidget/SequenceFeatureDetails/SequenceFeatureDetails.tsx +++ b/packages/core/BaseFeatureWidget/SequenceFeatureDetails/SequenceFeatureDetails.tsx @@ -1,11 +1,11 @@ -import React, { lazy, useRef, useState, Suspense } from 'react' +import React, { lazy, useRef, useState, Suspense, useEffect } from 'react' import { Button, Typography } from '@mui/material' import { observer } from 'mobx-react' // locals import { useFeatureSequence } from './hooks' import { ErrorMessage, LoadingEllipses } from '../../ui' -import { SimpleFeatureSerialized, getSession } from '../../util' +import { SimpleFeatureSerialized } from '../../util' import { BaseFeatureWidgetModel } from '../stateModelFactory' // icons @@ -29,6 +29,7 @@ const SequenceFeatureDetails = observer(function ({ const { upDownBp } = sequenceFeatureDetails const seqPanelRef = useRef(null) + const [openInDialog, setOpenInDialog] = useState(false) const [force, setForce] = useState(false) const { sequence, error } = useFeatureSequence( model, @@ -36,15 +37,14 @@ const SequenceFeatureDetails = observer(function ({ upDownBp, force, ) + useEffect(() => { + sequenceFeatureDetails.setFeature(feature) + }, [sequenceFeatureDetails, feature]) return ( <>
- - + { - getSession(model).queueDialog(handleClose => [ - SequenceDialog, - { model, feature, handleClose }, - ]) + // this is given a setTimeout because it allows the menu to + // close before dialog opens + setTimeout(() => setOpenInDialog(true), 1) }, }, ]} />
-
- {feature.type === 'gene' ? ( - - Note: inspect subfeature sequences for protein/CDS computations - - ) : null} - {error ? ( - - ) : !sequence ? ( - - ) : sequence ? ( - 'error' in sequence ? ( - <> - {sequence.error} - - + {openInDialog ? ( +
+ Open in dialog... + }> + setOpenInDialog(false)} + /> + +
+ ) : ( +
+ {feature.type === 'gene' ? ( + + Note: inspect subfeature sequences for protein/CDS computations + + ) : null} + {error ? ( + + ) : !sequence ? ( + + ) : sequence ? ( + 'error' in sequence ? ( + <> + {sequence.error} + + + ) : ( + }> + + + ) ) : ( - }> - - - ) - ) : ( - No sequence found - )} -
+ No sequence found + )} +
+ )} ) }) diff --git a/packages/core/BaseFeatureWidget/SequenceFeatureDetails/dialogs/SequenceDialog.tsx b/packages/core/BaseFeatureWidget/SequenceFeatureDetails/dialogs/SequenceDialog.tsx index e1379c67ea..1d1438bb21 100644 --- a/packages/core/BaseFeatureWidget/SequenceFeatureDetails/dialogs/SequenceDialog.tsx +++ b/packages/core/BaseFeatureWidget/SequenceFeatureDetails/dialogs/SequenceDialog.tsx @@ -52,10 +52,7 @@ const SequenceDialog = observer(function ({ >
- + sub.type === 'CDS') - const hasExon = feature.subfeatures?.some(sub => sub.type === 'exon') - const hasExonOrCDS = hasExon || hasCDS - - const [selectMode, setSelectMode] = useState( - hasCDS ? 'cds' : hasExon ? 'cdna' : 'genomic', - ) - - useEffect(() => { - setMode(selectMode) - }, [setMode, hasCDS, hasExon, selectMode]) + const { intronBp, upDownBp, mode, hasCDS, hasExonOrCDS } = model return (