@cosmicdrift/kumiko-framework 0.416.0 → 0.418.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/agents/api/framework-engine.md +32 -9
  2. package/agents/api/framework-ui-types.md +37 -10
  3. package/agents/api/renderer-web.md +25 -2
  4. package/agents/api/types.md +121 -64
  5. package/agents/api.md +1 -1
  6. package/agents/boot-rules.md +23 -1
  7. package/agents/examples/crypto-shredding-hr.md +2 -2
  8. package/agents/examples/dashboard-stats.md +51 -0
  9. package/agents/examples/event-sourcing.md +84 -0
  10. package/agents/examples/list-table-options.md +346 -12
  11. package/agents/examples/managed-config.md +9 -1
  12. package/agents/examples/record-detail-layout.md +71 -6
  13. package/agents/examples/secrets-demo.md +3 -1
  14. package/agents/examples/signature.md +3 -2
  15. package/agents/examples/writeform-section.md +329 -0
  16. package/agents/features.md +1 -1
  17. package/dist/api/server-boot-checks.d.ts +1 -0
  18. package/dist/api/server-boot-checks.js +25 -0
  19. package/dist/api/server-rate-limit-wiring.js +2 -1
  20. package/dist/db/queries/event-store.d.ts +3 -0
  21. package/dist/db/queries/event-store.js +12 -0
  22. package/dist/engine/boot-validator/action-form-preview-rules.d.ts +22 -0
  23. package/dist/engine/boot-validator/action-form-preview-rules.js +22 -0
  24. package/dist/engine/boot-validator/action-form-preview.d.ts +2 -0
  25. package/dist/engine/boot-validator/action-form-preview.js +54 -0
  26. package/dist/engine/boot-validator/boot-rules.d.ts +87 -1
  27. package/dist/engine/boot-validator/boot-rules.js +2 -0
  28. package/dist/engine/boot-validator/card-meta-overflow.js +5 -1
  29. package/dist/engine/boot-validator/config-key-rules.d.ts +5 -0
  30. package/dist/engine/boot-validator/config-key-rules.js +5 -0
  31. package/dist/engine/boot-validator/date-only-after-days.d.ts +4 -0
  32. package/dist/engine/boot-validator/date-only-after-days.js +32 -0
  33. package/dist/engine/boot-validator/entity-handler.d.ts +1 -0
  34. package/dist/engine/boot-validator/entity-handler.js +1 -1
  35. package/dist/engine/boot-validator/list-bulk-actions-rules.d.ts +40 -0
  36. package/dist/engine/boot-validator/list-bulk-actions-rules.js +40 -0
  37. package/dist/engine/boot-validator/list-bulk-actions.d.ts +2 -1
  38. package/dist/engine/boot-validator/list-bulk-actions.js +79 -9
  39. package/dist/engine/boot-validator/list-row-guidance.d.ts +1 -0
  40. package/dist/engine/boot-validator/list-row-guidance.js +1 -0
  41. package/dist/engine/boot-validator/list-table-options.d.ts +1 -1
  42. package/dist/engine/boot-validator/list-table-options.js +8 -6
  43. package/dist/engine/boot-validator/list-table-rules.d.ts +1 -1
  44. package/dist/engine/boot-validator/list-table-rules.js +1 -1
  45. package/dist/engine/boot-validator/query-output-columns.js +29 -2
  46. package/dist/engine/boot-validator/query-output-guidance.js +1 -0
  47. package/dist/engine/boot-validator/query-refs.js +3 -0
  48. package/dist/engine/boot-validator/screens-actions.d.ts +7 -2
  49. package/dist/engine/boot-validator/screens-actions.js +4 -2
  50. package/dist/engine/boot-validator/screens-forms.js +2 -0
  51. package/dist/engine/boot-validator/screens-kind-entity-list.js +5 -3
  52. package/dist/engine/boot-validator/screens-kind-projection-detail-rules.d.ts +10 -0
  53. package/dist/engine/boot-validator/screens-kind-projection-detail-rules.js +10 -0
  54. package/dist/engine/boot-validator/screens-kind-projection-detail.js +80 -0
  55. package/dist/engine/boot-validator/screens-kind-projection-list.js +2 -2
  56. package/dist/engine/boot-validator/screens-kind-shared.d.ts +1 -1
  57. package/dist/engine/boot-validator/screens-kind-shared.js +3 -1
  58. package/dist/engine/boot-validator/screens-lists-rules.d.ts +10 -0
  59. package/dist/engine/boot-validator/screens-lists-rules.js +10 -0
  60. package/dist/engine/boot-validator/screens-lists.js +13 -1
  61. package/dist/engine/boot-validator/screens.js +1 -2
  62. package/dist/engine/boot-validator/url-prefill-fields.js +8 -1
  63. package/dist/engine/boot-validator/zod-shape.d.ts +1 -0
  64. package/dist/engine/boot-validator/zod-shape.js +7 -0
  65. package/dist/engine/bridge-stub.js +1 -0
  66. package/dist/engine/build-config-feature-schema.js +30 -3
  67. package/dist/engine/screen-helpers.js +7 -3
  68. package/dist/engine/types/screen.d.ts +1 -1
  69. package/dist/engine/types/screen.js +1 -1
  70. package/dist/event-store/archive.d.ts +1 -0
  71. package/dist/event-store/archive.js +5 -1
  72. package/dist/event-store/event-store.d.ts +5 -0
  73. package/dist/event-store/event-store.js +23 -3
  74. package/dist/i18n/required-surface-keys.js +53 -13
  75. package/dist/pipeline/handler-context-events.js +15 -1
  76. package/dist/ui-types/card-column-roles.d.ts +3 -0
  77. package/dist/ui-types/card-column-roles.js +9 -5
  78. package/dist/ui-types/index.d.ts +1 -1
  79. package/package.json +3 -3
  80. package/src/changes.json +36 -0
