Skip to content

Commit 37df522

Browse files
committed
Save track data
1 parent 45b7d35 commit 37df522

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

packages/core/pluggableElementTypes/models/BaseTrackModel.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { lazy } from 'react'
12
import { transaction } from 'mobx'
23
import {
34
getRoot,
@@ -16,10 +17,14 @@ import {
1617
} from '../../configuration'
1718
import PluginManager from '../../PluginManager'
1819
import { MenuItem } from '../../ui'
20+
import { Save } from '../../ui/Icons'
1921
import { getContainingView, getEnv, getSession } from '../../util'
2022
import { isSessionModelWithConfigEditing } from '../../util/types'
2123
import { ElementId } from '../../util/types/mst'
2224

25+
// lazies
26+
const SaveTrackDataDlg = lazy(() => import('./components/SaveTrackData'))
27+
2328
export function getCompatibleDisplays(self: IAnyStateTreeNode) {
2429
const { pluginManager } = getEnv(self)
2530
const view = getContainingView(self)
@@ -210,6 +215,17 @@ export function createBaseTrackModel(
210215

211216
return [
212217
...menuItems,
218+
{
219+
label: 'Save track data',
220+
icon: Save,
221+
onClick: () => {
222+
getSession(self).queueDialog(handleClose => [
223+
SaveTrackDataDlg,
224+
// @ts-ignore
225+
{ model: self, handleClose },
226+
])
227+
},
228+
},
213229
...(compatDisp.length > 1
214230
? [
215231
{

plugins/linear-genome-view/src/LinearBasicDisplay/components/SaveTrackData.tsx renamed to packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ import { Dialog, ErrorMessage } from '@jbrowse/core/ui'
44
import {
55
getSession,
66
getContainingView,
7-
getContainingTrack,
87
Feature,
98
Region,
109
} from '@jbrowse/core/util'
1110
import { getConf } from '@jbrowse/core/configuration'
1211
import { makeStyles } from 'tss-react/mui'
13-
import {
14-
BaseDisplayModel,
15-
BaseTrackModel,
16-
} from '@jbrowse/core/pluggableElementTypes'
12+
import { BaseTrackModel } from '@jbrowse/core/pluggableElementTypes'
1713
import { observer } from 'mobx-react'
1814

1915
// locals
20-
import { LinearGenomeViewModel } from '../../LinearGenomeView'
2116
import { stringifyGFF3 } from './util'
2217

2318
const useStyles = makeStyles()(theme => ({
@@ -32,19 +27,12 @@ const useStyles = makeStyles()(theme => ({
3227
},
3328
}))
3429

35-
type LGV = LinearGenomeViewModel
36-
37-
/**
38-
* Fetches and returns a list features for a given list of regions
39-
*/
4030
async function fetchFeatures(
4131
track: BaseTrackModel,
42-
view: LGV,
4332
regions: Region[],
4433
signal?: AbortSignal,
4534
) {
46-
const session = getSession(view)
47-
const { rpcManager } = session
35+
const { rpcManager } = getSession(track)
4836
const adapterConfig = getConf(track, ['adapter'])
4937
const sessionId = 'getSequence'
5038
return rpcManager.call(sessionId, 'CoreGetFeatures', {
@@ -59,7 +47,7 @@ function SaveTrackDataDlg({
5947
model,
6048
handleClose,
6149
}: {
62-
model: BaseDisplayModel
50+
model: BaseTrackModel
6351
handleClose: () => void
6452
}) {
6553
const { classes } = useStyles()
@@ -70,11 +58,11 @@ function SaveTrackDataDlg({
7058
// eslint-disable-next-line @typescript-eslint/no-floating-promises
7159
;(async () => {
7260
try {
73-
const view = getContainingView(model) as LGV
74-
const track = getContainingTrack(model) as BaseTrackModel
61+
const view = getContainingView(model)
62+
const track = model
7563
const regions = view.dynamicBlocks.contentBlocks
7664
setError(undefined)
77-
const feats = await fetchFeatures(track, view, regions)
65+
const feats = await fetchFeatures(track, regions)
7866
const ret = stringifyGFF3(feats)
7967
setFeatures(ret)
8068
} catch (e) {

plugins/linear-genome-view/src/LinearBasicDisplay/model.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import VisibilityIcon from '@mui/icons-material/Visibility'
1313

1414
// locals
1515
import { BaseLinearDisplay } from '../BaseLinearDisplay'
16-
import { Save } from '@jbrowse/core/ui/Icons'
1716

1817
const SetMaxHeightDlg = lazy(() => import('./components/SetMaxHeight'))
19-
const SaveTrackDataDlg = lazy(() => import('./components/SaveTrackData'))
2018

2119
/**
2220
* #stateModel LinearBasicDisplay
@@ -175,16 +173,7 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
175173
checked: self.showLabels,
176174
onClick: () => self.toggleShowLabels(),
177175
},
178-
{
179-
label: 'Save track data',
180-
icon: Save,
181-
onClick: () => {
182-
getSession(self).queueDialog(handleClose => [
183-
SaveTrackDataDlg,
184-
{ model: self, handleClose },
185-
])
186-
},
187-
},
176+
188177
{
189178
label: 'Show descriptions',
190179
icon: VisibilityIcon,

0 commit comments

Comments
 (0)