-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new "Add track workflow" that allows pasting JSON track configs (
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
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
64 changes: 64 additions & 0 deletions
64
plugins/data-management/src/AddTrackWidget/components/PasteConfigWorkflow.tsx
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,64 @@ | ||
import React, { useState } from 'react' | ||
import { Button, TextField } from '@mui/material' | ||
import { ErrorMessage } from '@jbrowse/core/ui' | ||
import { makeStyles } from 'tss-react/mui' | ||
import { getSession } from '@jbrowse/core/util' | ||
import { observer } from 'mobx-react' | ||
|
||
// locals | ||
import { AddTrackModel } from '../model' | ||
|
||
const useStyles = makeStyles()({ | ||
textbox: { | ||
width: '100%', | ||
}, | ||
submit: { | ||
marginTop: 25, | ||
marginBottom: 100, | ||
display: 'block', | ||
}, | ||
}) | ||
|
||
function AddTrackWorkflow({ model }: { model: AddTrackModel }) { | ||
const { classes } = useStyles() | ||
const [val, setVal] = useState('') | ||
const [error, setError] = useState<unknown>() | ||
|
||
return ( | ||
<div> | ||
{error ? <ErrorMessage error={error} /> : null} | ||
<TextField | ||
multiline | ||
rows={10} | ||
value={val} | ||
onChange={event => setVal(event.target.value)} | ||
placeholder={ | ||
'Paste track config or array of track configs in JSON format' | ||
} | ||
variant="outlined" | ||
className={classes.textbox} | ||
/> | ||
<Button | ||
variant="contained" | ||
className={classes.submit} | ||
onClick={() => { | ||
try { | ||
setError(undefined) | ||
const session = getSession(model) | ||
const conf = JSON.parse(val) | ||
const confs = Array.isArray(conf) ? conf : [conf] | ||
confs.forEach(c => session.addTrackConf(c)) | ||
confs.forEach(c => c.trackId) | ||
model.clearData() | ||
session.hideWidget(model) | ||
} catch (e) { | ||
setError(e) | ||
} | ||
}} | ||
> | ||
Submit | ||
</Button> | ||
</div> | ||
) | ||
} | ||
export default observer(AddTrackWorkflow) |
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