UNPKG

@jbrowse/plugin-wiggle

Version:

JBrowse 2 wiggle adapters, tracks, etc.

93 lines (92 loc) 5.36 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useState } from 'react'; import { SanitizedHTML } from '@jbrowse/core/ui'; import ColorPicker, { ColorPopover } from '@jbrowse/core/ui/ColorPicker'; import { getStr, measureGridWidth } from '@jbrowse/core/util'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'; import KeyboardDoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown'; import KeyboardDoubleArrowUpIcon from '@mui/icons-material/KeyboardDoubleArrowUp'; import { Button } from '@mui/material'; import { DataGrid } from '@mui/x-data-grid'; import { makeStyles } from 'tss-react/mui'; import { moveDown, moveUp } from './util'; const useStyles = makeStyles()({ cell: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', }, }); function SourcesGrid({ rows, onChange, showTips, }) { const { classes } = useStyles(); const [anchorEl, setAnchorEl] = useState(null); const [selected, setSelected] = useState([]); const { name: _name, color: _color, baseUri: _baseUri, ...rest } = rows[0]; const [widgetColor, setWidgetColor] = useState('blue'); const [currSort, setCurrSort] = useState({ idx: 0, field: null, }); return (_jsxs("div", { children: [_jsx(Button, { disabled: !selected.length, onClick: event => { setAnchorEl(event.currentTarget); }, children: "Change color of selected items" }), _jsxs(Button, { disabled: !selected.length, onClick: () => { onChange(moveUp([...rows], selected)); }, children: [_jsx(KeyboardArrowUpIcon, {}), showTips ? 'Move selected items up' : null] }), _jsxs(Button, { disabled: !selected.length, onClick: () => { onChange(moveDown([...rows], selected)); }, children: [_jsx(KeyboardArrowDownIcon, {}), showTips ? 'Move selected items down' : null] }), _jsxs(Button, { disabled: !selected.length, onClick: () => { onChange(moveUp([...rows], selected, rows.length)); }, children: [_jsx(KeyboardDoubleArrowUpIcon, {}), showTips ? 'Move selected items to top' : null] }), _jsxs(Button, { disabled: !selected.length, onClick: () => { onChange(moveDown([...rows], selected, rows.length)); }, children: [_jsx(KeyboardDoubleArrowDownIcon, {}), showTips ? 'Move selected items to bottom' : null] }), _jsx(ColorPopover, { anchorEl: anchorEl, color: widgetColor, onChange: c => { setWidgetColor(c); for (const id of selected) { const elt = rows.find(f => f.name === id); if (elt) { elt.color = c; } } onChange([...rows]); }, onClose: () => { setAnchorEl(null); } }), _jsx("div", { style: { height: 400, width: '100%' }, children: _jsx(DataGrid, { disableRowSelectionOnClick: true, getRowId: row => row.name, checkboxSelection: true, onRowSelectionModelChange: arg => { setSelected([...arg.ids]); }, rows: rows, rowHeight: 25, columnHeaderHeight: 33, columns: [ { field: 'color', headerName: 'Color', renderCell: ({ value, id }) => (_jsx(ColorPicker, { color: value || 'blue', onChange: c => { const elt = rows.find(f => f.name === id); if (elt) { elt.color = c; } onChange([...rows]); } })), }, { field: 'name', headerName: 'Name', width: measureGridWidth(rows.map(r => r.name)), }, ...Object.keys(rest).map(val => ({ field: val, renderCell: ({ value }) => (_jsx("div", { className: classes.cell, children: _jsx(SanitizedHTML, { html: getStr(value) }) })), width: measureGridWidth(rows.map(r => `${r[val]}`)), })), ], sortModel: [], onSortModelChange: args => { const sort = args[0]; const idx = (currSort.idx + 1) % 2; const field = sort.field || currSort.field; setCurrSort({ idx, field }); onChange(field ? [...rows].sort((a, b) => { const aa = getStr(a[field]); const bb = getStr(b[field]); return idx === 1 ? aa.localeCompare(bb) : bb.localeCompare(aa); }) : rows); } }) })] })); } export default SourcesGrid;