diff --git a/webui/src/admin/components/RoverConfigurationEditor.jsx b/webui/src/admin/components/RoverConfigurationEditor.jsx index d1be0ad8..4e7d23c2 100644 --- a/webui/src/admin/components/RoverConfigurationEditor.jsx +++ b/webui/src/admin/components/RoverConfigurationEditor.jsx @@ -1,6 +1,5 @@ import { useEffect, useState } from 'react'; -import Form from '@rjsf/core'; -import validator from '@rjsf/validator-ajv8'; +import SchemaConfigurationForm from './SchemaConfigurationForm.jsx'; function request(socket, event, payload = {}) { return new Promise((resolve, reject) => { @@ -12,57 +11,12 @@ function request(socket, event, payload = {}) { }); } -function label(key) { return key.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/^./, (c) => c.toUpperCase()); } - -function fieldUI(schema, path = []) { - const ui = { 'ui:title': path.length ? label(path.at(-1)) : '', 'ui:options': { path } }; - if (schema.type === 'string') ui['ui:emptyValue'] = ''; - for (const [key, child] of Object.entries(schema.properties || {})) ui[key] = fieldUI(child, [...path, key]); - return ui; -} - -function FieldLayout({ id, label: title, children, errors, help, description, schema, uiSchema, registry }) { - const path = uiSchema?.['ui:options']?.path || []; - const object = schema.type === 'object'; - return
- {!object &&
- - -
} - {description}{children}{errors}{help} -
; -} - -function ObjectLayout({ title, properties, uiSchema, registry }) { - const path = uiSchema?.['ui:options']?.path || []; - const content =
{properties.map((property) =>
{property.content}
)} - {path.length === 2 && path[0] === 'media' && path[1] !== 'rtspPort' - && } -
; - if (!path.length) return content; - return
- {title}{content} -
; -} - -// Required boolean properties may be false; HTML required checkboxes may not. -function BooleanInput({ id, value, disabled, readonly, onChange }) { - return onChange(event.target.checked)} className="h-5 w-5 accent-sky-500" />; -} -const widgets = { CheckboxWidget: BooleanInput }; - -const templates = { FieldTemplate: FieldLayout, ObjectFieldTemplate: ObjectLayout }; - function RoverForm({ socket, record, online }) { const [draft, setDraft] = useState(() => structuredClone(record.config)); const [busy, setBusy] = useState(false); const [message, setMessage] = useState(''); const [results, setResults] = useState([]); const schema = structuredClone(record.schema); - const uiSchema = fieldUI(schema); for (const category of ['video', 'audioCapture', 'audioPlayback']) { const property = schema.properties?.media?.properties?.[category]?.properties?.profile; const profiles = record.profiles?.[category] || []; @@ -71,9 +25,7 @@ function RoverForm({ socket, record, online }) { const choices = profiles.map((profile) => ({ id: profile.id, name: profile.name })); const current = draft.media?.[category]?.profile; if (current && !choices.some((entry) => entry.id === current)) choices.push({ id: current, name: `${current} (unavailable)` }); - property.enum = choices.map((entry) => entry.id); - uiSchema.media[category].profile['ui:widget'] = 'select'; - uiSchema.media[category].profile['ui:enumNames'] = choices.map((entry) => entry.name); + property.oneOf = choices.map((entry) => ({ const: entry.id, title: entry.name })); } } async function save(path) { @@ -99,16 +51,13 @@ function RoverForm({ socket, record, online }) { {record.updateStatus &&

Update: {record.updateStatus.state} — {record.updateStatus.message}

}

{message}

{results.length > 0 && } -
-
setDraft(formData)} onSubmit={() => save()}> -
- -
-
-
+ } + renderObjectFooter={(path) => path.length === 2 && path[0] === 'media' && record.profiles?.[path[1]] + ? : null} /> + ; } @@ -128,10 +77,10 @@ function MediaProfiles({ socket, record, online, category, configDirty }) { } catch (error) { setMessage(error.message); } finally { setBusy(false); } } - return
+ return
{(record.profiles?.[category] || []).map((entry) =>

{entry.name}: {entry.description}

)}

Status: {record.mediaStatus?.[category] || (online ? 'Waiting for status' : 'Offline')}

-
+
Create or edit custom profile {configDirty &&

Save configuration changes before saving a custom profile, which restarts the rover.

}
@@ -200,8 +149,8 @@ export default function RoverConfigurationEditor({ socket, selected, onSelect }) }, [socket]); const id = selected || Object.keys(records)[0] || ''; const record = records[id]; - return
-

Configure rover

+ return
+

Configure rover

{error &&

{error}

}