diff --git a/plugins/config/src/ConfigurationEditorWidget/components/ConfigurationEditor.test.tsx b/plugins/config/src/ConfigurationEditorWidget/components/ConfigurationEditor.test.tsx index 7aa3b6d876..d6a2b4dac5 100644 --- a/plugins/config/src/ConfigurationEditorWidget/components/ConfigurationEditor.test.tsx +++ b/plugins/config/src/ConfigurationEditorWidget/components/ConfigurationEditor.test.tsx @@ -8,88 +8,86 @@ import SVG from '@jbrowse/plugin-svg' import { linearBasicDisplayConfigSchemaFactory } from '@jbrowse/plugin-linear-genome-view' import ConfigurationEditor from './ConfigurationEditor' -describe('ConfigurationEditor widget', () => { - it('renders with just the required model elements', () => { - const TestSchema = ConfigurationSchema('TestThing', { - foo: { - type: 'string', - defaultValue: 'bar', - }, - }) - - const { container } = render( - , - ) - expect(container).toMatchSnapshot() +test('renders with just the required model elements', () => { + const TestSchema = ConfigurationSchema('TestThing', { + foo: { + type: 'string', + defaultValue: 'bar', + }, }) - it('renders all the different types of built-in slots', () => { - const TestSchema = ConfigurationSchema('TestThing', { - stringTest: { - name: 'stringTest', - description: 'stringTest', - type: 'string', - defaultValue: 'string1', - }, - fileLocationTest: { - name: 'fileLocationTest', - description: 'fileLocationTest', - type: 'fileLocation', - defaultValue: { uri: '/path/to/my.file', locationType: 'UriLocation' }, - }, - stringArrayTest: { - name: 'stringArrayTest', - description: 'stringArrayTest', - type: 'stringArray', - defaultValue: ['string1', 'string2'], - }, - stringArrayMapTest: { - name: 'stringArrayMapTest', - description: 'stringArrayMapTest', - type: 'stringArrayMap', - defaultValue: { key1: ['string1', 'string2'] }, - }, - numberTest: { - name: 'numberTest', - description: 'numberTest', - type: 'number', - defaultValue: 88.5, - }, - integerTest: { - name: 'integerTest', - description: 'integerTest', - type: 'integer', - defaultValue: 42, - }, - colorTest: { - name: 'colorTest', - description: 'colorTest', - type: 'color', - defaultValue: '#396494', - }, - booleanTest: { - name: 'booleanTest', - description: 'booleanTest', - type: 'boolean', - defaultValue: true, - }, - }) + const { container } = render( + , + ) + expect(container).toMatchSnapshot() +}) - const { container } = render( - , - ) - expect(container).toMatchSnapshot() +test('renders all the different types of built-in slots', () => { + const TestSchema = ConfigurationSchema('TestThing', { + stringTest: { + name: 'stringTest', + description: 'stringTest', + type: 'string', + defaultValue: 'string1', + }, + fileLocationTest: { + name: 'fileLocationTest', + description: 'fileLocationTest', + type: 'fileLocation', + defaultValue: { uri: '/path/to/my.file', locationType: 'UriLocation' }, + }, + stringArrayTest: { + name: 'stringArrayTest', + description: 'stringArrayTest', + type: 'stringArray', + defaultValue: ['string1', 'string2'], + }, + stringArrayMapTest: { + name: 'stringArrayMapTest', + description: 'stringArrayMapTest', + type: 'stringArrayMap', + defaultValue: { key1: ['string1', 'string2'] }, + }, + numberTest: { + name: 'numberTest', + description: 'numberTest', + type: 'number', + defaultValue: 88.5, + }, + integerTest: { + name: 'integerTest', + description: 'integerTest', + type: 'integer', + defaultValue: 42, + }, + colorTest: { + name: 'colorTest', + description: 'colorTest', + type: 'color', + defaultValue: '#396494', + }, + booleanTest: { + name: 'booleanTest', + description: 'booleanTest', + type: 'boolean', + defaultValue: true, + }, }) - it('renders with defaults of the PileupTrack schema', () => { - const pluginManager = new PluginManager([new Alignments(), new SVG()]) - pluginManager.createPluggableElements() - pluginManager.configure() - const PileupDisplaySchema = - linearBasicDisplayConfigSchemaFactory(pluginManager) - const { container } = render( - , - ) - expect(container).toMatchSnapshot() - }) + const { container } = render( + , + ) + expect(container).toMatchSnapshot() +}) + +test('renders with defaults of the PileupTrack schema', () => { + const pluginManager = new PluginManager([new Alignments(), new SVG()]) + pluginManager.createPluggableElements() + pluginManager.configure() + const PileupDisplaySchema = + linearBasicDisplayConfigSchemaFactory(pluginManager) + const { container } = render( + , + ) + expect(container).toMatchSnapshot() }) diff --git a/plugins/config/src/ConfigurationEditorWidget/components/ConfigurationEditor.tsx b/plugins/config/src/ConfigurationEditorWidget/components/ConfigurationEditor.tsx index 4da3758d70..d7233e2868 100644 --- a/plugins/config/src/ConfigurationEditorWidget/components/ConfigurationEditor.tsx +++ b/plugins/config/src/ConfigurationEditorWidget/components/ConfigurationEditor.tsx @@ -1,11 +1,5 @@ import React from 'react' -import { - readConfObject, - getTypeNamesFromExplicitlyTypedUnion, - isConfigurationSchemaType, - isConfigurationSlotType, - AnyConfigurationModel, -} from '@jbrowse/core/configuration' + import { FormGroup, Accordion, @@ -18,21 +12,28 @@ import { observer } from 'mobx-react' import { getMembers, IAnyType } from 'mobx-state-tree' import { singular } from 'pluralize' +// jbrowse +import { AbstractSessionModel } from '@jbrowse/core/util' +import SanitizedHTML from '@jbrowse/core/ui/SanitizedHTML' +import { + readConfObject, + getTypeNamesFromExplicitlyTypedUnion, + isConfigurationSchemaType, + isConfigurationSlotType, + AnyConfigurationModel, +} from '@jbrowse/core/configuration' + // icons import ExpandMoreIcon from '@mui/icons-material/ExpandMore' // locals import SlotEditor from './SlotEditor' import TypeSelector from './TypeSelector' -import { AbstractSessionModel } from '@jbrowse/core/util' const useStyles = makeStyles()(theme => ({ - expandIcon: { + icon: { color: theme.palette.tertiary?.contrastText || '#fff', }, - root: { - padding: theme.spacing(1, 3, 1, 1), - }, expansionPanelDetails: { display: 'block', padding: theme.spacing(1), @@ -61,54 +62,49 @@ const Member = observer(function (props: { slot = schema[slotName], path = [], } = props - let typeSelector if (isConfigurationSchemaType(slotSchema)) { if (slot.length) { return slot.map((subslot: AnyConfigurationModel, slotIndex: number) => { - const key = `${singular(slotName)} ${slotIndex + 1}` + const key = subslot.type + ? `${singular(slotName)} ${subslot.type}` + : `${singular(slotName)} ${slotIndex + 1}` return }) } // if this is an explicitly typed schema, make a type-selecting dropdown // that can be used to change its type const typeNameChoices = getTypeNamesFromExplicitlyTypedUnion(slotSchema) - if (typeNameChoices.length) { - typeSelector = ( - { - if (evt.target.value !== slot.type) { - schema.setSubschema(slotName, { type: evt.target.value }) - } - }} - /> - ) - } return ( } + expandIcon={} > {[...path, slotName].join('➔')} - {typeSelector} + {typeNameChoices.length ? ( + { + if (evt.target.value !== slot.type) { + schema.setSubschema(slotName, { type: evt.target.value }) + } + }} + /> + ) : null} ) - } - - if (isConfigurationSlotType(slotSchema)) { - // this is a regular config slot + } else if (isConfigurationSlotType(slotSchema)) { return + } else { + return null } - - return null }) const Schema = observer(function ({ @@ -150,9 +146,11 @@ const ConfigurationEditor = observer(function ({ return ( } + expandIcon={} > - {name ?? 'Configuration'} + + +