Skip to content

Commit

Permalink
Avoid any
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Oct 3, 2023
1 parent c45e7ce commit f094ad3
Show file tree
Hide file tree
Showing 33 changed files with 211 additions and 145 deletions.
7 changes: 5 additions & 2 deletions packages/app-core/src/ui/App/ViewMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
IconButtonProps as IconButtonPropsType,
} from '@mui/material'
import { observer } from 'mobx-react'
import { getSession } from '@jbrowse/core/util'
import { AbstractSessionModel, getSession } from '@jbrowse/core/util'
import CascadingMenuButton from '@jbrowse/core/ui/CascadingMenuButton'
import { IBaseViewModel } from '@jbrowse/core/pluggableElementTypes/models'

Expand All @@ -22,7 +22,10 @@ const ViewMenu = observer(function ({
IconProps: SvgIconProps
}) {
const { menuItems } = model
const session = getSession(model)
const session = getSession(model) as AbstractSessionModel & {
moveViewDown: (arg: string) => void
moveViewUp: (arg: string) => void
}

const items = [
...(session.views.length > 1
Expand Down
20 changes: 2 additions & 18 deletions packages/core/pluggableElementTypes/models/BaseTrackModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ export function createBaseTrackModel(
return (
isSessionModelWithConfigEditing(session) &&
(adminMode ||
sessionTracks.find(
(track: { trackId: string }) =>
track.trackId === self.configuration?.trackId,
sessionTracks?.find(
track => track.trackId === self.configuration?.trackId,
))
)
},
Expand All @@ -130,21 +129,6 @@ export function createBaseTrackModel(
setMinimized(flag: boolean) {
self.minimized = flag
},
/**
* #action
*/
activateConfigurationUI() {
const session = getSession(self)
const view = getContainingView(self)
if (isSessionModelWithConfigEditing(session)) {
// @ts-expect-error
const trackConf = session.editTrackConfiguration(self.configuration)
if (trackConf && trackConf !== self.configuration) {
view.hideTrack(self.configuration)
view.showTrack(trackConf)
}
}
},

/**
* #action
Expand Down
3 changes: 2 additions & 1 deletion packages/core/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export function springAnimate(
export function findParentThatIs<T extends (a: IAnyStateTreeNode) => boolean>(
node: IAnyStateTreeNode,
predicate: T,
): TypeTestedByPredicate<T> & IAnyStateTreeNode {
): TypeTestedByPredicate<T> {
return findParentThat(node, predicate)
}

Expand Down Expand Up @@ -1141,6 +1141,7 @@ export function getTickDisplayStr(totalBp: number, bpPerPx: number) {
}

export function getViewParams(model: IAnyStateTreeNode, exportSVG?: boolean) {
// @ts-expect-error
const { dynamicBlocks, staticBlocks, offsetPx } = getContainingView(model)
const b = dynamicBlocks?.contentBlocks[0] || {}
const staticblock = staticBlocks?.contentBlocks[0] || {}
Expand Down
36 changes: 32 additions & 4 deletions packages/core/util/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import RpcManager from '../../rpc/RpcManager'
import { Feature } from '../simpleFeature'
import { BaseInternetAccountModel } from '../../pluggableElementTypes/models'
import { ThemeOptions } from '@mui/material'

export * from './util'

Expand Down Expand Up @@ -82,16 +83,26 @@ export type DialogComponentType =

/** minimum interface that all session state models must implement */
export interface AbstractSessionModel extends AbstractViewContainer {
jbrowse: IAnyStateTreeNode
drawerPosition?: string
setSelection(feature: Feature): void
clearSelection(): void
configuration: AnyConfigurationModel
rpcManager: RpcManager
assemblyNames: string[]
assemblies: AnyConfigurationModel[]
selection?: unknown
duplicateCurrentSession?(): void
notify(message: string, level?: NotificationLevel, action?: SnackAction): void
focusedViewId?: string
themeName?: string
setFocusedViewId?: (id: string) => void
allThemes?: () => Record<string, ThemeOptions | undefined>
setSelection: (feature: Feature) => void
setSession?: (arg: { name: string; [key: string]: unknown }) => void
clearSelection: () => void
duplicateCurrentSession?: () => void
notify: (
message: string,
level?: NotificationLevel,
action?: SnackAction,
) => void
assemblyManager: AssemblyManager
version: string
getTrackActionMenuItems?: Function
Expand All @@ -100,13 +111,20 @@ export interface AbstractSessionModel extends AbstractViewContainer {
textSearchManager?: TextSearchManager
connections: AnyConfigurationModel[]
deleteConnection?: Function
temporaryAssemblies?: unknown[]
addTemporaryAssembly?: (arg: Record<string, unknown>) => void
removeTemporaryAssembly?: (arg: string) => void
sessionConnections?: AnyConfigurationModel[]
sessionTracks?: AnyConfigurationModel[]
connectionInstances?: {
name: string
tracks: AnyConfigurationModel[]
configuration: AnyConfigurationModel
}[]
makeConnection?: Function
breakConnection?: Function
// eslint-disable-next-line @typescript-eslint/no-explicit-any
prepareToBreakConnection?: (arg: AnyConfigurationModel) => any
adminMode?: boolean
showWidget?: Function
addWidget?: Function
Expand Down Expand Up @@ -155,6 +173,16 @@ export function isSessionWithAddTracks(
)
}

/** abstract interface for a session allows adding tracks */
export interface SessionWithShareURL extends AbstractSessionModel {
shareURL: string
}
export function isSessionWithShareURL(
thing: unknown,
): thing is SessionWithShareURL {
return isSessionModel(thing) && 'shareURL' in thing && !!thing.shareURL
}

export interface Widget {
type: string
id: string
Expand Down
7 changes: 5 additions & 2 deletions plugins/alignments/src/shared/BaseDisplayComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react'
import { LoadingEllipses } from '@jbrowse/core/ui'
import { BlockMsg } from '@jbrowse/plugin-linear-genome-view'
import {
BlockMsg,
LinearGenomeViewModel,
} from '@jbrowse/plugin-linear-genome-view'
import { makeStyles } from 'tss-react/mui'
import { observer } from 'mobx-react'

Expand Down Expand Up @@ -56,7 +59,7 @@ const DataDisplay = observer(function ({
children?: React.ReactNode
}) {
const { drawn, loading } = model
const view = getContainingView(model)
const view = getContainingView(model) as LinearGenomeViewModel
const left = (model.lastDrawnOffsetPx || 0) - view.offsetPx
return (
// this data-testid is located here because changing props on the canvas
Expand Down
1 change: 1 addition & 0 deletions plugins/alignments/src/shared/fetchChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface ChainData {
export async function fetchChains(
self: LinearReadArcsDisplayModel | LinearReadCloudDisplayModel,
) {
// @ts-expect-error
const { rpcSessionId: sessionId } = getContainingTrack(self)
const { rpcManager } = getSession(self)
const view = getContainingView(self) as LGV
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import clone from 'clone'
import { getRpcSessionId } from '@jbrowse/core/util/tracks'
import { getSession, getContainingView } from '@jbrowse/core/util'
import { CircularViewModel } from '../../CircularView/models/CircularView'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function renderReactionData(self: any) {
const view = getContainingView(self)
const view = getContainingView(self) as CircularViewModel
const { rendererType } = self
const { rpcManager } = getSession(view)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useState } from 'react'
import { Button, Step, StepContent, StepLabel, Stepper } from '@mui/material'
import { getSession, getEnv } from '@jbrowse/core/util'
import { getSession, getEnv, isSessionModelWithWidgets } from '@jbrowse/core/util'
import { makeStyles } from 'tss-react/mui'
import { observer } from 'mobx-react'
import { ConnectionType } from '@jbrowse/core/pluggableElementTypes'
Expand Down Expand Up @@ -98,7 +98,10 @@ const AddConnectionWidget = observer(function ({ model }: { model: unknown }) {
session.notify('No config model to add')
}

if(isSessionModelWithWidgets(session)) {

session.hideWidget(model)
}
} else {
setActiveStep(activeStep + 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { getRoot } from 'mobx-state-tree'
import {
getSession,
isElectron,
isSessionModelWithWidgets,
isSessionWithAddTracks,
isSupportedIndexingAdapter,
} from '@jbrowse/core/util'
import { getConf } from '@jbrowse/core/configuration'
Expand Down Expand Up @@ -90,7 +92,10 @@ const DefaultAddTrackWorkflow = observer(function ({
].join('')

const assemblyInstance = session.assemblyManager.get(assembly)

if (!isSessionWithAddTracks(session)) {
setTrackErrorMessage('Unable to add tracks to this model')
return
}
if (assemblyInstance && trackAdapter && trackAdapter.type !== 'UNKNOWN') {
session.addTrackConf({
trackId,
Expand All @@ -102,40 +107,40 @@ const DefaultAddTrackWorkflow = observer(function ({
sequenceAdapter: getConf(assemblyInstance, ['sequence', 'adapter']),
},
})
if (model.view) {
model.view.showTrack(trackId)
if (
isElectron &&
textIndexTrack &&
isSupportedIndexingAdapter(trackAdapter.type)
) {
const attr = textIndexingConf || {
attributes: ['Name', 'ID'],
exclude: ['CDS', 'exon'],
}
const indexName = trackName + '-index'
const newEntry = {
indexingParams: {
...attr,
assemblies: [assembly],
tracks: [trackId],
indexType: 'perTrack',
name: indexName,
timestamp: new Date().toISOString(),
},
model.view.showTrack?.(trackId)
if (
isElectron &&
textIndexTrack &&
isSupportedIndexingAdapter(trackAdapter.type)
) {
const attr = textIndexingConf || {
attributes: ['Name', 'ID'],
exclude: ['CDS', 'exon'],
}
const indexName = trackName + '-index'
const newEntry = {
indexingParams: {
...attr,
assemblies: [assembly],
tracks: [trackId],
indexType: 'perTrack',
name: indexName,
cancelCallback: () => jobsManager.abortJob(),
}
jobsManager.queueJob(newEntry)
timestamp: new Date().toISOString(),
},
name: indexName,
cancelCallback: () => jobsManager.abortJob(),
}
jobsManager.queueJob(newEntry)
} else {
session.notify(
'Open a new view, or use the track selector in an existing view, to view this track',
'info',
)
}
model.clearData()
session.hideWidget(model)
if (isSessionModelWithWidgets(session)) {
session.hideWidget(model)
}
} else {
setTrackErrorMessage(
'Failed to add track.\nThe configuration of this file is not currently supported.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ 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 {
getSession,
isSessionModelWithWidgets,
isSessionWithAddTracks,
} from '@jbrowse/core/util'
import { observer } from 'mobx-react'

// locals
Expand Down Expand Up @@ -51,10 +55,15 @@ const PasteConfigAddTrackWorkflow = observer(function ({
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)
if (
isSessionWithAddTracks(session) &&
isSessionModelWithWidgets(session)
) {
confs.forEach(c => session.addTrackConf(c))
confs.forEach(c => model.view.showTrack(c.trackId))
model.clearData()
session.hideWidget(model)
}
} catch (e) {
console.error(e)
setError(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const HamburgerMenu = observer(function ({
deletingConnection?: boolean,
) {
const name = readConfObject(connectionConf, 'name')
const result = session.prepareToBreakConnection(connectionConf)
const result = session.prepareToBreakConnection?.(connectionConf)
if (result) {
const [safelyBreakConnection, dereferenceTypeCount] = result
if (Object.keys(dereferenceTypeCount).length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ const InstalledPlugin = observer(function ({
const [dialogPlugin, setDialogPlugin] = useState<string>()
const { pluginManager } = getEnv(model)
const session = getSession(model)
const { jbrowse, adminMode, sessionPlugins } = session
const isSessionPlugin = sessionPlugins?.some(
(p: { url: string }) =>
pluginManager.pluginMetadata[plugin.name].url === p.url,
)
const { jbrowse, adminMode } = session
const isSessionPlugin = isSessionWithSessionPlugins(session)
? session.sessionPlugins?.some(
p => pluginManager.pluginMetadata[plugin.name].url === p.url,
)
: false

return (
<>
Expand All @@ -76,7 +77,6 @@ const InstalledPlugin = observer(function ({
<ListItem key={plugin.name}>
{adminMode || isSessionPlugin ? (
<IconButton
aria-label="removePlugin"
data-testid={`removePlugin-${plugin.name}`}
onClick={() => setDialogPlugin(plugin.name)}
>
Expand Down
2 changes: 1 addition & 1 deletion plugins/data-management/src/ucsc-trackhub/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function UCSCTrackHubConnection(pluginManager: PluginManager) {
`There was a problem connecting to the UCSC Track Hub "${self.configuration.name}". Please make sure you have entered a valid hub.txt file. The error that was thrown is: "${e}"`,
'error',
)
session.breakConnection(self.configuration)
session.breakConnection?.(self.configuration)
}
},
}))
Expand Down
6 changes: 3 additions & 3 deletions plugins/dotplot-view/src/DotplotDisplay/stateModelFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
)
.views(self => ({
get shouldDisplay() {
const view = getContainingView(self)
const { vview, hview } = getContainingView(self) as DotplotViewModel
return (
view.vview.bpPerPx === self.data.bpPerPxY &&
view.hview.bpPerPx === self.data.bpPerPxX
vview.bpPerPx === self.data.bpPerPxY &&
hview.bpPerPx === self.data.bpPerPxX
)
},
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const Selector = observer(
}) => {
const session = getSession(model)
const { tracks, sessionTracks } = session
const allTracks = [...tracks, ...sessionTracks] as AnyConfigurationModel[]
const allTracks = [
...tracks,
...(sessionTracks || []),
] as AnyConfigurationModel[]
const filteredTracks = allTracks.filter(t => f(t, assembly2, assembly1))
const resetTrack = filteredTracks[0]?.trackId || ''
const [value, setValue] = useState(resetTrack)
Expand Down
Loading

0 comments on commit f094ad3

Please sign in to comment.