// WF-P8 S05 (Detail-Schablone Edit-Mode) + M05 (Modal Bestandsfeld) — Subframe // baseline for the project detail template of one board. // // Layout follows Davids export: a dense header with the board name and // Abbrechen/Fertig, one white card holding the rules note, the legend, the field // groups as a two-column grid and the Bestandsfelder strip, and a fixed 420px // inspector rail for the selected field. // // Pure/presentational: the VM comes from the route loader, every mutation goes // through one typed onSubmit(intent, fields) the route POSTs. Reordering uses // explicit up/down controls rather than HTML5 drag events — a pointer-only drag // would be unusable by keyboard, and the write path (moveFieldToGroup) is the // same either way. The grip glyph the export draws stays as the visual anchor of // a row. import { useState } from "react"; import { useTranslation } from "react-i18next"; import { AppLink } from "~/components/app/AppLink"; import { FeatherArchive, FeatherArrowDown, FeatherArrowUp, FeatherCheck, FeatherCopy, FeatherGripVertical, FeatherInfo, FeatherKanbanSquare, FeatherLayoutTemplate, FeatherLock, FeatherPin, FeatherPlus, FeatherTrash2, FeatherWandSparkles, FeatherX, } from "@subframe/core"; import type { CustomFieldOption, PipelineFieldTemplateData, TemplateFieldVM, TemplateGroupVM } from "@hivegrid/view-models"; import { datentypHasOptions, TEMPLATE_FIELD_TYPES } from "@hivegrid/view-models"; import { PAGE_HEADER_ICON_CLASS, PageHeader, PageShell } from "../shared/PageShell"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { Dialog } from "~/ui/components/Dialog"; import { EmptyState } from "~/ui/components/EmptyState"; import { IconButton } from "~/ui/components/IconButton"; import { Select } from "~/ui/components/Select"; import { Switch } from "~/ui/components/Switch"; import { TextArea } from "~/ui/components/TextArea"; import { TextInput } from "~/ui/components/TextInput"; export type FieldTemplateSubmit = (intent: string, fields?: Record) => void; export type PipelineFieldTemplatePageProps = { data: PipelineFieldTemplateData; /** Back target for "Abbrechen" / "Fertig" (the board settings screen). */ backHref: string; submitting: boolean; errorKey?: string | null; actions: { onSubmit: FieldTemplateSubmit }; }; /* --- Export tokens --------------------------------------------------------- The blue system tint and the muted locked tint are literal colours in Davids export; the theme has no semantic token for "system field row", so they are kept here as named constants instead of being spread over the JSX. */ const ROW_SYSTEM = "border-[#dbe6f8] bg-[#f5f9ff]"; const ROW_LOCKED = "border-[#dbe3ef] bg-[#eef3fa]"; const ROW_CUSTOM = "border-border-default bg-surface-neutral-primary"; const CHIP_SYSTEM = "whitespace-nowrap rounded-sm border border-solid border-[#cfdff5] bg-white px-1 uppercase tracking-wide text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-[#7591b5]"; const groupTitle = "min-w-[0px] grow shrink-0 basis-0 break-words uppercase tracking-wide text-body-extra-small-semibold-0 font-body-extra-small-semibold-0 text-text-neutral-tertiary"; const countText = "text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-subtle"; const legendText = "text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary"; const legendIcon = "text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-icon-neutral-subtle"; const rowLabel = "break-words text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-primary"; const mutedText = "text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary"; const cardTitle = "text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-primary"; /** No-stage sentinel — Select cannot carry an empty string value. */ const NO_STAGE = "__none__"; export function PipelineFieldTemplatePage(props: PipelineFieldTemplatePageProps) { const { t } = useTranslation(); const { data } = props; const submit = props.actions.onSubmit; const [selectedFieldId, setSelectedFieldId] = useState(null); const [poolDialogGroupId, setPoolDialogGroupId] = useState(null); const [poolSearch, setPoolSearch] = useState(""); // M05 picks one field and confirms it, rather than adding on the row click: // the dialog names the target group in its subtitle, so the user should be // able to check the pairing before it happens. const [poolPick, setPoolPick] = useState(null); const [newGroupOpen, setNewGroupOpen] = useState(false); const [newGroupName, setNewGroupName] = useState(""); const allFields = [...data.groups.flatMap((group) => group.fields), ...data.poolFields]; const selectedField = allFields.find((field) => field.id === selectedFieldId) ?? null; const selectedGroup = data.groups.find((group) => group.id === selectedField?.groupId) ?? null; /** Field name: system fields carry an i18n key, custom fields a stored label. */ function nameOf(field: TemplateFieldVM): string { return field.labelKey ? t(field.labelKey) : field.label; } function moveField(field: TemplateFieldVM, groupId: string | null, reihenfolge: number) { submit("moveTemplateField", { fieldConfigId: field.id, groupId: groupId ?? "", reihenfolge: String(reihenfolge), }); } const poolMatches = data.poolFields.filter((field) => nameOf(field).toLowerCase().includes(poolSearch.trim().toLowerCase())); function openPoolDialog(groupId: string) { setPoolSearch(""); setPoolPick(null); setPoolDialogGroupId(groupId); } const poolDialogGroup = data.groups.find((group) => group.id === poolDialogGroupId) ?? null; function confirmPoolPick() { const field = data.poolFields.find((candidate) => candidate.id === poolPick); if (field && poolDialogGroupId) moveField(field, poolDialogGroupId, 0); setPoolDialogGroupId(null); } return ( } title={t("projects.fieldTemplate.title")} subtitle={ {t("projects.fieldTemplate.board", { board: data.pipelineName })} } actions={ <> } /> {/* Split body: configuration on the left, the selected field on the right. No independently scrolling panes — the app shell's
has no definite height, so `overflow-y-auto` here would collapse the screen. */}
{props.errorKey ? (
{t(props.errorKey)}
) : null}
{/* --- Rules note --- */}
{t("projects.fieldTemplate.rules.title")} {t("projects.fieldTemplate.rules.body")}
{/* --- Legend --- */}
{t("projects.fieldTemplate.systemShort")} {t("projects.fieldTemplate.legend.systemBlue")}
{t("projects.fieldTemplate.legend.customFree")}
{t("projects.fieldTemplate.legend.pinned")}
{t("projects.fieldTemplate.legend.lockedRead")}
{/* --- Field groups --- */}
{data.groups.map((group) => ( openPoolDialog(group.id)} onDeleteGroup={() => submit("deleteFieldGroup", { groupId: group.id })} /> ))} {/* --- New group --- */} {data.canEdit ? (
{t("projects.fieldTemplate.newGroup.title")} {t("projects.fieldTemplate.newGroup.body")}
{newGroupOpen ? ( // Grid, not a wrapping flex row: the ~/ui TextInput root // carries `h-full w-full`, so `grow` alone leaves it claiming // the whole line and stretching to the row height.
setNewGroupName(event.target.value)} data-ui-id="ui.projects.fieldTemplate.newGroup.name" />
) : ( )}
) : null}
{/* --- Bestandsfelder strip --- */}
{t("projects.fieldTemplate.pool.title")} {t("projects.fieldTemplate.pool.short")} {t("projects.fieldTemplate.fieldCount", { count: data.poolFields.length })}
{data.poolFields.length === 0 ? ( {t("projects.fieldTemplate.pool.empty")} ) : (
{data.poolFields.map((field) => ( ))}
)}
{/* --- Live preview --- */} {/* The export draws an empty placeholder here ("the detail page will be shown after saving"). Showing the configured template instead is the same promise kept: the groups in their order with their visible fields, read-only, so a change is checked before the detail page is opened. Hidden fields stay out — that is what the detail page does. */}
{t("projects.fieldTemplate.preview.title")} {t("projects.fieldTemplate.preview.body")}
{data.groups.every((group) => group.fields.filter((field) => field.sichtbar).length === 0) ? ( ) : (
{data.groups.map((group) => { const visible = group.fields.filter((field) => field.sichtbar); if (visible.length === 0) return null; return (
{group.name} {visible.map((field) => (
{nameOf(field)} {field.pflicht ? " *" : ""} {field.datentyp ? t(`projects.fieldTemplate.type.${field.datentyp}`) : "—"}
))}
); })}
)}
{/* --- Selected field inspector --- */}
{t("projects.fieldTemplate.inspector.title")} {selectedField ? (
{selectedGroup ? t("projects.fieldTemplate.inspector.group", { group: selectedGroup.name }) : t("projects.fieldTemplate.inspector.groupNone")}
{t(selectedField.istSystem ? "projects.fieldTemplate.systemShort" : "projects.fieldTemplate.legend.custom")}
) : ( {t("projects.fieldTemplate.inspector.empty")} )}
{selectedField ? ( setSelectedFieldId(null)} /> ) : null}
{/* --- M05 Modal Bestandsfeld. Three stacked bands like the export: header, search, then the scrolling list of fields that exist but are not in this template yet. --- */} (open ? null : setPoolDialogGroupId(null))}>
{t("projects.fieldTemplate.poolDialog.title")} {t("projects.fieldTemplate.poolDialog.subtitle", { group: poolDialogGroup?.name ?? "" })}
} aria-label={t("projects.actions.cancel")} onClick={() => setPoolDialogGroupId(null)} data-ui-id="ui.projects.fieldTemplate.poolDialog.close" />
setPoolSearch(event.target.value)} data-ui-id="ui.projects.fieldTemplate.poolDialog.search" />
{poolMatches.length === 0 ? (
) : (
{poolMatches.map((field) => { const picked = poolPick === field.id; return ( ); })}
)}
); } /** One group cell of the export's two-column grid. */ function TemplateGroupCard(props: { group: TemplateGroupVM; canEdit: boolean; selectedFieldId: string | null; nameOf: (field: TemplateFieldVM) => string; onSelect: (fieldId: string) => void; onMove: (field: TemplateFieldVM, groupId: string | null, reihenfolge: number) => void; onAddField: () => void; onDeleteGroup: () => void; }) { const { t } = useTranslation(); const { group } = props; return (
{group.name} {t("projects.fieldTemplate.fieldCount", { count: group.fieldCount })} {props.canEdit && !group.istSystem ? ( } aria-label={t("projects.fieldTemplate.group.delete")} onClick={props.onDeleteGroup} data-ui-id={`ui.projects.fieldTemplate.group.${group.id}.delete`} /> ) : null}
{group.fields.length === 0 ? {t("projects.fieldTemplate.group.empty")} : null} {group.fields.map((field, index) => ( props.onSelect(field.id)} onMoveUp={() => props.onMove(field, group.id, index - 1)} onMoveDown={() => props.onMove(field, group.id, index + 1)} onUnfile={() => props.onMove(field, null, 0)} /> ))} {props.canEdit ? ( ) : null}
); } /** * One field row of a group. * * The export shows the row's state through its tint and two trailing glyphs * (pin = always visible, lock = read-only) and keeps the row itself at 32px. The * reorder and unfile controls only appear on the selected or hovered row so a * group stays as compact as in the export while remaining operable without a * drag gesture. */ function TemplateFieldRow(props: { field: TemplateFieldVM; name: string; selected: boolean; canEdit: boolean; isFirst: boolean; isLast: boolean; onSelect: () => void; onMoveUp: () => void; onMoveDown: () => void; onUnfile: () => void; }) { const { t } = useTranslation(); const { field } = props; const tint = field.gesperrt ? ROW_LOCKED : field.istSystem ? ROW_SYSTEM : ROW_CUSTOM; const idBase = `ui.projects.fieldTemplate.field.${field.id}`; return (
{props.canEdit ? (
} disabled={props.isFirst} aria-label={t("projects.fieldTemplate.moveUp")} onClick={props.onMoveUp} data-ui-id={`${idBase}.up`} /> } disabled={props.isLast} aria-label={t("projects.fieldTemplate.moveDown")} onClick={props.onMoveDown} data-ui-id={`${idBase}.down`} /> {/* Always-visible fields cannot be moved back into the pool; the service refuses it anyway. */} {!field.alwaysVisible ? ( } aria-label={t("projects.fieldTemplate.moveToPool")} onClick={props.onUnfile} data-ui-id={`${idBase}.unfile`} /> ) : null}
) : null} {field.alwaysVisible ? ( ) : null} {field.gesperrt ? : null}
); } /** Right-hand inspector: label, type, options, hint, required, actions. */ function SelectedFieldInspector(props: { field: TemplateFieldVM; fieldName: string; data: PipelineFieldTemplateData; submitting: boolean; onSubmit: FieldTemplateSubmit; onDeleted: () => void; }) { const { t } = useTranslation(); const { field, data } = props; const [draft, setDraft] = useState({ hinweis: field.hinweis ?? "", pflicht: field.pflicht, pflichtAbStageId: field.pflichtAbStageId ?? NO_STAGE, gesperrt: field.gesperrt, }); const editable = data.canEdit; const isCustom = field.definitionId !== null; return (
{/* System fields have no CustomFieldDefinition: their name and type are a fact of the code, not a setting. Custom fields get the real editors. */} {isCustom ? ( ) : ( <> {}} data-ui-id="ui.projects.fieldTemplate.inspector.label" /> {field.datentyp ? (
{t("projects.fieldTemplate.inspector.type")} {t(`projects.fieldTemplate.type.${field.datentyp}`)}
) : null}
{t("projects.fieldTemplate.inspector.systemHint")}
)}
{t("projects.fieldTemplate.inspector.required")} {t("projects.fieldTemplate.inspector.requiredHelp")}
setDraft((current) => ({ ...current, pflicht: checked }))} aria-label={t("projects.fieldTemplate.inspector.required")} data-ui-id="ui.projects.fieldTemplate.inspector.required" />
{/* "Pflicht ab Board-Spalte": only meaningful while the field is required — disabled rather than hidden, as in the export. */}
{t("projects.fieldTemplate.inspector.locked")} setDraft((current) => ({ ...current, gesperrt: checked }))} aria-label={t("projects.fieldTemplate.inspector.locked")} data-ui-id="ui.projects.fieldTemplate.inspector.locked" />
{editable ? (
{t("projects.fieldTemplate.inspector.actions")}
{/* System fields are never deletable — the service refuses it too. */} {!field.istSystem && !field.alwaysVisible ? ( ) : null}
{!field.istSystem && !field.alwaysVisible ? (
{t("projects.fieldTemplate.inspector.deleteHint")}
) : null}
) : null}
); } /** * WF-P8 S05 "Feldbezeichnung", "Feldtyp" and "Auswahlmöglichkeiten" of a custom * field. * * Label, type and options belong to the tenant-wide CustomFieldDefinition, not * to this pipeline's field config, so they save through their own intent and * their own button — mixing them into the config save would put two writes * behind one click and make a rejected retype look like a failed hint change. * * "Mehrfachauswahl" is not a separate flag: `select` and `multiselect` are two * values of the same type enum, and a flag next to them could contradict the * type. The switch moves between the two. */ function FieldDefinitionEditor(props: { field: TemplateFieldVM; editable: boolean; submitting: boolean; onSubmit: FieldTemplateSubmit }) { const { t } = useTranslation(); const { field, editable } = props; const [label, setLabel] = useState(field.label); const [datentyp, setDatentyp] = useState(field.datentyp ?? "text"); const [options, setOptions] = useState([...field.optionen]); const showOptions = datentypHasOptions(datentyp); function patchOption(index: number, patch: Partial) { setOptions((current) => current.map((option, position) => (position === index ? { ...option, ...patch } : option))); } function moveOption(index: number, direction: -1 | 1) { const target = index + direction; setOptions((current) => { if (target < 0 || target >= current.length) return current; const next = [...current]; const [moved] = next.splice(index, 1); next.splice(target, 0, moved!); return next; }); } function save() { props.onSubmit("updateCustomField", { definitionId: field.definitionId ?? "", label, datentyp, // Options travel even when the type carries none: switching a select to // text has to clear them, otherwise they would resurface on a switch back. optionen: JSON.stringify(showOptions ? options : []), }); } return (
setLabel(event.target.value)} data-ui-id="ui.projects.fieldTemplate.inspector.label" /> {showOptions ? (
{t("projects.fieldTemplate.inspector.options")} {t("projects.fieldTemplate.inspector.optionCount", { count: options.length })}
{options.length === 0 ? {t("projects.fieldTemplate.inspector.optionsEmpty")} : null} {options.map((option, index) => (
{/* The export reorders options by dragging the grip. The arrows stay for keyboard use and only surface on hover/focus, so the row keeps the export's height. */}
} disabled={!editable || index === 0} onClick={() => moveOption(index, -1)} aria-label={t("projects.fieldTemplate.moveUp")} data-ui-id={`ui.projects.fieldTemplate.inspector.option.${index}.up`} /> } disabled={!editable || index === options.length - 1} onClick={() => moveOption(index, 1)} aria-label={t("projects.fieldTemplate.moveDown")} data-ui-id={`ui.projects.fieldTemplate.inspector.option.${index}.down`} />
patchOption(index, { label: event.target.value })} data-ui-id={`ui.projects.fieldTemplate.inspector.option.${index}.label`} /> patchOption(index, { color: event.target.value })} aria-label={t("projects.fieldTemplate.inspector.optionColor")} data-ui-id={`ui.projects.fieldTemplate.inspector.option.${index}.color`} /> } disabled={!editable} onClick={() => setOptions((current) => current.filter((_, position) => position !== index))} aria-label={t("projects.fieldTemplate.inspector.removeOption")} data-ui-id={`ui.projects.fieldTemplate.inspector.option.${index}.remove`} />
))} {editable ? ( ) : null}
{t("projects.fieldTemplate.inspector.multiple")} {t("projects.fieldTemplate.inspector.multipleHelp")}
setDatentyp(checked ? "multiselect" : "select")} aria-label={t("projects.fieldTemplate.inspector.multiple")} data-ui-id="ui.projects.fieldTemplate.inspector.multiple" />
) : null} {editable ? ( ) : null}
); } /** Type list re-exported so the route can validate a submitted type. */ export { TEMPLATE_FIELD_TYPES }; export default PipelineFieldTemplatePage;