Skip to content

Commit

Permalink
Fix multi-wiggle add track selector
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 3, 2024
1 parent be177a4 commit 4e76b10
Show file tree
Hide file tree
Showing 4 changed files with 381 additions and 363 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"dependency-graph": "^1.0.0",
"dotenv": "^16.3.1",
"dotenv-expand": "^11.0.3",
"electron": "32.1.0",
"electron": "33.0.2",
"electron-builder": "^25.1.6",
"electron-mock-ipc": "^0.3.8",
"eslint": "^9.0.0",
Expand Down
103 changes: 55 additions & 48 deletions plugins/wiggle/src/MultiWiggleAddTrackWorkflow/AddTrackWorkflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import { storeBlobLocation } from '@jbrowse/core/util/tracks'
import { AddTrackModel } from '@jbrowse/plugin-data-management'

const useStyles = makeStyles()(theme => ({
textbox: {
width: '100%',
},
paper: {
margin: theme.spacing(),
padding: theme.spacing(),
Expand All @@ -25,6 +22,17 @@ const useStyles = makeStyles()(theme => ({
},
}))

// on electron, use path to LocalFileLocation, on web, use the BlobLocation
function makeFileLocation(file: File) {
const { webUtils } = window.require('electron')
return isElectron
? {
localPath: webUtils.getPathForFile(file),
locationType: 'LocalPathLocation',
}
: storeBlobLocation({ blob: file })
}

export default function MultiWiggleWidget({ model }: { model: AddTrackModel }) {
const { classes } = useStyles()
const [val, setVal] = useState('')
Expand All @@ -41,14 +49,14 @@ export default function MultiWiggleWidget({ model }: { model: AddTrackModel }) {

<TextField
multiline
fullWidth
rows={10}
value={val}
placeholder="Paste list of URLs here, or use file selector below"
variant="outlined"
onChange={event => {
setVal(event.target.value)
}}
placeholder={'Paste list of URLs here, or use file selector below'}
variant="outlined"
className={classes.textbox}
/>

<Button variant="outlined" component="label">
Expand All @@ -60,12 +68,7 @@ export default function MultiWiggleWidget({ model }: { model: AddTrackModel }) {
onChange={({ target }) => {
const res = [...(target.files || [])].map(file => ({
type: 'BigWigAdapter',
bigWigLocation: isElectron
? {
localPath: (file as File & { path: string }).path,
locationType: 'LocalPathLocation',
}
: storeBlobLocation({ blob: file }),
bigWigLocation: makeFileLocation(file),
source: file.name,
}))
setVal(JSON.stringify(res, null, 2))
Expand All @@ -74,54 +77,58 @@ export default function MultiWiggleWidget({ model }: { model: AddTrackModel }) {
</Button>
<TextField
value={trackName}
helperText="Track name"
onChange={event => {
setTrackName(event.target.value)
}}
helperText="Track name"
/>
<Button
variant="contained"
className={classes.submit}
onClick={() => {
const session = getSession(model)

const trackId = [
`${trackName.toLowerCase().replaceAll(' ', '_')}-${Date.now()}`,
session.adminMode ? '' : '-sessionTrack',
].join('')

// allow list of bigwigs in JSON format or line-by-line
let bigWigs: unknown[]
try {
bigWigs = JSON.parse(val)
} catch (e) {
bigWigs = val
.split(/\n|\r\n|\r/)
.map(f => f.trim())
.filter(f => !!f)
}
const obj =
typeof bigWigs[0] === 'string'
? { bigWigs }
: { subadapters: bigWigs }
const trackId = [
`${trackName.toLowerCase().replaceAll(' ', '_')}-${Date.now()}`,
session.adminMode ? '' : '-sessionTrack',
].join('')

if (isSessionWithAddTracks(session)) {
session.addTrackConf({
trackId,
type: 'MultiQuantitativeTrack',
name: trackName,
assemblyNames: [model.assembly],
adapter: {
type: 'MultiWiggleAdapter',
...obj,
},
})
// allow list of bigwigs in JSON format or line-by-line
let bigWigs: unknown[]
try {
bigWigs = JSON.parse(val)
} catch (e) {
bigWigs = val
.split(/\n|\r\n|\r/)
.map(f => f.trim())
.filter(f => !!f)
}
const obj =
typeof bigWigs[0] === 'string'
? { bigWigs }
: { subadapters: bigWigs }

model.view?.showTrack(trackId)
}
model.clearData()
if (isSessionModelWithWidgets(session)) {
session.hideWidget(model)
if (isSessionWithAddTracks(session)) {
session.addTrackConf({
trackId,
type: 'MultiQuantitativeTrack',
name: trackName,
assemblyNames: [model.assembly],
adapter: {
type: 'MultiWiggleAdapter',
...obj,
},
})

model.view?.showTrack(trackId)
}
model.clearData()
if (isSessionModelWithWidgets(session)) {
session.hideWidget(model)
}
} catch (e) {
console.error(e)
session.notifyError(`${e}`, e)
}
}}
>
Expand Down
4 changes: 2 additions & 2 deletions products/jbrowse-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@
"use-query-params": "^2.0.0"
},
"devDependencies": {
"electron": "32.1.0"
"electron": "33.0.2"
},
"browserslist": [
"last 1 chrome version"
],
"build": {
"electronVersion": "32.1.0",
"electronVersion": "33.0.2",
"extraMetadata": {
"main": "build/electron.js"
},
Expand Down
Loading

0 comments on commit 4e76b10

Please sign in to comment.