Skip to content

Commit

Permalink
Filter branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed May 15, 2024
1 parent 49539d0 commit d80f767
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React from 'react'
import { ThemeOptions } from '@mui/material'
import { BaseDisplay } from '@jbrowse/core/pluggableElementTypes/models'
import { ConfigurationReference } from '@jbrowse/core/configuration'
import { ConfigurationReference, getConf } from '@jbrowse/core/configuration'
import { MenuItem } from '@jbrowse/core/ui'
import {
getContainingView,
Expand All @@ -17,7 +17,7 @@ import { BaseBlock } from '@jbrowse/core/util/blockTypes'
import CompositeMap from '@jbrowse/core/util/compositeMap'
import { getParentRenderProps } from '@jbrowse/core/util/tracks'
import { autorun } from 'mobx'
import { addDisposer, isAlive, types, Instance } from 'mobx-state-tree'
import { addDisposer, isAlive, types, Instance, cast } from 'mobx-state-tree'

// icons
import MenuOpenIcon from '@mui/icons-material/MenuOpen'
Expand Down Expand Up @@ -80,14 +80,20 @@ function stateModelFactory() {
/**
* #property
*/
jexlFilters: types.optional(types.array(types.string), []),
jexlFilters: types.maybe(types.array(types.string)),
}),
)
.volatile(() => ({
featureIdUnderMouse: undefined as undefined | string,
contextMenuFeature: undefined as undefined | Feature,
}))
.views(self => ({
/**
* #getter
*/
get activeFilters() {
return self.jexlFilters ?? getConf(self, 'jexlFilters')
},
/**
* #getter
*/
Expand Down Expand Up @@ -204,6 +210,12 @@ function stateModelFactory() {
}))

.actions(self => ({
/**
* #action
*/
setJexlFilters(f: string[]) {
self.jexlFilters = cast(f)
},
/**
* #action
*/
Expand Down Expand Up @@ -319,9 +331,11 @@ function stateModelFactory() {
...getParentRenderProps(self),
notReady: !self.featureDensityStatsReady,
rpcDriverName: self.rpcDriverName,
filters: new SerializableFilterChain({
filters: ["jexl:get(feature,'score')>400"],
}),
filters: self.activeFilters.length
? new SerializableFilterChain({
filters: self.activeFilters,
})
: undefined,
displayModel: self,
onFeatureClick(_: unknown, featureId?: string) {
const f = featureId || self.featureIdUnderMouse
Expand Down Expand Up @@ -396,15 +410,6 @@ function stateModelFactory() {
})
}),
)

addDisposer(
self,
autorun(() => {
if (!self.jexlFilters) {
self.jexlFilters = getConf(self, 'jexlFilters')
}
}),
)
},
}))
.preProcessSnapshot(snap => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ const baseLinearDisplayConfigSchema = ConfigurationSchema(
/**
* #slot
*/
filter: {
type: 'string',
description: 'default filter to apply to a track',
contextVariable: ['feature'],
defaultValue: '',
jexlFilters: {
type: 'stringArray',
description: 'default set of jexl filters to apply to a track',
defaultValue: [],
},
},
{
Expand Down

0 comments on commit d80f767

Please sign in to comment.