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,36 @@
|
||||
import { apiFetch } from './client.js'
|
||||
|
||||
export function listArchetypeFieldDefinitions(entityType, archetypeKey) {
|
||||
const params = new URLSearchParams({
|
||||
entity_type: entityType,
|
||||
archetype_key: archetypeKey,
|
||||
})
|
||||
return apiFetch(`/api/entity-archetypes/field-definitions?${params}`)
|
||||
}
|
||||
|
||||
export function getInitiativeFieldDefinitions(initiativeId) {
|
||||
return apiFetch(`/api/initiatives/${initiativeId}/field-definitions`)
|
||||
}
|
||||
|
||||
export function getInitiativeFields(initiativeId) {
|
||||
return apiFetch(`/api/initiatives/${initiativeId}/fields`)
|
||||
}
|
||||
|
||||
export function patchInitiativeFields(initiativeId, fields) {
|
||||
return apiFetch(`/api/initiatives/${initiativeId}/fields`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ fields }),
|
||||
})
|
||||
}
|
||||
|
||||
export async function saveInitiativeDynamicFields(initiativeId, dynamicFields) {
|
||||
if (!dynamicFields || Object.keys(dynamicFields).length === 0) {
|
||||
return
|
||||
}
|
||||
await patchInitiativeFields(initiativeId, dynamicFields)
|
||||
}
|
||||
|
||||
export function splitInitiativeFormPayload(payload) {
|
||||
const { dynamicFields, ...core } = payload
|
||||
return { core, dynamicFields: dynamicFields || {} }
|
||||
}
|
||||
@@ -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 && (
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
updateInitiative,
|
||||
} from '../api/initiatives.js'
|
||||
import { updateAction, setActionAssignments } from '../api/actions.js'
|
||||
import { saveInitiativeDynamicFields, splitInitiativeFormPayload } from '../api/entityFields.js'
|
||||
import {
|
||||
listInitiativeBlockers,
|
||||
createInitiativeBlocker,
|
||||
@@ -312,8 +313,10 @@ export function InitiativeOperationsProvider({ children, initiativeId: initiativ
|
||||
|
||||
async function handleUpdateInitiative(body) {
|
||||
setFormBusy(true)
|
||||
const { core, dynamicFields } = splitInitiativeFormPayload(body)
|
||||
try {
|
||||
await updateInitiative(id, body)
|
||||
await updateInitiative(id, core)
|
||||
await saveInitiativeDynamicFields(id, dynamicFields)
|
||||
await load()
|
||||
return true
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { listInitiatives, listInitiativeActions, createInitiative } from '../api/initiatives.js'
|
||||
import { saveInitiativeDynamicFields, splitInitiativeFormPayload } from '../api/entityFields.js'
|
||||
import { countOpenActions } from '../api/actions.js'
|
||||
import { StatusBadge } from '../components/StatusBadge.jsx'
|
||||
import { PriorityBadge } from '../components/PriorityBadge.jsx'
|
||||
@@ -55,8 +56,10 @@ export function InitiativesPage() {
|
||||
|
||||
async function handleCreate(payload) {
|
||||
setFormBusy(true)
|
||||
const { core, dynamicFields } = splitInitiativeFormPayload(payload)
|
||||
try {
|
||||
await createInitiative({ ...payload, owner_actor_id: context?.actor?.id })
|
||||
const created = await createInitiative({ ...core, owner_actor_id: context?.actor?.id })
|
||||
await saveInitiativeDynamicFields(created.id, dynamicFields)
|
||||
setShowForm(false)
|
||||
await load()
|
||||
} catch (err) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getWidgetsForArea } from '../registry/widgetRegistry.js'
|
||||
import { useSession } from '../context/SessionContext.jsx'
|
||||
import { InitiativeForm } from '../components/InitiativeForm.jsx'
|
||||
import { createInitiative } from '../api/initiatives.js'
|
||||
import { saveInitiativeDynamicFields, splitInitiativeFormPayload } from '../api/entityFields.js'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
export function WorkspacePage() {
|
||||
@@ -19,11 +20,13 @@ export function WorkspacePage() {
|
||||
async function handleCreateInitiative(payload) {
|
||||
setFormBusy(true)
|
||||
setFormError(null)
|
||||
const { core, dynamicFields } = splitInitiativeFormPayload(payload)
|
||||
try {
|
||||
await createInitiative({
|
||||
...payload,
|
||||
const created = await createInitiative({
|
||||
...core,
|
||||
owner_actor_id: context?.actor?.id,
|
||||
})
|
||||
await saveInitiativeDynamicFields(created.id, dynamicFields)
|
||||
setShowForm(false)
|
||||
navigate('/initiatives')
|
||||
} catch (err) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { getWidgetsForArea } from '../../registry/widgetRegistry.js'
|
||||
import { useSession } from '../../context/SessionContext.jsx'
|
||||
import { InitiativeForm } from '../../components/InitiativeForm.jsx'
|
||||
import { createInitiative } from '../../api/initiatives.js'
|
||||
import { saveInitiativeDynamicFields, splitInitiativeFormPayload } from '../../api/entityFields.js'
|
||||
import { ModeShell } from '../../components/ModeShell.jsx'
|
||||
import { initiativeCatalogPath } from '../../utils/routes.js'
|
||||
|
||||
@@ -21,11 +22,13 @@ export function CockpitPage() {
|
||||
async function handleCreateInitiative(payload) {
|
||||
setFormBusy(true)
|
||||
setFormError(null)
|
||||
const { core, dynamicFields } = splitInitiativeFormPayload(payload)
|
||||
try {
|
||||
await createInitiative({
|
||||
...payload,
|
||||
const created = await createInitiative({
|
||||
...core,
|
||||
owner_actor_id: context?.actor?.id,
|
||||
})
|
||||
await saveInitiativeDynamicFields(created.id, dynamicFields)
|
||||
setShowForm(false)
|
||||
navigate(initiativeCatalogPath())
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { RequireInitiativeScope } from '../../components/RequireInitiativeScope.jsx'
|
||||
import { ScopedInitiativeProvider } from '../../layout/ScopedInitiativeProvider.jsx'
|
||||
import { StatusBadge } from '../../components/StatusBadge.jsx'
|
||||
@@ -8,6 +8,68 @@ import { InitiativeForm } from '../../components/InitiativeForm.jsx'
|
||||
import { useInitiativeOperations } from '../../context/InitiativeOperationsContext.jsx'
|
||||
import { useProgramScope } from '../../context/ProgramScopeContext.jsx'
|
||||
import { initiativeArchetypeLabel } from '../../constants/initiativeArchetypes.js'
|
||||
import {
|
||||
getInitiativeFieldDefinitions,
|
||||
getInitiativeFields,
|
||||
} from '../../api/entityFields.js'
|
||||
|
||||
function DynamicFieldsDisplay({ initiativeId }) {
|
||||
const [definitions, setDefinitions] = useState([])
|
||||
const [values, setValues] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
async function load() {
|
||||
try {
|
||||
const [defs, fieldValues] = await Promise.all([
|
||||
getInitiativeFieldDefinitions(initiativeId),
|
||||
getInitiativeFields(initiativeId),
|
||||
])
|
||||
if (!cancelled) {
|
||||
setDefinitions(defs)
|
||||
setValues(fieldValues)
|
||||
}
|
||||
} catch {
|
||||
if (!cancelled) {
|
||||
setDefinitions([])
|
||||
setValues({})
|
||||
}
|
||||
}
|
||||
}
|
||||
load()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [initiativeId])
|
||||
|
||||
if (!definitions.length || values === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
const visible = definitions.filter((def) => {
|
||||
const val = values[def.field_key]
|
||||
if (def.field_type === 'boolean') return val === true
|
||||
return val != null && String(val).trim() !== ''
|
||||
})
|
||||
|
||||
if (!visible.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
return visible.map((def) => (
|
||||
<div key={def.field_key} className="plan-profile__field">
|
||||
<h3 className="plan-profile__label">{def.label}</h3>
|
||||
<p>{formatFieldValue(def, values[def.field_key])}</p>
|
||||
</div>
|
||||
))
|
||||
}
|
||||
|
||||
function formatFieldValue(definition, value) {
|
||||
if (definition.field_type === 'boolean') {
|
||||
return value ? 'Ja' : 'Nein'
|
||||
}
|
||||
return String(value ?? '')
|
||||
}
|
||||
|
||||
function PlanProfileInner() {
|
||||
const ops = useInitiativeOperations()
|
||||
@@ -77,13 +139,12 @@ function PlanProfileInner() {
|
||||
<p>{initiative.target_state_summary}</p>
|
||||
</div>
|
||||
)}
|
||||
<p className="muted plan-profile__note">
|
||||
Dynamische Zusatzfelder (EFS) folgen in AP1.10c.
|
||||
</p>
|
||||
<DynamicFieldsDisplay initiativeId={initiative.id} key={editing ? 'closed' : 'open'} />
|
||||
</section>
|
||||
|
||||
<Modal open={editing} title="Vorhaben bearbeiten" onClose={() => setEditing(false)} size="lg">
|
||||
<InitiativeForm
|
||||
initiativeId={initiative.id}
|
||||
initial={initiative}
|
||||
onSubmit={handleSave}
|
||||
onCancel={() => setEditing(false)}
|
||||
|
||||
Reference in new issue
Block a user