UNPKG

@jbrowse/plugin-linear-genome-view

Version:

JBrowse 2 linear genome view

58 lines (57 loc) 3.59 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { getEnv, getSession } from '@jbrowse/core/util'; import { Button, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, } from '@mui/material'; import { getRoot, resolveIdentifier } from 'mobx-state-tree'; export default function SearchResultsTable({ searchResults, assemblyName: optAssemblyName, model, handleClose, }) { const session = getSession(model); const { pluginManager } = getEnv(session); const { assemblyManager } = session; const assemblyName = optAssemblyName || model.displayedRegions[0].assemblyName; const assembly = assemblyManager.get(assemblyName); if (!assembly) { throw new Error(`assembly ${assemblyName} not found`); } if (!assembly.regions) { throw new Error(`assembly ${assemblyName} regions not loaded`); } function getTrackName(trackId) { var _a; if (trackId) { const schema = pluginManager.pluggableConfigSchemaType('track'); const configuration = resolveIdentifier(schema, getRoot(model), trackId); return ((_a = configuration === null || configuration === void 0 ? void 0 : configuration.name) === null || _a === void 0 ? void 0 : _a.value) || ''; } return ''; } async function handleClick(location) { var _a; try { const newRegion = (_a = assembly === null || assembly === void 0 ? void 0 : assembly.regions) === null || _a === void 0 ? void 0 : _a.find(region => location === region.refName); if (newRegion) { model.setDisplayedRegions([newRegion]); model.showAllRegions(); } else { await model.navToLocString(location, assemblyName); } } catch (e) { console.warn(e); session.notify(`${e}`, 'warning'); } } return (_jsx(TableContainer, { component: Paper, children: _jsxs(Table, { children: [_jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableCell, { children: "Name" }), _jsx(TableCell, { align: "right", children: "Location" }), _jsx(TableCell, { align: "right", children: "Track" }), _jsx(TableCell, { align: "right" })] }) }), _jsx(TableBody, { children: searchResults.map(result => (_jsxs(TableRow, { children: [_jsx(TableCell, { component: "th", scope: "row", children: result.getLabel() }), _jsx(TableCell, { align: "right", children: result.getLocation() }), _jsx(TableCell, { align: "right", children: getTrackName(result.getTrackId()) || 'N/A' }), _jsx(TableCell, { align: "right", children: _jsx(Button, { onClick: async () => { try { await handleClick(result.getLocation() || result.getLabel()); const resultTrackId = result.getTrackId(); if (resultTrackId) { model.showTrack(resultTrackId); } } catch (e) { console.error(e); session.notifyError(`${e}`, e); } handleClose(); }, color: "primary", variant: "contained", children: "Go" }) })] }, result.getId()))) })] }) })); }