UNPKG

@jbrowse/plugin-wiggle

Version:

JBrowse 2 wiggle adapters, tracks, etc.

82 lines (81 loc) 5.06 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useState } from 'react'; import { ErrorMessage } from '@jbrowse/core/ui'; import { Button, DialogActions, DialogContent, TextField, Typography, } from '@mui/material'; import { makeStyles } from 'tss-react/mui'; const useStyles = makeStyles()({ textAreaFont: { fontFamily: 'Courier New', }, }); export default function SetColorDialogBulkEditPanel({ onClose, currLayout, }) { const { classes } = useStyles(); const [val, setVal] = useState(''); const [error, setError] = useState(); return (_jsxs(_Fragment, { children: [_jsxs(DialogContent, { children: [_jsx(Typography, { children: "Paste CSV or TSV. If a header column is present. First line is a header. If a column called \"name\" is present, it uses that to connect to IDs in the table, otherwise it uses the first column no." }), error ? _jsx(ErrorMessage, { error: error }) : null, _jsx(TextField, { variant: "outlined", multiline: true, minRows: 5, placeholder: 'name,population\nHG00098,GBR\nHG00101,GBR\nHG00459,CHS\n...', maxRows: 10, fullWidth: true, value: val, onChange: event => { setVal(event.target.value); }, slotProps: { input: { classes: { input: classes.textAreaFont, }, }, } })] }), _jsxs(DialogActions, { children: [_jsx(Button, { variant: "contained", color: "secondary", onClick: () => { const lines = val .split('\n') .map(f => f.trim()) .filter(f => !!f); const fields = lines[0].split(/[,\t]/gm); if (fields.includes('name')) { setError(''); const oldLayout = Object.fromEntries(currLayout.map(record => [record.name, record])); const newData = Object.fromEntries(lines.slice(1).map(line => { const cols = line.split(/[,\t]/gm); const newRecord = Object.fromEntries(cols.map((col, idx) => [fields[idx], col])); return [ newRecord.name, { ...newRecord, ...oldLayout[newRecord.name], }, ]; })); onClose(currLayout.map(record => ({ ...record, ...newData[record.name], }))); } else { setError(new Error('No "name" column found on line 1')); } }, children: "Update rows" }), _jsx(Button, { variant: "contained", color: "primary", onClick: () => { const lines = val .split('\n') .map(f => f.trim()) .filter(f => !!f); const fields = lines[0].split(/[,\t]/gm); if (fields.includes('name')) { setError(''); const oldLayout = Object.fromEntries(currLayout.map(record => [record.name, record])); const newData = Object.fromEntries(lines.slice(1).map(line => { const cols = line.split(/[,\t]/gm); const newRecord = Object.fromEntries(cols.map((col, idx) => [fields[idx], col])); return [ newRecord.name, { ...newRecord, ...oldLayout[newRecord.name], }, ]; })); onClose(currLayout.map(record => ({ ...newData[record.name], }))); } else { setError(new Error('No "name" column found on line 1')); } }, children: "Replace rows" }), _jsx(Button, { variant: "contained", color: "inherit", onClick: () => { onClose(); }, children: "Cancel" })] })] })); }