From 37df52202f4d76f88493dd99464fc13c00f5a6f0 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 5 Jan 2023 12:34:10 -0700 Subject: [PATCH] Save track data --- .../models/BaseTrackModel.ts | 16 +++++++++++++ .../models}/components/SaveTrackData.tsx | 24 +++++-------------- .../models}/components/util.ts | 0 .../src/LinearBasicDisplay/model.ts | 13 +--------- 4 files changed, 23 insertions(+), 30 deletions(-) rename {plugins/linear-genome-view/src/LinearBasicDisplay => packages/core/pluggableElementTypes/models}/components/SaveTrackData.tsx (80%) rename {plugins/linear-genome-view/src/LinearBasicDisplay => packages/core/pluggableElementTypes/models}/components/util.ts (100%) diff --git a/packages/core/pluggableElementTypes/models/BaseTrackModel.ts b/packages/core/pluggableElementTypes/models/BaseTrackModel.ts index 99a95582195..605152bb28d 100644 --- a/packages/core/pluggableElementTypes/models/BaseTrackModel.ts +++ b/packages/core/pluggableElementTypes/models/BaseTrackModel.ts @@ -1,3 +1,4 @@ +import { lazy } from 'react' import { transaction } from 'mobx' import { getRoot, @@ -16,10 +17,14 @@ import { } from '../../configuration' import PluginManager from '../../PluginManager' import { MenuItem } from '../../ui' +import { Save } from '../../ui/Icons' import { getContainingView, getEnv, getSession } from '../../util' import { isSessionModelWithConfigEditing } from '../../util/types' import { ElementId } from '../../util/types/mst' +// lazies +const SaveTrackDataDlg = lazy(() => import('./components/SaveTrackData')) + export function getCompatibleDisplays(self: IAnyStateTreeNode) { const { pluginManager } = getEnv(self) const view = getContainingView(self) @@ -210,6 +215,17 @@ export function createBaseTrackModel( return [ ...menuItems, + { + label: 'Save track data', + icon: Save, + onClick: () => { + getSession(self).queueDialog(handleClose => [ + SaveTrackDataDlg, + // @ts-ignore + { model: self, handleClose }, + ]) + }, + }, ...(compatDisp.length > 1 ? [ { diff --git a/plugins/linear-genome-view/src/LinearBasicDisplay/components/SaveTrackData.tsx b/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx similarity index 80% rename from plugins/linear-genome-view/src/LinearBasicDisplay/components/SaveTrackData.tsx rename to packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx index 88be2b51fa2..8614de223a0 100644 --- a/plugins/linear-genome-view/src/LinearBasicDisplay/components/SaveTrackData.tsx +++ b/packages/core/pluggableElementTypes/models/components/SaveTrackData.tsx @@ -4,20 +4,15 @@ import { Dialog, ErrorMessage } from '@jbrowse/core/ui' import { getSession, getContainingView, - getContainingTrack, Feature, Region, } from '@jbrowse/core/util' import { getConf } from '@jbrowse/core/configuration' import { makeStyles } from 'tss-react/mui' -import { - BaseDisplayModel, - BaseTrackModel, -} from '@jbrowse/core/pluggableElementTypes' +import { BaseTrackModel } from '@jbrowse/core/pluggableElementTypes' import { observer } from 'mobx-react' // locals -import { LinearGenomeViewModel } from '../../LinearGenomeView' import { stringifyGFF3 } from './util' const useStyles = makeStyles()(theme => ({ @@ -32,19 +27,12 @@ const useStyles = makeStyles()(theme => ({ }, })) -type LGV = LinearGenomeViewModel - -/** - * Fetches and returns a list features for a given list of regions - */ async function fetchFeatures( track: BaseTrackModel, - view: LGV, regions: Region[], signal?: AbortSignal, ) { - const session = getSession(view) - const { rpcManager } = session + const { rpcManager } = getSession(track) const adapterConfig = getConf(track, ['adapter']) const sessionId = 'getSequence' return rpcManager.call(sessionId, 'CoreGetFeatures', { @@ -59,7 +47,7 @@ function SaveTrackDataDlg({ model, handleClose, }: { - model: BaseDisplayModel + model: BaseTrackModel handleClose: () => void }) { const { classes } = useStyles() @@ -70,11 +58,11 @@ function SaveTrackDataDlg({ // eslint-disable-next-line @typescript-eslint/no-floating-promises ;(async () => { try { - const view = getContainingView(model) as LGV - const track = getContainingTrack(model) as BaseTrackModel + const view = getContainingView(model) + const track = model const regions = view.dynamicBlocks.contentBlocks setError(undefined) - const feats = await fetchFeatures(track, view, regions) + const feats = await fetchFeatures(track, regions) const ret = stringifyGFF3(feats) setFeatures(ret) } catch (e) { diff --git a/plugins/linear-genome-view/src/LinearBasicDisplay/components/util.ts b/packages/core/pluggableElementTypes/models/components/util.ts similarity index 100% rename from plugins/linear-genome-view/src/LinearBasicDisplay/components/util.ts rename to packages/core/pluggableElementTypes/models/components/util.ts diff --git a/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts b/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts index 5b5ee6fc5bf..3c0905bb5a3 100644 --- a/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts +++ b/plugins/linear-genome-view/src/LinearBasicDisplay/model.ts @@ -13,10 +13,8 @@ import VisibilityIcon from '@mui/icons-material/Visibility' // locals import { BaseLinearDisplay } from '../BaseLinearDisplay' -import { Save } from '@jbrowse/core/ui/Icons' const SetMaxHeightDlg = lazy(() => import('./components/SetMaxHeight')) -const SaveTrackDataDlg = lazy(() => import('./components/SaveTrackData')) /** * #stateModel LinearBasicDisplay @@ -175,16 +173,7 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) { checked: self.showLabels, onClick: () => self.toggleShowLabels(), }, - { - label: 'Save track data', - icon: Save, - onClick: () => { - getSession(self).queueDialog(handleClose => [ - SaveTrackDataDlg, - { model: self, handleClose }, - ]) - }, - }, + { label: 'Show descriptions', icon: VisibilityIcon,