Skip to content

Commit

Permalink
Allow selecting session assemblies, improve session adding (#3180)
Browse files Browse the repository at this point in the history
* Include session assemblies in assemblyNames

* Use assembly's displayName in more places

* Improve waitForAssembly

* Return assembly config when added
  • Loading branch information
garrettjstevens authored Sep 14, 2022
1 parent c892a5d commit 33c0970
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions packages/core/assemblyManager/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export default function assemblyFactory(
return getConf(self, 'aliases')
},

get displayName(): string | undefined {
return getConf(self, 'displayName')
},

hasName(name: string) {
return this.allAliases.includes(name)
},
Expand Down
14 changes: 11 additions & 3 deletions packages/core/assemblyManager/assemblyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,22 @@ export default function assemblyManagerFactory(
if (!assemblyName) {
throw new Error('no assembly name supplied to waitForAssembly')
}
const assembly = self.get(assemblyName)
let assembly = self.get(assemblyName)
if (!assembly) {
try {
await when(() => Boolean(self.get(assemblyName)), { timeout: 1000 })
assembly = self.get(assemblyName)
} catch (e) {
// ignore
}
}
if (!assembly) {
return undefined
}
await when(
() =>
Boolean(assembly.regions && assembly.refNameAliases) ||
!!assembly.error,
Boolean(assembly?.regions && assembly.refNameAliases) ||
!!assembly?.error,
)
if (assembly.error) {
throw assembly.error
Expand Down
4 changes: 3 additions & 1 deletion packages/core/ui/AboutDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export default function AboutDialog({
)

trackName = asm
? `Reference Sequence (${readConfObject(asm, 'name')})`
? `Reference Sequence (${
readConfObject(asm, 'displayName') || readConfObject(asm, 'name')
})`
: 'Reference Sequence'
}

Expand Down
6 changes: 2 additions & 4 deletions packages/core/util/when.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { when as mobxWhen } from 'mobx'
import { when as mobxWhen, IWhenOptions } from 'mobx'
import { makeAbortError } from './aborting'

interface WhenOpts {
timeout?: number
interface WhenOpts extends IWhenOptions {
signal?: AbortSignal
name?: string
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ function getTrackName(config: AnyConfigurationModel): string {
}
return (
readConfObject(config, 'name') ||
`Reference sequence (${readConfObject(getParent(config), 'name')})`
`Reference sequence (${
readConfObject(getParent(config), 'displayName') ||
readConfObject(getParent(config), 'name')
})`
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ function SVGTracks({
const current = offset
const trackName =
getConf(track, 'name') ||
`Reference sequence (${readConfObject(
getParent(track.configuration),
'name',
)})`
`Reference sequence (${
readConfObject(getParent(track.configuration), 'displayName') ||
readConfObject(getParent(track.configuration), 'name')
})`
const display = track.displays[0]
offset += display.height + paddingHeight + textHeight
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function getTrackName(
return (
trackName ||
(asm
? `Reference Sequence (${readConfObject(asm, 'name')})`
? `Reference Sequence (${
readConfObject(asm, 'displayName') || readConfObject(asm, 'name')
})`
: 'Reference Sequence')
)
}
Expand Down
9 changes: 7 additions & 2 deletions products/jbrowse-web/src/sessionModelFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export default function sessionModelFactory(
return getParent<any>(self).jbrowse.assemblies
},
get assemblyNames() {
return getParent<any>(self).jbrowse.assemblyNames
const { assemblyNames } = getParent<any>(self).jbrowse
const sessionAssemblyNames = self.sessionAssemblies.map(assembly =>
readConfObject(assembly, 'name'),
)
return [...assemblyNames, ...sessionAssemblyNames]
},
get tracks() {
return [...self.sessionTracks, ...getParent<any>(self).jbrowse.tracks]
Expand Down Expand Up @@ -244,7 +248,8 @@ export default function sessionModelFactory(
console.warn(`Assembly ${assemblyConfig.name} was already existing`)
return asm
}
self.sessionAssemblies.push(assemblyConfig)
const length = self.sessionAssemblies.push(assemblyConfig)
return self.sessionAssemblies[length - 1]
},
addSessionPlugin(plugin: JBrowsePlugin) {
if (self.sessionPlugins.find(p => p.name === plugin.name)) {
Expand Down

0 comments on commit 33c0970

Please sign in to comment.