Skip to content

Commit

Permalink
Include sessionAssemblies in session->"get assemblies()" and session-…
Browse files Browse the repository at this point in the history
…>"get assemblyNames" (#3724)
  • Loading branch information
cmdcolin authored May 23, 2023
1 parent c62df4a commit d4b70fb
Show file tree
Hide file tree
Showing 4 changed files with 616 additions and 603 deletions.
140 changes: 69 additions & 71 deletions packages/core/ui/AssemblySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,80 +18,78 @@ const useStyles = makeStyles()({
},
})

const AssemblySelector = observer(
({
session,
onChange,
selected,
InputProps,
TextFieldProps,
localStorageKey,
helperText = 'Select assembly to view',
}: {
session: AbstractSessionModel
helperText?: string
onChange: (arg: string) => void
selected?: string
localStorageKey?: string
InputProps?: IIP
TextFieldProps?: TFP
}) => {
const { classes } = useStyles()
const { assemblyNames, assemblyManager } = session
const AssemblySelector = observer(function ({
session,
onChange,
selected,
InputProps,
TextFieldProps,
localStorageKey,
helperText = 'Select assembly to view',
}: {
session: AbstractSessionModel
helperText?: string
onChange: (arg: string) => void
selected?: string
localStorageKey?: string
InputProps?: IIP
TextFieldProps?: TFP
}) {
const { classes } = useStyles()
const { assemblyNames, assemblyManager } = session

// constructs a localstorage key based on host/path/config to help
// remember. non-config assists usage with e.g. embedded apps
const config = new URLSearchParams(window.location.search).get('config')
const [lastSelected, setLastSelected] =
typeof jest === 'undefined' && localStorageKey
? useLocalStorage(
`lastAssembly-${[
window.location.host + window.location.pathname,
config,
localStorageKey,
].join('-')}`,
selected,
)
: useState(selected)
// constructs a localstorage key based on host/path/config to help
// remember. non-config assists usage with e.g. embedded apps
const config = new URLSearchParams(window.location.search).get('config')
const [lastSelected, setLastSelected] =
typeof jest === 'undefined' && localStorageKey
? useLocalStorage(
`lastAssembly-${[
window.location.host + window.location.pathname,
config,
localStorageKey,
].join('-')}`,
selected,
)
: useState(selected)

const selection = assemblyNames.includes(lastSelected || '')
? lastSelected
: selected
const selection = assemblyNames.includes(lastSelected || '')
? lastSelected
: selected

useEffect(() => {
if (selection && selection !== selected) {
onChange(selection)
}
}, [selection, onChange, selected])
useEffect(() => {
if (selection && selection !== selected) {
onChange(selection)
}
}, [selection, onChange, selected])

const error = assemblyNames.length ? '' : 'No configured assemblies'
return (
<TextField
select
label="Assembly"
variant="outlined"
helperText={error || helperText}
value={selection || ''}
inputProps={{ 'data-testid': 'assembly-selector' }}
onChange={event => setLastSelected(event.target.value)}
error={!!error}
InputProps={InputProps}
disabled={!!error}
className={classes.importFormEntry}
{...TextFieldProps}
>
{assemblyNames.map(name => {
const assembly = assemblyManager.get(name)
const displayName = assembly ? getConf(assembly, 'displayName') : ''
return (
<MenuItem key={name} value={name}>
{displayName || name}
</MenuItem>
)
})}
</TextField>
)
},
)
const error = assemblyNames.length ? '' : 'No configured assemblies'
return (
<TextField
select
label="Assembly"
variant="outlined"
helperText={error || helperText}
value={selection || ''}
inputProps={{ 'data-testid': 'assembly-selector' }}
onChange={event => setLastSelected(event.target.value)}
error={!!error}
InputProps={InputProps}
disabled={!!error}
className={classes.importFormEntry}
{...TextFieldProps}
>
{assemblyNames.map(name => {
const assembly = assemblyManager.get(name)
const displayName = assembly ? getConf(assembly, 'displayName') : ''
return (
<MenuItem key={name} value={name}>
{displayName || name}
</MenuItem>
)
})}
</TextField>
)
})

export default AssemblySelector
10 changes: 10 additions & 0 deletions packages/web-core/src/BaseWebSession/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getSnapshot,
types,
SnapshotIn,
Instance,
} from 'mobx-state-tree'
import TextSearchManager from '@jbrowse/core/TextSearch/TextSearchManager'
import { BaseTrackConfig } from '@jbrowse/core/pluggableElementTypes'
Expand Down Expand Up @@ -92,6 +93,15 @@ export function BaseWebSession({
get root() {
return getParent<any>(self)
},
/**
* #getter
* list of sessionAssemblies and jbrowse config assemblies, does not
* include temporaryAssemblies. basically the list to be displayed in a
* AssemblySelector dropdown
*/
get assemblies(): Instance<BaseAssemblyConfigSchema[]> {
return [...self.jbrowse.assemblies, ...self.sessionAssemblies]
},
}))
.actions(self => ({
/**
Expand Down
12 changes: 8 additions & 4 deletions products/jbrowse-desktop/src/sessionModel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ export default function sessionModelFactory({
/**
* #getter
*/
get assemblyNames() {
return [...self.assemblies, ...self.sessionAssemblies].map(r =>
readConfObject(r, 'name'),
)
get assemblies(): Instance<BaseAssemblyConfigSchema[]> {
return [...self.jbrowse.assemblies, ...self.sessionAssemblies]
},
/**
* #getter
Expand All @@ -95,6 +93,12 @@ export default function sessionModelFactory({
},
}))
.views(self => ({
/**
* #getter
*/
get assemblyNames(): string[] {
return self.assemblies.map(a => readConfObject(a, 'name'))
},
/**
* #getter
*/
Expand Down
Loading

0 comments on commit d4b70fb

Please sign in to comment.