AP1.10b/10c: Entity Field System mit dynamischen Vorhaben-Zusatzfeldern.
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 1m54s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 19s
Test Suite / playwright-smoke (push) Successful in 15s
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 1m54s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 19s
Test Suite / playwright-smoke (push) Successful in 15s
EFS-Tabellen, Registry-Sync und Fields-API ermöglichen archetyp-spezifische Felder; Frontend rendert sie im Profil-Modal per FieldRenderer. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
408050bcb8
commit
a6fc86025c
23 files changed
+1107
-20
No files matched your search
@@ -0,0 +1,104 @@
|
||||
export function FieldRenderer({ definitions, values, onChange, disabled = false }) {
|
||||
if (!definitions?.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<fieldset className="field-renderer">
|
||||
<legend className="field-renderer__legend">Zusatzfelder</legend>
|
||||
{definitions.map((def) => (
|
||||
<DynamicField
|
||||
key={def.field_key}
|
||||
definition={def}
|
||||
value={values?.[def.field_key]}
|
||||
onChange={(next) => onChange(def.field_key, next)}
|
||||
disabled={disabled}
|
||||
/>
|
||||
))}
|
||||
</fieldset>
|
||||
)
|
||||
}
|
||||
|
||||
function DynamicField({ definition, value, onChange, disabled }) {
|
||||
const { field_key, field_type, label, required, validation_json: validation } = definition
|
||||
const inputId = `field-${field_key}`
|
||||
|
||||
if (field_type === 'longtext') {
|
||||
return (
|
||||
<label htmlFor={inputId}>
|
||||
{label}
|
||||
{required && ' *'}
|
||||
<textarea
|
||||
id={inputId}
|
||||
name={field_key}
|
||||
rows={4}
|
||||
value={value ?? ''}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
required={required}
|
||||
disabled={disabled}
|
||||
/>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
if (field_type === 'boolean') {
|
||||
return (
|
||||
<label className="checkbox-label" htmlFor={inputId}>
|
||||
<input
|
||||
id={inputId}
|
||||
name={field_key}
|
||||
type="checkbox"
|
||||
checked={Boolean(value)}
|
||||
onChange={(e) => onChange(e.target.checked)}
|
||||
disabled={disabled}
|
||||
/>
|
||||
{label}
|
||||
{required && ' *'}
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
if (field_type === 'enum') {
|
||||
const options = validation?.options || []
|
||||
return (
|
||||
<label htmlFor={inputId}>
|
||||
{label}
|
||||
{required && ' *'}
|
||||
<select
|
||||
id={inputId}
|
||||
name={field_key}
|
||||
value={value ?? ''}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
required={required}
|
||||
disabled={disabled}
|
||||
>
|
||||
<option value="">—</option>
|
||||
{options.map((opt) => (
|
||||
<option key={opt} value={opt}>
|
||||
{opt}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
const inputType =
|
||||
field_type === 'number' ? 'number' : field_type === 'date' ? 'date' : field_type === 'url' ? 'url' : 'text'
|
||||
|
||||
return (
|
||||
<label htmlFor={inputId}>
|
||||
{label}
|
||||
{required && ' *'}
|
||||
<input
|
||||
id={inputId}
|
||||
name={field_key}
|
||||
type={inputType}
|
||||
value={value ?? ''}
|
||||
onChange={(e) => onChange(field_type === 'number' ? e.target.value : e.target.value)}
|
||||
required={required}
|
||||
disabled={disabled}
|
||||
/>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
@@ -3,15 +3,26 @@ import { INITIATIVE_STATUSES, PRIORITIES } from '../constants/status.js'
|
||||
import { INITIATIVE_STATUS_LABELS, PRIORITY_LABELS } from '../constants/status.js'
|
||||
import { INITIATIVE_ARCHETYPE_LABELS } from '../constants/initiativeArchetypes.js'
|
||||
import { listEntityArchetypes } from '../api/entityArchetypes.js'
|
||||
import {
|
||||
getInitiativeFieldDefinitions,
|
||||
getInitiativeFields,
|
||||
listArchetypeFieldDefinitions,
|
||||
} from '../api/entityFields.js'
|
||||
import { FieldRenderer } from './FieldRenderer.jsx'
|
||||
|
||||
export function InitiativeForm({
|
||||
initial = {},
|
||||
initiativeId = null,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
busy = false,
|
||||
submitLabel = 'Speichern',
|
||||
}) {
|
||||
const [archetypes, setArchetypes] = useState(null)
|
||||
const [archetypeKey, setArchetypeKey] = useState(initial.archetype_key || 'initiative.generic')
|
||||
const [fieldDefinitions, setFieldDefinitions] = useState([])
|
||||
const [dynamicValues, setDynamicValues] = useState({})
|
||||
const [fieldsLoading, setFieldsLoading] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
@@ -34,6 +45,40 @@ export function InitiativeForm({
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
setFieldsLoading(true)
|
||||
|
||||
async function loadFields() {
|
||||
try {
|
||||
let definitions = []
|
||||
let values = {}
|
||||
if (initiativeId) {
|
||||
definitions = await getInitiativeFieldDefinitions(initiativeId)
|
||||
values = await getInitiativeFields(initiativeId)
|
||||
} else if (archetypeKey) {
|
||||
definitions = await listArchetypeFieldDefinitions('initiative', archetypeKey)
|
||||
}
|
||||
if (!cancelled) {
|
||||
setFieldDefinitions(definitions)
|
||||
setDynamicValues(values)
|
||||
}
|
||||
} catch {
|
||||
if (!cancelled) {
|
||||
setFieldDefinitions([])
|
||||
setDynamicValues({})
|
||||
}
|
||||
} finally {
|
||||
if (!cancelled) setFieldsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
loadFields()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [initiativeId, archetypeKey])
|
||||
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
const form = e.target
|
||||
@@ -45,9 +90,16 @@ export function InitiativeForm({
|
||||
target_state_summary: form.target_state_summary.value,
|
||||
status: form.status.value,
|
||||
priority: form.priority.value,
|
||||
dynamicFields: dynamicValues,
|
||||
})
|
||||
}
|
||||
|
||||
function handleDynamicChange(fieldKey, value) {
|
||||
setDynamicValues((prev) => ({ ...prev, [fieldKey]: value }))
|
||||
}
|
||||
|
||||
const formReady = archetypes && !fieldsLoading
|
||||
|
||||
return (
|
||||
<form className="form workspace-form" onSubmit={handleSubmit}>
|
||||
<label>
|
||||
@@ -58,7 +110,8 @@ export function InitiativeForm({
|
||||
Archetyp
|
||||
<select
|
||||
name="archetype_key"
|
||||
defaultValue={initial.archetype_key || 'initiative.generic'}
|
||||
value={archetypeKey}
|
||||
onChange={(e) => setArchetypeKey(e.target.value)}
|
||||
disabled={!archetypes}
|
||||
>
|
||||
{(archetypes || []).map((item) => (
|
||||
@@ -84,6 +137,12 @@ export function InitiativeForm({
|
||||
defaultValue={initial.target_state_summary || ''}
|
||||
/>
|
||||
</label>
|
||||
<FieldRenderer
|
||||
definitions={fieldDefinitions}
|
||||
values={dynamicValues}
|
||||
onChange={handleDynamicChange}
|
||||
disabled={busy || fieldsLoading}
|
||||
/>
|
||||
<div className="form-row form-row--2">
|
||||
<label>
|
||||
Status
|
||||
@@ -107,7 +166,7 @@ export function InitiativeForm({
|
||||
</label>
|
||||
</div>
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !archetypes}>
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !formReady}>
|
||||
{busy ? 'Speichern …' : submitLabel}
|
||||
</button>
|
||||
{onCancel && (
|
||||
|
||||
Reference in new issue
Block a user