Skip to content

Commit

Permalink
Improve TypeScript for queueDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens authored and cmdcolin committed Sep 29, 2022
1 parent 214b57c commit c60651c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 39 deletions.
7 changes: 3 additions & 4 deletions packages/core/util/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ export interface AbstractSessionModel extends AbstractViewContainer {
DialogComponent?: DialogComponentType
// eslint-disable-next-line @typescript-eslint/no-explicit-any
DialogProps: any
queueDialog: (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback: (doneCallback: Function) => [DialogComponentType, any],
) => void
queueDialog<T extends DialogComponentType>(
callback: (doneCallback: () => void) => [T, React.ComponentProps<T>],
): void
name: string
id?: string
tracks: AnyConfigurationModel[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ const useStyles = makeStyles()(theme => ({

function SetFeatureHeightDlg(props: {
model: {
minScore: number
maxScore: number
setMinScore: Function
setMaxScore: Function
setFeatureHeight: Function
setNoSpacing: Function
featureHeightSetting: number
noSpacing: boolean
noSpacing?: boolean
}
handleClose: () => void
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@mui/material'
import { ErrorMessage } from '@jbrowse/core/ui'
import CloseIcon from '@mui/icons-material/Close'
import { LinearGenomeViewModel as LGV } from '..'
import { ExportSvgOptions } from '..'

const useStyles = makeStyles()(theme => ({
closeButton: {
Expand All @@ -39,7 +39,7 @@ export default function ExportSvgDlg({
model,
handleClose,
}: {
model: LGV
model: { exportSvg(opts: ExportSvgOptions): void }
handleClose: () => void
}) {
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import { getSession } from '@jbrowse/core/util'
// icons
import CloseIcon from '@mui/icons-material/Close'

// locals
import { LinearGenomeViewModel } from '..'

const useStyles = makeStyles()(theme => ({
closeButton: {
position: 'absolute',
Expand All @@ -40,7 +37,7 @@ function SequenceDialog({
model,
handleClose,
}: {
model: LinearGenomeViewModel
model: { assemblyNames: string[]; toggleTrack(trackId: string): void }
handleClose: () => void
}) {
const { classes } = useStyles()
Expand Down
32 changes: 16 additions & 16 deletions plugins/linear-genome-view/src/LinearGenomeView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,22 @@ export function stateModelFactory(pluginManager: PluginManager) {
setScaleFactor(factor: number) {
self.scaleFactor = factor
},
// this "clears the view" and makes the view return to the import form
clearView() {
this.setDisplayedRegions([])
self.tracks.clear()
// it is necessary to run these after setting displayed regions empty
// or else model.offsetPx gets set to Infinity and breaks
// mobx-state-tree snapshot
self.scrollTo(0)
self.zoomTo(10)
},
async exportSvg(opts: ExportSvgOptions = {}) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const html = await renderToSvg(self as any, opts)
const blob = new Blob([html], { type: 'image/svg+xml' })
saveAs(blob, opts.filename || 'image.svg')
},
}))
.actions(self => {
let cancelLastAnimation = () => {}
Expand Down Expand Up @@ -899,16 +915,6 @@ export function stateModelFactory(pluginManager: PluginManager) {
}
})
.actions(self => ({
// this "clears the view" and makes the view return to the import form
clearView() {
self.setDisplayedRegions([])
self.tracks.clear()
// it is necessary to run these after setting displayed regions empty
// or else model.offsetPx gets set to Infinity and breaks
// mobx-state-tree snapshot
self.scrollTo(0)
self.zoomTo(10)
},
setCoarseDynamicBlocks(blocks: BlockSet) {
self.coarseDynamicBlocks = blocks.contentBlocks
self.coarseTotalBp = blocks.totalBp
Expand All @@ -928,12 +934,6 @@ export function stateModelFactory(pluginManager: PluginManager) {
},
}))
.actions(self => ({
async exportSvg(opts: ExportSvgOptions = {}) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const html = await renderToSvg(self as any, opts)
const blob = new Blob([html], { type: 'image/svg+xml' })
saveAs(blob, opts.filename || 'image.svg')
},
/**
* offset is the base-pair-offset in the displayed region, index is the index of the
* displayed region in the linear genome view
Expand Down
4 changes: 2 additions & 2 deletions plugins/wiggle/src/CreateMultiWiggleExtension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default function (pm: PluginManager) {
ConfirmDialog,
{
tracks,
onClose: (arg: boolean, arg1: { name: string }) => {
if (arg) {
onClose: (arg: boolean, arg1?: { name: string }) => {
if (arg && arg1) {
makeTrack(arg1)
}
handleClose()
Expand Down
6 changes: 3 additions & 3 deletions plugins/wiggle/src/LinearWiggleDisplay/models/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ const stateModelFactory = (
self.statsReady = true
}
},
setColor(color: string) {
setColor(color?: string) {
self.color = color
},
setPosColor(color: string) {
setPosColor(color?: string) {
self.posColor = color
},
setNegColor(color: string) {
setNegColor(color?: string) {
self.negColor = color
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function SetColorDialog({
handleClose,
}: {
model: {
sources: Source[]
sources?: Source[]
setLayout: (s: Source[]) => void
clearLayout: () => void
}
Expand Down Expand Up @@ -132,7 +132,7 @@ export default function SetColorDialog({
color="inherit"
onClick={() => {
model.clearLayout()
setCurrLayout(model.sources)
setCurrLayout(model.sources || [])
}}
>
Clear custom settings
Expand All @@ -142,7 +142,7 @@ export default function SetColorDialog({
color="secondary"
onClick={() => {
handleClose()
setCurrLayout([...model.sources])
setCurrLayout([...(model.sources || [])])
}}
>
Cancel
Expand Down

0 comments on commit c60651c

Please sign in to comment.