Skip to content

Commit 02f70e1

Browse files
committed
Pre-process config
1 parent 615377b commit 02f70e1

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

packages/core/src/util/tracks.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,17 @@ export function showTrackGeneric(
515515
return found
516516
}
517517

518-
const conf = session.getTracksById()[trackId]
519-
if (!conf) {
518+
const rawConf = session.getTracksById()[trackId]
519+
if (!rawConf) {
520520
throw new Error(`Could not resolve identifier "${trackId}"`)
521521
}
522522

523+
// Allow plugins to preprocess the track config (e.g. to add default displays)
524+
const conf = pluginManager.evaluateExtensionPoint(
525+
'Core-preProcessTrackConfig',
526+
structuredClone(rawConf),
527+
) as typeof rawConf
528+
523529
const trackType = pluginManager.getTrackType(conf.type)
524530
if (!trackType) {
525531
throw new Error(`Unknown track type ${conf.type}`)
@@ -550,6 +556,10 @@ export function showTrackGeneric(
550556
// Generate displayId based on the actual display type being used
551557
const displayId = displayConf?.displayId ?? `${trackId}-${displayType}`
552558

559+
// Extract initial state properties from displayConf (excluding config-specific fields)
560+
const { type: _type, displayId: _displayId, ...displayConfState } =
561+
displayConf ?? {}
562+
553563
// Create track with just the trackId - the ConfigurationReference will resolve it
554564
const track = trackType.stateModel.create({
555565
...initialSnapshot,
@@ -559,6 +569,7 @@ export function showTrackGeneric(
559569
{
560570
type: displayType,
561571
configuration: displayId,
572+
...displayConfState,
562573
...displayInitialSnapshot,
563574
},
564575
],

test_data/volvox/umd_plugin.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,37 @@
189189
}
190190
return snap
191191
})
192+
193+
// Example: Add LinearReadCloudDisplay as the first display for AlignmentsTracks
194+
// that have "_sv" in their trackId (e.g. structural variant tracks)
195+
// This now works because showTrackGeneric calls Core-preProcessTrackConfig
196+
// and spreads display config properties into the display state
197+
pluginManager.addToExtensionPoint('Core-preProcessTrackConfig', snap => {
198+
if (snap.type === 'AlignmentsTrack' && snap.trackId?.includes('_sv')) {
199+
const displays = snap.displays || []
200+
const hasReadCloud = displays.some(
201+
d => d.type === 'LinearReadCloudDisplay',
202+
)
203+
if (!hasReadCloud) {
204+
console.log(
205+
'Adding LinearReadCloudDisplay with drawCloud:true for',
206+
snap.trackId,
207+
)
208+
return {
209+
...snap,
210+
displays: [
211+
{
212+
type: 'LinearReadCloudDisplay',
213+
displayId: `${snap.trackId}-LinearReadCloudDisplay`,
214+
drawCloud: true,
215+
},
216+
...displays,
217+
],
218+
}
219+
}
220+
}
221+
return snap
222+
})
192223
}
193224

194225
configure(pluginManager) {

0 commit comments

Comments
 (0)