// TODO: verify each rule // oxlint-disable max-lines // oxlint-disable react/hooks -- RJSF renders the nested templates/widgets as components with per-instance hooks; retain this structure pending extraction to module scope to stabilize component identities. // oxlint-disable unicorn/no-negated-condition // oxlint-disable react/no-unstable-nested-components // oxlint-disable typescript/no-unsafe-type-assertion // @mui/icons-material import Add from '@mui/icons-material/Add'; // For AddButton import BluetoothIcon from '@mui/icons-material/Bluetooth'; // For selectDevice icon=ble import DeleteForever from '@mui/icons-material/DeleteForever'; // For RemoveButton import DeviceHubIcon from '@mui/icons-material/DeviceHub'; // For entities icon=matter import ErrorOutlineIcon from '@mui/icons-material/ErrorOutlineOutlined'; // For ErrorListTemplate import HubIcon from '@mui/icons-material/Hub'; // For selectDevice icon=hub import KeyboardDoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown'; import KeyboardDoubleArrowUpIcon from '@mui/icons-material/KeyboardDoubleArrowUp'; import ListIcon from '@mui/icons-material/List'; import ViewInArIcon from '@mui/icons-material/ViewInAr'; // For entities icon=component import WifiIcon from '@mui/icons-material/Wifi'; // For selectDevice icon=wifi // @mui/material import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Checkbox from '@mui/material/Checkbox'; import Dialog from '@mui/material/Dialog'; import DialogActions from '@mui/material/DialogActions'; import DialogContent from '@mui/material/DialogContent'; import DialogTitle from '@mui/material/DialogTitle'; import IconButton from '@mui/material/IconButton'; import List from '@mui/material/List'; import ListItem from '@mui/material/ListItem'; import ListItemButton from '@mui/material/ListItemButton'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import MenuItem from '@mui/material/MenuItem'; import TextField from '@mui/material/TextField'; import Tooltip from '@mui/material/Tooltip'; import Typography from '@mui/material/Typography'; // @rjsf import Form, { type IChangeEvent } from '@rjsf/core'; import { getSubmitButtonOptions, getUiOptions, getTemplate, enumOptionsValueForIndex, ariaDescribedByIds, enumOptionsIndexForValue, ADDITIONAL_PROPERTY_FLAG, type WidgetProps, type SubmitButtonProps, type IconButtonProps, type FieldTemplateProps, type DescriptionFieldProps, type TitleFieldProps, type FieldHelpProps, type ErrorListProps, type FieldErrorProps, type BaseInputTemplateProps, type ArrayFieldTitleProps, type ArrayFieldDescriptionProps, type ArrayFieldTemplateProps, type ArrayFieldItemTemplateProps, type ObjectFieldTemplateProps, type WrapIfAdditionalTemplateProps, type UiSchema, type RJSFSchema, } from '@rjsf/utils'; import validator from '@rjsf/validator-ajv8'; // React import { useContext, useEffect, useState, useRef } from 'react'; import { debug } from '../appState'; import { type ApiPlugin, type ApiSelectDevice, type ApiSelectDeviceEntity, type ApiSelectEntity, isApiResponse, type WsMessage } from '../utils/backendShared'; import { WebSocketContext } from './WebSocketProvider'; const rjsfDebug = false; const titleSx = { fontSize: '16px', fontWeight: 'bold', color: 'var(--div-text-color)', backgroundColor: 'var(--div-bg-color)' }; const descriptionSx = { fontSize: '12px', fontWeight: 'normal', color: 'var(--div-text-color)', backgroundColor: 'var(--div-bg-color)' }; const descriptionButtonSx = { fontSize: '16px', fontWeight: 'bold', color: 'var(--div-text-color)', backgroundColor: 'var(--div-bg-color)' }; const helpSx = { fontSize: '14px', fontWeight: 'normal', color: 'var(--secondary-color)', backgroundColor: 'var(--div-bg-color)' }; const errorTitleSx = { fontSize: '16px', fontWeight: 'bold', backgroundColor: 'var(--div-bg-color)' }; const iconButtonSx = { padding: '0px', margin: '0px' }; const boxPadding = '5px 10px 5px 10px'; const listItemButtonSx = {}; const listItemIconStyle = {}; const listItemTextPrimaryStyle = {}; const listItemTextSecondaryStyle = {}; // Stable empty default for the optional rawErrors prop, so the destructuring default keeps a single reference across renders. const emptyRawErrors: string[] = []; let selectDevices: ApiSelectDevice[] = []; let selectEntities: ApiSelectEntity[] = []; type RjsfPropertyWithStringType = RJSFSchema & { type: string }; function hasSchemaPropertyWithStringType(schema: RJSFSchema, name: string): schema is RJSFSchema & { properties: Record } { const properties: unknown = schema?.properties; if (!properties || typeof properties !== 'object') return false; const property: unknown = (properties as Record)[name]; if (!property || typeof property !== 'object') return false; return typeof (property as { type?: unknown }).type === 'string'; } function hasSchemaItemsWithDefault(schema: RJSFSchema): schema is RJSFSchema & { items: RJSFSchema & { default: unknown } } { const items = schema.items; return items !== undefined && typeof items === 'object' && !Array.isArray(items); } function hasSchemaPropertyArrayMultiSelect( schema: RJSFSchema, name: string, ): schema is RJSFSchema & { properties: Record< string, RJSFSchema & { type: 'array'; uniqueItems: true; items: RJSFSchema & { enum: unknown[] }; } >; } { const properties: unknown = schema?.properties; if (!properties || typeof properties !== 'object') return false; const property: unknown = (properties as Record)[name]; if (!property || typeof property !== 'object') return false; if ((property as { type?: unknown }).type !== 'array' || (property as { uniqueItems?: unknown }).uniqueItems !== true) return false; const items = (property as { items?: unknown }).items; return items !== undefined && typeof items === 'object' && !Array.isArray(items) && Array.isArray((items as { enum?: unknown[] }).enum); } export interface ConfigPluginDialogProps { open: boolean; onClose: () => void; onSave: (configJson: ApiPlugin['configJson']) => void; plugin: ApiPlugin; } // oxlint-disable-next-line max-lines-per-function export const ConfigPluginDialog = ({ open, onClose, onSave, plugin }: ConfigPluginDialogProps) => { // Contexts const { sendMessage, addListener, removeListener, getUniqueId } = useContext(WebSocketContext); // Refs const uniqueId = useRef(getUniqueId()); const schemaRef = useRef({} as RJSFSchema); const uiSchemaRef = useRef({} as UiSchema); const currentFormDataRef = useRef(plugin.configJson); // States const [formData, setFormData] = useState(plugin.configJson); const [schema, setSchema] = useState(plugin.schemaJson); const [uiSchema, setUiSchema] = useState({ 'ui:submitButtonOptions': { submitText: 'Confirm', }, 'ui:globalOptions': { orderable: true }, }); /** For ObjectFieldTemplate select from device list */ const pendingAdditionalPropertyKeyRef = useRef(''); useEffect(() => { currentFormDataRef.current = plugin.configJson; }, [plugin]); // WebSocket message handler effect useEffect(() => { const handleWebSocketMessage = (msg: WsMessage) => { if (msg.src === 'Matterbridge' && msg.dst === 'Frontend') { // Local messages if (isApiResponse(msg) && msg.id === uniqueId.current && msg.method === '/api/select-devices') { if (msg.response) { if (debug) console.log(`ConfigPluginDialog (id: ${msg.id}) received ${msg.response.length} /api/select-devices:`, msg.response); selectDevices = msg.response; } } if (isApiResponse(msg) && msg.id === uniqueId.current && msg.method === '/api/select-entities') { if (msg.response) { if (debug) console.log(`ConfigPluginDialog (id: ${msg.id}) received ${msg.response.length} /api/select-entities:`, msg.response); selectEntities = msg.response; } } } }; addListener(handleWebSocketMessage, uniqueId.current); if (debug) console.log('ConfigPluginDialog added WebSocket listener id:', uniqueId.current); if (debug) console.log('ConfigPluginDialog mounting...'); if (debug) console.log('ConfigPluginDialog mounting with form:', formData); if (debug) console.log('ConfigPluginDialog mounting with schema:', schema); if (debug) console.log('ConfigPluginDialog mounting with uiSchema:', uiSchema); // Move the ui: properties from the schema to the uiSchema if (formData && schema?.properties) { if (rjsfDebug) console.log('ConfigPluginDialog moveToUiSchema:', schema, uiSchema); const moveUiPropertiesToUiSchema = (schemaObj: RJSFSchema, uiSchemaObj: UiSchema, path: string[] = []) => { if (rjsfDebug) console.log('ConfigPluginDialog moveUiPropertiesToUiSchema:', schemaObj, uiSchemaObj, path); if (!schemaObj || typeof schemaObj !== 'object') return; // Handle properties object if (schemaObj.properties) { Object.keys(schemaObj.properties).forEach((key) => { const property = schemaObj.properties?.[key] as RJSFSchema; const currentPath = [...path, key]; // Move ui:* properties from this property Object.keys(property).forEach((subkey) => { if (subkey.startsWith('ui:')) { if (rjsfDebug) console.log('ConfigPluginDialog moveToUiSchema:', currentPath.join('.'), subkey, property[subkey]); // Create nested uiSchema structure let currentUiSchema = uiSchemaObj; currentPath.forEach((p) => { if (!currentUiSchema[p]) currentUiSchema[p] = {}; currentUiSchema = currentUiSchema[p]; }); currentUiSchema[subkey] = property[subkey]; // oxlint-disable-next-line typescript/no-dynamic-delete delete property[subkey]; } }); // Recursively process nested properties moveUiPropertiesToUiSchema(property, uiSchemaObj, currentPath); }); } // Handle oneOf/anyOf/allOf arrays ['oneOf', 'anyOf', 'allOf'].forEach((keyword) => { if (Array.isArray(schemaObj[keyword])) { schemaObj[keyword].forEach((subSchema) => { moveUiPropertiesToUiSchema(subSchema, uiSchemaObj, path); }); } }); // Handle items (for arrays) if (schemaObj.items && typeof schemaObj.items === 'object') { moveUiPropertiesToUiSchema(schemaObj.items, uiSchemaObj, path); } }; moveUiPropertiesToUiSchema(schema, uiSchema); // oxlint-disable-next-line react/set-state-in-effect -- Preserve existing form schema initialization until schema preparation is separated from the subscription effect. setUiSchema(uiSchema); schemaRef.current = schema; // We make sure state is updated uiSchemaRef.current = uiSchema; // We make sure state is updated if (rjsfDebug) console.log('ConfigPluginDialog moveToUiSchema:', schema, uiSchema); } // Send the select devices and entities messages if (plugin.name && plugin.configJson && plugin.schemaJson) { setFormData(plugin.configJson); setSchema(plugin.schemaJson); sendMessage({ id: uniqueId.current, sender: 'ConfigPlugin', method: '/api/select-devices', src: 'Frontend', dst: 'Matterbridge', params: { plugin: plugin.name } }); sendMessage({ id: uniqueId.current, sender: 'ConfigPlugin', method: '/api/select-entities', src: 'Frontend', dst: 'Matterbridge', params: { plugin: plugin.name } }); if (debug) console.log('HomePlugins sent "/api/select-devices" and "/api/select-entities" for plugin:', plugin.name); } return () => { removeListener(handleWebSocketMessage); if (debug) console.log('ConfigPluginDialog removed WebSocket listener'); }; }, [addListener, formData, plugin, removeListener, schema, sendMessage, uiSchema]); const handleFormChange = (data: IChangeEvent, id?: string) => { currentFormDataRef.current = data.formData; if (rjsfDebug) console.log(`handleFormChange id ${id} formData:`, data.formData); }; const handleSaveChanges = (data: IChangeEvent) => { if (debug) console.log('ConfigPluginDialog handleSaveChanges:', data.formData); // Save the configuration setFormData(data.formData); onSave(data.formData); sendMessage({ id: uniqueId.current, sender: 'ConfigPlugin', method: '/api/save-plugin-config', src: 'Frontend', dst: 'Matterbridge', params: { pluginName: data.formData.name, formData: data.formData }, }); // Close the dialog onClose(); }; function WrapIfAdditionalTemplate(props: WrapIfAdditionalTemplateProps) { const { id, label, onKeyRenameBlur, onRemoveProperty, disabled, schema, children, registry, readonly, required } = props; const { templates } = registry; const { RemoveButton } = templates.ButtonTemplates; if (rjsfDebug) console.log('WrapIfAdditionalTemplate:', props); const additional = ADDITIONAL_PROPERTY_FLAG in schema; const keyInputRef = useRef(null); useEffect(() => { const pendingAdditionalPropertyKey = pendingAdditionalPropertyKeyRef.current; if (!additional || pendingAdditionalPropertyKey === '' || !/^newKey(?:-\d+)?$/.test(label) || !keyInputRef.current) return; if (debug) console.log(`WrapIfAdditionalTemplate: renaming additional property "${label}" to "${pendingAdditionalPropertyKey}"`); keyInputRef.current.value = pendingAdditionalPropertyKey; onKeyRenameBlur({ target: keyInputRef.current } as React.FocusEvent); pendingAdditionalPropertyKeyRef.current = ''; }, [additional, label, onKeyRenameBlur]); if (!additional) { return ( {children} ); } return ( {children} ); } function FieldTemplate(props: FieldTemplateProps) { const { children, description, displayLabel, errors, help, hidden, registry, uiSchema } = props; const uiOptions = getUiOptions(uiSchema); const WrapIfAdditionalTemplate = getTemplate('WrapIfAdditionalTemplate', registry, uiOptions); // const rjsfDebug = true; if (rjsfDebug) console.log('FieldTemplate:', props, 'WrapIfAdditionalTemplate:', WrapIfAdditionalTemplate !== undefined); if (hidden) { return
{children}
; } return ( {/* displayLabel===true && !isArray && id: {id} label: {label} {required && ***} */} {displayLabel === true && description} {children} {errors} {help} ); } function DescriptionFieldTemplate(props: DescriptionFieldProps) { const { description } = props; if (rjsfDebug) console.log('DescriptionFieldTemplate:', props); if (!description) return null; return ( {/* id: {id} desc: */} {description} ); } function TitleFieldTemplate(props: TitleFieldProps) { const { required, title } = props; if (rjsfDebug) console.log('TitleFieldTemplate:', props); if (!title) return null; return ( {/* id: {id} title: */}Title {title} {required && ***} ); } function FieldHelpTemplate(props: FieldHelpProps) { const { help } = props; if (rjsfDebug) console.log('FieldHelpTemplate:', props); if (!help) return null; return ( {/* id: {id} help: */} {help} ); } // Shows a list of errors at the top of the form function ErrorListTemplate(props: ErrorListProps) { const { errors } = props; if (rjsfDebug) console.log('ErrorListTemplate:', props); if (!errors) return null; return ( Please fix the following errors: {errors.map((error, index) => ( ))} ); } // Shows the field error at the bottom of the field function FieldErrorTemplate(props: FieldErrorProps) { const { errors } = props; if (rjsfDebug) console.log('FieldErrorTemplate:', props); if (!errors) return null; return ( {errors.map((error, index) => ( This field {error} ))} ); } function BaseInputTemplate(props: BaseInputTemplateProps) { const { id, name, _schema, _uiSchema, value, options, label, type, placeholder, required, disabled, readonly, autofocus, onChange, onChangeOverride, onBlur, onFocus, _rawErrors, _hideError, _registry, _formContext, } = props; if (rjsfDebug) console.log('BaseInputTemplate:', props); const handleChange = ({ target: { value } }: React.ChangeEvent) => onChange(value === '' ? options.emptyValue : value); const handleBlur = ({ target }: React.FocusEvent) => onBlur(id, target?.value); const handleFocus = ({ target }: React.FocusEvent) => onFocus(id, target?.value); return ( ); } function ArrayFieldTitleTemplate(props: ArrayFieldTitleProps) { console.log('ArrayFieldTitleTemplate:', props); return null; } function ArrayFieldDescriptionTemplate(props: ArrayFieldDescriptionProps) { console.log('ArrayFieldDescriptionTemplate:', props); return null; } function ArrayFieldItemTemplate(props: ArrayFieldItemTemplateProps) { const { buttonsProps, children } = props; if (rjsfDebug) console.log('ArrayFieldItemTemplate:', props); return ( {children} {buttonsProps.hasRemove && ( )} ); } function ArrayFieldTemplate(props: ArrayFieldTemplateProps) { const { canAdd, onAddClick, schema, title, formData } = props; if (rjsfDebug) console.log(`ArrayFieldTemplate for ${title}:`, props); const [dialogDeviceOpen, setDialogDeviceOpen] = useState(false); const [dialogEntityOpen, setDialogEntityOpen] = useState(false); const [dialogDeviceEntityOpen, setDialogDeviceEntityOpen] = useState(false); const [filter, setFilter] = useState(''); const handleFilterChange = (event: React.ChangeEvent) => { setFilter(event.target.value); }; const handleDialogDeviceToggle = () => { if (debug) console.log('ArrayFieldTemplate: handleDialogDeviceToggle filter:', filter, 'selectDevices:', selectDevices); setDialogDeviceOpen(!dialogDeviceOpen); }; const handleDialogEntityToggle = () => { if (debug) console.log('ArrayFieldTemplate: handleDialogEntityToggle filter:', filter, 'selectEntities:', selectEntities); setDialogEntityOpen(!dialogEntityOpen); }; const handleDialogDeviceEntityToggle = () => { if (debug) console.log('ArrayFieldTemplate: handleDialogDeviceEntityToggle filter:', filter, 'selectDevices:', selectDevices); setDialogDeviceEntityOpen(!dialogDeviceEntityOpen); }; const handleSelectDeviceValue = (value: ApiSelectDevice) => { // console.log('ArrayFieldTemplate: handleSelectValue', value); setDialogDeviceOpen(false); // Trigger onAddClick to add the selected new item if (schema.selectFrom === 'serial' && hasSchemaItemsWithDefault(schema)) schema.items.default = value.serialNumber; else if (schema.selectFrom === 'name' && hasSchemaItemsWithDefault(schema)) schema.items.default = value.deviceName; onAddClick(); }; const handleSelectEntityValue = (value: ApiSelectEntity) => { // console.log('ArrayFieldTemplate: handleSelectEntityValue', value); setDialogEntityOpen(false); // Trigger onAddClick to add the selected new item if (schema.selectEntityFrom === 'name' && hasSchemaItemsWithDefault(schema)) schema.items.default = value.name; else if (schema.selectEntityFrom === 'description' && hasSchemaItemsWithDefault(schema)) schema.items.default = value.description; onAddClick(); }; const handleSelectDeviceEntityValue = (value: ApiSelectDeviceEntity) => { // console.log('ArrayFieldTemplate: handleSelectEntityValue', value); setDialogDeviceEntityOpen(false); // Trigger onAddClick to add the selected new item if (schema.selectDeviceEntityFrom === 'name' && hasSchemaItemsWithDefault(schema)) schema.items.default = value.name; else if (schema.selectDeviceEntityFrom === 'description' && hasSchemaItemsWithDefault(schema)) schema.items.default = value.description; onAddClick(); }; // const rjsfDebug = true; return ( {title && ( {title && {title}} {canAdd && ( {schema.selectFrom && ( )} {schema.selectEntityFrom && ( )} {schema.selectDeviceEntityFrom && ( )} )} )} {schema.description && {schema.description}} {props.items} {/* Dialog for selecting a device */} Select a device Filter by: {selectDevices .filter((v) => v.serialNumber.toLowerCase().includes(filter.toLowerCase()) || v.deviceName.toLowerCase().includes(filter.toLowerCase())) .filter((d) => !schema.uniqueItems || !formData.includes(schema.selectFrom === 'serial' ? d.serialNumber : d.deviceName)) .map((value, index) => ( handleSelectDeviceValue(value)} key={index} sx={listItemButtonSx}> {value.icon === 'wifi' && ( )} {value.icon === 'ble' && ( )} {value.icon === 'hub' && ( )} ))} {/* Dialog for selecting an entity */} Select an entity Filter by: {selectEntities .filter((v) => v.name.toLowerCase().includes(filter.toLowerCase()) || v.description.toLowerCase().includes(filter.toLowerCase())) .filter((e) => !schema.uniqueItems || !formData.includes(schema.selectEntityFrom === 'name' ? e.name : e.description)) .map((value, index) => ( handleSelectEntityValue(value)} key={index} sx={listItemButtonSx}> {value.icon === 'wifi' && ( )} {value.icon === 'ble' && ( )} {value.icon === 'hub' && ( )} {value.icon === 'component' && ( )} {value.icon === 'matter' && ( )} ))} {/* Dialog for selecting a device entity */} Select an entity for {title} {selectDevices .filter((d) => d.serialNumber === title || d.deviceName === title) .map((value) => { // console.log('ArrayFieldTemplate: handleSelectDeviceEntityValue value:', value, value.entities); // console.log('ArrayFieldTemplate: handleSelectDeviceEntityValue schema:', schema); return value.entities ?.filter( (entity) => !schema.uniqueItems || !Array.isArray(formData) || !formData.includes(schema.selectDeviceEntityFrom === 'name' ? entity.name : entity.description), ) .map((entity, index) => ( handleSelectDeviceEntityValue(entity)} key={index} sx={listItemButtonSx}> {entity.icon === 'wifi' && ( )} {entity.icon === 'ble' && ( )} {entity.icon === 'hub' && ( )} {entity.icon === 'component' && ( )} {entity.icon === 'matter' && ( )} )); })} ); } function ObjectFieldTemplate(props: ObjectFieldTemplateProps) { const { onAddProperty, schema, properties, title, description } = props; const [dialogDeviceOpen, setDialogDeviceOpen] = useState(false); const [filter, setFilter] = useState(''); const handleFilterChange = (event: React.ChangeEvent) => { setFilter(event.target.value); }; const handleDialogDeviceToggle = () => { setDialogDeviceOpen(!dialogDeviceOpen); }; const handleSelectDeviceValue = (value: ApiSelectDevice) => { if (debug) console.log(`ObjectFieldTemplate: handleSelectValue value "${value.serialNumber}" for schema "${schema.selectFrom}"`); setDialogDeviceOpen(false); let nextKey = ''; if (schema.selectFrom === 'serial') nextKey = value.serialNumber; else if (schema.selectFrom === 'name') nextKey = value.deviceName; pendingAdditionalPropertyKeyRef.current = nextKey; if (debug) console.log(`ObjectFieldTemplate: handleSelectValue pendingAdditionalPropertyKey "${nextKey}"`); // Trigger onAddClick returned function to add the selected new item onAddProperty(); }; const handleAddItem = () => { onAddProperty(); }; // Check if this is the entire schema or an individual object const isRoot = !schema.additionalProperties; if (rjsfDebug) console.log('ObjectFieldTemplate: title', title, 'description', description, 'schema', schema, 'isRoot', isRoot, 'props', props); if (debug) console.log(`ObjectFieldTemplate: isRoot ${isRoot} pendingAdditionalPropertyKey "${pendingAdditionalPropertyKeyRef.current}"`); return ( {/* Title for root */} {schema.title && isRoot && ( {schema.title} )} {/* Title, Select and Add for object */} {title && !isRoot && ( {title} {schema.selectFrom && ( )} )} {/* Description for both */} {schema.description && ( {schema.description} )} {/* Iterate over each property in the object */} {properties.map(({ content, name, hidden }) => { if (hidden) return null; const hasStringTypeProperty = hasSchemaPropertyWithStringType(schema, name); const isArrayMultiSelectProperty = hasSchemaPropertyArrayMultiSelect(schema, name); const isObjectOrArrayProperty = hasStringTypeProperty && ['object', 'array'].includes(schema.properties[name].type); return ( {hasStringTypeProperty && !['object', 'array', 'boolean'].includes(schema.properties[name].type) && ( {schema.properties[name].title || name} )} {isArrayMultiSelectProperty && {schema.properties[name].title || name}} {content} ); })} {/* Dialog for selecting a device */} Select a device Filter by: {selectDevices .filter((v) => v.serialNumber.toLowerCase().includes(filter.toLowerCase()) || v.deviceName.toLowerCase().includes(filter.toLowerCase())) .map((value, index) => ( handleSelectDeviceValue(value)} key={index} sx={listItemButtonSx}> {value.icon === 'wifi' && ( )} {value.icon === 'ble' && ( )} {value.icon === 'hub' && ( )} ))} ); } function SubmitButton(props: SubmitButtonProps) { const { uiSchema } = props; if (rjsfDebug) console.log('SubmitButton:', props); const { submitText, norender } = getSubmitButtonOptions(uiSchema); if (norender) { return null; } return (
); } function RemoveButton(props: IconButtonProps) { const { className, disabled, onClick, registry, style, uiSchema, ...otherProps } = props; if (rjsfDebug) console.log('RemoveButton:', otherProps); return ( ); } function AddButton(props: IconButtonProps) { const { className, disabled, onClick, registry, uiSchema, ...otherProps } = props; if (rjsfDebug) console.log('AddButton:', otherProps); return ( ); } function MoveUpButton(props: IconButtonProps) { const { disabled, onClick, registry, style, uiSchema, ...otherProps } = props; if (rjsfDebug) console.log('MoveUpButton:', otherProps); return ( ); } function MoveDownButton(props: IconButtonProps) { const { disabled, onClick, registry, style, uiSchema, ...otherProps } = props; if (rjsfDebug) console.log('MoveDownButton:', otherProps); return ( ); } function CheckboxWidget(props: WidgetProps) { const { id, name, value, schema, readonly, onChange } = props; if (rjsfDebug) console.log(`CheckboxWidget ${name}:`, props); if (rjsfDebug) console.log(`CheckboxWidget formData:`, currentFormDataRef.current); const [fieldValue, setFieldValue] = useState(); const onChangeField = (value: string) => { if (debug) console.log(`CheckboxWidget ${name} onChangeField:`, value); setFieldValue(value && value !== '' ? value : undefined); }; const onClick = () => { if (debug) console.log(`CheckboxWidget onClick plugin="${plugin.name}" action="${name}" value="${fieldValue}"`); sendMessage({ id: uniqueId.current, sender: 'ConfigPlugin', method: '/api/action', src: 'Frontend', dst: 'Matterbridge', params: { plugin: plugin.name, action: name, value: fieldValue, formData: currentFormDataRef.current, id }, }); if (schema.buttonClose === true) onClose(); // oxlint-disable-next-line typescript/no-explicit-any else if (schema.buttonSave === true) handleSaveChanges({ formData } as any); // Save changes and we don't close (no need for other props). }; if (schema.buttonText && (schema.title || schema.description)) { /* SPECIAL: button with description */ return ( {schema.title || schema.description} ); } else if (schema.buttonField && (schema.title || schema.description)) { /* SPECIAL: text field with button and description */ return ( {schema.title || schema.description} onChangeField(event.target.value)} sx={{ width: '250px', minWidth: '250px', maxWidth: '250px' }} /> ); } return ( {name && ( {schema.title || name} onChange(!value)} sx={{ padding: '0px', margin: '0px' }} /> )} {schema.description && {schema.description}} ); } function SelectWidget({ schema, id, name, options, label, hideLabel, required, disabled, placeholder, readonly, value, multiple, autofocus, onChange, onBlur, onFocus, errorSchema, rawErrors = emptyRawErrors, registry, uiSchema, hideError, ...textFieldProps }: WidgetProps) { const { enumOptions, enumDisabled, emptyValue: optEmptyVal } = options; /* v8 ignore if -- debug only */ if (rjsfDebug) console.log(`SelectWidget ${name}:`, { schema, id, options, label, hideLabel, required, disabled, placeholder, readonly, value, multiple, autofocus, errorSchema, rawErrors, registry, uiSchema, hideError, textFieldProps, }); const emptyValue = multiple ? [] : ''; const isEmpty = typeof value === 'undefined' || (multiple && value.length < 1) || (!multiple && value === emptyValue); const handleChange = ({ target: { value } }: React.ChangeEvent) => onChange(enumOptionsValueForIndex(value, enumOptions, optEmptyVal)); const handleBlur = ({ target }: React.FocusEvent) => onBlur(id, enumOptionsValueForIndex(target?.value, enumOptions, optEmptyVal)); const handleFocus = ({ target }: React.FocusEvent) => onFocus(id, enumOptionsValueForIndex(target?.value, enumOptions, optEmptyVal)); const selectedIndexes = enumOptionsIndexForValue(value, enumOptions, multiple); const renderSelectedValues = (selected: unknown) => { if (!Array.isArray(selected) || !Array.isArray(enumOptions)) return ''; return selected .map((index) => enumOptions[Number(index)]?.label) .filter((optionLabel): optionLabel is string => typeof optionLabel === 'string') .join(', '); }; return ( 0} onChange={handleChange} onBlur={handleBlur} onFocus={handleFocus} select slotProps={{ select: { multiple, ...(multiple ? { renderValue: renderSelectedValues } : {}), }, }} aria-describedby={ariaDescribedByIds(id)} > {Array.isArray(enumOptions) && enumOptions.map(({ value, label }, i) => { const disabled = Array.isArray(enumDisabled) && enumDisabled.includes(value); const isSelected = Array.isArray(selectedIndexes) && selectedIndexes.includes(String(i)); return ( {multiple && ( )} {label} ); })} ); } if (debug) console.log('ConfigPluginDialog rendering...'); if (!open || !schema || !formData) return null; return (
Matterbridge Logo

Matterbridge plugin configuration

); };