1084 lines
51 KiB
TypeScript
1084 lines
51 KiB
TypeScript
// 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<string, string>) => 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<string | null>(null);
|
|
const [poolDialogGroupId, setPoolDialogGroupId] = useState<string | null>(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<string | null>(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 (
|
|
<PageShell uiId="ui.projects.fieldTemplate" className="bg-surface-neutral-primary">
|
|
<PageHeader
|
|
uiId="ui.projects.fieldTemplate.header"
|
|
dense
|
|
icon={<FeatherLayoutTemplate className={PAGE_HEADER_ICON_CLASS} />}
|
|
title={t("projects.fieldTemplate.title")}
|
|
subtitle={
|
|
<span className="flex items-center gap-1.5">
|
|
<FeatherKanbanSquare className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
|
|
{t("projects.fieldTemplate.board", { board: data.pipelineName })}
|
|
</span>
|
|
}
|
|
actions={
|
|
<>
|
|
<AppLink href={props.backHref} className="no-underline" data-ui-id="ui.projects.fieldTemplate.cancel">
|
|
<Button variant="tertiary" icon={<FeatherX />}>
|
|
{t("projects.actions.cancel")}
|
|
</Button>
|
|
</AppLink>
|
|
<AppLink href={props.backHref} className="no-underline" data-ui-id="ui.projects.fieldTemplate.done">
|
|
<Button className="w-32 flex-none" icon={<FeatherCheck />}>
|
|
{t("projects.fieldTemplate.done")}
|
|
</Button>
|
|
</AppLink>
|
|
</>
|
|
}
|
|
/>
|
|
|
|
{/* Split body: configuration on the left, the selected field on the right.
|
|
No independently scrolling panes — the app shell's <main> has no
|
|
definite height, so `overflow-y-auto` here would collapse the screen. */}
|
|
<div className="flex w-full items-stretch mobile:flex-col">
|
|
<div className="flex min-w-[0px] grow shrink-0 basis-0 flex-col gap-4 px-8 py-6 mobile:px-4">
|
|
{props.errorKey ? (
|
|
<div data-ui-id="ui.projects.fieldTemplate.error">
|
|
<BadgeFeedback farbe="subtle-negative">{t(props.errorKey)}</BadgeFeedback>
|
|
</div>
|
|
) : null}
|
|
|
|
<div className="flex w-full flex-col items-start overflow-hidden rounded-md border border-solid border-border-default bg-surface-neutral-secondary">
|
|
{/* --- Rules note --- */}
|
|
<div className="flex w-full items-start gap-3 border-b border-solid border-border-default px-4 py-3 mobile:flex-col">
|
|
<FeatherInfo className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
|
|
<div className="flex min-w-[0px] grow shrink-0 basis-0 flex-col items-start gap-1">
|
|
<span className={cardTitle}>{t("projects.fieldTemplate.rules.title")}</span>
|
|
<span className="break-words text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.rules.body")}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* --- Legend --- */}
|
|
<div
|
|
className="flex w-full flex-wrap items-center gap-x-6 gap-y-1 border-b border-solid border-border-default px-4 py-2 mobile:flex-col mobile:flex-nowrap mobile:items-start mobile:gap-2"
|
|
data-ui-id="ui.projects.fieldTemplate.legend"
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<span className={CHIP_SYSTEM}>{t("projects.fieldTemplate.systemShort")}</span>
|
|
<span className={legendText}>{t("projects.fieldTemplate.legend.systemBlue")}</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<FeatherWandSparkles className={legendIcon} />
|
|
<span className={legendText}>{t("projects.fieldTemplate.legend.customFree")}</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<FeatherPin className={legendIcon} />
|
|
<span className={legendText}>{t("projects.fieldTemplate.legend.pinned")}</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<FeatherLock className={legendIcon} />
|
|
<span className={legendText}>{t("projects.fieldTemplate.legend.lockedRead")}</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* --- Field groups --- */}
|
|
<div className="grid w-full grid-cols-2 items-start gap-3 px-4 py-4 mobile:grid-cols-1">
|
|
{data.groups.map((group) => (
|
|
<TemplateGroupCard
|
|
key={group.id}
|
|
group={group}
|
|
canEdit={data.canEdit}
|
|
selectedFieldId={selectedFieldId}
|
|
nameOf={nameOf}
|
|
onSelect={setSelectedFieldId}
|
|
onMove={moveField}
|
|
onAddField={() => openPoolDialog(group.id)}
|
|
onDeleteGroup={() => submit("deleteFieldGroup", { groupId: group.id })}
|
|
/>
|
|
))}
|
|
|
|
{/* --- New group --- */}
|
|
{data.canEdit ? (
|
|
<div
|
|
className="flex flex-col items-start justify-between gap-3 rounded-md border border-dashed border-border-strong bg-surface-neutral-primary px-3 py-3"
|
|
data-ui-id="ui.projects.fieldTemplate.newGroup"
|
|
>
|
|
<div className="flex flex-col items-start gap-1">
|
|
<span className={cardTitle}>{t("projects.fieldTemplate.newGroup.title")}</span>
|
|
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.newGroup.body")}
|
|
</span>
|
|
</div>
|
|
{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.
|
|
<div className="grid w-full items-end gap-2 sm:grid-cols-[1fr_auto]">
|
|
<TextInput label={t("projects.fieldTemplate.newGroup.name")} showLabel fillContainer className="w-full">
|
|
<TextInput.Input
|
|
autoFocus
|
|
value={newGroupName}
|
|
onChange={(event) => setNewGroupName(event.target.value)}
|
|
data-ui-id="ui.projects.fieldTemplate.newGroup.name"
|
|
/>
|
|
</TextInput>
|
|
<Button
|
|
size="small"
|
|
icon={<FeatherPlus />}
|
|
disabled={newGroupName.trim().length === 0}
|
|
loading={props.submitting}
|
|
onClick={() => {
|
|
submit("createFieldGroup", { name: newGroupName });
|
|
setNewGroupName("");
|
|
setNewGroupOpen(false);
|
|
}}
|
|
data-ui-id="ui.projects.fieldTemplate.newGroup.submit"
|
|
>
|
|
{t("projects.fieldTemplate.newGroup.submit")}
|
|
</Button>
|
|
</div>
|
|
) : (
|
|
<Button
|
|
variant="tertiary"
|
|
size="small"
|
|
icon={<FeatherPlus />}
|
|
onClick={() => setNewGroupOpen(true)}
|
|
data-ui-id="ui.projects.fieldTemplate.newGroup.open"
|
|
>
|
|
{t("projects.fieldTemplate.newGroup.submit")}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
|
|
{/* --- Bestandsfelder strip --- */}
|
|
<div
|
|
className="flex w-full flex-col items-start gap-2 border-t border-solid border-border-default bg-surface-neutral-secondary px-4 py-3"
|
|
data-ui-id="ui.projects.fieldTemplate.pool"
|
|
>
|
|
<div className="flex w-full flex-wrap items-center gap-2">
|
|
<FeatherArchive className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
|
|
<span className="uppercase tracking-wide text-body-extra-small-semibold-0 font-body-extra-small-semibold-0 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.pool.title")}
|
|
</span>
|
|
<span className={`min-w-[0px] grow shrink-0 basis-0 break-words ${countText}`}>{t("projects.fieldTemplate.pool.short")}</span>
|
|
<span className={countText}>{t("projects.fieldTemplate.fieldCount", { count: data.poolFields.length })}</span>
|
|
</div>
|
|
{data.poolFields.length === 0 ? (
|
|
<span className={countText}>{t("projects.fieldTemplate.pool.empty")}</span>
|
|
) : (
|
|
<div className="flex w-full flex-wrap items-start gap-1.5">
|
|
{data.poolFields.map((field) => (
|
|
<button
|
|
key={field.id}
|
|
type="button"
|
|
className={`flex min-h-[28px] items-center gap-1.5 rounded-md border border-dashed px-2 py-0.5 ${
|
|
selectedFieldId === field.id ? "border-border-strong bg-surface-neutral-tertiary" : "border-border-default bg-surface-neutral-primary"
|
|
}`}
|
|
onClick={() => setSelectedFieldId(field.id)}
|
|
data-row-id={field.id}
|
|
data-ui-id={`ui.projects.fieldTemplate.pool.${field.id}`}
|
|
>
|
|
<FeatherGripVertical className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-subtle" />
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary">{nameOf(field)}</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* --- 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. */}
|
|
<div
|
|
className="flex w-full flex-col items-start gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-4"
|
|
data-ui-id="ui.projects.fieldTemplate.preview"
|
|
>
|
|
<div className="flex w-full flex-col items-start gap-1">
|
|
<span className={cardTitle}>{t("projects.fieldTemplate.preview.title")}</span>
|
|
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.preview.body")}
|
|
</span>
|
|
</div>
|
|
{data.groups.every((group) => group.fields.filter((field) => field.sichtbar).length === 0) ? (
|
|
<EmptyState title={t("projects.fieldTemplate.preview.empty")} />
|
|
) : (
|
|
<div className="grid w-full grid-cols-2 items-start gap-x-6 gap-y-3 mobile:grid-cols-1">
|
|
{data.groups.map((group) => {
|
|
const visible = group.fields.filter((field) => field.sichtbar);
|
|
if (visible.length === 0) return null;
|
|
return (
|
|
<div key={group.id} className="flex w-full flex-col gap-1" data-ui-id={`ui.projects.fieldTemplate.preview.${group.id}`}>
|
|
<span className={groupTitle}>{group.name}</span>
|
|
{visible.map((field) => (
|
|
<div
|
|
key={field.id}
|
|
className="flex w-full items-center justify-between gap-3 border-b border-solid border-border-default py-1 last:border-b-0"
|
|
data-ui-id={`ui.projects.fieldTemplate.preview.field.${field.id}`}
|
|
>
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary">
|
|
{nameOf(field)}
|
|
{field.pflicht ? " *" : ""}
|
|
</span>
|
|
<span className={countText}>{field.datentyp ? t(`projects.fieldTemplate.type.${field.datentyp}`) : "—"}</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="w-px flex-none self-stretch bg-border-default mobile:hidden" />
|
|
|
|
{/* --- Selected field inspector --- */}
|
|
<div className="w-[420px] flex-none bg-surface-neutral-secondary mobile:w-full" data-ui-id="ui.projects.fieldTemplate.inspector">
|
|
<div className="flex w-full flex-col items-start">
|
|
<div className="flex w-full flex-col items-start gap-1 border-b border-solid border-border-default px-5 py-5">
|
|
<span className="text-body-large font-body-large text-text-neutral-primary">{t("projects.fieldTemplate.inspector.title")}</span>
|
|
{selectedField ? (
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<span className={mutedText}>
|
|
{selectedGroup
|
|
? t("projects.fieldTemplate.inspector.group", { group: selectedGroup.name })
|
|
: t("projects.fieldTemplate.inspector.groupNone")}
|
|
</span>
|
|
<div className="flex items-center gap-1 rounded-sm bg-surface-neutral-tertiary px-1.5 py-0.5">
|
|
<FeatherWandSparkles className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-icon-neutral-tertiary" />
|
|
<span className={legendText}>
|
|
{t(selectedField.istSystem ? "projects.fieldTemplate.systemShort" : "projects.fieldTemplate.legend.custom")}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<span className={mutedText}>{t("projects.fieldTemplate.inspector.empty")}</span>
|
|
)}
|
|
</div>
|
|
{selectedField ? (
|
|
<SelectedFieldInspector
|
|
key={selectedField.id}
|
|
field={selectedField}
|
|
fieldName={nameOf(selectedField)}
|
|
data={data}
|
|
submitting={props.submitting}
|
|
onSubmit={submit}
|
|
onDeleted={() => setSelectedFieldId(null)}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* --- 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. --- */}
|
|
<Dialog open={poolDialogGroupId !== null} onOpenChange={(open) => (open ? null : setPoolDialogGroupId(null))}>
|
|
<Dialog.Content className="w-[460px] max-w-[92vw] gap-0 p-0" data-ui-id="ui.projects.fieldTemplate.poolDialog">
|
|
<div className="flex w-full items-start gap-3 border-b border-solid border-border-default px-5 py-4">
|
|
<div className="flex min-w-[0px] grow shrink-0 basis-0 flex-col items-start gap-1">
|
|
<span className="w-full break-words text-body-default-semibold-0 font-body-default-semibold-0 text-text-neutral-primary">
|
|
{t("projects.fieldTemplate.poolDialog.title")}
|
|
</span>
|
|
<span className="w-full break-words text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.poolDialog.subtitle", { group: poolDialogGroup?.name ?? "" })}
|
|
</span>
|
|
</div>
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
square
|
|
icon={<FeatherX />}
|
|
aria-label={t("projects.actions.cancel")}
|
|
onClick={() => setPoolDialogGroupId(null)}
|
|
data-ui-id="ui.projects.fieldTemplate.poolDialog.close"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex w-full flex-col items-start px-5 py-4">
|
|
<TextInput className="h-auto w-full flex-none" fillContainer label="" helpText="">
|
|
<TextInput.Input
|
|
type="search"
|
|
placeholder={t("projects.fieldTemplate.poolDialog.search")}
|
|
value={poolSearch}
|
|
onChange={(event) => setPoolSearch(event.target.value)}
|
|
data-ui-id="ui.projects.fieldTemplate.poolDialog.search"
|
|
/>
|
|
</TextInput>
|
|
</div>
|
|
|
|
{poolMatches.length === 0 ? (
|
|
<div className="w-full border-t border-solid border-border-default px-5 py-4">
|
|
<EmptyState title={t("projects.fieldTemplate.poolDialog.empty")} />
|
|
</div>
|
|
) : (
|
|
<div className="flex max-h-[280px] w-full flex-col items-start overflow-y-auto border-t border-solid border-border-default">
|
|
{poolMatches.map((field) => {
|
|
const picked = poolPick === field.id;
|
|
return (
|
|
<button
|
|
key={field.id}
|
|
type="button"
|
|
className={
|
|
picked
|
|
? "flex w-full items-center gap-3 border-b border-solid border-border-default bg-surface-feedback-subtle-information px-5 py-2.5 text-left"
|
|
: "flex w-full items-center gap-3 border-b border-solid border-border-default px-5 py-2.5 text-left hover:bg-surface-neutral-tertiary"
|
|
}
|
|
// Clicking the picked row again clears it: the row is a
|
|
// toggle, so taking a choice back must not need the
|
|
// detour of picking something else first.
|
|
onClick={() => setPoolPick((current) => (current === field.id ? null : field.id))}
|
|
data-row-id={field.id}
|
|
data-ui-id={`ui.projects.fieldTemplate.poolDialog.option.${field.id}`}
|
|
aria-pressed={picked}
|
|
>
|
|
<span
|
|
className={
|
|
picked
|
|
? "min-w-[0px] grow shrink-0 basis-0 break-words text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary"
|
|
: "min-w-[0px] grow shrink-0 basis-0 break-words text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary"
|
|
}
|
|
>
|
|
{nameOf(field)}
|
|
</span>
|
|
{field.datentyp ? (
|
|
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-subtle">
|
|
{t(`projects.fieldTemplate.type.${field.datentyp}`)}
|
|
</span>
|
|
) : null}
|
|
{picked ? <FeatherCheck aria-hidden className="flex-none text-body-small-regular-0 text-icon-feedback-information" /> : null}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
|
|
<div className="flex w-full items-center justify-end gap-2 border-t border-solid border-border-default bg-surface-neutral-primary px-5 py-3 mobile:flex-col mobile:items-stretch">
|
|
<Button
|
|
className="mobile:w-full"
|
|
variant="tertiary"
|
|
size="small"
|
|
onClick={() => setPoolDialogGroupId(null)}
|
|
data-ui-id="ui.projects.fieldTemplate.poolDialog.cancel"
|
|
>
|
|
{t("projects.actions.cancel")}
|
|
</Button>
|
|
<Button
|
|
className="mobile:w-full"
|
|
size="small"
|
|
icon={<FeatherCheck />}
|
|
// Nothing picked yet means there is nothing to add — a live
|
|
// button that silently does nothing reads as a broken dialog.
|
|
disabled={!poolPick}
|
|
loading={props.submitting}
|
|
onClick={confirmPoolPick}
|
|
data-ui-id="ui.projects.fieldTemplate.poolDialog.confirm"
|
|
>
|
|
{t("projects.fieldTemplate.poolDialog.add")}
|
|
</Button>
|
|
</div>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
/** 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 (
|
|
<div
|
|
className="flex flex-col items-start gap-2 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-2 py-2"
|
|
data-ui-id={`ui.projects.fieldTemplate.group.${group.id}`}
|
|
data-row-id={group.id}
|
|
>
|
|
<div className="flex w-full items-center gap-2 px-1">
|
|
<FeatherGripVertical className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-subtle" />
|
|
<span className={groupTitle}>{group.name}</span>
|
|
<span className={countText}>{t("projects.fieldTemplate.fieldCount", { count: group.fieldCount })}</span>
|
|
{props.canEdit && !group.istSystem ? (
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
icon={<FeatherTrash2 />}
|
|
aria-label={t("projects.fieldTemplate.group.delete")}
|
|
onClick={props.onDeleteGroup}
|
|
data-ui-id={`ui.projects.fieldTemplate.group.${group.id}.delete`}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
|
|
<div className="flex w-full flex-col items-start gap-1.5">
|
|
{group.fields.length === 0 ? <span className={`px-1.5 ${countText}`}>{t("projects.fieldTemplate.group.empty")}</span> : null}
|
|
{group.fields.map((field, index) => (
|
|
<TemplateFieldRow
|
|
key={field.id}
|
|
field={field}
|
|
name={props.nameOf(field)}
|
|
selected={props.selectedFieldId === field.id}
|
|
canEdit={props.canEdit}
|
|
isFirst={index === 0}
|
|
isLast={index === group.fields.length - 1}
|
|
onSelect={() => 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 ? (
|
|
<button
|
|
type="button"
|
|
className="flex min-h-[32px] w-full items-center gap-2 rounded-md border border-dashed border-border-strong bg-surface-neutral-primary px-1.5 py-0.5"
|
|
onClick={props.onAddField}
|
|
data-ui-id={`ui.projects.fieldTemplate.group.${group.id}.addExisting`}
|
|
>
|
|
<FeatherPlus className="text-body-large font-body-large text-icon-neutral-tertiary" />
|
|
<span className="text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.addField")}
|
|
</span>
|
|
</button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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 (
|
|
<div
|
|
className={`group/row flex min-h-[32px] w-full items-center gap-2 rounded-md border border-dashed px-1.5 py-0.5 ${tint} ${
|
|
props.selected ? "ring-1 ring-brand-brand-primary-border-strong-default" : ""
|
|
}`}
|
|
data-row-id={field.id}
|
|
data-ui-id={idBase}
|
|
>
|
|
<FeatherGripVertical className="text-body-large font-body-large text-icon-neutral-subtle" />
|
|
<button
|
|
type="button"
|
|
className="flex min-w-[0px] grow shrink-0 basis-0 items-center gap-1.5 text-left"
|
|
onClick={props.onSelect}
|
|
data-ui-id={`${idBase}.select`}
|
|
>
|
|
<span className={field.gesperrt ? rowLabel.replace("text-text-neutral-primary", "text-text-neutral-subtle") : rowLabel}>{props.name}</span>
|
|
{field.istSystem ? <span className={CHIP_SYSTEM}>{t("projects.fieldTemplate.systemShort")}</span> : null}
|
|
{field.pflicht ? (
|
|
<span className="text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-tertiary" title={t("projects.fieldTemplate.required")}>
|
|
*
|
|
</span>
|
|
) : null}
|
|
</button>
|
|
|
|
{props.canEdit ? (
|
|
<div className="hidden items-center gap-0.5 group-hover/row:flex group-focus-within/row:flex">
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
icon={<FeatherArrowUp />}
|
|
disabled={props.isFirst}
|
|
aria-label={t("projects.fieldTemplate.moveUp")}
|
|
onClick={props.onMoveUp}
|
|
data-ui-id={`${idBase}.up`}
|
|
/>
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
icon={<FeatherArrowDown />}
|
|
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 ? (
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
icon={<FeatherArchive />}
|
|
aria-label={t("projects.fieldTemplate.moveToPool")}
|
|
onClick={props.onUnfile}
|
|
data-ui-id={`${idBase}.unfile`}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
) : null}
|
|
|
|
{field.alwaysVisible ? (
|
|
<FeatherPin className={`${legendIcon} flex-none`} aria-label={t("projects.fieldTemplate.legend.pinned")} />
|
|
) : null}
|
|
{field.gesperrt ? <FeatherLock className={`${legendIcon} flex-none`} aria-label={t("projects.fieldTemplate.locked")} /> : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/** 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 (
|
|
<div className="flex w-full flex-col items-start gap-5 px-5 py-5">
|
|
{/* 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 ? (
|
|
<FieldDefinitionEditor field={field} editable={editable} submitting={props.submitting} onSubmit={props.onSubmit} />
|
|
) : (
|
|
<>
|
|
<TextInput
|
|
className="h-auto w-full flex-none"
|
|
fillContainer
|
|
showLabel
|
|
disabled
|
|
label={t("projects.fieldTemplate.inspector.label")}
|
|
helpText={t("projects.fieldTemplate.inspector.labelHelp")}
|
|
>
|
|
<TextInput.Input value={props.fieldName} readOnly onChange={() => {}} data-ui-id="ui.projects.fieldTemplate.inspector.label" />
|
|
</TextInput>
|
|
{field.datentyp ? (
|
|
<div className="flex w-full flex-col items-start gap-1">
|
|
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.inspector.type")}
|
|
</span>
|
|
<span className={mutedText}>{t(`projects.fieldTemplate.type.${field.datentyp}`)}</span>
|
|
</div>
|
|
) : null}
|
|
<div className="flex w-full items-start gap-2">
|
|
<FeatherInfo className={`${legendIcon} flex-none`} />
|
|
<span className="min-w-[0px] grow shrink-0 basis-0 break-words text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.inspector.systemHint")}
|
|
</span>
|
|
</div>
|
|
</>
|
|
)}
|
|
|
|
<TextArea
|
|
className="h-auto w-full flex-none"
|
|
variant="outline"
|
|
showLabel
|
|
label={t("projects.fieldTemplate.inspector.hint")}
|
|
helpText={t("projects.fieldTemplate.inspector.hintHelp")}
|
|
>
|
|
<TextArea.Input
|
|
value={draft.hinweis}
|
|
disabled={!editable}
|
|
onChange={(event) => setDraft((current) => ({ ...current, hinweis: event.target.value }))}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.hint"
|
|
/>
|
|
</TextArea>
|
|
|
|
<div className="flex w-full flex-col items-start gap-4">
|
|
<div className="h-px w-full flex-none bg-border-default" />
|
|
<div className="flex w-full items-center justify-between gap-4">
|
|
<div className="flex flex-col items-start gap-0.5">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
|
{t("projects.fieldTemplate.inspector.required")}
|
|
</span>
|
|
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.inspector.requiredHelp")}
|
|
</span>
|
|
</div>
|
|
<Switch
|
|
checked={draft.pflicht}
|
|
disabled={!editable}
|
|
onCheckedChange={(checked) => setDraft((current) => ({ ...current, pflicht: checked }))}
|
|
aria-label={t("projects.fieldTemplate.inspector.required")}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.required"
|
|
/>
|
|
</div>
|
|
|
|
{/* "Pflicht ab Board-Spalte": only meaningful while the field is
|
|
required — disabled rather than hidden, as in the export. */}
|
|
<Select
|
|
className="h-auto w-full flex-none"
|
|
variant="outline"
|
|
showLabel
|
|
label={t("projects.fieldTemplate.inspector.requiredFrom")}
|
|
helpText={t("projects.fieldTemplate.inspector.requiredFromHelp")}
|
|
disabled={!editable || !draft.pflicht}
|
|
value={draft.pflichtAbStageId}
|
|
onValueChange={(value) => setDraft((current) => ({ ...current, pflichtAbStageId: value }))}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.requiredFrom"
|
|
>
|
|
<Select.Item value={NO_STAGE}>{t("projects.fieldTemplate.inspector.requiredAlways")}</Select.Item>
|
|
{data.stages.map((stage) => (
|
|
<Select.Item key={stage.id} value={stage.id}>
|
|
{t("projects.fieldTemplate.inspector.fromStage", { stage: stage.name })}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
|
|
<div className="flex w-full items-center justify-between gap-4">
|
|
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
|
|
{t("projects.fieldTemplate.inspector.locked")}
|
|
</span>
|
|
<Switch
|
|
checked={draft.gesperrt}
|
|
disabled={!editable}
|
|
onCheckedChange={(checked) => setDraft((current) => ({ ...current, gesperrt: checked }))}
|
|
aria-label={t("projects.fieldTemplate.inspector.locked")}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.locked"
|
|
/>
|
|
</div>
|
|
<div className="h-px w-full flex-none bg-border-default" />
|
|
</div>
|
|
|
|
{editable ? (
|
|
<div className="flex w-full flex-col items-start gap-3">
|
|
<span className={cardTitle}>{t("projects.fieldTemplate.inspector.actions")}</span>
|
|
<div className="flex w-full flex-col items-start gap-2">
|
|
<Button
|
|
className="w-full"
|
|
loading={props.submitting}
|
|
onClick={() =>
|
|
props.onSubmit("updateTemplateField", {
|
|
fieldConfigId: field.id,
|
|
fieldKey: field.fieldKey,
|
|
hinweis: draft.hinweis,
|
|
pflicht: draft.pflicht ? "1" : "",
|
|
pflichtAbStageId: draft.pflichtAbStageId === NO_STAGE ? "" : draft.pflichtAbStageId,
|
|
gesperrt: draft.gesperrt ? "1" : "",
|
|
})
|
|
}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.save"
|
|
>
|
|
{t("projects.actions.save")}
|
|
</Button>
|
|
<div className="flex w-full items-center gap-2">
|
|
<Button
|
|
className="h-8 grow shrink-0 basis-0"
|
|
variant="secondary"
|
|
size="small"
|
|
icon={<FeatherCopy />}
|
|
onClick={() => props.onSubmit("duplicateTemplateField", { fieldConfigId: field.id })}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.duplicate"
|
|
>
|
|
{t("projects.fieldTemplate.inspector.duplicate")}
|
|
</Button>
|
|
{/* System fields are never deletable — the service refuses it too. */}
|
|
{!field.istSystem && !field.alwaysVisible ? (
|
|
<Button
|
|
className="h-8 grow shrink-0 basis-0"
|
|
variant="destructive"
|
|
size="small"
|
|
icon={<FeatherTrash2 />}
|
|
onClick={() => {
|
|
props.onSubmit("deleteTemplateField", { fieldConfigId: field.id });
|
|
props.onDeleted();
|
|
}}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.delete"
|
|
>
|
|
{t("projects.fieldTemplate.inspector.delete")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
{!field.istSystem && !field.alwaysVisible ? (
|
|
<div className="flex w-full items-start gap-2">
|
|
<FeatherWandSparkles className={`${legendIcon} flex-none`} />
|
|
<span className="min-w-[0px] grow shrink-0 basis-0 break-words text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.inspector.deleteHint")}
|
|
</span>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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<string>(field.datentyp ?? "text");
|
|
const [options, setOptions] = useState<CustomFieldOption[]>([...field.optionen]);
|
|
const showOptions = datentypHasOptions(datentyp);
|
|
|
|
function patchOption(index: number, patch: Partial<CustomFieldOption>) {
|
|
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 (
|
|
<div className="flex w-full flex-col items-start gap-5" data-ui-id="ui.projects.fieldTemplate.inspector.typeEditor">
|
|
<TextInput
|
|
className="h-auto w-full flex-none"
|
|
fillContainer
|
|
showLabel
|
|
label={t("projects.fieldTemplate.inspector.label")}
|
|
helpText={t("projects.fieldTemplate.inspector.labelHelp")}
|
|
>
|
|
<TextInput.Input
|
|
value={label}
|
|
disabled={!editable}
|
|
onChange={(event) => setLabel(event.target.value)}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.label"
|
|
/>
|
|
</TextInput>
|
|
|
|
<Select
|
|
className="h-auto w-full flex-none"
|
|
variant="outline"
|
|
showLabel
|
|
label={t("projects.fieldTemplate.inspector.type")}
|
|
helpText={t("projects.fieldTemplate.inspector.typeHelp")}
|
|
disabled={!editable}
|
|
value={datentyp}
|
|
onValueChange={setDatentyp}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.type"
|
|
>
|
|
{TEMPLATE_FIELD_TYPES.map((type) => (
|
|
<Select.Item key={type} value={type}>
|
|
{t(`projects.fieldTemplate.type.${type}`)}
|
|
</Select.Item>
|
|
))}
|
|
</Select>
|
|
|
|
{showOptions ? (
|
|
<div
|
|
className="flex w-full flex-col items-start gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-3 py-3"
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.options"
|
|
>
|
|
<div className="flex w-full items-center gap-2">
|
|
<span className={`min-w-[0px] grow shrink-0 basis-0 break-words ${cardTitle}`}>{t("projects.fieldTemplate.inspector.options")}</span>
|
|
<span className={countText}>{t("projects.fieldTemplate.inspector.optionCount", { count: options.length })}</span>
|
|
</div>
|
|
|
|
<div className="flex w-full flex-col items-start gap-1.5">
|
|
{options.length === 0 ? <span className={countText}>{t("projects.fieldTemplate.inspector.optionsEmpty")}</span> : null}
|
|
{options.map((option, index) => (
|
|
<div
|
|
key={`${option.value}-${index}`}
|
|
className="group/option flex min-h-[32px] w-full items-center gap-2 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-1.5 py-0.5"
|
|
data-ui-id={`ui.projects.fieldTemplate.inspector.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. */}
|
|
<FeatherGripVertical className="text-body-large font-body-large text-icon-neutral-subtle group-hover/option:hidden group-focus-within/option:hidden" />
|
|
<div className="hidden items-center gap-0.5 group-hover/option:flex group-focus-within/option:flex">
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
icon={<FeatherArrowUp />}
|
|
disabled={!editable || index === 0}
|
|
onClick={() => moveOption(index, -1)}
|
|
aria-label={t("projects.fieldTemplate.moveUp")}
|
|
data-ui-id={`ui.projects.fieldTemplate.inspector.option.${index}.up`}
|
|
/>
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
icon={<FeatherArrowDown />}
|
|
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`}
|
|
/>
|
|
</div>
|
|
<input
|
|
className="min-w-[0px] grow shrink-0 basis-0 border-none bg-transparent text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-primary outline-none"
|
|
value={option.label}
|
|
disabled={!editable}
|
|
placeholder={t("projects.fieldTemplate.inspector.optionLabel")}
|
|
aria-label={t("projects.fieldTemplate.inspector.optionLabel")}
|
|
onChange={(event) => patchOption(index, { label: event.target.value })}
|
|
data-ui-id={`ui.projects.fieldTemplate.inspector.option.${index}.label`}
|
|
/>
|
|
<input
|
|
type="color"
|
|
// The export draws the option colour as a 12px dot. A native
|
|
// colour input paints a square swatch with its own chrome, so
|
|
// the swatch pseudo-elements are what has to be rounded.
|
|
className="h-3 w-3 flex-none cursor-pointer appearance-none rounded-full border-none bg-transparent p-0 [&::-webkit-color-swatch-wrapper]:p-0 [&::-webkit-color-swatch]:rounded-full [&::-webkit-color-swatch]:border-none"
|
|
value={option.color ?? "#cbd5e1"}
|
|
disabled={!editable}
|
|
onChange={(event) => patchOption(index, { color: event.target.value })}
|
|
aria-label={t("projects.fieldTemplate.inspector.optionColor")}
|
|
data-ui-id={`ui.projects.fieldTemplate.inspector.option.${index}.color`}
|
|
/>
|
|
<IconButton
|
|
variant="ghost"
|
|
size="small"
|
|
icon={<FeatherX />}
|
|
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`}
|
|
/>
|
|
</div>
|
|
))}
|
|
|
|
{editable ? (
|
|
<button
|
|
type="button"
|
|
className="flex min-h-[32px] w-full items-center gap-2 rounded-md border border-dashed border-border-strong bg-surface-neutral-primary px-1.5 py-0.5"
|
|
onClick={() =>
|
|
// An empty value is filled from the label on save; existing
|
|
// options keep their stored value so field data stays matched.
|
|
setOptions((current) => [...current, { value: "", label: "", color: null }])
|
|
}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.addOption"
|
|
>
|
|
<FeatherPlus className="text-body-large font-body-large text-icon-neutral-tertiary" />
|
|
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.inspector.addOption")}
|
|
</span>
|
|
</button>
|
|
) : null}
|
|
</div>
|
|
|
|
<div className="flex w-full items-center justify-between gap-4">
|
|
<div className="flex flex-col items-start gap-0.5">
|
|
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary">
|
|
{t("projects.fieldTemplate.inspector.multiple")}
|
|
</span>
|
|
<span className="text-body-extra-small-regular-150 font-body-extra-small-regular-150 text-text-neutral-tertiary">
|
|
{t("projects.fieldTemplate.inspector.multipleHelp")}
|
|
</span>
|
|
</div>
|
|
<Switch
|
|
checked={datentyp === "multiselect"}
|
|
disabled={!editable}
|
|
onCheckedChange={(checked: boolean) => setDatentyp(checked ? "multiselect" : "select")}
|
|
aria-label={t("projects.fieldTemplate.inspector.multiple")}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.multiple"
|
|
/>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
{editable ? (
|
|
<Button
|
|
className="w-full"
|
|
variant="neutral"
|
|
loading={props.submitting}
|
|
onClick={save}
|
|
data-ui-id="ui.projects.fieldTemplate.inspector.saveType"
|
|
>
|
|
{t("projects.fieldTemplate.inspector.saveDefinition")}
|
|
</Button>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/** Type list re-exported so the route can validate a submitted type. */
|
|
export { TEMPLATE_FIELD_TYPES };
|
|
|
|
export default PipelineFieldTemplatePage;
|