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 14fdaa8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 40 deletions.
15 changes: 4 additions & 11 deletions packages/core/configuration/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,10 @@ export function readConfObject<CONFMODEL extends AnyConfigurationModel>(
// )
}

if (slot.expr) {
const appliedFunc = slot.expr.evalSync(args)
if (isStateTreeNode(appliedFunc)) {
return JSON.parse(JSON.stringify(getSnapshot(appliedFunc)))
}
return appliedFunc
}
if (isStateTreeNode(slot)) {
return JSON.parse(JSON.stringify(getSnapshot(slot)))
}
return slot
const val = slot.expr ? slot.expr.evalSync(args) : slot
return isStateTreeNode(val)
? JSON.parse(JSON.stringify(getSnapshot(val)))
: val
}

if (Array.isArray(slotPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ function stateModelFactory() {
* #method
* @param region -
* @returns falsy if the region is fine to try rendering. Otherwise,
* return a react node + string of text.
* string of text describes why it cannot be rendered
* react node allows user to force load at current setting
* return a react node + string of text. string of text describes why it
* cannot be rendered react node allows user to force load at current
* setting
*/
regionCannotBeRendered(/* region */) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ 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,
getSnapshot,
} from 'mobx-state-tree'

// icons
import MenuOpenIcon from '@mui/icons-material/MenuOpen'
Expand All @@ -29,7 +36,6 @@ import BlockState from './serverSideRenderedBlock'
import configSchema from './configSchema'
import TrackHeightMixin from './TrackHeightMixin'
import FeatureDensityMixin from './FeatureDensityMixin'
import SerializableFilterChain from '@jbrowse/core/pluggableElementTypes/renderers/util/serializableFilterChain'

type LGV = LinearGenomeViewModel

Expand Down Expand Up @@ -77,10 +83,6 @@ function stateModelFactory() {
* #property
*/
configuration: ConfigurationReference(configSchema),
/**
* #property
*/
jexlFilters: types.optional(types.array(types.string), []),
}),
)
.volatile(() => ({
Expand Down Expand Up @@ -319,9 +321,7 @@ function stateModelFactory() {
...getParentRenderProps(self),
notReady: !self.featureDensityStatsReady,
rpcDriverName: self.rpcDriverName,
filters: new SerializableFilterChain({
filters: ["jexl:get(feature,'score')>400"],
}),

displayModel: self,
onFeatureClick(_: unknown, featureId?: string) {
const f = featureId || self.featureIdUnderMouse
Expand Down Expand Up @@ -396,15 +396,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,10 +53,9 @@ const baseLinearDisplayConfigSchema = ConfigurationSchema(
/**
* #slot
*/
filter: {
jexlFilters: {
type: 'string',
description: 'default filter to apply to a track',
contextVariable: ['feature'],
description: 'default set of jexl filters to apply to a track',
defaultValue: '',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const blockState = types
renderInProgress = undefined
},
setError(error: unknown) {
console.error(error)
if (renderInProgress && !renderInProgress.signal.aborted) {
renderInProgress.abort()
}
Expand Down
28 changes: 23 additions & 5 deletions plugins/linear-genome-view/src/LinearBasicDisplay/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
} from '@jbrowse/core/configuration'
import { getSession } from '@jbrowse/core/util'
import { MenuItem } from '@jbrowse/core/ui'
import { types, getEnv, Instance } from 'mobx-state-tree'
import { types, getEnv, Instance, cast } from 'mobx-state-tree'

// icons
import VisibilityIcon from '@mui/icons-material/Visibility'

// locals
import { BaseLinearDisplay } from '../BaseLinearDisplay'
import SerializableFilterChain from '@jbrowse/core/pluggableElementTypes/renderers/util/serializableFilterChain'

const SetMaxHeightDialog = lazy(() => import('./components/SetMaxHeightDialog'))
const AddFiltersDialog = lazy(() => import('./components/AddFiltersDialog'))
Expand Down Expand Up @@ -56,9 +57,19 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
* #property
*/
configuration: ConfigurationReference(configSchema),
/**
* #property
*/
jexlFilters: types.maybe(types.array(types.string)),
}),
)
.views(self => ({
/**
* #getter
*/
get activeFilters() {
return self.jexlFilters ?? [`jexl:${getConf(self, 'jexlFilters')}`]
},
/**
* #getter
*/
Expand Down Expand Up @@ -121,6 +132,12 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
}))

.actions(self => ({
/**
* #action
*/
setJexlFilters(f: string[]) {
self.jexlFilters = cast(f)
},
/**
* #action
*/
Expand Down Expand Up @@ -156,12 +173,13 @@ function stateModelFactory(configSchema: AnyConfigurationSchemaType) {
* #method
*/
renderProps() {
const config = self.rendererConfig
const superProps = superRenderProps()
const superPropsOmit = superProps as Omit<typeof superProps, symbol>
return {
...superPropsOmit,
config,
...(superProps as Omit<typeof superProps, symbol>),
config: self.rendererConfig,
filters: new SerializableFilterChain({
filters: self.activeFilters,
}),
}
},

Expand Down

0 comments on commit 14fdaa8

Please sign in to comment.