Compare commits

..

8 Commits

Author SHA1 Message Date
mAi
3e93e94d10 feat(builder): B3 — event-triggered mode + universal search (m/paliad#153)
Some checks failed
Paliad CI gate / build (push) Has been cancelled
Paliad CI gate / test-go (push) Has been cancelled
Paliad CI gate / deploy (push) Has been cancelled
PRD §2.2 + §3.1: the page-header search box drives a typed dropdown
returning grouped event / scenario / project hits, and the "Ereignis"
entry mode is enabled. Picking an event creates a scratch scenario
with one triplet anchored on that event's proceeding type, with the
event card auto-anchored (lime band + "━━━━ DU BIST HIER ━━━━" divider
above the next-coming events).

Backend: new GET /api/builder/search reuses
DeadlineSearchService.SearchEvents for the events corpus (UPC v1),
filters owned scenarios by ILIKE on name, and reuses ProjectService.List
for the Akten group (team-RLS via visibilityPredicate). Each group is
capped independently (default 8 events / 5 scenarios / 5 projects, max
30). Missing services degrade gracefully — empty group, not 503.

Frontend: builder-search.ts owns the dropdown (debounced 180ms,
arrow-key navigation, Enter to pick, abort on next query). builder.ts
gains mode state ("cold" | "event" | "akte"), wires the mode bar +
search input, and runs applyAnchorHighlight after triplet hydration —
the helper finds the .fr-col-item with the picked rule_id, adds the
.builder-anchor-card lime band, and inserts a full-width
.builder-anchor-divider after the anchor's row in the columns grid
via JS row-index math (the grid is row-major with 3 header cells
+ 3-cells-per-row body).

Filter pill reset: setMode() clears the search input and closes the
dropdown when switching entry modes. Forum/proc/party/kind chips are
not yet rendered separately (they live in the search dropdown today);
the reset hook attaches there too when those land in a follow-up.

Verification:
  - bun build (frontend bundles + i18n scan clean)
  - go vet ./... + go test ./... (all packages pass)
  - Playwright: mode switch focuses search, debounced fetch fires,
    typed result groups render with N · M · K pluralization, event
    pick creates scratch scenario + adds proceeding, anchor card
    + DU BIST HIER divider render in the columns grid (screenshots
    confirmed visually)
2026-05-28 10:10:33 +02:00
mAi
28ea103260 Merge: t-paliad-345 — surface proceeding_type id so Builder add-proceeding works (m/paliad#153)
Some checks failed
Paliad CI gate / build (push) Has been cancelled
Paliad CI gate / test-go (push) Has been cancelled
Paliad CI gate / deploy (push) Has been cancelled
2026-05-28 09:50:57 +02:00
mAi
1c77cb6e67 fix(builder): surface proceeding_type id so add-proceeding POST works (t-paliad-345)
Some checks failed
Paliad CI gate / build (push) Has been cancelled
Paliad CI gate / test-go (push) Has been cancelled
Paliad CI gate / build (pull_request) Has been cancelled
Paliad CI gate / test-go (pull_request) Has been cancelled
Paliad CI gate / deploy (push) Has been cancelled
Paliad CI gate / deploy (pull_request) Has been cancelled
The Litigation Builder's "+ Verfahren hinzufügen" silently failed in
prod after t-paliad-343 B2 shipped — clicking a Verfahren chip in the
picker did nothing, no visible error.

Root cause: the wire shape FristenrechnerType (the response of
/api/tools/proceeding-types) carried code+name+nameEN+group but not
id. Builder.ts mountAddProceedingPicker's callback POSTed
`{proceeding_type_id: meta.id}` to
/api/builder/scenarios/{id}/proceedings — meta.id was undefined,
JSON.stringify dropped the key, the server returned 400 ("invalid
input: proceeding_type_id is required"), and fetchJSON swallowed the
error to console. The user saw "nothing happens".

Fix:
- Add `ID int json:"id"` to lp.FristenrechnerType.
- SELECT id in FristenrechnerService.ListProceedings + Scan into the
  new field.
- Defensive guard in builder.ts openAddProceedingPicker — refuse to
  POST without a positive integer id and log a clear error, so a
  future wire-shape regression cannot recreate the silent-fail.
- Regression test in pkg/litigationplanner/types_wire_test.go pins the
  contract (id present in JSON, round-trips as integer).

Side-benefit: fristenrechner-wizard.ts:599-628 documented this exact
gap as a known limitation ("S5/follow-up can extend the wire shape to
include id"). That workaround can now be retired in a follow-up.

Refs m/paliad#153 (Litigation Builder)
2026-05-28 09:48:32 +02:00
mAi
1f6e586c63 Merge: t-paliad-344 — fix stale deadlines.rule_id refs + builder null-guards (m/paliad#154)
Some checks failed
Paliad CI gate / build (push) Has been cancelled
Paliad CI gate / test-go (push) Has been cancelled
Paliad CI gate / deploy (push) Has been cancelled
2026-05-28 00:48:17 +02:00
mAi
a4b865d6bd fix(builder): initialise scenario sub-arrays + client null-guard (t-paliad-344)
Some checks failed
Paliad CI gate / build (push) Has been cancelled
Paliad CI gate / test-go (push) Has been cancelled
Paliad CI gate / deploy (push) Has been cancelled
GetScenarioDeep returned nil slices for proceedings/events/shares when
a scenario had zero rows, which Go's encoding/json serialises as `null`
rather than `[]`. The builder's renderCanvas then unconditionally calls
`state.active.proceedings.filter(...)` on a null and dies with
`procedures.js:101 TypeError: Cannot read properties of null
(reading 'filter')` — every cold-open scenario crashed the page before
the empty canvas could render.

Backend (root cause): initialise Proceedings / Events / Shares to empty
slices in BuilderScenarioDeep before SelectContext, so the wire shape
is always arrays. Existing rows still load via SelectContext, which
truncates the placeholder and refills from the DB.

Frontend (defence in depth): on loadScenario(), normalise each of the
three arrays to `[]` if the server response is not an array. Catches a
future regression (or an older deployed build) without re-introducing
the same crash class.

bun build clean, go vet + go test ./... green.
2026-05-28 00:47:19 +02:00
mAi
a905911cf4 fix(deadlines): restore /api/events deadline rail after mig 140 column drop (t-paliad-344)
Two SELECTs still referenced paliad.deadlines.rule_id after mig 140
(Slice B.4) dropped that column in favour of sequencing_rule_id:

  - internal/services/deadline_service.go:268 — DeadlineService.
    ListVisibleForUser. Powers /api/events?type=deadline (dashboard
    deadline rail, /deadlines page, every status bucket). Threw
    `pq: column f.rule_id does not exist` on every request → 500
    for any authenticated user hitting the dashboard.

  - internal/services/projection_service.go:1250 — collectActualsForOverrides.
    Same column on `paliad.deadlines d`. Logged once per projection
    pass (`ERROR service: projection: deadlines: ...`); aliased the
    rename to `rule_id` so the receiving struct tag still scans.

Live container logs confirmed the failure mode — a 60-row burst of
`pq: column f.rule_id does not exist at position 3:36 (42703)` starting
the minute the post-B0 container came up (mig 140 had applied to the
DB but the SELECT still used the dropped name). EXPLAIN against the
live schema after the edit plans cleanly; the LEFT JOIN to
paliad.deadline_rules_unified on sequencing_rule_id was already correct
(only the SELECT projection was stale).

Root cause: mig 140 commit (1129bab) renamed the JOIN to
`f.sequencing_rule_id` but left the SELECT clause on the older name.
The model tag is already `db:"sequencing_rule_id" json:"rule_id"`, so
the wire shape is unchanged — only the column reference flips.

bun build clean, go vet ./... clean, go test ./... green.
2026-05-28 00:47:08 +02:00
mAi
88c03e922f Merge: t-paliad-343 B2 — multi-triplet + spawn + per-event state (m/paliad#153)
Some checks failed
Paliad CI gate / build (push) Has been cancelled
Paliad CI gate / test-go (push) Has been cancelled
Paliad CI gate / deploy (push) Has been cancelled
2026-05-28 00:29:50 +02:00
mAi
6bcac2dd20 Merge: t-paliad-343 B1 — Litigation Builder shell + cold-open (m/paliad#153) 2026-05-28 00:29:50 +02:00
14 changed files with 1064 additions and 10 deletions

View File

@@ -0,0 +1,412 @@
// Universal search dropdown for the Litigation Builder (m/paliad#153 B3).
//
// PRD §2.2 + §3.1 + §6.3: the page-header search box ("Suche") drives
// a typed dropdown returning grouped event / scenario / project hits.
// Picking an event lands the user on a scratch scenario with one
// triplet anchored on that event's proceeding type. Picking a scenario
// loads it; picking a project (Akte) is deferred to B4 (the dropdown
// row renders but pick falls through to a console hint until B4 wires
// project-backed scenarios).
//
// The controller is owned by builder.ts; this module exports
// `mountBuilderSearch` which wires the input + dropdown lifecycle and
// invokes the supplied callbacks. No module-level state — re-mounting
// is safe.
import { t } from "./i18n";
export interface EventSearchHit {
id: string;
code: string;
name_de: string;
name_en: string;
event_kind?: string | null;
primary_party?: string | null;
anchor_rule_id: string;
follow_up_count: number;
proceeding_type: {
id: number;
code: string;
name_de: string;
name_en: string;
jurisdiction?: string | null;
};
}
export interface ScenarioSearchHit {
id: string;
name: string;
status: string;
updated_at: string;
}
export interface ProjectSearchHit {
id: string;
type: string;
title: string;
reference?: string | null;
case_number?: string | null;
matter_number?: string | null;
client_number?: string | null;
}
export interface UniversalSearchResponse {
query: string;
events: EventSearchHit[];
scenarios: ScenarioSearchHit[];
projects: ProjectSearchHit[];
counts: { events: number; scenarios: number; projects: number };
}
export interface BuilderSearchCallbacks {
onPickEvent: (hit: EventSearchHit) => void | Promise<void>;
onPickScenario: (hit: ScenarioSearchHit) => void | Promise<void>;
onPickProject?: (hit: ProjectSearchHit) => void | Promise<void>;
}
interface Controller {
input: HTMLInputElement;
dropdown: HTMLElement;
open: boolean;
abort: AbortController | null;
debounceTimer: number | null;
lang: "de" | "en";
}
let active: Controller | null = null;
// mountBuilderSearch wires the universal search behavior onto an
// existing <input>. Idempotent — re-calling tears down the previous
// dropdown and rebinds. Returns a controller exposing focus() so the
// entry-mode toggle in builder.ts can land on the search input.
export function mountBuilderSearch(
input: HTMLInputElement,
cb: BuilderSearchCallbacks,
): { focus: () => void; close: () => void } {
teardown();
const lang: "de" | "en" = document.documentElement.lang === "en" ? "en" : "de";
// Single dropdown container, anchored under the input. Positioned
// absolutely so it floats above the canvas without reflowing layout.
const dropdown = document.createElement("div");
dropdown.className = "builder-search-dropdown";
dropdown.setAttribute("role", "listbox");
dropdown.hidden = true;
document.body.appendChild(dropdown);
active = {
input,
dropdown,
open: false,
abort: null,
debounceTimer: null,
lang,
};
input.addEventListener("input", onInput);
input.addEventListener("focus", onFocus);
input.addEventListener("keydown", onKeydown);
document.addEventListener("click", onOutsideClick, true);
window.addEventListener("resize", reposition);
window.addEventListener("scroll", reposition, true);
// Click handler is wired once on the dropdown root via event
// delegation; per-row data attributes identify the hit type.
dropdown.addEventListener("click", (ev) => {
const row = (ev.target as HTMLElement).closest<HTMLElement>(".builder-search-row");
if (!row) return;
const kind = row.getAttribute("data-hit-kind");
const payload = row.getAttribute("data-hit-payload");
if (!kind || !payload) return;
try {
const hit = JSON.parse(payload);
ev.stopPropagation();
closeDropdown();
if (kind === "event") void cb.onPickEvent(hit);
else if (kind === "scenario") void cb.onPickScenario(hit);
else if (kind === "project" && cb.onPickProject) void cb.onPickProject(hit);
} catch (err) {
console.error("builder-search: bad payload", err);
}
});
return {
focus: () => {
input.focus();
// Open the dropdown on focus even when input is empty — show the
// "start typing" hint per PRD §2.2 (search box auto-focuses).
openDropdown();
renderHint(t("builder.search.hint.start"));
},
close: closeDropdown,
};
}
function teardown(): void {
if (!active) return;
if (active.abort) active.abort.abort();
if (active.debounceTimer !== null) window.clearTimeout(active.debounceTimer);
active.dropdown.remove();
active.input.removeEventListener("input", onInput);
active.input.removeEventListener("focus", onFocus);
active.input.removeEventListener("keydown", onKeydown);
document.removeEventListener("click", onOutsideClick, true);
window.removeEventListener("resize", reposition);
window.removeEventListener("scroll", reposition, true);
active = null;
}
function onInput(): void {
if (!active) return;
const q = active.input.value.trim();
if (active.debounceTimer !== null) window.clearTimeout(active.debounceTimer);
if (q.length === 0) {
openDropdown();
renderHint(t("builder.search.hint.start"));
return;
}
if (q.length < 2) {
openDropdown();
renderHint(t("builder.search.hint.short"));
return;
}
active.debounceTimer = window.setTimeout(() => {
void runSearch(q);
}, 180);
}
function onFocus(): void {
if (!active) return;
const q = active.input.value.trim();
if (q.length === 0) {
openDropdown();
renderHint(t("builder.search.hint.start"));
} else if (q.length >= 2) {
void runSearch(q);
}
}
function onKeydown(ev: KeyboardEvent): void {
if (!active) return;
if (ev.key === "Escape") {
closeDropdown();
return;
}
if (ev.key === "ArrowDown" || ev.key === "ArrowUp") {
const rows = Array.from(active.dropdown.querySelectorAll<HTMLElement>(".builder-search-row"));
if (rows.length === 0) return;
ev.preventDefault();
const current = active.dropdown.querySelector<HTMLElement>(".builder-search-row.is-focus");
let idx = current ? rows.indexOf(current) : -1;
idx = ev.key === "ArrowDown"
? Math.min(rows.length - 1, idx + 1)
: Math.max(0, idx - 1);
rows.forEach((r) => r.classList.remove("is-focus"));
rows[idx].classList.add("is-focus");
rows[idx].scrollIntoView({ block: "nearest" });
return;
}
if (ev.key === "Enter") {
const focused = active.dropdown.querySelector<HTMLElement>(".builder-search-row.is-focus");
if (focused) {
ev.preventDefault();
focused.click();
}
}
}
function onOutsideClick(ev: Event): void {
if (!active) return;
const target = ev.target as Node;
if (active.input.contains(target)) return;
if (active.dropdown.contains(target)) return;
closeDropdown();
}
async function runSearch(q: string): Promise<void> {
if (!active) return;
// Cancel any in-flight request so a slow earlier query can't clobber
// a faster newer one.
if (active.abort) active.abort.abort();
const ctl = new AbortController();
active.abort = ctl;
openDropdown();
renderHint(t("builder.search.hint.loading"));
try {
const url = "/api/builder/search?q=" + encodeURIComponent(q);
const resp = await fetch(url, { signal: ctl.signal });
if (!resp.ok) {
renderHint(t("builder.search.hint.error"));
return;
}
const data = (await resp.json()) as UniversalSearchResponse;
if (active.abort !== ctl) return;
renderResults(data);
} catch (err) {
if ((err as { name?: string })?.name === "AbortError") return;
console.error("builder-search error:", err);
renderHint(t("builder.search.hint.error"));
}
}
function renderHint(message: string): void {
if (!active) return;
active.dropdown.innerHTML = `<div class="builder-search-hint">${escHtml(message)}</div>`;
reposition();
}
function renderResults(data: UniversalSearchResponse): void {
if (!active) return;
const lang = active.lang;
const total = data.events.length + data.scenarios.length + data.projects.length;
if (total === 0) {
renderHint(t("builder.search.hint.empty"));
return;
}
// Result-count summary per PRD §2.2: "N Ereignisse · M Szenarios · K Akten"
const counts = `<div class="builder-search-summary">` +
escHtml(tCount("builder.search.summary.events", data.events.length)) +
` · ` +
escHtml(tCount("builder.search.summary.scenarios", data.scenarios.length)) +
` · ` +
escHtml(tCount("builder.search.summary.projects", data.projects.length)) +
`</div>`;
const sections: string[] = [counts];
if (data.events.length > 0) {
sections.push(renderGroup(
t("builder.search.group.events"),
data.events.map((e) => renderEventRow(e, lang)).join(""),
));
}
if (data.scenarios.length > 0) {
sections.push(renderGroup(
t("builder.search.group.scenarios"),
data.scenarios.map((s) => renderScenarioRow(s)).join(""),
));
}
if (data.projects.length > 0) {
sections.push(renderGroup(
t("builder.search.group.projects"),
data.projects.map((p) => renderProjectRow(p, lang)).join(""),
));
}
active.dropdown.innerHTML = sections.join("");
reposition();
}
function renderGroup(label: string, rowsHtml: string): string {
return `<section class="builder-search-group">` +
`<header class="builder-search-group-label">${escHtml(label)}</header>` +
rowsHtml +
`</section>`;
}
function renderEventRow(hit: EventSearchHit, lang: "de" | "en"): string {
const name = lang === "en" ? (hit.name_en || hit.name_de) : (hit.name_de || hit.name_en);
const ptName = lang === "en"
? (hit.proceeding_type.name_en || hit.proceeding_type.name_de)
: (hit.proceeding_type.name_de || hit.proceeding_type.name_en);
const party = hit.primary_party ? `<span class="builder-search-party">${escHtml(hit.primary_party)}</span>` : "";
const kind = hit.event_kind ? `<span class="builder-search-kind">${escHtml(hit.event_kind)}</span>` : "";
// Payload for the click handler — we embed the full hit so builder.ts
// doesn't need a second lookup. JSON-encoded into a data attribute,
// attr-escaped on the way in.
const payload = escAttr(JSON.stringify(hit));
return `<div class="builder-search-row" data-hit-kind="event" data-hit-payload="${payload}" tabindex="-1" role="option">` +
`<div class="builder-search-row-main">` +
`<span class="builder-search-pt-code">${escHtml(hit.proceeding_type.code)}</span>` +
`<span class="builder-search-event-name">${escHtml(name)}</span>` +
`</div>` +
`<div class="builder-search-row-meta">` +
`<span class="builder-search-pt-name">${escHtml(ptName)}</span>` +
kind + party +
`</div>` +
`</div>`;
}
function renderScenarioRow(hit: ScenarioSearchHit): string {
const payload = escAttr(JSON.stringify(hit));
return `<div class="builder-search-row" data-hit-kind="scenario" data-hit-payload="${payload}" tabindex="-1" role="option">` +
`<div class="builder-search-row-main">` +
`<span class="builder-search-scenario-name">${escHtml(hit.name)}</span>` +
`</div>` +
`<div class="builder-search-row-meta">` +
`<span class="builder-search-status">${escHtml(hit.status)}</span>` +
`</div>` +
`</div>`;
}
function renderProjectRow(hit: ProjectSearchHit, _lang: "de" | "en"): string {
const meta: string[] = [];
if (hit.case_number) meta.push(hit.case_number);
if (hit.matter_number) meta.push(hit.matter_number);
if (hit.client_number) meta.push(hit.client_number);
if (hit.reference) meta.push(hit.reference);
const metaText = meta.length > 0 ? meta.join(" · ") : "";
const payload = escAttr(JSON.stringify(hit));
return `<div class="builder-search-row" data-hit-kind="project" data-hit-payload="${payload}" tabindex="-1" role="option">` +
`<div class="builder-search-row-main">` +
`<span class="builder-search-project-type">${escHtml(hit.type)}</span>` +
`<span class="builder-search-project-title">${escHtml(hit.title)}</span>` +
`</div>` +
`<div class="builder-search-row-meta">${escHtml(metaText)}</div>` +
`</div>`;
}
function openDropdown(): void {
if (!active) return;
active.dropdown.hidden = false;
active.open = true;
reposition();
}
function closeDropdown(): void {
if (!active) return;
active.dropdown.hidden = true;
active.open = false;
if (active.abort) {
active.abort.abort();
active.abort = null;
}
}
function reposition(): void {
if (!active || !active.open) return;
const rect = active.input.getBoundingClientRect();
const top = rect.bottom + window.scrollY + 4;
const left = rect.left + window.scrollX;
const width = Math.max(rect.width, 380);
active.dropdown.style.position = "absolute";
active.dropdown.style.top = `${top}px`;
active.dropdown.style.left = `${left}px`;
active.dropdown.style.width = `${width}px`;
active.dropdown.style.zIndex = "60";
}
// tCount applies a simple plural pick: keys ".one" / ".other" carry
// the singular/plural variants; the caller's key is the bare stem.
function tCount(key: string, n: number): string {
const variant = n === 1 ? `${key}.one` : `${key}.other`;
return t(variant).replace("{n}", String(n));
}
function escHtml(s: string): string {
return s
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}
function escAttr(s: string): string {
return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
}

View File

@@ -26,6 +26,12 @@ import {
} from "./views/verfahrensablauf-core";
import { mountAddProceedingPicker, type ProceedingTypeMeta } from "./builder-picker";
import { overlayEventStates, renderTriplet, type ScenarioFlagCatalogEntry } from "./builder-triplet";
import {
mountBuilderSearch,
type EventSearchHit,
type ScenarioSearchHit,
type ProjectSearchHit,
} from "./builder-search";
// Spawn map (PRD §3.6). When a scenario_flag transitions OFF → ON on a
// parent proceeding, the builder auto-creates a child proceeding row
@@ -102,6 +108,8 @@ export interface BuilderScenarioDeep extends BuilderScenario {
// Module state — single active scenario per tab.
// ────────────────────────────────────────────────────────────────────────────
type EntryMode = "cold" | "event" | "akte";
interface State {
active: BuilderScenarioDeep | null;
list: BuilderScenario[];
@@ -114,6 +122,14 @@ interface State {
// racing PATCHes overwriting each other when the user changes more
// than one field inside a 500ms window.
pending: { name?: string; stichtag?: string; notes?: string };
// B3: entry mode + anchor highlight. PRD §2.2 — when the user picks
// an event from universal search, the canvas renders one triplet
// with the picked rule highlighted (lime band + "DU BIST HIER"
// divider). anchorRuleID survives across re-renders within a single
// mode session; switching mode away from "event" clears it.
mode: EntryMode;
anchorRuleID: string | null;
searchCtl: { focus: () => void; close: () => void } | null;
}
const state: State = {
@@ -125,6 +141,9 @@ const state: State = {
flagCatalog: [],
saveTimer: null,
pending: {},
mode: "cold",
anchorRuleID: null,
searchCtl: null,
};
// ────────────────────────────────────────────────────────────────────────────
@@ -544,6 +563,59 @@ async function hydrateTriplet(
void onEventHorizon(proc, ruleId, delta);
},
});
// B3 — apply the event-anchor highlight + "DU BIST HIER" divider on
// the matching card. Only fires when the active mode is "event" and
// an anchor rule was set by the search-pick flow.
if (state.mode === "event" && state.anchorRuleID) {
applyAnchorHighlight(host, state.anchorRuleID);
}
}
// applyAnchorHighlight spotlights the picked event card on a freshly
// rendered triplet. PRD §2.2: lime band on the card + a horizontal
// "━━ DU BIST HIER ━━" divider above the next-coming events. The
// divider spans all 3 columns of the grid via grid-column: 1 / -1.
function applyAnchorHighlight(host: HTMLElement, ruleId: string): void {
const ruleKey = ruleId.toLowerCase();
// Attribute-value comparison via JS rather than a CSS selector so
// either-cased UUIDs from the server still match.
const anchorCard = Array.from(
host.querySelectorAll<HTMLElement>(".fr-col-item[data-rule-id]"),
).find((el) => (el.getAttribute("data-rule-id") || "").toLowerCase() === ruleKey);
if (!anchorCard) return;
anchorCard.classList.add("builder-anchor-card");
// Locate the anchor's row in the .fr-columns-view grid. The grid
// is row-major with 3 cells per row after the 3 column headers
// (ours/court/opponent). The cell containing the anchor card is
// the closest .fr-col-cell ancestor; once we know its index in the
// grid's cell list, the row index is floor((idx - 3) / 3) (the
// -3 accounts for the header row).
const cell = anchorCard.closest<HTMLElement>(".fr-col-cell");
if (!cell) return;
const grid = cell.parentElement;
if (!grid || !grid.classList.contains("fr-columns-view")) return;
const cells = Array.from(grid.children) as HTMLElement[];
const idx = cells.indexOf(cell);
if (idx < 0) return;
// Insertion point: after the last cell of the anchor's row. The
// grid renders cells in row-major order; we step forward from the
// anchor cell to the end of the current row (2 cells past, modulo
// header row offset). A guarded fall-through inserts at the end of
// the grid if positions don't line up cleanly.
// Header row contributes 3 cells; body rows are 3 cells each.
const headerCells = 3;
if (idx < headerCells) return; // anchor on a header? shouldn't happen, no-op.
const bodyIdx = idx - headerCells;
const rowStart = headerCells + Math.floor(bodyIdx / 3) * 3;
const rowEnd = rowStart + 2; // inclusive
const after = cells[rowEnd] || cells[cells.length - 1];
const divider = document.createElement("div");
divider.className = "builder-anchor-divider";
divider.textContent = t("builder.search.anchor.divider");
divider.setAttribute("aria-hidden", "true");
after.insertAdjacentElement("afterend", divider);
}
function buildEventsByRule(proceedingID: string): Map<string, BuilderEvent> {
@@ -815,6 +887,13 @@ async function loadScenario(id: string): Promise<void> {
setSaveState("error");
return;
}
// Defensive: Go's encoding/json serialises a nil slice as `null`, not
// `[]`. The server initialises these arrays today, but normalising on
// the client too means a future regression (or an older deployed
// build) can't crash renderCanvas with `null.filter(...)`.
if (!Array.isArray(deep.proceedings)) deep.proceedings = [];
if (!Array.isArray(deep.events)) deep.events = [];
if (!Array.isArray(deep.shares)) deep.shares = [];
state.active = deep;
state.pending = {};
writeScenarioToUrl(id);
@@ -848,6 +927,16 @@ function openAddProceedingPicker(anchor: HTMLElement): void {
if (!state.active) return;
mountAddProceedingPicker(anchor, state.procTypes, async (meta) => {
if (!state.active) return;
// Guard against a wire-shape regression: if the proceeding-types
// endpoint stops returning `id`, `meta.id` is undefined and
// JSON.stringify silently drops the field, the server rejects the
// POST with a 400, and fetchJSON swallows the error — the user
// sees "nothing happens" (t-paliad-345). Fail loud instead.
if (typeof meta.id !== "number" || meta.id <= 0) {
console.error("builder: missing proceeding_type id in picker meta", meta);
setSaveState("error");
return;
}
const proc = await addProceeding(state.active.id, {
proceeding_type_id: meta.id,
});
@@ -888,6 +977,114 @@ function onStichtagChange(value: string): void {
// Wiring
// ────────────────────────────────────────────────────────────────────────────
// ────────────────────────────────────────────────────────────────────────────
// Entry-mode + universal search (B3)
// ────────────────────────────────────────────────────────────────────────────
function setMode(mode: EntryMode): void {
if (mode === state.mode) return;
// PRD §2.2 step 6: filter pills reset on mode switch. The current
// surface doesn't yet render forum/proc/party/kind chips, so the
// reset is a search-input clear; once the filter strip lands in a
// follow-up slice the chip state attaches here too.
const searchInput = document.getElementById("builder-search-input") as HTMLInputElement | null;
if (searchInput) searchInput.value = "";
state.searchCtl?.close();
state.mode = mode;
state.anchorRuleID = null;
// Reflect the mode on the radio strip.
document.querySelectorAll<HTMLElement>(".builder-mode[data-mode]").forEach((btn) => {
const isActive = btn.getAttribute("data-mode") === mode;
btn.classList.toggle("is-active", isActive);
btn.setAttribute("aria-selected", String(isActive));
});
// On entering Ereignis mode, autofocus the search input per PRD §2.2.
if (mode === "event" && state.searchCtl) {
state.searchCtl.focus();
}
// On leaving event mode, redraw the canvas so any anchor highlights
// are dropped.
if (mode !== "event") {
renderCanvas();
}
}
async function onPickEvent(hit: EventSearchHit): Promise<void> {
// PRD §2.2 — picking an event creates a scratch scenario with one
// triplet anchored on that event's proceeding type, with the event
// card auto-anchored (lime band + DU BIST HIER divider).
const sc = await createScenario();
if (!sc) {
setSaveState("error");
return;
}
state.list.unshift(sc);
// Load the new (empty) scenario, then add the anchored proceeding.
await loadScenario(sc.id);
if (!state.active) return;
state.anchorRuleID = hit.anchor_rule_id;
const proc = await addProceeding(state.active.id, {
proceeding_type_id: hit.proceeding_type.id,
});
if (!proc) {
setSaveState("error");
return;
}
state.active.proceedings.push(proc);
setSaveState("saved");
renderCanvas();
}
async function onPickScenarioFromSearch(hit: ScenarioSearchHit): Promise<void> {
await loadScenario(hit.id);
}
function onPickProjectFromSearch(hit: ProjectSearchHit): void {
// PRD §2.3 — Akte (project-backed) builder lands at B4. For now we
// surface a console hint and a visible save-state message so the
// user gets feedback rather than silence.
console.info("builder: project pick deferred to B4", hit);
setSaveState("idle");
const status = document.getElementById("builder-save-status");
if (status) {
const span = status.querySelector("span");
if (span) span.textContent = t("builder.search.hint.akte_b4");
}
}
function wireModeBar(): void {
document.querySelectorAll<HTMLElement>(".builder-mode[data-mode]").forEach((btn) => {
if (btn.hasAttribute("disabled")) return;
btn.addEventListener("click", () => {
const m = btn.getAttribute("data-mode") as EntryMode | null;
if (m) setMode(m);
});
});
}
function wireSearch(): void {
const input = document.getElementById("builder-search-input") as HTMLInputElement | null;
if (!input) return;
state.searchCtl = mountBuilderSearch(input, {
onPickEvent: (hit) => {
// Picking an event implicitly switches to event mode if not
// already there — keeps the affordance honest when the user
// searches without first clicking "Ereignis".
if (state.mode !== "event") setMode("event");
void onPickEvent(hit);
},
onPickScenario: (hit) => {
void onPickScenarioFromSearch(hit);
},
onPickProject: (hit) => {
onPickProjectFromSearch(hit);
},
});
}
function wirePageHeader(): void {
document.getElementById("builder-rename-btn")?.addEventListener("click", () => {
void onRenameClick();
@@ -916,6 +1113,8 @@ function wirePageHeader(): void {
export async function mountBuilder(): Promise<void> {
wirePageHeader();
wireModeBar();
wireSearch();
// Parallel boot — proceeding type catalog (Forum=UPC, Kind=proceeding)
// for the add-proceeding picker + scenario_flag_catalog for the
// per-triplet flag strip. PRD §0.4 — UPC v1.

View File

@@ -276,6 +276,22 @@ const translations: Record<Lang, Record<string, string>> = {
"builder.save.saving": "Speichert \u2026",
"builder.save.saved": "Gespeichert \u2713",
"builder.save.error": "Speichern fehlgeschlagen",
"builder.search.hint.start": "Tippe \u2026 z.\u202fB. \u201eKlageerwiderung\u201c, \u201eHinweis\u201c, \u201eHL-2024\u201c",
"builder.search.hint.short": "Mindestens 2 Zeichen.",
"builder.search.hint.loading": "Suche \u2026",
"builder.search.hint.empty": "Keine Treffer.",
"builder.search.hint.error": "Suche fehlgeschlagen. Erneut versuchen.",
"builder.search.hint.akte_b4": "Akten-Modus folgt in B4.",
"builder.search.group.events": "Ereignisse",
"builder.search.group.scenarios": "Szenarien",
"builder.search.group.projects": "Akten",
"builder.search.summary.events.one": "{n} Ereignis",
"builder.search.summary.events.other": "{n} Ereignisse",
"builder.search.summary.scenarios.one": "{n} Szenario",
"builder.search.summary.scenarios.other": "{n} Szenarien",
"builder.search.summary.projects.one": "{n} Akte",
"builder.search.summary.projects.other": "{n} Akten",
"builder.search.anchor.divider": "\u2501\u2501\u2501\u2501 DU BIST HIER \u2501\u2501\u2501\u2501",
"deadlines.step1": "Verfahrensart w\u00e4hlen",
"deadlines.step2": "Ausgangsdatum eingeben",
@@ -3543,6 +3559,22 @@ const translations: Record<Lang, Record<string, string>> = {
"builder.save.saving": "Saving …",
"builder.save.saved": "Saved ✓",
"builder.save.error": "Save failed",
"builder.search.hint.start": "Type … e.g. \"defence\", \"hearing\", \"HL-2024\"",
"builder.search.hint.short": "At least 2 characters.",
"builder.search.hint.loading": "Searching …",
"builder.search.hint.empty": "No matches.",
"builder.search.hint.error": "Search failed. Try again.",
"builder.search.hint.akte_b4": "Matter mode coming in B4.",
"builder.search.group.events": "Events",
"builder.search.group.scenarios": "Scenarios",
"builder.search.group.projects": "Matters",
"builder.search.summary.events.one": "{n} event",
"builder.search.summary.events.other": "{n} events",
"builder.search.summary.scenarios.one": "{n} scenario",
"builder.search.summary.scenarios.other": "{n} scenarios",
"builder.search.summary.projects.one": "{n} matter",
"builder.search.summary.projects.other": "{n} matters",
"builder.search.anchor.divider": "━━━━ YOU ARE HERE ━━━━",
"deadlines.step1": "Select Proceeding Type",
"deadlines.step2": "Enter Trigger Date",

View File

@@ -771,7 +771,23 @@ export type I18nKey =
| "builder.save.idle"
| "builder.save.saved"
| "builder.save.saving"
| "builder.search.anchor.divider"
| "builder.search.group.events"
| "builder.search.group.projects"
| "builder.search.group.scenarios"
| "builder.search.hint.akte_b4"
| "builder.search.hint.empty"
| "builder.search.hint.error"
| "builder.search.hint.loading"
| "builder.search.hint.short"
| "builder.search.hint.start"
| "builder.search.placeholder"
| "builder.search.summary.events.one"
| "builder.search.summary.events.other"
| "builder.search.summary.projects.one"
| "builder.search.summary.projects.other"
| "builder.search.summary.scenarios.one"
| "builder.search.summary.scenarios.other"
| "builder.subtitle"
| "builder.triplet.collapse"
| "builder.triplet.detailgrad.all_options"

View File

@@ -93,8 +93,7 @@ export function renderProcedures(): string {
<input type="search" id="builder-search-input" className="builder-search-input"
data-i18n-placeholder="builder.search.placeholder"
placeholder="Ereignis, Szenario, Akte &hellip;"
autocomplete="off" spellcheck="false" disabled
title="Universelle Suche kommt in B3" />
autocomplete="off" spellcheck="false" />
</label>
</div>
</section>
@@ -116,9 +115,7 @@ export function renderProcedures(): string {
role="tab"
aria-selected="false"
data-mode="event"
id="builder-mode-event"
disabled
title="In B3 verf&uuml;gbar">
id="builder-mode-event">
<span className="builder-mode-label" data-i18n="builder.mode.event">Ereignis</span>
</button>
<button type="button"

View File

@@ -20474,6 +20474,135 @@ a.fristen-overhaul-rule-source {
background: var(--color-accent-strong-bg);
}
/* B3 — anchor highlight + DU BIST HIER divider. Picked event card
carries a lime band (left border + soft background) and a
horizontal divider is injected after its row in the columns grid.
The divider spans all 3 columns via grid-column: 1 / -1. */
.builder-anchor-card {
background: var(--color-accent-soft-bg);
border-color: var(--color-accent);
border-left: 4px solid var(--color-accent);
box-shadow: 0 0 0 1px var(--color-accent-soft-border) inset;
}
.builder-anchor-divider {
grid-column: 1 / -1;
text-align: center;
font-family: var(--font-sans);
font-size: 0.78rem;
font-weight: 600;
letter-spacing: 0.12em;
color: var(--color-accent-dark, #5b7b04);
background: var(--color-accent-soft-bg);
border: 1px dashed var(--color-accent);
border-radius: var(--radius);
padding: 0.35rem 0.6rem;
margin: 0.2rem 0;
}
/* B3 — universal search dropdown. Floated under the page-header
search input by JS (position: absolute, top/left set per
reposition()). The dropdown renders typed result groups
(events / scenarios / projects). */
.builder-search-dropdown {
background: var(--color-surface);
border: 1px solid var(--color-border);
border-radius: var(--radius);
box-shadow: 0 12px 28px rgba(0, 0, 0, 0.12);
max-height: 70vh;
overflow-y: auto;
font-family: var(--font-sans);
}
.builder-search-hint {
padding: 0.7rem 0.9rem;
font-size: 0.85rem;
color: var(--color-text-muted);
font-style: italic;
}
.builder-search-summary {
padding: 0.5rem 0.9rem;
font-size: 0.78rem;
color: var(--color-text-muted);
border-bottom: 1px solid var(--color-border);
background: var(--color-surface-2);
}
.builder-search-group {
padding: 0.25rem 0;
border-bottom: 1px solid var(--color-border);
}
.builder-search-group:last-child {
border-bottom: 0;
}
.builder-search-group-label {
padding: 0.4rem 0.9rem 0.25rem;
font-size: 0.72rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(--color-text-muted);
}
.builder-search-row {
display: flex;
flex-direction: column;
gap: 0.18rem;
padding: 0.45rem 0.9rem;
cursor: pointer;
border-left: 3px solid transparent;
}
.builder-search-row:hover,
.builder-search-row.is-focus {
background: var(--color-accent-soft-bg);
border-left-color: var(--color-accent);
}
.builder-search-row-main {
display: flex;
align-items: baseline;
gap: 0.45rem;
font-size: 0.92rem;
color: var(--color-text);
}
.builder-search-pt-code,
.builder-search-project-type {
font-family: ui-monospace, "SF Mono", Menlo, monospace;
font-size: 0.78rem;
color: var(--color-text-muted);
background: var(--color-surface-2);
border: 1px solid var(--color-border);
border-radius: 0.22rem;
padding: 0 0.32rem;
}
.builder-search-event-name,
.builder-search-scenario-name,
.builder-search-project-title {
font-weight: 500;
}
.builder-search-row-meta {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
font-size: 0.76rem;
color: var(--color-text-muted);
}
.builder-search-kind,
.builder-search-party,
.builder-search-status {
font-style: italic;
}
/* Responsive: collapse side panel into stacked block on narrow viewports. */
@media (max-width: 900px) {

View File

@@ -0,0 +1,199 @@
package handlers
import (
"net/http"
"strconv"
"strings"
"github.com/google/uuid"
"mgit.msbls.de/m/paliad/internal/services"
)
// t-paliad-346 / m/paliad#153 B3 — universal search for the Litigation
// Builder. Returns events + scenarios + projects (Akten) keyed by type
// so the search dropdown can render typed result groups.
//
// GET /api/builder/search?q=<term>&limit=<n>
//
// Response shape:
//
// {
// "query": "<echoed q>",
// "events": [ EventSearchHit, ... ], // anchor_rule_id + proceeding_type embedded
// "scenarios": [ { id, name, status, updated_at }, ... ],
// "projects": [ { id, title, type, reference, case_number, matter_number, client_number }, ... ],
// "counts": { "events": N, "scenarios": M, "projects": K }
// }
//
// Each group is independently capped (default 8 events / 5 scenarios /
// 5 projects, max 30 per group). Missing services degrade gracefully —
// an unavailable group is returned as an empty array, not an error,
// so a knowledge-only deploy (DATABASE_URL unset) can still serve a
// best-effort empty response shape rather than a 503 wall.
type builderSearchScenarioHit struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
UpdatedAt string `json:"updated_at"`
}
type builderSearchProjectHit struct {
ID uuid.UUID `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
Reference *string `json:"reference,omitempty"`
CaseNumber *string `json:"case_number,omitempty"`
MatterNumber *string `json:"matter_number,omitempty"`
ClientNumber *string `json:"client_number,omitempty"`
}
type builderSearchResponse struct {
Query string `json:"query"`
Events []services.EventSearchHit `json:"events"`
Scenarios []builderSearchScenarioHit `json:"scenarios"`
Projects []builderSearchProjectHit `json:"projects"`
Counts builderSearchCounts `json:"counts"`
}
type builderSearchCounts struct {
Events int `json:"events"`
Scenarios int `json:"scenarios"`
Projects int `json:"projects"`
}
// handleBuilderSearch — GET /api/builder/search?q=<term>&limit=<n>
//
// Auth required. Returns 200 with empty groups when q is empty (matches
// the fristenrechner search ergonomic — frontend can boot without a
// pre-flight round trip).
func handleBuilderSearch(w http.ResponseWriter, r *http.Request) {
uid, ok := requireUser(w, r)
if !ok {
return
}
q := strings.TrimSpace(r.URL.Query().Get("q"))
perGroupLimit := parseBuilderSearchLimit(r.URL.Query().Get("limit"))
resp := builderSearchResponse{
Query: q,
Events: []services.EventSearchHit{},
Scenarios: []builderSearchScenarioHit{},
Projects: []builderSearchProjectHit{},
}
if q == "" {
// Match fristenrechner search: empty query → empty groups, not 400.
writeJSON(w, http.StatusOK, resp)
return
}
ctx := r.Context()
// Events: reuse the SearchEvents shape so anchor_rule_id +
// proceeding_type travel with each hit. UPC v1 (PRD §0.4) — the
// jurisdiction filter pins the corpus the builder serves today.
if dbSvc != nil && dbSvc.deadlineSearch != nil {
eventsResp, err := dbSvc.deadlineSearch.SearchEvents(ctx, q, services.EventSearchOptions{
Jurisdiction: "UPC",
Limit: perGroupLimit.events,
})
if err == nil && eventsResp != nil {
resp.Events = eventsResp.Events
}
}
// Scenarios: caller's own scenarios filtered by ILIKE on name.
// Borrows ListMyScenarios + filters in-memory; the list endpoint
// already caps at the small per-user fan-out and there's no index
// on (owner_id, name) yet — in-memory filter is cheap at 10s-of-
// rows scale.
if dbSvc != nil && dbSvc.scenarioBuilder != nil {
scenarios, err := dbSvc.scenarioBuilder.ListMyScenarios(ctx, uid, "active")
if err == nil {
needle := strings.ToLower(q)
hits := []builderSearchScenarioHit{}
for _, sc := range scenarios {
if !strings.Contains(strings.ToLower(sc.Name), needle) {
continue
}
hits = append(hits, builderSearchScenarioHit{
ID: sc.ID,
Name: sc.Name,
Status: sc.Status,
UpdatedAt: sc.UpdatedAt.Format("2006-01-02T15:04:05Z07:00"),
})
if len(hits) >= perGroupLimit.scenarios {
break
}
}
resp.Scenarios = hits
}
}
// Projects (Akten): visible projects filtered by trigram/ILIKE on
// title, reference, client_number, matter_number. ProjectService.List
// already applies team-based RLS via visibilityPredicate.
if dbSvc != nil && dbSvc.projects != nil {
projects, err := dbSvc.projects.List(ctx, uid, services.ProjectFilter{
Search: q,
})
if err == nil {
hits := make([]builderSearchProjectHit, 0, len(projects))
for _, p := range projects {
hits = append(hits, builderSearchProjectHit{
ID: p.ID,
Type: p.Type,
Title: p.Title,
Reference: p.Reference,
CaseNumber: p.CaseNumber,
MatterNumber: p.MatterNumber,
ClientNumber: p.ClientNumber,
})
if len(hits) >= perGroupLimit.projects {
break
}
}
resp.Projects = hits
}
}
resp.Counts = builderSearchCounts{
Events: len(resp.Events),
Scenarios: len(resp.Scenarios),
Projects: len(resp.Projects),
}
writeJSON(w, http.StatusOK, resp)
}
type builderSearchPerGroup struct {
events int
scenarios int
projects int
}
// parseBuilderSearchLimit reads ?limit=<n> as a hint for the events
// group (largest expected hit count). Scenarios + projects use smaller
// caps because their drop-down rows are visually heavier. The shared
// caller-supplied bound is interpreted as the events cap; scenarios
// and projects are derived from it.
func parseBuilderSearchLimit(raw string) builderSearchPerGroup {
def := builderSearchPerGroup{events: 8, scenarios: 5, projects: 5}
if raw == "" {
return def
}
n, err := strconv.Atoi(raw)
if err != nil || n <= 0 {
return def
}
if n > 30 {
n = 30
}
return builderSearchPerGroup{
events: n,
scenarios: max(1, n/2),
projects: max(1, n/2),
}
}

View File

@@ -540,6 +540,8 @@ func Register(mux *http.ServeMux, client *auth.Client, giteaAPIToken string, svc
// m/paliad#153 B2 — read-only passthrough so the builder can render
// per-triplet flag toggles without a per-project round-trip.
protected.HandleFunc("GET /api/builder/scenario-flag-catalog", handleBuilderFlagCatalog)
// m/paliad#153 B3 — universal search (events + scenarios + projects).
protected.HandleFunc("GET /api/builder/search", handleBuilderSearch)
// Dev-only test route — gated to PaliadinOwnerEmail (m).
protected.HandleFunc("GET /dev/scenario-builder", handleBuilderDevTestPage)

View File

@@ -265,7 +265,7 @@ func (s *DeadlineService) ListVisibleForUser(ctx context.Context, userID uuid.UU
query := `
SELECT f.id, f.project_id, f.title, f.description, f.due_date, f.original_due_date,
f.warning_date, f.source, f.rule_id, f.rule_code, f.custom_rule_text, f.status, f.completed_at,
f.warning_date, f.source, f.sequencing_rule_id, f.rule_code, f.custom_rule_text, f.status, f.completed_at,
f.caldav_uid, f.caldav_etag, f.notes, f.created_by,
f.created_at, f.updated_at,
f.approval_status, f.pending_request_id, f.approved_by, f.approved_at,

View File

@@ -145,7 +145,7 @@ func (s *FristenrechnerService) ListProceedings(ctx context.Context, opts Procee
AND pe.event_kind = $%d
)`, opts.EventKind)
}
query := `SELECT code, name, name_en, jurisdiction
query := `SELECT id, code, name, name_en, jurisdiction
FROM paliad.proceeding_types
WHERE ` + strings.Join(where, " AND ") + `
ORDER BY sort_order`
@@ -160,7 +160,7 @@ func (s *FristenrechnerService) ListProceedings(ctx context.Context, opts Procee
for rows.Next() {
var t lp.FristenrechnerType
var juris sql.NullString
if err := rows.Scan(&t.Code, &t.Name, &t.NameEN, &juris); err != nil {
if err := rows.Scan(&t.ID, &t.Code, &t.Name, &t.NameEN, &juris); err != nil {
return nil, err
}
if juris.Valid {

View File

@@ -1247,7 +1247,7 @@ func (s *ProjectionService) collectActualsForOverrides(
}
var dRows []drow
scopeFilter := scopeProjectIDFilter("d", "project_id", projectID, directOnly)
q := `SELECT d.rule_id, d.rule_code, d.due_date, d.completed_at, d.status
q := `SELECT d.sequencing_rule_id AS rule_id, d.rule_code, d.due_date, d.completed_at, d.status
FROM paliad.deadlines d
WHERE ` + scopeFilter
if err := s.db.SelectContext(ctx, &dRows, q, projectID); err != nil {

View File

@@ -204,7 +204,15 @@ func (s *ScenarioBuilderService) GetScenarioDeep(ctx context.Context, userID, sc
return nil, ErrScenarioBuilderNotVisible
}
deep := &BuilderScenarioDeep{BuilderScenario: *sc}
deep := &BuilderScenarioDeep{
BuilderScenario: *sc,
// Initialise to empty so the JSON response always carries arrays,
// not null — the builder frontend's renderCanvas calls .filter on
// proceedings/events unconditionally once state.active is set.
Proceedings: []BuilderProceeding{},
Events: []BuilderEvent{},
Shares: []BuilderShare{},
}
if err := s.db.SelectContext(ctx, &deep.Proceedings, `
SELECT id, scenario_id, proceeding_type_id, primary_party, scenario_flags,

View File

@@ -531,7 +531,17 @@ type RuleCalculationProceeding struct {
// FristenrechnerType mirrors the /api/tools/proceeding-types response
// metadata.
//
// ID is the paliad.proceeding_types primary key. Surfaces so frontend
// pickers (Litigation Builder add-proceeding, fristenrechner-wizard
// project prefill) can POST the FK directly without a code→id round
// trip. Historically code-keyed; the Litigation Builder POSTing
// proceeding_type_id (int) to /api/builder/scenarios/{id}/proceedings
// forced surfacing the id (t-paliad-345 — the missing id meant the
// POST silently sent body={} and the "+ Verfahren hinzufügen" button
// did nothing).
type FristenrechnerType struct {
ID int `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
NameEN string `json:"nameEN"`

View File

@@ -0,0 +1,50 @@
package litigationplanner
import (
"encoding/json"
"strings"
"testing"
)
// TestFristenrechnerType_WireShapeIncludesID is the regression test for
// t-paliad-345: the /api/tools/proceeding-types JSON response must
// include `id` so frontend pickers (Litigation Builder add-proceeding,
// fristenrechner-wizard project prefill) can POST proceeding_type_id
// directly without a code→id round trip. When the id was missing the
// Litigation Builder "+ Verfahren hinzufügen" button silently dropped
// the proceeding_type_id from the POST body (JSON.stringify omits
// undefined keys), the server rejected with 400, and the client
// swallowed the error — user-visible symptom was "nothing happens".
func TestFristenrechnerType_WireShapeIncludesID(t *testing.T) {
in := FristenrechnerType{
ID: 42,
Code: "upc.inf.cfi",
Name: "UPC Verletzungsverfahren",
NameEN: "UPC Infringement Action",
Group: "UPC",
}
b, err := json.Marshal(in)
if err != nil {
t.Fatalf("marshal: %v", err)
}
got := string(b)
if !strings.Contains(got, `"id":42`) {
t.Errorf("missing id in wire shape: %s", got)
}
for _, want := range []string{`"code":"upc.inf.cfi"`, `"nameEN":"UPC Infringement Action"`} {
if !strings.Contains(got, want) {
t.Errorf("missing %q in wire shape: %s", want, got)
}
}
// Round-trip — a client that posts the id back to /api/builder/
// scenarios/{id}/proceedings should see it preserved as an integer
// (paliad.scenario_proceedings.proceeding_type_id is INT, not UUID).
var out FristenrechnerType
if err := json.Unmarshal(b, &out); err != nil {
t.Fatalf("unmarshal: %v", err)
}
if out.ID != 42 {
t.Errorf("id lost on round-trip: got %d want 42", out.ID)
}
}