@jbrowse/plugin-linear-genome-view
Version:
JBrowse 2 linear genome view
60 lines (59 loc) • 3.39 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { 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',
},
});
function checkJexl(code) {
stringToJexlExpression(code);
}
const AddFiltersDialog = observer(function ({ model, handleClose, }) {
const { classes } = useStyles();
const { activeFilters } = model;
const [data, setData] = useState(activeFilters.join('\n'));
const [error, setError] = useState();
useEffect(() => {
try {
data
.split('\n')
.map(line => line.trim())
.filter(line => !!line)
.map(line => {
checkJexl(line.trim());
});
setError(undefined);
}
catch (e) {
console.error(e);
setError(e);
}
}, [data]);
return (_jsxs(Dialog, { maxWidth: "xl", open: true, onClose: handleClose, title: "Add track filters", children: [_jsxs(DialogContent, { children: [_jsxs("div", { children: ["Add filters, in jexl format, one per line, starting with the string jexl:. Examples:", ' ', _jsxs("ul", { children: [_jsxs("li", { children: [_jsx("code", { children: "jexl:get(feature,'name')=='BRCA1'" }), " - show only feature where the name attribute is BRCA1"] }), _jsxs("li", { children: [_jsx("code", { children: "jexl:get(feature,'type')=='gene'" }), " - show only gene type features in a GFF that has many other feature types"] }), _jsxs("li", { children: [_jsx("code", { children: "jexl:get(feature,'score') > 400" }), " - show only features that have a score greater than 400"] }), _jsxs("li", { children: [_jsx("code", { children: "jexl:get(feature,'end') - get(feature,'start') < 1000000" }), ' ', "- show only features with length less than 1Mbp"] })] })] }), error ? _jsx("p", { className: classes.error, children: `${error}` }) : null, _jsx(TextField, { variant: "outlined", multiline: true, minRows: 5, maxRows: 10, className: classes.dialogContent, fullWidth: true, value: data, onChange: event => {
setData(event.target.value);
}, slotProps: {
input: {
classes: {
input: classes.textAreaFont,
},
},
} })] }), _jsxs(DialogActions, { children: [_jsx(Button, { variant: "contained", color: "primary", type: "submit", autoFocus: true, disabled: !!error, onClick: () => {
model.setJexlFilters(data.split('\n'));
handleClose();
}, children: "Submit" }), _jsx(Button, { variant: "contained", color: "secondary", onClick: () => {
handleClose();
}, children: "Cancel" })] })] }));
});
export default AddFiltersDialog;