@@ -229,6 +229,59 @@ describe("Event Sourcing Showcase", () => {
229
229
  expect(byCustomer.get("Globex")).toMatchObject({ paidInvoices: 1, totalCents: 300 });
230
230
  });
231
231
 
232
+ test("loadByTypes: statuses of the requested invoices from approved/paid events only", async () => {
233
+ const requestedPaid = await stack.http.writeOk<{ id: string }>(
234
+ "showcase:write:invoice:create",
235
+ { customer: "Acme" },
236
+ admin,
237
+ );
238
+ const requestedApproved = await stack.http.writeOk<{ id: string }>(
239
+ "showcase:write:invoice:create",
240
+ { customer: "Acme" },
241
+ admin,
242
+ );
243
+ const notRequested = await stack.http.writeOk<{ id: string }>(
244
+ "showcase:write:invoice:create",
245
+ { customer: "Globex" },
246
+ admin,
247
+ );
248
+ for (const invoice of [requestedPaid, requestedApproved, notRequested]) {
249
+ await stack.http.writeOk(
250
+ "showcase:write:invoice:approve",
251
+ { id: invoice.id, amountCents: 100, approvedBy: "cfo" },
252
+ admin,
253
+ );
254
+ }
255
+ await stack.http.writeOk(
256
+ "showcase:write:invoice:pay",
257
+ { id: requestedPaid.id, amountCents: 100 },
258
+ admin,
259
+ );
260
+ await stack.http.writeOk(
261
+ "showcase:write:invoice:pay",
262
+ { id: notRequested.id, amountCents: 100 },
263
+ admin,
264
+ );
265
+ await stack.http.writeOk(
266
+ "showcase:write:invoice:acknowledge",
267
+ { id: requestedApproved.id, approverId: "cfo" },
268
+ admin,
269
+ );
270
+
271
+ const { statuses } = await stack.http.queryOk<{
272
+ statuses: Array<{ id: string; status: string }>;
273
+ }>(
274
+ "showcase:query:invoice:payment-statuses",
275
+ { ids: [requestedPaid.id, requestedApproved.id] },
276
+ admin,
277
+ );
278
+
279
+ expect(statuses).toEqual([
280
+ { id: requestedPaid.id, status: "paid" },
281
+ { id: requestedApproved.id, status: "approved" },
282
+ ]);
283
+ });
284
+
232
285
  test("asOf point-in-time read: invoice state before the pay event", async () => {
233
286
  const { id } = await stack.http.writeOk<{ id: string }>(
234
287
  "showcase:write:invoice:create",
@@ -837,6 +890,7 @@ describe("role-restricted write handlers", () => {
837
890
  // - r.projection — single-stream read model (inline in the write TX)
838
891
  // - r.multiStreamProjection — cross-aggregate async read model
839
892
  // - ctx.events.load with { asOf } — point-in-time aggregate state
893
+ // - ctx.events.loadByTypes — events of many aggregates, filtered by type, in one query
840
894
  // - ctx.events.archive / ctx.events.restore — Marten ArchiveStream
841
895
  // - ctx.dispatch.queryProjection — tenant-scoped read of a projection table
842
896
  // - ctx.events.snapshot + ctx.events.loadWithSnapshot — perf path
@@ -1225,6 +1279,36 @@ export const invoiceFeature = defineFeature("showcase", (r) => {
1225
1279
  },
1226
1280
  });
1227
1281
 
1282
+ // List page over many invoices: ONE query for just the approved/paid events of the
1283
+ // requested aggregates instead of ctx.events.load per invoice.
1284
+ r.queryHandler({
1285
+ name: "invoice:payment-statuses",
1286
+ schema: z.object({ ids: z.array(z.uuid()).max(200) }),
1287
+ handler: async (query, ctx) => {
1288
+ const events = await ctx.events.loadByTypes({
1289
+ aggregateIds: query.payload.ids,
1290
+ eventTypes: [approved.name, paid.name],
1291
+ });
1292
+ const lastEventByInvoice = new Map<string, string>();
1293
+ for (const evt of events) {
1294
+ lastEventByInvoice.set(evt.aggregateId, evt.type);
1295
+ }
1296
+ return {
1297
+ statuses: [...lastEventByInvoice].map(([id, lastEventType]) => ({
1298
+ id,
1299
+ status: lastEventType === paid.name ? "paid" : "approved",
1300
+ })),
1301
+ };
1302
+ },
1303
+ access: {
1304
+ openToAll: {
1305
+ reason:
1306
+ "demo recipe: any signed-in user may read invoice payment statuses; " +
1307
+ "there is no per-user invoice ownership in this sample",
1308
+ },
1309
+ },
1310
+ });
1311
+
1228
1312
  // Snapshot-aware fast path. Uses the latest snapshot if available and
1229
1313
  // only replays delta events past it. Identical state shape to
1230
1314
  // invoice:state — the two are interchangeable modulo the perf profile.
@@ -29,12 +29,27 @@ the `table` block renders and behaves as before.
29
29
  file; `maxRows` lowers the default limit of 10000 rows.
30
30
  Reference columns export their label and timestamps use the browser time zone.
31
31
  - `bulkActions`: row checkboxes and a selection bar. "Delete" runs the delete
32
- row action once per selected row; done tasks are skipped.
32
+ row action once per selected row (done tasks are skipped); "Set status" opens
33
+ an actionForm once for the whole selection. Its `taskIds` field is a
34
+ `multiSelect` with `display: "count"`, and the `task:set-status` handler
35
+ updates every id in one write, bounded by `.max(MAX_BULK_SELECTION)` and
36
+ reading each id through the tenant-scoped executor. The form has a `preview`:
37
+ the `task:set-status-preview` query returns the affected tasks with old and
38
+ new status from the same plan function the handler applies.
33
39
  - `table.grouping`: the server groups the list by status; each header shows the
34
40
  group's count and estimate sum, "done" starts collapsed and the view menu
35
41
  offers grouping by priority or none.
36
42
  - `table.totals`: a footer row with the estimate sum over the filtered list.
37
43
  - `facets.estimateHours: { display: "range" }`: from/to inputs for a number field.
44
+ - `mutedRowField: "parked"`: a parked task is drawn entirely in the muted colour.
45
+ - `toolbarSort: true`: the desktop "Sorted by" select in the filter row (opt-in).
46
+ - Column options: `ellipsis` (one truncated line), `multiline` (line breaks stay),
47
+ `tone: "muted"`, `cardAbove` (phone card line above the title), `hideWhenDocked`,
48
+ `emptyPlaceholder` (`false` keeps the cell blank, a string shows muted text),
49
+ `cardBadge` (phone-card pill), `dateOnlyAfterDays` on a timestamp column,
50
+ `pillField` / `pillToneField` (a second pill beside the cell value).
51
+ - Row action `display: "text"`: muted text without a button, shown for done tasks.
52
+ - `hideCountFooter` is not set here: no screen declaration reaches it (relatedList sets it itself).
38
53
  - The same block on a `projectionList`, and `task:workload`, a hand-written list
39
54
  query that keeps grouping and totals by accepting `aggregate`
40
55
  (`entityListSchema`) and answering it with `answerListAggregate`.
@@ -53,9 +68,9 @@ bun test
53
68
  The test boots the feature through the boot validator and checks that a
54
69
  misspelled key, a hidden column without the picker, an unknown density, a pinned column
55
70
  without `pinning`, a width without `resizing` and a bulk action on a navigate
56
- row action are rejected.
71
+ row action, a form bulk action whose `idsField` is no count list and a preview over an unknown query or field are rejected.
57
72
  `workload.integration.test.ts` runs the hand-written query over HTTP and checks
58
- the grouped sums and the filtered total.
73
+ the grouped sums and the filtered total, the preview query, and the handler's unknown-id and over-cap rejections.
59
74
 
60
75
  ## Source files
61
76
 
@@ -70,6 +85,7 @@ import {
70
85
  } from "@cosmicdrift/kumiko-framework/engine";
71
86
  import type { ListTableOptions } from "@cosmicdrift/kumiko-framework/ui-types";
72
87
  import { withBootValidatorFixture } from "@cosmicdrift/kumiko-testing/helpers";
88
+ import * as z from "zod";
73
89
  import { createTaskBoardFeature, openAccess, taskEntity } from "../feature";
74
90
 
75
91
  // The boot validator is the net for blocks the type system never sees (JS, generated features).
@@ -100,15 +116,79 @@ describe("list-table-options recipe", () => {
100
116
  });
101
117
  });
102
118
 
103
- test("the bulk action resolves to the delete row action", () => {
119
+ test("the bulk actions resolve to the delete row action and the status form", () => {
104
120
  const screen = createRegistry([createTaskBoardFeature()]).getScreen(
105
121
  "task-board:screen:task-list",
106
122
  );
107
123
  expect(screen?.type === "entityList" ? screen.bulkActions : undefined).toEqual([
108
124
  { id: "delete", rowAction: "delete" },
125
+ {
126
+ id: "set-status",
127
+ label: "Set status",
128
+ icon: "pencil",
129
+ screen: "task-set-status",
130
+ idsField: "taskIds",
131
+ },
109
132
  ]);
110
133
  });
111
134
 
135
+ test("the form bulk action boots and a missing count field is rejected", () => {
136
+ expect(() => validateBoot([createTaskBoardFeature()])).not.toThrow();
137
+ const feature = defineFeature("bulk-form-bad", (r) => {
138
+ r.crud("task", taskEntity, { write: openAccess, read: openAccess });
139
+ r.screen({
140
+ id: "task-list",
141
+ type: "entityList",
142
+ entity: "task",
143
+ columns: ["title"],
144
+ bulkActions: [{ id: "set", label: "Set", screen: "set-form", idsField: "taskIds" }],
145
+ access: openAccess.access,
146
+ });
147
+ r.screen({
148
+ id: "set-form",
149
+ type: "actionForm",
150
+ dormant: true,
151
+ handler: "bulk-form-bad:write:task:create",
152
+ fields: { taskIds: { type: "text" } },
153
+ layout: { sections: [{ fields: ["taskIds"] }] },
154
+ });
155
+ });
156
+ expect(() => validateBoot([feature])).toThrow(/idsField "taskIds", which is not a list field/);
157
+ });
158
+
159
+ test("a preview over an unknown query or an undeclared field is rejected", () => {
160
+ const withPreview = (preview: object) =>
161
+ defineFeature("preview-bad", (r) => {
162
+ r.queryHandler({
163
+ name: "task:p",
164
+ schema: z.object({ status: z.string().optional() }),
165
+ handler: async () => ({ count: 0 }),
166
+ access: openAccess.access,
167
+ });
168
+ r.writeHandler({
169
+ name: "task:noop",
170
+ schema: z.object({ status: z.string() }),
171
+ handler: async () => ({ isSuccess: true as const, data: {} }),
172
+ access: openAccess.access,
173
+ });
174
+ r.screen({
175
+ id: "noop-form",
176
+ type: "actionForm",
177
+ dormant: true,
178
+ handler: "preview-bad:write:task:noop",
179
+ fields: { status: { type: "text" } },
180
+ layout: { sections: [{ fields: ["status"] }] },
181
+ preview: { facts: [{ field: "count", label: "Count" }], ...preview },
182
+ } as never);
183
+ });
184
+ expect(() => validateBoot([withPreview({ query: "preview-bad:query:task:missing" })])).toThrow(
185
+ /Screen "noop-form" \(actionForm\) preview/,
186
+ );
187
+ expect(() =>
188
+ validateBoot([withPreview({ query: "preview-bad:query:task:p", fields: ["owner"] })]),
189
+ ).toThrow(/sends field "owner"/);
190
+ });
191
+
112
192
  test("a bulk action that points at a navigate row action is rejected", () => {
113
193
  const feature = defineFeature("bulk-on-navigate", (r) => {
114
194
  r.crud("task", taskEntity, { write: openAccess, read: openAccess });
@@ -145,9 +225,21 @@ describe("list-table-options recipe", () => {
145
225
  );
146
226
  });
147
227
 
148
- test("a hidden column needs the column picker", () => {
149
- expect(() => validateBoot([featureWithBlock({ rememberState: true, resetAll: true })])).toThrow(
150
- /column "estimateHours" is hidden but table\.columnPicker is not enabled/,
228
+ // A hidden column that backs a facet needs no picker (the facet is its UI), so the recipe's
229
+ // own hidden estimateHours column does not trip the rule; a plain hidden column does.
230
+ test("a hidden column without a facet needs the column picker", () => {
231
+ const feature = defineFeature("task-board", (r) => {
232
+ r.crud("task", taskEntity, { write: openAccess, read: openAccess });
233
+ r.screen({
234
+ id: "task-list",
235
+ type: "entityList",
236
+ entity: "task",
237
+ columns: ["title", { field: "assignee", hidden: true }],
238
+ table: { rememberState: true },
239
+ });
240
+ });
241
+ expect(() => validateBoot([feature])).toThrow(
242
+ /column "assignee" is hidden but table\.columnPicker is not enabled/,
151
243
  );
152
244
  });
153
245
 
@@ -172,6 +264,7 @@ describe("list-table-options recipe", () => {
172
264
  ```ts
173
265
  import { afterAll, beforeAll, describe, expect, test } from "bun:test";
174
266
  import { createTestUser, testTenantId } from "@cosmicdrift/kumiko-framework/seeding";
267
+ import { MAX_BULK_SELECTION } from "@cosmicdrift/kumiko-framework/ui-types";
175
268
  import { setupTestStack, type TestStack } from "@cosmicdrift/kumiko-testing/stack";
176
269
  import { createTaskBoardFeature } from "../feature";
177
270
 
@@ -237,6 +330,82 @@ describe("hand-written list query with aggregate", () => {
237
330
  ]);
238
331
  });
239
332
  });
333
+
334
+ describe("form bulk action handler", () => {
335
+ test("one write sets the status of every selected task", async () => {
336
+ const created = await Promise.all(
337
+ ["Bulk A", "Bulk B"].map((title) =>
338
+ stack.http.writeOk<{ data: { id: string } }>(
339
+ "task-board:write:task:create",
340
+ { title },
341
+ user,
342
+ ),
343
+ ),
344
+ );
345
+ const taskIds = created.map((task) => task.data.id);
346
+ await stack.http.writeOk(
347
+ "task-board:write:task:set-status",
348
+ { taskIds, status: "blocked", note: "waiting" },
349
+ user,
350
+ );
351
+ const list = await stack.http.queryOk<{
352
+ rows: { title: string; status: string; note: string }[];
353
+ }>("task-board:query:task:list", { sort: "title" }, user);
354
+ expect(
355
+ list.rows.filter((row) => row.title.startsWith("Bulk")).map((row) => [row.status, row.note]),
356
+ ).toEqual([
357
+ ["blocked", "waiting"],
358
+ ["blocked", "waiting"],
359
+ ]);
360
+ });
361
+
362
+ test("the preview query shows the same plan the handler applies", async () => {
363
+ const created = await Promise.all(
364
+ ["Plan A", "Plan B"].map((title) =>
365
+ stack.http.writeOk<{ data: { id: string } }>(
366
+ "task-board:write:task:create",
367
+ { title, status: title === "Plan B" ? "blocked" : "open" },
368
+ user,
369
+ ),
370
+ ),
371
+ );
372
+ const taskIds = created.map((task) => task.data.id);
373
+ const preview = await stack.http.queryOk<{
374
+ count: number;
375
+ tasks: { title: string; before: string; after: string }[];
376
+ }>("task-board:query:task:set-status-preview", { taskIds, status: "blocked" }, user);
377
+ expect(preview).toEqual({
378
+ count: 1,
379
+ tasks: [
380
+ { title: "Plan A", before: "open", after: "blocked" },
381
+ { title: "Plan B", before: "blocked", after: "blocked" },
382
+ ],
383
+ });
384
+ });
385
+
386
+ test("an unknown id fails the whole write and a list above the cap is rejected", async () => {
387
+ const unknown = await stack.http.write(
388
+ "task-board:write:task:set-status",
389
+ { taskIds: ["11111111-1111-4111-8111-111111111111"], status: "done" },
390
+ user,
391
+ );
392
+ const unknownBody = (await unknown.json()) as { isSuccess: boolean; error?: { code: string } };
393
+ expect(unknownBody.isSuccess).toBe(false);
394
+ expect(unknownBody.error?.code).toBe("not_found");
395
+
396
+ const tooMany = await stack.http.write(
397
+ "task-board:write:task:set-status",
398
+ {
399
+ taskIds: Array.from({ length: MAX_BULK_SELECTION + 1 }, () => crypto.randomUUID()),
400
+ status: "done",
401
+ },
402
+ user,
403
+ );
404
+ const tooManyBody = (await tooMany.json()) as { isSuccess: boolean; error?: { code: string } };
405
+ expect(tooManyBody.isSuccess).toBe(false);
406
+ expect(tooManyBody.error?.code).toBe("validation_error");
407
+ });
408
+ });
240
409
  ```
241
410
 
242
411
  ### src/feature.ts
@@ -248,16 +417,19 @@ import {
248
417
  createEventStoreExecutor,
249
418
  } from "@cosmicdrift/kumiko-framework/db";
250
419
  import {
420
+ createBooleanField,
251
421
  createDateField,
252
422
  createEntity,
253
423
  createNumberField,
254
424
  createSelectField,
255
425
  createTextField,
426
+ createTimestampField,
256
427
  defineFeature,
257
428
  entityListSchema,
258
429
  type FeatureDefinition,
259
430
  } from "@cosmicdrift/kumiko-framework/engine";
260
- import type { ListTableOptions } from "@cosmicdrift/kumiko-framework/ui-types";
431
+ import { failNotFound, NotFoundError } from "@cosmicdrift/kumiko-framework/errors";
432
+ import { type ListTableOptions, MAX_BULK_SELECTION } from "@cosmicdrift/kumiko-framework/ui-types";
261
433
  import { z } from "zod";
262
434
 
263
435
  export const taskEntity = createEntity({
@@ -285,6 +457,14 @@ export const taskEntity = createEntity({
285
457
  dueDate: createDateField({ sortable: true }),
286
458
  assignee: createTextField({ personal: false, reason: "is_business_data", sortable: true }),
287
459
  estimateHours: createNumberField({ sortable: true, filterable: true }),
460
+ parked: createBooleanField({ default: false }),
461
+ note: createTextField({ personal: false, reason: "is_business_data" }),
462
+ team: createTextField({ personal: false, reason: "is_business_data" }),
463
+ teamTone: createSelectField({
464
+ options: ["positive", "warn", "negative", "neutral"] as const,
465
+ default: "neutral",
466
+ }),
467
+ lastUpdate: createTimestampField({ sortable: true }),
288
468
  },
289
469
  });
290
470
 
@@ -294,6 +474,39 @@ export const openAccess = {
294
474
  },
295
475
  } as const;
296
476
 
477
+ const setStatusInput = z.object({
478
+ taskIds: z.array(z.uuid()).min(1).max(MAX_BULK_SELECTION),
479
+ status: z.enum(taskEntity.fields.status.options),
480
+ });
481
+
482
+ type StatusPlanRow = {
483
+ readonly id: string;
484
+ readonly version: number;
485
+ readonly title: string;
486
+ readonly before: string;
487
+ readonly after: string;
488
+ };
489
+
490
+ // The one rule behind the status form: the write handler applies it and the preview query shows it.
491
+ async function planStatusChanges(
492
+ taskIds: readonly string[],
493
+ status: string,
494
+ loadTask: (id: string) => Promise<Readonly<Record<string, unknown>> | null | undefined>,
495
+ ): Promise<{ readonly rows: readonly StatusPlanRow[] } | { readonly missingId: string }> {
496
+ const rows: StatusPlanRow[] = [];
497
+ for (const id of taskIds) {
498
+ const task = await loadTask(id);
499
+ if (!task) return { missingId: id };
500
+ rows.push({
501
+ id,
502
+ version: Number(task["version"]),
503
+ title: String(task["title"]),
504
+ before: String(task["status"]),
505
+ after: status,
506
+ });
507
+ }
508
+ return { rows };
509
+ }
297
510
  // Overridable so a test can feed the boot validator a block that must be rejected.
298
511
  export function createTaskBoardFeature(
299
512
  taskTable: ListTableOptions = {
@@ -320,9 +533,29 @@ export function createTaskBoardFeature(
320
533
  // Starts pinned left; width and minWidth are start values for resizing.
321
534
  { field: "title", pinned: "left", width: 280, minWidth: 160 },
322
535
  "status",
323
- "priority",
536
+ // The phone card shows the priority as its outlined pill instead of the first select column.
537
+ { field: "priority", cardBadge: true },
324
538
  { field: "dueDate", hideOnNarrow: true },
325
- { field: "assignee", hideOnNarrow: true },
539
+ // The team pill sits beside the assignee name; its tone comes from the row.
540
+ {
541
+ field: "assignee",
542
+ hideOnNarrow: true,
543
+ pillField: "team",
544
+ pillToneField: "teamTone",
545
+ emptyPlaceholder: "Unassigned",
546
+ },
547
+ // One truncated line in the table; a line break starts a new line on the phone card.
548
+ {
549
+ field: "note",
550
+ ellipsis: true,
551
+ multiline: true,
552
+ tone: "muted",
553
+ cardAbove: true,
554
+ hideWhenDocked: true,
555
+ emptyPlaceholder: false,
556
+ },
557
+ // Recent edits show date and time, older ones the date only.
558
+ { field: "lastUpdate", dateOnlyAfterDays: 7, hideOnNarrow: true },
326
559
  // Starts hidden; the user can add it back in the view menu.
327
560
  { field: "estimateHours", hidden: true, hideOnNarrow: true },
328
561
  ],
@@ -330,7 +563,22 @@ export function createTaskBoardFeature(
330
563
  defaultSort: { field: "dueDate", dir: "asc" },
331
564
  searchable: true,
332
565
  table: taskTable,
566
+ mutedRowField: "parked",
567
+ toolbarSort: true,
568
+ sortOptions: [
569
+ { field: "dueDate", dir: "asc", label: "Due date" },
570
+ { field: "priority", dir: "desc", label: "Priority" },
571
+ ],
333
572
  rowActions: [
573
+ // A closed state as muted text instead of a button.
574
+ {
575
+ kind: "navigate",
576
+ id: "closed",
577
+ label: "Closed",
578
+ screen: "task-edit",
579
+ display: "text",
580
+ visible: { field: "status", eq: "done" },
581
+ },
334
582
  { kind: "navigate", id: "open", label: "Open", screen: "task-edit", rowClick: true },
335
583
  {
336
584
  kind: "writeHandler",
@@ -342,8 +590,17 @@ export function createTaskBoardFeature(
342
590
  visible: { field: "status", ne: "done" },
343
591
  },
344
592
  ],
345
- // Row checkboxes and a selection bar; each selected row gets its own delete write.
346
- bulkActions: [{ id: "delete", rowAction: "delete" }],
593
+ // Row checkboxes and a selection bar; delete writes once per row, set-status once for all.
594
+ bulkActions: [
595
+ { id: "delete", rowAction: "delete" },
596
+ {
597
+ id: "set-status",
598
+ label: "Set status",
599
+ icon: "pencil",
600
+ screen: "task-set-status",
601
+ idsField: "taskIds",
602
+ },
603
+ ],
347
604
  access: openAccess.access,
348
605
  });
349
606
 
@@ -439,6 +696,83 @@ export function createTaskBoardFeature(
439
696
  },
440
697
  });
441
698
 
699
+ // One write for the whole selection: the bulk action below opens this form and `taskIds`
700
+ // arrives as a string array. The client cap is no protection, so the schema bounds the list
701
+ // and every id is read through the tenant-scoped executor before anything is written.
702
+ r.writeHandler({
703
+ name: "task:set-status",
704
+ schema: setStatusInput.extend({ note: z.string().optional() }),
705
+ access: openAccess.access,
706
+ handler: async (event, ctx) => {
707
+ const { taskIds, status, note } = event.payload;
708
+ const plan = await planStatusChanges(taskIds, status, (id) =>
709
+ taskExecutor.detail({ id }, event.user, ctx.db),
710
+ );
711
+ if ("missingId" in plan) return failNotFound("task", plan.missingId);
712
+ const changed = plan.rows.filter((row) => row.before !== row.after);
713
+ for (const row of changed) {
714
+ const result = await taskExecutor.update(
715
+ { id: row.id, version: row.version, changes: { status, note } },
716
+ event.user,
717
+ ctx.db,
718
+ );
719
+ if (!result.isSuccess) return result;
720
+ }
721
+ return { isSuccess: true as const, data: { count: changed.length } };
722
+ },
723
+ });
724
+
725
+ // The preview runs the same plan the write handler runs, so the two cannot drift apart.
726
+ r.queryHandler({
727
+ name: "task:set-status-preview",
728
+ schema: setStatusInput,
729
+ access: openAccess.access,
730
+ handler: async (query, ctx) => {
731
+ const { taskIds, status } = query.payload;
732
+ const plan = await planStatusChanges(taskIds, status, (id) =>
733
+ taskExecutor.detail({ id }, query.user, ctx.db),
734
+ );
735
+ if ("missingId" in plan) throw new NotFoundError("task");
736
+ return {
737
+ count: plan.rows.filter((row) => row.before !== row.after).length,
738
+ tasks: plan.rows.map(({ title, before, after }) => ({ title, before, after })),
739
+ };
740
+ },
741
+ });
742
+
743
+ r.screen({
744
+ id: "task-set-status",
745
+ type: "actionForm",
746
+ dormant: true,
747
+ handler: "task-board:write:task:set-status",
748
+ listScreenId: "task-list",
749
+ redirect: "task-list",
750
+ fields: {
751
+ taskIds: { type: "multiSelect", options: [], display: "count" },
752
+ status: createSelectField({
753
+ options: ["open", "inProgress", "blocked", "done"] as const,
754
+ required: true,
755
+ }),
756
+ note: createTextField({ personal: false, reason: "is_business_data" }),
757
+ },
758
+ layout: { sections: [{ fields: ["taskIds", "status", "note"] }] },
759
+ // Which tasks change and from what to what, shown before the user submits.
760
+ preview: {
761
+ query: "task-board:query:task:set-status-preview",
762
+ fields: ["taskIds", "status"],
763
+ title: "Preview",
764
+ facts: [{ field: "count", label: "Tasks that change" }],
765
+ list: {
766
+ field: "tasks",
767
+ columns: [
768
+ { field: "title", label: "Task" },
769
+ { field: "before", label: "Now" },
770
+ { field: "after", label: "New" },
771
+ ],
772
+ },
773
+ },
774
+ });
775
+
442
776
  r.nav({ id: "tasks", label: "task-board:nav.tasks", icon: "list", order: 10 });
443
777
  r.nav({
444
778
  id: "task-list",
@@ -404,7 +404,14 @@ export const integrationsFeature = defineFeature(FEATURE, (r) => {
404
404
  default: "smtp.platform.example",
405
405
  write: access.roles("SystemAdmin", "Admin"),
406
406
  read: access.admin,
407
- mask: { title: "integrations.smtp-host", icon: "mail", order: 2 },
407
+ // compact: the generated screen drops origin icons and accent bars; section: groups the key under its own titled section.
408
+ mask: {
409
+ title: "integrations.smtp-host",
410
+ icon: "mail",
411
+ order: 2,
412
+ compact: true,
413
+ section: "integrations.mail",
414
+ },
408
415
  }),
409
416
  },
410
417
  });
@@ -426,6 +433,7 @@ export const integrationsFeature = defineFeature(FEATURE, (r) => {
426
433
  "integrations.settings": { de: "Integrationen", en: "Integrations" },
427
434
  "integrations.payment-api-key": { de: "Zahlungs-API-Schlüssel", en: "Payment API Key" },
428
435
  "integrations.smtp-host": { de: "SMTP-Server", en: "SMTP Host" },
436
+ "integrations.mail": { de: "E-Mail-Versand", en: "Mail delivery" },
429
437
  },
430
438
  });
431
439
  });