/
createSessionModel.ts
163 lines (156 loc) · 4.55 KB
/
createSessionModel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* eslint-disable @typescript-eslint/no-explicit-any */
import { lazy } from 'react'
import { AbstractSessionModel } from '@jbrowse/core/util/types'
import SnackbarModel from '@jbrowse/core/ui/SnackbarModel'
import { getConf } from '@jbrowse/core/configuration'
import { cast, getParent, types, Instance } from 'mobx-state-tree'
import PluginManager from '@jbrowse/core/PluginManager'
import InfoIcon from '@mui/icons-material/Info'
import { LinearGenomeViewStateModel } from '@jbrowse/plugin-linear-genome-view'
import {
BaseSessionModel,
ConnectionManagementSessionMixin,
DialogQueueSessionMixin,
DrawerWidgetSessionMixin,
ReferenceManagementSessionMixin,
SessionTracksManagerSessionMixin,
TracksManagerSessionMixin,
} from '@jbrowse/product-core'
const AboutDialog = lazy(() => import('./AboutDialog'))
/**
* #stateModel JBrowseReactLinearGenomeViewSessionModel
* composed of
* - [BaseSessionModel](../basesessionmodel)
* - [DrawerWidgetSessionMixin](../drawerwidgetsessionmixin)
* - [ConnectionManagementSessionMixin](../connectionmanagementsessionmixin)
* - [DialogQueueSessionMixin](../dialogqueuesessionmixin)
* - [TracksManagerSessionMixin](../tracksmanagersessionmixin)
* - [ReferenceManagementSessionMixin](../referencemanagementsessionmixin)
* - [SessionTracksManagerSessionMixin](../sessiontracksmanagersessionmixin)
* - [SnackbarModel](../snackbarmodel)
*/
function x() {} // eslint-disable-line @typescript-eslint/no-unused-vars
export default function sessionModelFactory(pluginManager: PluginManager) {
return types
.compose(
'ReactLinearGenomeViewSession',
BaseSessionModel(pluginManager),
DrawerWidgetSessionMixin(pluginManager),
ConnectionManagementSessionMixin(pluginManager),
DialogQueueSessionMixin(pluginManager),
TracksManagerSessionMixin(pluginManager),
ReferenceManagementSessionMixin(pluginManager),
SessionTracksManagerSessionMixin(pluginManager),
SnackbarModel(),
)
.props({
/**
* #property
*/
view: pluginManager.getViewType('LinearGenomeView')
.stateModel as LinearGenomeViewStateModel,
/**
* #property
*/
sessionTracks: types.array(
pluginManager.pluggableConfigSchemaType('track'),
),
})
.views(self => ({
/**
* #getter
*/
get version() {
return getParent<any>(self).version
},
/**
* #getter
*/
get disableAddTracks() {
return getParent<any>(self).disableAddTracks
},
/**
* #getter
*/
get assemblies() {
return [getParent<any>(self).config.assembly]
},
/**
* #getter
*/
get assemblyNames() {
return [getParent<any>(self).config.assemblyName]
},
/**
* #getter
*/
get connections() {
return getParent<any>(self).config.connections
},
/**
* #getter
*/
get assemblyManager() {
return getParent<any>(self).assemblyManager
},
/**
* #getter
*/
get views() {
return [self.view]
},
/**
* #method
*/
renderProps() {
return {
theme: getConf(self, 'theme'),
highResolutionScaling: getConf(self, 'highResolutionScaling'),
}
},
}))
.actions(self => ({
/**
* #action
*/
addView(typeName: string, initialState = {}) {
const typeDefinition = pluginManager.getElementType('view', typeName)
if (!typeDefinition) {
throw new Error(`unknown view type ${typeName}`)
}
self.view = cast({
...initialState,
type: typeName,
})
return self.view
},
removeView() {},
}))
.views(self => ({
/**
* #method
*/
getTrackActionMenuItems(config: any) {
return [
{
label: 'About track',
onClick: () => {
self.queueDialog(doneCallback => [
AboutDialog,
{ config, handleClose: doneCallback },
])
},
icon: InfoIcon,
},
]
},
}))
}
export type SessionStateModel = ReturnType<typeof sessionModelFactory>
export type SessionModel = Instance<SessionStateModel>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function z(x: Instance<SessionStateModel>): AbstractSessionModel {
// this function's sole purpose is to get typescript to check
// that the session model implements all of AbstractSessionModel
return x
}