@jbrowse/plugin-config 2.3.3 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ConfigurationEditorWidget/components/BooleanEditor.d.ts +10 -0
- package/dist/ConfigurationEditorWidget/components/BooleanEditor.js +14 -0
- package/dist/ConfigurationEditorWidget/components/BooleanEditor.js.map +1 -0
- package/dist/ConfigurationEditorWidget/components/ConfigurationEditor.js +25 -22
- package/dist/ConfigurationEditorWidget/components/ConfigurationEditor.js.map +1 -1
- package/dist/ConfigurationEditorWidget/components/ConfigurationTextField.d.ts +5 -0
- package/dist/ConfigurationEditorWidget/components/ConfigurationTextField.js +19 -0
- package/dist/ConfigurationEditorWidget/components/ConfigurationTextField.js.map +1 -0
- package/dist/ConfigurationEditorWidget/components/NumberEditor.d.ts +11 -0
- package/dist/ConfigurationEditorWidget/components/NumberEditor.js +46 -0
- package/dist/ConfigurationEditorWidget/components/NumberEditor.js.map +1 -0
- package/dist/ConfigurationEditorWidget/components/NumberMapEditor.d.ts +11 -0
- package/dist/ConfigurationEditorWidget/components/NumberMapEditor.js +66 -0
- package/dist/ConfigurationEditorWidget/components/NumberMapEditor.js.map +1 -0
- package/dist/ConfigurationEditorWidget/components/SlotEditor.js +15 -97
- package/dist/ConfigurationEditorWidget/components/SlotEditor.js.map +1 -1
- package/dist/ConfigurationEditorWidget/components/StringArrayEditor.js +1 -1
- package/dist/ConfigurationEditorWidget/components/StringArrayEditor.js.map +1 -1
- package/dist/ConfigurationEditorWidget/components/StringArrayMapEditor.d.ts +14 -0
- package/dist/ConfigurationEditorWidget/components/StringArrayMapEditor.js +71 -0
- package/dist/ConfigurationEditorWidget/components/StringArrayMapEditor.js.map +1 -0
- package/dist/RefNameAliasAdapter/RefNameAliasAdapter.js +3 -4
- package/dist/RefNameAliasAdapter/RefNameAliasAdapter.js.map +1 -1
- package/esm/ConfigurationEditorWidget/components/BooleanEditor.d.ts +10 -0
- package/esm/ConfigurationEditorWidget/components/BooleanEditor.js +9 -0
- package/esm/ConfigurationEditorWidget/components/BooleanEditor.js.map +1 -0
- package/esm/ConfigurationEditorWidget/components/ConfigurationEditor.js +25 -22
- package/esm/ConfigurationEditorWidget/components/ConfigurationEditor.js.map +1 -1
- package/esm/ConfigurationEditorWidget/components/ConfigurationTextField.d.ts +5 -0
- package/esm/ConfigurationEditorWidget/components/ConfigurationTextField.js +13 -0
- package/esm/ConfigurationEditorWidget/components/ConfigurationTextField.js.map +1 -0
- package/esm/ConfigurationEditorWidget/components/NumberEditor.d.ts +11 -0
- package/esm/ConfigurationEditorWidget/components/NumberEditor.js +18 -0
- package/esm/ConfigurationEditorWidget/components/NumberEditor.js.map +1 -0
- package/esm/ConfigurationEditorWidget/components/NumberMapEditor.d.ts +11 -0
- package/esm/ConfigurationEditorWidget/components/NumberMapEditor.js +38 -0
- package/esm/ConfigurationEditorWidget/components/NumberMapEditor.js.map +1 -0
- package/esm/ConfigurationEditorWidget/components/SlotEditor.js +13 -95
- package/esm/ConfigurationEditorWidget/components/SlotEditor.js.map +1 -1
- package/esm/ConfigurationEditorWidget/components/StringArrayEditor.js +1 -1
- package/esm/ConfigurationEditorWidget/components/StringArrayEditor.js.map +1 -1
- package/esm/ConfigurationEditorWidget/components/StringArrayMapEditor.d.ts +14 -0
- package/esm/ConfigurationEditorWidget/components/StringArrayMapEditor.js +43 -0
- package/esm/ConfigurationEditorWidget/components/StringArrayMapEditor.js.map +1 -0
- package/esm/RefNameAliasAdapter/RefNameAliasAdapter.js +3 -4
- package/esm/RefNameAliasAdapter/RefNameAliasAdapter.js.map +1 -1
- package/package.json +2 -2
- package/src/ConfigurationEditorWidget/components/BooleanEditor.tsx +35 -0
- package/src/ConfigurationEditorWidget/components/ConfigurationEditor.tsx +116 -123
- package/src/ConfigurationEditorWidget/components/ConfigurationTextField.tsx +22 -0
- package/src/ConfigurationEditorWidget/components/NumberEditor.tsx +34 -0
- package/src/ConfigurationEditorWidget/components/NumberMapEditor.tsx +94 -0
- package/src/ConfigurationEditorWidget/components/SlotEditor.tsx +57 -304
- package/src/ConfigurationEditorWidget/components/StringArrayEditor.tsx +1 -4
- package/src/ConfigurationEditorWidget/components/StringArrayMapEditor.tsx +104 -0
- package/src/ConfigurationEditorWidget/components/__snapshots__/ConfigurationEditor.test.tsx.snap +138 -83
- package/src/RefNameAliasAdapter/RefNameAliasAdapter.ts +3 -4
|
@@ -2,34 +2,16 @@ import React, { useEffect, useState } from 'react'
|
|
|
2
2
|
import { observer } from 'mobx-react'
|
|
3
3
|
import { getPropertyMembers, IAnyType } from 'mobx-state-tree'
|
|
4
4
|
import { getEnv, FileLocation } from '@jbrowse/core/util'
|
|
5
|
-
import { FileSelector
|
|
5
|
+
import { FileSelector } from '@jbrowse/core/ui'
|
|
6
6
|
import {
|
|
7
7
|
getPropertyType,
|
|
8
8
|
getSubType,
|
|
9
9
|
getUnionSubTypes,
|
|
10
10
|
} from '@jbrowse/core/util/mst-reflection'
|
|
11
|
-
import {
|
|
12
|
-
Card,
|
|
13
|
-
CardContent,
|
|
14
|
-
CardHeader,
|
|
15
|
-
Checkbox,
|
|
16
|
-
FormControl,
|
|
17
|
-
FormControlLabel,
|
|
18
|
-
FormHelperText,
|
|
19
|
-
IconButton,
|
|
20
|
-
InputAdornment,
|
|
21
|
-
InputLabel,
|
|
22
|
-
MenuItem,
|
|
23
|
-
Paper,
|
|
24
|
-
SvgIcon,
|
|
25
|
-
TextField,
|
|
26
|
-
TextFieldProps,
|
|
27
|
-
} from '@mui/material'
|
|
11
|
+
import { IconButton, MenuItem, Paper, SvgIcon, TextField } from '@mui/material'
|
|
28
12
|
import { makeStyles } from 'tss-react/mui'
|
|
29
13
|
|
|
30
14
|
// icons
|
|
31
|
-
import DeleteIcon from '@mui/icons-material/Delete'
|
|
32
|
-
import AddIcon from '@mui/icons-material/Add'
|
|
33
15
|
import RadioButtonUncheckedIcon from '@mui/icons-material/RadioButtonUnchecked'
|
|
34
16
|
|
|
35
17
|
// locals
|
|
@@ -37,23 +19,11 @@ import StringArrayEditor from './StringArrayEditor'
|
|
|
37
19
|
import CallbackEditor from './CallbackEditor'
|
|
38
20
|
import ColorEditor from './ColorEditor'
|
|
39
21
|
import JsonEditor from './JsonEditor'
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<TextField
|
|
47
|
-
{...props}
|
|
48
|
-
helperText={<SanitizedHTML html={helperText || ''} />}
|
|
49
|
-
FormHelperTextProps={{
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
component: 'div',
|
|
52
|
-
}}
|
|
53
|
-
fullWidth
|
|
54
|
-
/>
|
|
55
|
-
)
|
|
56
|
-
}
|
|
22
|
+
import StringArrayMapEditor from './StringArrayMapEditor'
|
|
23
|
+
import ConfigurationTextField from './ConfigurationTextField'
|
|
24
|
+
import NumberMapEditor from './NumberMapEditor'
|
|
25
|
+
import NumberEditor from './NumberEditor'
|
|
26
|
+
import BooleanEditor from './BooleanEditor'
|
|
57
27
|
|
|
58
28
|
const StringEditor = observer(
|
|
59
29
|
({
|
|
@@ -66,7 +36,7 @@ const StringEditor = observer(
|
|
|
66
36
|
set: (arg: string) => void
|
|
67
37
|
}
|
|
68
38
|
}) => (
|
|
69
|
-
<
|
|
39
|
+
<ConfigurationTextField
|
|
70
40
|
label={slot.name}
|
|
71
41
|
helperText={slot.description}
|
|
72
42
|
value={slot.value}
|
|
@@ -103,198 +73,6 @@ const SvgCheckbox = () => (
|
|
|
103
73
|
</SvgIcon>
|
|
104
74
|
)
|
|
105
75
|
|
|
106
|
-
const useMapEditorStyles = makeStyles()(theme => ({
|
|
107
|
-
card: {
|
|
108
|
-
marginTop: theme.spacing(1),
|
|
109
|
-
},
|
|
110
|
-
}))
|
|
111
|
-
|
|
112
|
-
const StringArrayMapEditor = observer(
|
|
113
|
-
({
|
|
114
|
-
slot,
|
|
115
|
-
}: {
|
|
116
|
-
slot: {
|
|
117
|
-
name: string
|
|
118
|
-
value: Map<string, string[]>
|
|
119
|
-
remove: (key: string) => void
|
|
120
|
-
add: (key: string, val: string[]) => void
|
|
121
|
-
description: string
|
|
122
|
-
setAtKeyIndex: (key: string, idx: number, val: string) => void
|
|
123
|
-
removeAtKeyIndex: (key: string, idx: number) => void
|
|
124
|
-
addToKey: (key: string, val: string) => void
|
|
125
|
-
}
|
|
126
|
-
}) => {
|
|
127
|
-
const { classes } = useMapEditorStyles()
|
|
128
|
-
const [value, setValue] = useState('')
|
|
129
|
-
return (
|
|
130
|
-
<>
|
|
131
|
-
<InputLabel>{slot.name}</InputLabel>
|
|
132
|
-
{Array.from(slot.value, ([key, val]) => (
|
|
133
|
-
<Card raised key={key} className={classes.card}>
|
|
134
|
-
<CardHeader
|
|
135
|
-
title={key}
|
|
136
|
-
action={
|
|
137
|
-
<IconButton color="secondary" onClick={() => slot.remove(key)}>
|
|
138
|
-
<DeleteIcon />
|
|
139
|
-
</IconButton>
|
|
140
|
-
}
|
|
141
|
-
/>
|
|
142
|
-
<CardContent>
|
|
143
|
-
<StringArrayEditor
|
|
144
|
-
slot={{
|
|
145
|
-
name: slot.name,
|
|
146
|
-
value: val,
|
|
147
|
-
description: `Values associated with entry ${key}`,
|
|
148
|
-
setAtIndex: (idx: number, val: string) =>
|
|
149
|
-
slot.setAtKeyIndex(key, idx, val),
|
|
150
|
-
removeAtIndex: (idx: number) =>
|
|
151
|
-
slot.removeAtKeyIndex(key, idx),
|
|
152
|
-
add: (val: string) => slot.addToKey(key, val),
|
|
153
|
-
}}
|
|
154
|
-
/>
|
|
155
|
-
</CardContent>
|
|
156
|
-
</Card>
|
|
157
|
-
))}
|
|
158
|
-
<Card raised className={classes.card}>
|
|
159
|
-
<CardHeader
|
|
160
|
-
disableTypography
|
|
161
|
-
title={
|
|
162
|
-
<TextField
|
|
163
|
-
fullWidth
|
|
164
|
-
value={value}
|
|
165
|
-
placeholder="add new"
|
|
166
|
-
onChange={event => setValue(event.target.value)}
|
|
167
|
-
InputProps={{
|
|
168
|
-
endAdornment: (
|
|
169
|
-
<InputAdornment position="end">
|
|
170
|
-
<IconButton
|
|
171
|
-
disabled={value === ''}
|
|
172
|
-
onClick={() => {
|
|
173
|
-
slot.add(value, [])
|
|
174
|
-
setValue('')
|
|
175
|
-
}}
|
|
176
|
-
color="secondary"
|
|
177
|
-
>
|
|
178
|
-
<AddIcon />
|
|
179
|
-
</IconButton>
|
|
180
|
-
</InputAdornment>
|
|
181
|
-
),
|
|
182
|
-
}}
|
|
183
|
-
/>
|
|
184
|
-
}
|
|
185
|
-
/>
|
|
186
|
-
</Card>
|
|
187
|
-
<FormHelperText>{slot.description}</FormHelperText>
|
|
188
|
-
</>
|
|
189
|
-
)
|
|
190
|
-
},
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
const NumberMapEditor = observer(
|
|
194
|
-
({
|
|
195
|
-
slot,
|
|
196
|
-
}: {
|
|
197
|
-
slot: {
|
|
198
|
-
name: string
|
|
199
|
-
value: Map<string, string>
|
|
200
|
-
remove: (key: string) => void
|
|
201
|
-
add: (key: string, val: number) => void
|
|
202
|
-
description: string
|
|
203
|
-
}
|
|
204
|
-
}) => {
|
|
205
|
-
const { classes } = useMapEditorStyles()
|
|
206
|
-
const [value, setValue] = useState('')
|
|
207
|
-
return (
|
|
208
|
-
<>
|
|
209
|
-
<InputLabel>{slot.name}</InputLabel>
|
|
210
|
-
{Array.from(slot.value, ([key, val]) => (
|
|
211
|
-
<Card raised key={key} className={classes.card}>
|
|
212
|
-
<CardHeader
|
|
213
|
-
title={key}
|
|
214
|
-
action={
|
|
215
|
-
<IconButton color="secondary" onClick={() => slot.remove(key)}>
|
|
216
|
-
<DeleteIcon />
|
|
217
|
-
</IconButton>
|
|
218
|
-
}
|
|
219
|
-
/>
|
|
220
|
-
<CardContent>
|
|
221
|
-
<NumberEditor
|
|
222
|
-
slot={{
|
|
223
|
-
value: val,
|
|
224
|
-
set: (val: number) => slot.add(key, val),
|
|
225
|
-
}}
|
|
226
|
-
/>
|
|
227
|
-
</CardContent>
|
|
228
|
-
</Card>
|
|
229
|
-
))}
|
|
230
|
-
<Card raised className={classes.card}>
|
|
231
|
-
<CardHeader
|
|
232
|
-
disableTypography
|
|
233
|
-
title={
|
|
234
|
-
<TextField
|
|
235
|
-
fullWidth
|
|
236
|
-
value={value}
|
|
237
|
-
placeholder="add new"
|
|
238
|
-
onChange={event => setValue(event.target.value)}
|
|
239
|
-
InputProps={{
|
|
240
|
-
endAdornment: (
|
|
241
|
-
<InputAdornment position="end">
|
|
242
|
-
<IconButton
|
|
243
|
-
disabled={value === ''}
|
|
244
|
-
onClick={() => {
|
|
245
|
-
slot.add(value, 0)
|
|
246
|
-
setValue('')
|
|
247
|
-
}}
|
|
248
|
-
color="secondary"
|
|
249
|
-
>
|
|
250
|
-
<AddIcon />
|
|
251
|
-
</IconButton>
|
|
252
|
-
</InputAdornment>
|
|
253
|
-
),
|
|
254
|
-
}}
|
|
255
|
-
/>
|
|
256
|
-
}
|
|
257
|
-
/>
|
|
258
|
-
</Card>
|
|
259
|
-
<FormHelperText>{slot.description}</FormHelperText>
|
|
260
|
-
</>
|
|
261
|
-
)
|
|
262
|
-
},
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
const NumberEditor = observer(
|
|
266
|
-
({
|
|
267
|
-
slot,
|
|
268
|
-
}: {
|
|
269
|
-
slot: {
|
|
270
|
-
name?: string
|
|
271
|
-
value: string
|
|
272
|
-
description?: string
|
|
273
|
-
set: (val: number) => void
|
|
274
|
-
reset?: () => void
|
|
275
|
-
}
|
|
276
|
-
}) => {
|
|
277
|
-
const [val, setVal] = useState(slot.value)
|
|
278
|
-
useEffect(() => {
|
|
279
|
-
const num = parseFloat(val)
|
|
280
|
-
if (!Number.isNaN(num)) {
|
|
281
|
-
slot.set(num)
|
|
282
|
-
} else {
|
|
283
|
-
slot.reset?.()
|
|
284
|
-
}
|
|
285
|
-
}, [slot, val])
|
|
286
|
-
return (
|
|
287
|
-
<MyTextField
|
|
288
|
-
label={slot.name}
|
|
289
|
-
helperText={slot.description}
|
|
290
|
-
value={val}
|
|
291
|
-
type="number"
|
|
292
|
-
onChange={evt => setVal(evt.target.value)}
|
|
293
|
-
/>
|
|
294
|
-
)
|
|
295
|
-
},
|
|
296
|
-
)
|
|
297
|
-
|
|
298
76
|
const IntegerEditor = observer(
|
|
299
77
|
({
|
|
300
78
|
slot,
|
|
@@ -314,7 +92,7 @@ const IntegerEditor = observer(
|
|
|
314
92
|
}
|
|
315
93
|
}, [slot, val])
|
|
316
94
|
return (
|
|
317
|
-
<
|
|
95
|
+
<ConfigurationTextField
|
|
318
96
|
label={slot.name}
|
|
319
97
|
helperText={slot.description}
|
|
320
98
|
value={val}
|
|
@@ -325,80 +103,56 @@ const IntegerEditor = observer(
|
|
|
325
103
|
},
|
|
326
104
|
)
|
|
327
105
|
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
slot: {
|
|
333
|
-
name: string
|
|
334
|
-
value: boolean
|
|
335
|
-
set: (arg: boolean) => void
|
|
336
|
-
description: string
|
|
337
|
-
}
|
|
338
|
-
}) => (
|
|
339
|
-
<FormControl>
|
|
340
|
-
<FormControlLabel
|
|
341
|
-
label={slot.name}
|
|
342
|
-
control={
|
|
343
|
-
<Checkbox
|
|
344
|
-
checked={slot.value}
|
|
345
|
-
onChange={evt => slot.set(evt.target.checked)}
|
|
346
|
-
/>
|
|
347
|
-
}
|
|
348
|
-
/>
|
|
349
|
-
<FormHelperText>{slot.description}</FormHelperText>
|
|
350
|
-
</FormControl>
|
|
351
|
-
),
|
|
352
|
-
)
|
|
353
|
-
|
|
354
|
-
const StringEnumEditor = observer(
|
|
106
|
+
const StringEnumEditor = observer(function ({
|
|
107
|
+
slot,
|
|
108
|
+
slotSchema,
|
|
109
|
+
}: {
|
|
355
110
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
<MyTextField
|
|
364
|
-
value={slot.value}
|
|
365
|
-
label={slot.name}
|
|
366
|
-
select
|
|
367
|
-
helperText={slot.description}
|
|
368
|
-
onChange={evt => slot.set(evt.target.value)}
|
|
369
|
-
>
|
|
370
|
-
{choices.map(str => (
|
|
371
|
-
<MenuItem key={str} value={str}>
|
|
372
|
-
{str}
|
|
373
|
-
</MenuItem>
|
|
374
|
-
))}
|
|
375
|
-
</MyTextField>
|
|
376
|
-
)
|
|
377
|
-
},
|
|
378
|
-
)
|
|
111
|
+
slot: any
|
|
112
|
+
slotSchema: IAnyType
|
|
113
|
+
}) {
|
|
114
|
+
const p = getPropertyMembers(getSubType(slotSchema))
|
|
115
|
+
const choices = getUnionSubTypes(
|
|
116
|
+
getUnionSubTypes(getSubType(getPropertyType(p, 'value')))[1],
|
|
117
|
+
).map(t => t.value)
|
|
379
118
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
value
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
119
|
+
return (
|
|
120
|
+
<ConfigurationTextField
|
|
121
|
+
value={slot.value}
|
|
122
|
+
label={slot.name}
|
|
123
|
+
select
|
|
124
|
+
helperText={slot.description}
|
|
125
|
+
onChange={evt => slot.set(evt.target.value)}
|
|
126
|
+
>
|
|
127
|
+
{choices.map(str => (
|
|
128
|
+
<MenuItem key={str} value={str}>
|
|
129
|
+
{str}
|
|
130
|
+
</MenuItem>
|
|
131
|
+
))}
|
|
132
|
+
</ConfigurationTextField>
|
|
133
|
+
)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const FileSelectorWrapper = observer(function ({
|
|
137
|
+
slot,
|
|
138
|
+
}: {
|
|
139
|
+
slot: {
|
|
140
|
+
name: string
|
|
141
|
+
value: FileLocation
|
|
142
|
+
set: (arg: FileLocation) => void
|
|
143
|
+
description: string
|
|
144
|
+
}
|
|
145
|
+
}) {
|
|
146
|
+
return (
|
|
147
|
+
<FileSelector
|
|
148
|
+
location={slot.value}
|
|
149
|
+
setLocation={location => slot.set(location)}
|
|
150
|
+
name={slot.name}
|
|
151
|
+
description={slot.description}
|
|
152
|
+
rootModel={getEnv(slot).pluginManager?.rootModel}
|
|
153
|
+
/>
|
|
154
|
+
)
|
|
155
|
+
})
|
|
402
156
|
|
|
403
157
|
const valueComponents = {
|
|
404
158
|
string: StringEditor,
|
|
@@ -466,7 +220,6 @@ const SlotEditor = observer(
|
|
|
466
220
|
title={`convert to ${
|
|
467
221
|
slot.isCallback ? 'regular value' : 'callback'
|
|
468
222
|
}`}
|
|
469
|
-
color="secondary"
|
|
470
223
|
>
|
|
471
224
|
{!slot.isCallback ? (
|
|
472
225
|
<RadioButtonUncheckedIcon />
|
|
@@ -42,10 +42,7 @@ const StringArrayEditor = observer(
|
|
|
42
42
|
InputProps={{
|
|
43
43
|
endAdornment: (
|
|
44
44
|
<InputAdornment position="end">
|
|
45
|
-
<IconButton
|
|
46
|
-
color="secondary"
|
|
47
|
-
onClick={() => slot.removeAtIndex(idx)}
|
|
48
|
-
>
|
|
45
|
+
<IconButton onClick={() => slot.removeAtIndex(idx)}>
|
|
49
46
|
<DeleteIcon />
|
|
50
47
|
</IconButton>
|
|
51
48
|
</InputAdornment>
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { observer } from 'mobx-react'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Card,
|
|
6
|
+
CardContent,
|
|
7
|
+
CardHeader,
|
|
8
|
+
FormHelperText,
|
|
9
|
+
IconButton,
|
|
10
|
+
InputAdornment,
|
|
11
|
+
InputLabel,
|
|
12
|
+
TextField,
|
|
13
|
+
} from '@mui/material'
|
|
14
|
+
import { makeStyles } from 'tss-react/mui'
|
|
15
|
+
|
|
16
|
+
// icons
|
|
17
|
+
import DeleteIcon from '@mui/icons-material/Delete'
|
|
18
|
+
import AddIcon from '@mui/icons-material/Add'
|
|
19
|
+
|
|
20
|
+
// locals
|
|
21
|
+
import StringArrayEditor from './StringArrayEditor'
|
|
22
|
+
|
|
23
|
+
const useStyles = makeStyles()(theme => ({
|
|
24
|
+
card: {
|
|
25
|
+
marginTop: theme.spacing(1),
|
|
26
|
+
},
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
export default observer(function ({
|
|
30
|
+
slot,
|
|
31
|
+
}: {
|
|
32
|
+
slot: {
|
|
33
|
+
name: string
|
|
34
|
+
value: Map<string, string[]>
|
|
35
|
+
remove: (key: string) => void
|
|
36
|
+
add: (key: string, val: string[]) => void
|
|
37
|
+
description: string
|
|
38
|
+
setAtKeyIndex: (key: string, idx: number, val: string) => void
|
|
39
|
+
removeAtKeyIndex: (key: string, idx: number) => void
|
|
40
|
+
addToKey: (key: string, val: string) => void
|
|
41
|
+
}
|
|
42
|
+
}) {
|
|
43
|
+
const { classes } = useStyles()
|
|
44
|
+
const [value, setValue] = useState('')
|
|
45
|
+
return (
|
|
46
|
+
<>
|
|
47
|
+
<InputLabel>{slot.name}</InputLabel>
|
|
48
|
+
{Array.from(slot.value, ([key, val]) => (
|
|
49
|
+
<Card raised key={key} className={classes.card}>
|
|
50
|
+
<CardHeader
|
|
51
|
+
title={key}
|
|
52
|
+
action={
|
|
53
|
+
<IconButton onClick={() => slot.remove(key)}>
|
|
54
|
+
<DeleteIcon />
|
|
55
|
+
</IconButton>
|
|
56
|
+
}
|
|
57
|
+
/>
|
|
58
|
+
<CardContent>
|
|
59
|
+
<StringArrayEditor
|
|
60
|
+
slot={{
|
|
61
|
+
name: slot.name,
|
|
62
|
+
value: val,
|
|
63
|
+
description: `Values associated with entry ${key}`,
|
|
64
|
+
setAtIndex: (idx: number, val: string) =>
|
|
65
|
+
slot.setAtKeyIndex(key, idx, val),
|
|
66
|
+
removeAtIndex: (idx: number) => slot.removeAtKeyIndex(key, idx),
|
|
67
|
+
add: (val: string) => slot.addToKey(key, val),
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
</CardContent>
|
|
71
|
+
</Card>
|
|
72
|
+
))}
|
|
73
|
+
<Card raised className={classes.card}>
|
|
74
|
+
<CardHeader
|
|
75
|
+
disableTypography
|
|
76
|
+
title={
|
|
77
|
+
<TextField
|
|
78
|
+
fullWidth
|
|
79
|
+
value={value}
|
|
80
|
+
placeholder="add new"
|
|
81
|
+
onChange={event => setValue(event.target.value)}
|
|
82
|
+
InputProps={{
|
|
83
|
+
endAdornment: (
|
|
84
|
+
<InputAdornment position="end">
|
|
85
|
+
<IconButton
|
|
86
|
+
disabled={value === ''}
|
|
87
|
+
onClick={() => {
|
|
88
|
+
slot.add(value, [])
|
|
89
|
+
setValue('')
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
<AddIcon />
|
|
93
|
+
</IconButton>
|
|
94
|
+
</InputAdornment>
|
|
95
|
+
),
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
}
|
|
99
|
+
/>
|
|
100
|
+
</Card>
|
|
101
|
+
<FormHelperText>{slot.description}</FormHelperText>
|
|
102
|
+
</>
|
|
103
|
+
)
|
|
104
|
+
})
|