Skip to content

Commit

Permalink
T1
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 7, 2023
1 parent 7b15ac8 commit 5096330
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import React, { useEffect, useState } from 'react'
import { Button, DialogActions, DialogContent, TextField } from '@mui/material'
import { Dialog, ErrorMessage } from '@jbrowse/core/ui'
import {
Button,
DialogActions,
DialogContent,
TextField,
Typography,
} from '@mui/material'
import { makeStyles } from 'tss-react/mui'
import { observer } from 'mobx-react'
import { Dialog, ErrorMessage, LoadingEllipses } from '@jbrowse/core/ui'
import {
getSession,
getContainingView,
Feature,
Region,
} from '@jbrowse/core/util'
import { getConf } from '@jbrowse/core/configuration'
import { makeStyles } from 'tss-react/mui'
import { BaseTrackModel } from '@jbrowse/core/pluggableElementTypes'
import { observer } from 'mobx-react'

// locals
import { stringifyGFF3 } from './util'

const useStyles = makeStyles()(theme => ({
const useStyles = makeStyles()({
root: {
width: '80em',
},
textAreaFont: {
fontFamily: 'Courier New',
},
field: {
margin: theme.spacing(2),
},
}))
})

async function fetchFeatures(
track: BaseTrackModel,
Expand All @@ -34,7 +37,7 @@ async function fetchFeatures(
) {
const { rpcManager } = getSession(track)
const adapterConfig = getConf(track, ['adapter'])
const sessionId = 'getSequence'
const sessionId = 'getFeatures'
return rpcManager.call(sessionId, 'CoreGetFeatures', {
adapterConfig,
regions,
Expand All @@ -43,7 +46,7 @@ async function fetchFeatures(
}) as Promise<Feature[]>
}

function SaveTrackDataDlg({
export default observer(function SaveTrackDataDlg({
model,
handleClose,
}: {
Expand All @@ -52,37 +55,42 @@ function SaveTrackDataDlg({
}) {
const { classes } = useStyles()
const [error, setError] = useState<unknown>()
const [features, setFeatures] = useState<string>()
const [features, setFeatures] = useState<Feature[]>()

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
try {
const view = getContainingView(model)
const track = model
const regions = view.dynamicBlocks.contentBlocks
setError(undefined)
const feats = await fetchFeatures(track, regions)
const ret = stringifyGFF3(feats)
setFeatures(ret)
setFeatures(
await fetchFeatures(model, view.dynamicBlocks.contentBlocks),
)
} catch (e) {
console.error(e)
setError(e)
}
})()
}, [model])

const str = features ? stringifyGFF3(features) : ''

return (
<Dialog maxWidth="xl" open onClose={handleClose} title="Save track data">
<DialogContent className={classes.root}>
{error ? <ErrorMessage error={error} /> : null}
{!features ? (
<LoadingEllipses />
) : !features.length ? (
<Typography>No features found</Typography>
) : null}
<TextField
variant="outlined"
multiline
minRows={5}
maxRows={15}
fullWidth
value={features}
value={str}
InputProps={{
readOnly: true,
classes: {
Expand All @@ -92,17 +100,10 @@ function SaveTrackDataDlg({
/>
</DialogContent>
<DialogActions>
<Button
variant="contained"
color="primary"
type="submit"
onClick={() => handleClose()}
>
<Button variant="contained" type="submit" onClick={() => handleClose()}>
Close
</Button>
</DialogActions>
</Dialog>
)
}

export default observer(SaveTrackDataDlg)
})
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ function SequenceDialog({
setTimeout(() => setCopied(false), 500)
}}
disabled={loading || !!error || sequenceTooLarge}
color="primary"
startIcon={<ContentCopyIcon />}
>
{copied ? 'Copied' : 'Copy to clipboard'}
Expand All @@ -258,7 +257,6 @@ function SequenceDialog({
)
}}
disabled={loading || !!error}
color="primary"
startIcon={<GetAppIcon />}
>
Download FASTA
Expand Down

0 comments on commit 5096330

Please sign in to comment.