UNPKG

@jbrowse/core

Version:

JBrowse 2 core libraries used by plugins

40 lines (39 loc) 2.03 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useEffect } from 'react'; import { MenuItem, TextField } from '@mui/material'; import { observer } from 'mobx-react'; import { useLocalStorage } from "../util/index.js"; import { makeStyles } from "../util/tss-react/index.js"; const useStyles = makeStyles()({ importFormEntry: { minWidth: 180, }, }); const AssemblySelector = observer(function AssemblySelector({ session, onChange, label = 'Assembly', selected, InputProps, TextFieldProps, localStorageKey, helperText = 'Select assembly to view', }) { const { classes } = useStyles(); const { assemblyNames, assemblyManager } = session; const config = new URLSearchParams(window.location.search).get('config'); const [lastSelected, setLastSelected] = useLocalStorage(`lastAssembly-${[ window.location.host + window.location.pathname, config, localStorageKey, ].join('-')}`, selected, typeof jest === 'undefined' && Boolean(localStorageKey)); const selection = assemblyNames.includes(lastSelected || '') ? lastSelected : selected; useEffect(() => { if (selection && selection !== selected) { onChange(selection); } }, [selection, onChange, selected]); const error = assemblyNames.length ? '' : 'No configured assemblies'; return (_jsx(TextField, { select: true, "data-testid": "assembly-selector-textfield", label: label, variant: "outlined", helperText: error || helperText, value: selection || '', onChange: event => { setLastSelected(event.target.value); }, error: !!error, disabled: !!error, className: classes.importFormEntry, ...TextFieldProps, slotProps: { input: InputProps, htmlInput: { 'data-testid': 'assembly-selector', }, }, children: assemblyNames.map(name => (_jsx(MenuItem, { value: name, children: assemblyManager.get(name)?.displayName || name }, name))) })); }); export default AssemblySelector;