Skip to content

Commit

Permalink
Alt
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed May 20, 2024
1 parent 98ab8f6 commit 0c564c9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ exports[`open up a widget 1`] = `
>
<span
class="MuiTypography-root MuiTypography-button css-1f0on15-MuiTypography-root"
>
</span>
/>
</div>
<div
class="MuiAccordionSummary-expandIconWrapper Mui-expanded css-yw020d-MuiAccordionSummary-expandIconWrapper"
Expand Down
51 changes: 35 additions & 16 deletions packages/product-core/src/ui/AboutDialogContents.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react'
import { observer } from 'mobx-react'
import clone from 'clone'
import copy from 'copy-to-clipboard'
import { Button } from '@mui/material'
Expand All @@ -14,7 +15,7 @@ import {
Attributes,
} from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail'
import FileInfoPanel from './FileInfoPanel'
import RefNamePanel from './RefNameInfoPanel'
import RefNameInfoDialog from './RefNameInfoDialog'

const useStyles = makeStyles()({
content: {
Expand All @@ -36,7 +37,7 @@ function removeAttr(obj: Record<string, unknown>, attr: string) {
return obj
}

export default function AboutContents({
const AboutDialogContents = observer(function ({
config,
}: {
config: AnyConfigurationModel
Expand All @@ -45,6 +46,7 @@ export default function AboutContents({
const conf = readConfObject(config)
const session = getSession(config)
const { classes } = useStyles()
const [showRefNames, setShowRefNames] = useState(false)

const hideUris =
getConf(session, ['formatAbout', 'hideUris']) ||
Expand Down Expand Up @@ -75,18 +77,28 @@ export default function AboutContents({
<div className={classes.content}>
<BaseCard title="Configuration">
{!hideUris ? (
<Button
variant="contained"
className={classes.button}
onClick={() => {
const snap = removeAttr(clone(conf), 'baseUri')
copy(JSON.stringify(snap, null, 2))
setCopied(true)
setTimeout(() => setCopied(false), 1000)
}}
>
{copied ? 'Copied to clipboard!' : 'Copy config'}
</Button>
<span className={classes.button}>
<Button
variant="contained"
color="secondary"
onClick={() => {
setShowRefNames(true)
}}
>
Show ref names
</Button>
<Button
variant="contained"
onClick={() => {
const snap = removeAttr(clone(conf), 'baseUri')
copy(JSON.stringify(snap, null, 2))
setCopied(true)
setTimeout(() => setCopied(false), 1000)
}}
>
{copied ? 'Copied to clipboard!' : 'Copy config'}
</Button>
</span>
) : null}
<Attributes
attributes={confPostExt}
Expand All @@ -100,7 +112,14 @@ export default function AboutContents({
</BaseCard>
) : null}
<FileInfoPanel config={config} />
<RefNamePanel config={config} />
{showRefNames ? (
<RefNameInfoDialog
config={config}
onClose={() => setShowRefNames(false)}
/>
) : null}
</div>
)
}
})

export default AboutDialogContents
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import React, { useState, useEffect } from 'react'
import { Button, Typography } from '@mui/material'
import { Button, DialogContent, Typography } from '@mui/material'
import {
readConfObject,
AnyConfigurationModel,
} from '@jbrowse/core/configuration'
import LoadingEllipses from '@jbrowse/core/ui/LoadingEllipses'
import { Dialog, LoadingEllipses } from '@jbrowse/core/ui'
import { getSession } from '@jbrowse/core/util'
import { BaseCard } from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail'
import { observer } from 'mobx-react'
import { makeStyles } from 'tss-react/mui'
import FieldName from '@jbrowse/core/BaseFeatureWidget/BaseFeatureDetail/FieldName'
import copy from 'copy-to-clipboard'

const MAX_REF_NAMES = 10_000

const useStyles = makeStyles()(theme => ({
container: {
minWidth: 800,
},
refNames: {
maxHeight: 300,
width: '100%',
overflow: 'auto',
flexGrow: 1,
background: theme.palette.background.default,
},
button: {
float: 'right',
},
}))

const RefNamePanel = observer(function ({
const RefNameInfoDialog = observer(function ({
config,
onClose,
}: {
config: AnyConfigurationModel
onClose: () => void
}) {
const [error, setError] = useState<unknown>()
const [refNames, setRefNames] = useState<string[]>()
Expand Down Expand Up @@ -72,37 +73,39 @@ const RefNamePanel = observer(function ({
}, [config, rpcManager])

return (
<BaseCard title="Reference sequences in track">
{error ? (
<Typography color="error">{`${error}`}</Typography>
) : refNames === undefined ? (
<LoadingEllipses message="Loading refNames" />
) : (
<>
<Button
variant="contained"
className={classes.button}
onClick={() => {
copy(JSON.stringify(refNames.join('\n'), null, 2))
setCopied(true)
setTimeout(() => setCopied(false), 1000)
}}
>
{copied ? 'Copied to clipboard!' : 'Copy ref names'}
</Button>
<div style={{ display: 'flex', flexWrap: 'wrap' }}>
<FieldName name="refNames" />
<Dialog
open
title="Reference sequence names used in track"
onClose={onClose}
>
<DialogContent className={classes.container}>
{error ? (
<Typography color="error">{`${error}`}</Typography>
) : refNames === undefined ? (
<LoadingEllipses message="Loading refNames" />
) : (
<>
<Button
variant="contained"
onClick={() => {
copy(JSON.stringify(refNames.join('\n'), null, 2))
setCopied(true)
setTimeout(() => setCopied(false), 1000)
}}
>
{copied ? 'Copied to clipboard!' : 'Copy ref names'}
</Button>
<pre className={classes.refNames}>
{refNames.slice(0, MAX_REF_NAMES).join('\n')}
{refNames.length > MAX_REF_NAMES
? '\nToo many refNames to show in browser, use "Copy ref names" button to copy to clipboard'
: ''}
</pre>
</div>
</>
)}
</BaseCard>
</>
)}
</DialogContent>
</Dialog>
)
})

export default RefNamePanel
export default RefNameInfoDialog
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ exports[`open up a widget 1`] = `
<span
class="MuiTypography-root MuiTypography-button css-1f0on15-MuiTypography-root"
>
ctgA_3_555_0:0:0_2:0... - match
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ exports[`renders with just the required model elements 1`] = `
<span
class="MuiTypography-root MuiTypography-button css-1f0on15-MuiTypography-root"
>
rs123
</span>
</div>
Expand Down

0 comments on commit 0c564c9

Please sign in to comment.