import React, { useEffect, useState } from 'react' import { Dialog } from '@jbrowse/core/ui' import { stringToJexlExpression } from '@jbrowse/core/util/jexlStrings' import { Button, DialogActions, DialogContent, TextField } from '@mui/material' import { observer } from 'mobx-react' import { makeStyles } from 'tss-react/mui' const useStyles = makeStyles()({ dialogContent: { width: '80em', }, textAreaFont: { fontFamily: 'Courier New', }, error: { color: 'red', fontSize: '0.8em', }, }) const AddFiltersDialog = observer(function ({ model, handleClose, }: { model: { jexlFilters?: string[] activeFilters: string[] setJexlFilters: (arg?: string[]) => void } handleClose: () => void }) { const { classes } = useStyles() const { activeFilters } = model const [data, setData] = useState(activeFilters.join('\n')) const [error, setError] = useState() useEffect(() => { try { for (const line of data.split('\n')) { const trimmed = line.trim() if (trimmed) { stringToJexlExpression(trimmed) } } setError(undefined) } catch (e) { console.error(e) setError(e) } }, [data]) return (
Add filters, in jexl format, one per line, starting with the string jexl:. Examples:{' '}
  • jexl:get(feature,'name')=='BRCA1' - show only feature where the name attribute is BRCA1
  • jexl:get(feature,'type')=='gene' - show only gene type features in a GFF that has many other feature types
  • jexl:get(feature,'score') > 400 - show only features that have a score greater than 400
{error ?

{`${error}`}

: null} { setData(event.target.value) }} slotProps={{ input: { classes: { input: classes.textAreaFont, }, }, }} />
) }) export default AddFiltersDialog