MCPcopy Create free account
hub / github.com/Botloader/botloader / EditSettingsOptionList

Function EditSettingsOptionList

frontend/src/components/GuildScriptPage.tsx:325–453  ·  view source on GitHub ↗
({ list }: {
    list: SettingsOptionList,
})

Source from the content-addressed store, hash-verified

323}
324
325function EditSettingsOptionList({ list }: {
326 list: SettingsOptionList,
327}) {
328 const { value: rawValue, setValue } = useSettingsField(list.name)
329 const settingsValuesContext = useContext(SettingsValuesContext)
330 if (!settingsValuesContext) {
331 throw new Error("no settings context")
332 }
333
334
335 const value: SettingsOptionValue[][] = rawValue === undefined
336 ? Array.isArray(list.defaultValue)
337 ? (list.defaultValue as any[])
338 .filter(row => Array.isArray(row))
339 .map(row => (row as any[])
340 .filter(field => field
341 && typeof field === "object"
342 && typeof field.name === "string"
343 && "value" in field)
344 .map(field => ({
345 name: field.name,
346 value: Array.isArray(field.value) ? [...field.value] : field.value,
347 })))
348 : []
349 : Array.isArray(rawValue.value)
350 ? (rawValue.value as SettingsOptionValue[][]).map(row => [...row])
351 : []
352
353
354 function newItem() {
355
356 setValue([
357 ...value.map(row => [...row]),
358 [],
359 ])
360 }
361
362 function deleteItem(index: number) {
363 const copy = value.map(row => [...row])
364 copy.splice(index, 1)
365 setValue(copy)
366 }
367
368 return <Paper sx={{ marginTop: 3, padding: 1 }} elevation={2}>
369 <Box display={"flex"} justifyContent={"space-between"} alignItems={"start"} gap={1}>
370 <Box>
371 <Typography>{list.label}</Typography>
372 <Typography variant='body2'>{list.description}</Typography>
373 </Box>
374 <Box display={"flex"} gap={1}>
375 {(Boolean(rawValue) && (list.defaultValue || !list.required)) &&
376 <IconButton
377 type="button"
378 color='warning'
379 onClick={() => setValue(null)}
380 >
381 <ReplayIcon />
382 </IconButton>}

Callers

nothing calls this directly

Calls 4

useSettingsFieldFunction · 0.85
setValueFunction · 0.85
deleteItemFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected