wcz-layout 10.1.9 → 10.2.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 (107) hide show
  1. package/dist/{Approval-DoD-GRRH.mjs → Approval-D1TfISUL.mjs} +11 -21
  2. package/dist/Approval-D1TfISUL.mjs.map +1 -0
  3. package/dist/{LayoutTable-CRo43iWr.d.mts → ChatLayout-BmLySLXy.d.mts} +11 -18
  4. package/dist/ChatLayout-Tpuwo8-b.mjs +1622 -0
  5. package/dist/ChatLayout-Tpuwo8-b.mjs.map +1 -0
  6. package/dist/{DialogsContext-DLqA8RJ_.mjs → DialogsContext-D23fJjYR.mjs} +2 -3
  7. package/dist/DialogsContext-D23fJjYR.mjs.map +1 -0
  8. package/dist/{Email-CKUxOURX.d.mts → Email-Dz5k0UWE.d.mts} +1 -3
  9. package/dist/{Email-BzQQkbe9.mjs → Email-rnz3H0x3.mjs} +3 -5
  10. package/dist/Email-rnz3H0x3.mjs.map +1 -0
  11. package/dist/{Employee-agVPiGrJ.d.mts → Employee-C8xIlBxY.d.mts} +1 -7
  12. package/dist/{FileMeta-Be9viU7D.d.mts → FileMeta-B39e2FLC.d.mts} +1 -3
  13. package/dist/{FileMeta-DDqUju1Y.mjs → FileMeta-CPBWI_jA.mjs} +2 -3
  14. package/dist/FileMeta-CPBWI_jA.mjs.map +1 -0
  15. package/dist/{QueryClientParam-JcH0mJWl.d.mts → QueryClientParam-CTV1vj76.d.mts} +1 -3
  16. package/dist/RouterListItemButton-CF-8w-08.mjs +62 -0
  17. package/dist/RouterListItemButton-CF-8w-08.mjs.map +1 -0
  18. package/dist/{User-D4__w1I1.d.mts → User-aJksXItw.d.mts} +1 -3
  19. package/dist/{approval-L09uPzTU.mjs → approval-HB2w5jzc.mjs} +4 -5
  20. package/dist/approval-HB2w5jzc.mjs.map +1 -0
  21. package/dist/auth.d.mts +0 -4
  22. package/dist/auth.mjs +5 -6
  23. package/dist/auth.mjs.map +1 -1
  24. package/dist/components.d.mts +63 -33
  25. package/dist/components.mjs +658 -748
  26. package/dist/components.mjs.map +1 -1
  27. package/dist/{createApi-BhNkG4jz.mjs → createApi-CKgFi53y.mjs} +4 -6
  28. package/dist/createApi-CKgFi53y.mjs.map +1 -0
  29. package/dist/data/client.d.mts +2 -8
  30. package/dist/data/client.mjs +6 -9
  31. package/dist/data/client.mjs.map +1 -1
  32. package/dist/data/server.d.mts +2 -4
  33. package/dist/data/server.mjs +6 -7
  34. package/dist/data/server.mjs.map +1 -1
  35. package/dist/env-BwFl7nWc.mjs +48 -0
  36. package/dist/env-BwFl7nWc.mjs.map +1 -0
  37. package/dist/{file-Chlljz3o.mjs → file-X1sK4ok6.mjs} +7 -8
  38. package/dist/file-X1sK4ok6.mjs.map +1 -0
  39. package/dist/{file-Dl8JCcqy.mjs → file-tkfsnk5F.mjs} +8 -8
  40. package/dist/file-tkfsnk5F.mjs.map +1 -0
  41. package/dist/generatedChart-k7NEdi5Z.mjs +211 -0
  42. package/dist/generatedChart-k7NEdi5Z.mjs.map +1 -0
  43. package/dist/hooks.d.mts +30 -30
  44. package/dist/hooks.mjs +1828 -1304
  45. package/dist/hooks.mjs.map +1 -1
  46. package/dist/index.d.mts +11 -14
  47. package/dist/index.mjs +1273 -1051
  48. package/dist/index.mjs.map +1 -1
  49. package/dist/middleware.d.mts +1 -7
  50. package/dist/middleware.mjs +5 -8
  51. package/dist/middleware.mjs.map +1 -1
  52. package/dist/models.d.mts +4 -32
  53. package/dist/models.mjs +7 -11
  54. package/dist/models.mjs.map +1 -1
  55. package/dist/{peoplesoft-D6q3cYsH.d.mts → peoplesoft-C-zPdRVj.d.mts} +3 -9
  56. package/dist/{peoplesoft-BhintHQz.mjs → peoplesoft-RnvfLbWH.mjs} +5 -25
  57. package/dist/peoplesoft-RnvfLbWH.mjs.map +1 -0
  58. package/dist/{providers-BvuZWkpD.mjs → providers-BfFg_3eo.mjs} +5 -23
  59. package/dist/providers-BfFg_3eo.mjs.map +1 -0
  60. package/dist/{tokens-XuFhVbh5.mjs → tokens-C4SErO-K.mjs} +12 -8
  61. package/dist/tokens-C4SErO-K.mjs.map +1 -0
  62. package/dist/{utils-CaeVFWF-.mjs → utils-C2MZoH9U.mjs} +8 -39
  63. package/dist/utils-C2MZoH9U.mjs.map +1 -0
  64. package/dist/{utils-Bhi0KiBx.d.mts → utils-CNYCSgip.d.mts} +3 -5
  65. package/dist/utils-DnMFybj3.mjs +27 -0
  66. package/dist/utils-DnMFybj3.mjs.map +1 -0
  67. package/dist/utils.d.mts +11 -2
  68. package/dist/utils.mjs +3 -5
  69. package/dist/vite.d.mts +0 -2
  70. package/dist/vite.mjs +2 -4
  71. package/dist/vite.mjs.map +1 -1
  72. package/package.json +131 -131
  73. package/skills/ai/SKILL.md +136 -39
  74. package/skills/client-db/SKILL.md +104 -90
  75. package/skills/db-schema/SKILL.md +28 -20
  76. package/skills/dialogs/SKILL.md +26 -38
  77. package/skills/forms/SKILL.md +133 -73
  78. package/skills/general/SKILL.md +99 -105
  79. package/skills/general/references/auth.md +70 -0
  80. package/skills/migrations/versions/migrate-v10-to-v11.md +30 -4
  81. package/skills/routing/SKILL.md +60 -58
  82. package/skills/scanning/SKILL.md +67 -0
  83. package/skills/server-functions/SKILL.md +71 -26
  84. package/skills/services/SKILL.md +4 -4
  85. package/skills/services/docs/approval.md +70 -24
  86. package/skills/services/docs/email.md +24 -3
  87. package/skills/services/docs/file.md +69 -27
  88. package/skills/services/docs/peoplesoft.md +55 -39
  89. package/skills/start/steps/03-apm-setup.md +9 -9
  90. package/skills/table/SKILL.md +250 -267
  91. package/dist/AggregatedCell-oGcwbetF.mjs +0 -559
  92. package/dist/AggregatedCell-oGcwbetF.mjs.map +0 -1
  93. package/dist/Approval-DoD-GRRH.mjs.map +0 -1
  94. package/dist/DialogsContext-DLqA8RJ_.mjs.map +0 -1
  95. package/dist/Email-BzQQkbe9.mjs.map +0 -1
  96. package/dist/FileMeta-DDqUju1Y.mjs.map +0 -1
  97. package/dist/RouterListItemButton-ULMlaQh6.mjs +0 -80
  98. package/dist/RouterListItemButton-ULMlaQh6.mjs.map +0 -1
  99. package/dist/approval-L09uPzTU.mjs.map +0 -1
  100. package/dist/createApi-BhNkG4jz.mjs.map +0 -1
  101. package/dist/file-Chlljz3o.mjs.map +0 -1
  102. package/dist/file-Dl8JCcqy.mjs.map +0 -1
  103. package/dist/peoplesoft-BhintHQz.mjs.map +0 -1
  104. package/dist/providers-BvuZWkpD.mjs.map +0 -1
  105. package/dist/tokens-XuFhVbh5.mjs.map +0 -1
  106. package/dist/utils-CaeVFWF-.mjs.map +0 -1
  107. package/skills/general/references/exports.md +0 -114
@@ -1,267 +1,250 @@
1
- ---
2
- name: table
3
- description: "Use when building or changing a data table. Covers useLayoutTable, LayoutTable, createLayoutColumnHelper, column definitions and headers, cell formatters, filter variants, sorting, row selection and bulk actions, per-row actions, pagination, footer aggregation."
4
- metadata:
5
- type: convention
6
- library: wcz-layout
7
- ---
8
-
9
- # Table patterns
10
-
11
- > Mechanics (`createTableHook`, column helpers, row models, faceting, the state
12
- > atoms) belong to TanStack Table v9 itself. List the skills shipped by
13
- > `@tanstack/table-core` and `@tanstack/react-table` and load whichever cover the task at
14
- > hand. This skill covers only the wcz-layout conventions on top of it.
15
-
16
- ## Rules
17
-
18
- - Build the instance with `useLayoutTable({ data, columns })` and pass it to
19
- `<LayoutTable table={table} />`. Rows are keyed by `row.id`, so every row object
20
- needs an `id`.
21
- - For selection and actions display columns, always set `size: 50`,
22
- `enableResizing: false`, and `enableCellSelection: false`. An actions column
23
- that shows more than one button needs about 40px more per extra button.
24
- - Render cells with the bound components off the render prop
25
- (`cell.ValueCell`, `NumberCell`, `DateCell`, `DateTimeCell`, `BooleanCell`)
26
- instead of raw JSX. They carry the alignment, the number and date locale, and
27
- the noWrap behaviour. Write raw JSX only when the cell is a link or
28
- another interactive element.
29
- - Give `meta.label` to any column whose `header` is not a plain string. A string
30
- header supplies the label automatically; a function or JSX header leaves the
31
- header menu and column selector without a label; the filter picker falls back to
32
- `column.id`. `meta` has five keys: `label`, `align`, `variant`, `options`, `flex`.
33
- - `meta.flex` makes a column grow or shrink, in proportion like CSS `flex`, so the
34
- table fills its container exactly with no horizontal scroll. `size` is the starting
35
- width; it shrinks no further than `minSize` (default 20), and when that still cannot
36
- fit the columns keep their sizes and the table scrolls. Resizing the column pins it
37
- to a fixed width.
38
- - Wrap the table in `Fullscreen` when it is the only content on the page.
39
- - Props: `title`, `actions`, `showToolbar`,
40
- `loading`, `pagination`, `pageSizeOptions`, `onRowClick`, `onRowDoubleClick`,
41
- `sx`, and the `disableSearch` / `disableColumnFilter` / `disableColumnSelector` /
42
- `disableColumnMenu` escape hatches.
43
- - Rows and columns virtualize by default. Rows are measured, so a cell may grow to several
44
- lines: give its content `whiteSpace: "normal"` (cells are one ellipsized line otherwise).
45
- - Set `meta.variant` for non-text filters. Omission means `"text"`.
46
- - Do not enumerate `meta.options` for a free-text column. `select` and
47
- `multi-select` read their options from the faceted unique values, so the choices
48
- track the data. Pass explicit string options when labels differ from stored values or
49
- the UI needs a fixed list. Derive database-enum options from `enumValues`, never a
50
- second hand-written list.
51
-
52
- ## Example
53
-
54
- ```tsx
55
- import { Fullscreen, LayoutTable, RouterIconButton, RouterLink } from "wcz-layout/components";
56
- import {
57
- createLayoutColumnHelper,
58
- useDialogs,
59
- useLayoutTable,
60
- useTranslation,
61
- } from "wcz-layout/hooks";
62
-
63
- const columnHelper = createLayoutColumnHelper<Todo>();
64
-
65
- function RouteComponent() {
66
- const { t } = useTranslation();
67
- const { confirm, alert } = useDialogs();
68
- const navigate = useNavigate();
69
- const todos = useTodoCollection();
70
- const { data, isLoading } = useLiveQuery(todosQueryOptions);
71
-
72
- const columns = columnHelper.columns([
73
- columnHelper.display({
74
- id: "select",
75
- header: ({ header }) => <header.SelectAllCell scope="all" />,
76
- cell: ({ cell }) => <cell.SelectCell />,
77
- size: 50,
78
- enableResizing: false,
79
- enableCellSelection: false,
80
- }),
81
- columnHelper.accessor("name", {
82
- header: t("Todo.Name"),
83
- cell: ({ cell }) => (
84
- <RouterLink
85
- to="/todos/$id"
86
- params={{ id: cell.row.original.id }}
87
- underline="hover"
88
- color="inherit"
89
- >
90
- {cell.getValue()}
91
- </RouterLink>
92
- ),
93
- size: 260,
94
- }),
95
- columnHelper.accessor("assignee", {
96
- header: t("Todo.Assignee"),
97
- cell: ({ cell }) => <cell.ValueCell />,
98
- // No options: the filter builds them from the faceted unique values.
99
- meta: { variant: "multi-select" },
100
- size: 180,
101
- }),
102
- columnHelper.accessor("priority", {
103
- header: t("Todo.Priority"),
104
- cell: ({ cell }) => <cell.NumberCell />,
105
- footer: ({ header }) => <header.AggregationFooter options={{ maximumFractionDigits: 1 }} />,
106
- aggregationFn: "mean",
107
- meta: { variant: "number", align: "right" },
108
- size: 120,
109
- }),
110
- columnHelper.accessor("starred", {
111
- header: t("Todo.Starred"),
112
- cell: ({ cell }) => <cell.BooleanCell />,
113
- meta: { variant: "boolean", align: "center" },
114
- size: 120,
115
- }),
116
- columnHelper.accessor("createdAt", {
117
- header: t("Todo.CreatedAt"),
118
- cell: ({ cell }) => <cell.DateTimeCell />,
119
- meta: { variant: "date" },
120
- size: 190,
121
- }),
122
- ]);
123
-
124
- const table = useLayoutTable({ data, columns });
125
- const selectedIds = table.getSelectedRowIds();
126
-
127
- const handleOnDelete = createOptimisticAction<Array<string>>({
128
- onMutate: (ids) => {
129
- ids.forEach((id) => {
130
- todos.delete(id);
131
- });
132
- },
133
- mutationFn: async (ids) => {
134
- await deleteTodos({ data: ids });
135
- await todos.utils.refetch({ throwOnError: true });
136
- },
137
- });
138
-
139
- return (
140
- <Fullscreen>
141
- <LayoutTable
142
- table={table}
143
- loading={isLoading}
144
- showToolbar
145
- title={t("Todo.Todos")}
146
- onRowDoubleClick={(row) => navigate({ to: "/todos/$id", params: { id: row.id } })}
147
- actions={
148
- <>
149
- <Tooltip title={t("Create")}>
150
- <RouterIconButton to="/todos/create">
151
- <Add fontSize="small" />
152
- </RouterIconButton>
153
- </Tooltip>
154
-
155
- {selectedIds.length === 1 && (
156
- <Tooltip title={t("Edit")}>
157
- <RouterIconButton to="/todos/edit/$id" params={{ id: selectedIds[0] }}>
158
- <Edit fontSize="small" />
159
- </RouterIconButton>
160
- </Tooltip>
161
- )}
162
-
163
- {selectedIds.length > 0 && (
164
- <Tooltip title={t("Delete")}>
165
- <IconButton
166
- onClick={async () => {
167
- const confirmed = await confirm(
168
- t("DeleteConfirmation", { count: selectedIds.length }),
169
- );
170
- if (!confirmed) return;
171
-
172
- try {
173
- const transaction = handleOnDelete(selectedIds);
174
- await transaction.isPersisted.promise;
175
- table.resetRowSelection();
176
- } catch (error) {
177
- if (error instanceof Error) await alert(error.message);
178
- }
179
- }}
180
- >
181
- <Badge
182
- badgeContent={selectedIds.length}
183
- invisible={selectedIds.length <= 1}
184
- color="error"
185
- >
186
- <Delete fontSize="small" />
187
- </Badge>
188
- </IconButton>
189
- </Tooltip>
190
- )}
191
- </>
192
- }
193
- />
194
- </Fullscreen>
195
- );
196
- }
197
- ```
198
-
199
- ### Per-row actions
200
-
201
- ```tsx
202
- columnHelper.display({
203
- id: "actions",
204
- cell: ({ cell }) => (
205
- <cell.ActionsCell
206
- actions={[
207
- {
208
- label: t("Edit"),
209
- icon: <Edit fontSize="small" />,
210
- onClick: (row) => navigate({ to: "/todos/edit/$id", params: { id: row.id } }),
211
- },
212
- {
213
- label: t("Delete"),
214
- icon: <Delete fontSize="small" />,
215
- showInMenu: true,
216
- onClick: (row) => remove(row.id),
217
- },
218
- ]}
219
- />
220
- ),
221
- size: 50,
222
- enableResizing: false,
223
- enableCellSelection: false,
224
- });
225
- ```
226
-
227
- ### Other bound components
228
-
229
- On the header render prop: `SelectAllCell`, `ExpandAllCell`, `AggregationFooter`,
230
- `HeaderMenu`, `HeaderSortLabel`, `HeaderResizeHandle`. On the cell one:
231
- `SelectCell`, `ExpandCell`, `GroupCell`, `PinRowCell`, `ActionsCell` and the
232
- formatter cells. `LayoutTable` already places the menu, the sort label and the
233
- resize handle, so reach for those three only when building a table by hand.
234
-
235
- ### Custom cells and headers
236
-
237
- The render prop only exposes the components registered in the library. To write your
238
- own, read the context directly inside a plain component: `useCellContext<TValue>()`,
239
- `useHeaderContext()` or `useTableContext()` from `wcz-layout/hooks`.
240
- `layoutTableFeatures` and the `LayoutTableFeatures` type are the feature set
241
- `useLayoutTable` installs — you need them only to type a hand-built table instance.
242
-
243
- ## Common Mistakes
244
-
245
- ### CRITICAL: Writing TanStack Table v8 column definitions
246
-
247
- Wrong: `accessorKey: "name"`, `cell: (info) => info.getValue()`, `getCoreRowModel:
248
- getCoreRowModel()`.
249
-
250
- Correct: `columnHelper.accessor("name", { cell: ({ cell }) => <cell.ValueCell /> })`
251
- inside `columnHelper.columns([...])`, and no row models at all.
252
-
253
- This is v9. v8 column defs either type-error inside `columnHelper.columns()` or
254
- silently no-op, and row models are gone.
255
-
256
- ### HIGH: Adding your own virtualizer or pager
257
-
258
- Wrong: wrapping rows in `useVirtualizer` from `@tanstack/react-virtual`, or bolting on
259
- a `TablePagination`.
260
-
261
- Correct: render `<LayoutTable table={table} />` and pass `pagination` if the user wants
262
- a pager.
263
-
264
- `LayoutTable` already virtualizes rows and columns. A second virtualizer fights the
265
- first over scroll position.
266
-
267
- Use only `LayoutTable`'s `pagination` prop for its pager.
1
+ ---
2
+ name: table
3
+ description: "Use when building or changing a data table or list page in app: useLayoutTable, LayoutTable, createLayoutColumnHelper, columns and headers, cell formatters, filter variants, sorting, row selection and bulk actions, per-row actions, pagination or server paging, footer aggregation, column sizing, or styling table parts."
4
+ metadata:
5
+ type: convention
6
+ library: wcz-layout
7
+ ---
8
+
9
+ `useLayoutTable` and `createLayoutColumnHelper` (`wcz-layout/hooks`) are the `useAppTable` and
10
+ `createAppColumnHelper` of TanStack Table v9's `createTableHook`, with wcz-layout's features and
11
+ components; feature APIs: load `@tanstack/table-core#table-features`. Never render a
12
+ `<table>` or `useTable` yourself, and ignore upstream's own virtualization and pagination
13
+ setup: `LayoutTable` (`wcz-layout/components`) does both.
14
+
15
+ ## Rules
16
+
17
+ - `const table = useLayoutTable({ data, columns })`, then `<LayoutTable table={table} />`.
18
+ Rows are keyed by `row.id`, so every row needs an `id`. A list page wraps it in
19
+ `Fullscreen` and passes `loading={isLoading}` from `useLiveQuery`.
20
+ - Columns: `columnHelper.columns([...])` with `columnHelper.accessor("field", …)` or
21
+ `columnHelper.display({ id, … })`, from a module-level
22
+ `const columnHelper = createLayoutColumnHelper<Entity>()`. No row models: the features are
23
+ installed.
24
+ - Cells render the bound formatters, `cell.ValueCell`, `NumberCell`, `DateCell`, `DateTimeCell`,
25
+ `BooleanCell`: they carry alignment, locale formats and one-line ellipsis. Raw JSX only for a
26
+ link or another interactive element.
27
+ - Selection and actions display columns: `size: 50`, `enableResizing: false`,
28
+ `enableCellSelection: false`; each extra visible action button adds about 40 px.
29
+ - `meta` keys: `label`, `align`, `variant`, `options`, `flex`. A column whose `header` is not
30
+ a plain string needs `meta.label` (header menu, column selector and filter picker read it).
31
+ - `meta.variant` picks the filter: `"text"` (default), `"number"`, `"boolean"`, `"date"`,
32
+ `"select"`, `"multi-select"`. Select variants build their options from the faceted unique
33
+ values; pass `options` only when labels differ from stored values or the list is fixed, and
34
+ for a database enum derive them from `.enumValues`.
35
+ - `size` is the starting width. `meta.flex` lets a column grow and shrink in proportion, like
36
+ CSS `flex`, so the table fills its container without horizontal scroll; it stops at
37
+ `minSize` (default 20), after which the table scrolls. A resized column keeps its width.
38
+ - Rows and columns virtualize and rows are measured: a cell may wrap onto several lines once
39
+ its content has `whiteSpace: "normal"`.
40
+ - Toolbar actions: create (`RouterIconButton` to the create page), edit when exactly one row is
41
+ selected, delete when any are: `confirm(t("DeleteConfirmation", { count }))`, the optimistic
42
+ delete, `when("settled")`, then `table.resetRowSelection()`; `catch` alerts. Icons are
43
+ `fontSize="small"` inside a `Tooltip`.
44
+ - `LayoutTable` props: `title`, `actions`, `showToolbar`, `loading`, `pagination`,
45
+ `pageSizeOptions`, `onRowClick`, `onRowDoubleClick`, `sx`, and `disableSearch`,
46
+ `disableColumnFilter`, `disableColumnSelector`, `disableColumnMenu`.
47
+ - Server-paged tables (reports, lists sorted over more rows than the browser should hold;
48
+ deep offset collection queries load a growing prefix, see client-db): use Query/server pages.
49
+ Load upstream Query integration/state guidance for request keys, totals and manual flags; pass
50
+ `manualPagination: true`, `rowCount` and controlled `state.pagination` /
51
+ `onPaginationChange` (plus the `manual*` flags for what the server sorts and filters) to
52
+ `useLayoutTable`, with `pagination` on `LayoutTable`.
53
+
54
+ ## Example
55
+
56
+ ```tsx
57
+ // src/routes/features/index.tsx
58
+ import { Fullscreen, LayoutTable, RouterIconButton, RouterLink } from "wcz-layout/components";
59
+ import {
60
+ createLayoutColumnHelper,
61
+ useDialogs,
62
+ useLayoutTable,
63
+ useTranslation,
64
+ } from "wcz-layout/hooks";
65
+
66
+ export const Route = createFileRoute("/features/")({
67
+ component: RouteComponent,
68
+ beforeLoad: requireAuth("admin"),
69
+ loader: ({ context }) => context.dbClient.preloadLiveQuery(featuresQueryOptions),
70
+ });
71
+
72
+ const columnHelper = createLayoutColumnHelper<Feature>();
73
+
74
+ function RouteComponent() {
75
+ const { t } = useTranslation();
76
+ const { confirm, alert } = useDialogs();
77
+ const navigate = useNavigate();
78
+ const features = useFeatureCollection();
79
+ const { data, isLoading } = useLiveQuery(featuresQueryOptions);
80
+
81
+ const columns = columnHelper.columns([
82
+ columnHelper.display({
83
+ id: "select",
84
+ header: ({ header }) => <header.SelectAllCell scope="all" />,
85
+ cell: ({ cell }) => <cell.SelectCell />,
86
+ size: 50,
87
+ enableResizing: false,
88
+ enableCellSelection: false,
89
+ }),
90
+ columnHelper.accessor("name", {
91
+ header: t("Feature.Name"),
92
+ cell: ({ cell }) => (
93
+ <RouterLink
94
+ to="/features/$id"
95
+ params={{ id: cell.row.original.id }}
96
+ underline="hover"
97
+ color="inherit"
98
+ >
99
+ {cell.getValue()}
100
+ </RouterLink>
101
+ ),
102
+ size: 260,
103
+ meta: { flex: 1 },
104
+ }),
105
+ ]);
106
+
107
+ const table = useLayoutTable({ data, columns });
108
+ const selectedIds = table.getSelectedRowIds();
109
+
110
+ const handleOnDelete = createOptimisticAction<Array<string>>({
111
+ onMutate: (ids) => {
112
+ ids.forEach((id) => {
113
+ features.delete(id);
114
+ });
115
+ },
116
+ mutationFn: async (ids) => {
117
+ await deleteFeatures({ data: ids });
118
+ await features.utils.refetch({ throwOnError: true });
119
+ },
120
+ });
121
+
122
+ return (
123
+ <Fullscreen>
124
+ <LayoutTable
125
+ table={table}
126
+ loading={isLoading}
127
+ showToolbar
128
+ title={t("Feature.Features")}
129
+ onRowDoubleClick={(row) => navigate({ to: "/features/$id", params: { id: row.id } })}
130
+ actions={
131
+ <>
132
+ <Tooltip title={t("Create")}>
133
+ <RouterIconButton to="/features/create">
134
+ <Add fontSize="small" />
135
+ </RouterIconButton>
136
+ </Tooltip>
137
+ {selectedIds.length === 1 && (
138
+ <Tooltip title={t("Edit")}>
139
+ <RouterIconButton to="/features/edit/$id" params={{ id: selectedIds[0] }}>
140
+ <Edit fontSize="small" />
141
+ </RouterIconButton>
142
+ </Tooltip>
143
+ )}
144
+ {selectedIds.length > 0 && (
145
+ <Tooltip title={t("Delete")}>
146
+ <IconButton
147
+ onClick={async () => {
148
+ if (!(await confirm(t("DeleteConfirmation", { count: selectedIds.length }))))
149
+ return;
150
+ try {
151
+ await handleOnDelete(selectedIds).when("settled");
152
+ table.resetRowSelection();
153
+ } catch (error) {
154
+ if (error instanceof Error) await alert(error.message);
155
+ }
156
+ }}
157
+ >
158
+ <Badge
159
+ badgeContent={selectedIds.length}
160
+ invisible={selectedIds.length <= 1}
161
+ color="error"
162
+ >
163
+ <Delete fontSize="small" />
164
+ </Badge>
165
+ </IconButton>
166
+ </Tooltip>
167
+ )}
168
+ </>
169
+ }
170
+ />
171
+ </Fullscreen>
172
+ );
173
+ }
174
+ ```
175
+
176
+ Additional columns only when the entity schema has these fields:
177
+
178
+ ```tsx
179
+ import { Typography } from "@mui/material";
180
+ import { featureStatusEnum } from "~/server/db/schemas/feature";
181
+
182
+ columnHelper.accessor("quantity", {
183
+ header: t("Feature.Quantity"),
184
+ cell: ({ cell }) => <cell.NumberCell />,
185
+ footer: ({ header }) => <header.AggregationFooter />,
186
+ aggregationFn: "sum",
187
+ meta: { variant: "number", align: "right" },
188
+ });
189
+ columnHelper.accessor("active", {
190
+ header: t("Feature.Active"),
191
+ cell: ({ cell }) => <cell.BooleanCell />,
192
+ meta: { variant: "boolean", align: "center" },
193
+ });
194
+ columnHelper.accessor("dueAt", {
195
+ header: t("Feature.DueAt"),
196
+ cell: ({ cell }) => <cell.DateCell />,
197
+ meta: { variant: "date" },
198
+ });
199
+ columnHelper.accessor("status", {
200
+ header: t("Feature.Status"),
201
+ cell: ({ cell }) => (
202
+ <Typography variant="body2" noWrap>
203
+ {t(`Feature.StatusLabels.${cell.getValue()}`)}
204
+ </Typography>
205
+ ),
206
+ meta: {
207
+ variant: "multi-select",
208
+ options: featureStatusEnum.enumValues.map((value) => ({
209
+ value,
210
+ label: t(`Feature.StatusLabels.${value}`),
211
+ })),
212
+ },
213
+ });
214
+ ```
215
+
216
+ ```tsx
217
+ // per-row actions: one inline button, the rest in the row menu
218
+ columnHelper.display({
219
+ id: "actions",
220
+ cell: ({ cell }) => (
221
+ <cell.ActionsCell
222
+ actions={[
223
+ {
224
+ label: t("Edit"),
225
+ icon: <Edit fontSize="small" />,
226
+ onClick: (row) => navigate({ to: "/features/edit/$id", params: { id: row.id } }),
227
+ },
228
+ {
229
+ label: t("Delete"),
230
+ icon: <Delete fontSize="small" />,
231
+ showInMenu: true,
232
+ onClick: (row) => remove(row.id),
233
+ },
234
+ ]}
235
+ />
236
+ ),
237
+ size: 50,
238
+ enableResizing: false,
239
+ enableCellSelection: false,
240
+ });
241
+ ```
242
+
243
+ ## Bound components
244
+
245
+ Header render prop: `SelectAllCell`, `ExpandAllCell`, `AggregationFooter`, `HeaderMenu`,
246
+ `HeaderSortLabel`, `HeaderResizeHandle`. Cell render prop: `SelectCell`, `ExpandCell`,
247
+ `GroupCell`, `PinRowCell`, `ActionsCell` and the formatters. `LayoutTable` already places the
248
+ menu, sort label and resize handle. A custom cell or header is a plain component reading
249
+ `useCellContext<TValue>()`, `useHeaderContext()` or `useTableContext()` from `wcz-layout/hooks`;
250
+ `layoutTableFeatures` and `LayoutTableFeatures` only type a hand-built table instance.