wcz-layout 10.0.0 → 10.1.2
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.
- package/dist/{AggregatedCell-BtKC5-m6.mjs → AggregatedCell-C7nAQyMO.mjs} +15 -2
- package/dist/AggregatedCell-C7nAQyMO.mjs.map +1 -0
- package/dist/{Approval-C-hF4jbT.mjs → Approval-DoD-GRRH.mjs} +18 -14
- package/dist/Approval-DoD-GRRH.mjs.map +1 -0
- package/dist/{Employee-DbdStvU0.d.mts → Employee-N9fRSnIl.d.mts} +30 -14
- package/dist/FileMeta-DDqUju1Y.mjs.map +1 -1
- package/dist/{LayoutTable-4DLs-NI-.d.mts → LayoutTable-DX9IaO8V.d.mts} +205 -197
- package/dist/RouterListItemButton-ULMlaQh6.mjs.map +1 -1
- package/dist/{approval-DFExxyAJ.mjs → approval-DiNOXd4B.mjs} +4 -4
- package/dist/approval-DiNOXd4B.mjs.map +1 -0
- package/dist/auth.mjs +4 -4
- package/dist/components.d.mts +1 -1
- package/dist/components.mjs +47 -21
- package/dist/components.mjs.map +1 -1
- package/dist/{createApi-CLYWCzR2.mjs → createApi-DGJJ4I_R.mjs} +3 -3
- package/dist/{createApi-CLYWCzR2.mjs.map → createApi-DGJJ4I_R.mjs.map} +1 -1
- package/dist/data/client.d.mts +183 -64
- package/dist/data/client.mjs +5 -5
- package/dist/data/client.mjs.map +1 -1
- package/dist/data/server.d.mts +1 -1
- package/dist/data/server.mjs +4 -4
- package/dist/{file-aSQto2rw.mjs → file-C14fhUeg.mjs} +4 -4
- package/dist/{file-aSQto2rw.mjs.map → file-C14fhUeg.mjs.map} +1 -1
- package/dist/{file-CZwQfvTU.mjs → file-C5BOj1q8.mjs} +4 -4
- package/dist/file-C5BOj1q8.mjs.map +1 -0
- package/dist/hooks.d.mts +1 -1
- package/dist/hooks.mjs +461 -452
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.mjs +2 -2
- package/dist/middleware.mjs.map +1 -1
- package/dist/models.d.mts +22 -2
- package/dist/models.mjs +1 -1
- package/dist/{peoplesoft-BY_75WTS.d.mts → peoplesoft-BIdTNshE.d.mts} +2 -3
- package/dist/{peoplesoft-CQnc01Hc.mjs → peoplesoft-BkJMCcHb.mjs} +3 -3
- package/dist/peoplesoft-BkJMCcHb.mjs.map +1 -0
- package/dist/{providers-Dbl95AxR.mjs → providers-DrairEO2.mjs} +2 -2
- package/dist/providers-DrairEO2.mjs.map +1 -0
- package/dist/{tokens-D8CVIFTb.mjs → tokens-BLRreL1j.mjs} +3 -3
- package/dist/tokens-BLRreL1j.mjs.map +1 -0
- package/dist/{utils-KaM5VMTJ.mjs → utils-BUpDoqme.mjs} +13 -13
- package/dist/utils-BUpDoqme.mjs.map +1 -0
- package/dist/utils.mjs +1 -1
- package/package.json +16 -14
- package/skills/ai/SKILL.md +59 -0
- package/skills/client-db/SKILL.md +47 -43
- package/skills/db-schema/SKILL.md +6 -0
- package/skills/dialogs/SKILL.md +8 -6
- package/skills/forms/SKILL.md +19 -1
- package/skills/general/SKILL.md +21 -19
- package/skills/general/references/exports.md +6 -3
- package/skills/migrations/versions/migrate-v10-to-v11.md +1 -0
- package/skills/migrations/versions/migrate-v9-to-v10.md +26 -25
- package/skills/routing/SKILL.md +7 -4
- package/skills/server-functions/SKILL.md +8 -5
- package/skills/services/SKILL.md +1 -1
- package/skills/services/docs/approval.md +258 -257
- package/skills/services/docs/peoplesoft.md +4 -0
- package/skills/start/SKILL.md +3 -2
- package/skills/start/steps/02-project-name-setup.md +1 -1
- package/skills/start/steps/07-vault-setup.md +5 -4
- package/skills/table/SKILL.md +20 -31
- package/dist/AggregatedCell-BtKC5-m6.mjs.map +0 -1
- package/dist/Approval-C-hF4jbT.mjs.map +0 -1
- package/dist/approval-DFExxyAJ.mjs.map +0 -1
- package/dist/file-CZwQfvTU.mjs.map +0 -1
- package/dist/peoplesoft-CQnc01Hc.mjs.map +0 -1
- package/dist/providers-Dbl95AxR.mjs.map +0 -1
- package/dist/tokens-D8CVIFTb.mjs.map +0 -1
- package/dist/utils-KaM5VMTJ.mjs.map +0 -1
- package/skills/unslop/SKILL.md +0 -80
- /package/skills/start/steps/{10-gitlab-ci.md → 09-gitlab-ci.md} +0 -0
- /package/skills/start/steps/{09-commit.md → 10-commit.md} +0 -0
|
@@ -26,11 +26,15 @@ metadata:
|
|
|
26
26
|
components.
|
|
27
27
|
- Preload in the route loader and return the promise:
|
|
28
28
|
`loader: ({ context }) => context.dbClient.preloadLiveQuery(<x>QueryOptions)`.
|
|
29
|
-
This transports the query result
|
|
30
|
-
|
|
29
|
+
This transports the query result, so `useLiveQuery` has rows on the first render. Never
|
|
30
|
+
fire it with `void`: the server then renders an empty table and the browser fetches
|
|
31
|
+
again. Explicit collection preload transports source rows and is a no-op for on-demand
|
|
32
|
+
collections.
|
|
33
|
+
- A detail route awaits the preload, then throws `notFound()` when the row is missing,
|
|
34
|
+
and shows a skeleton `pendingComponent` meanwhile (see the example).
|
|
31
35
|
- `useLiveQuery` for list pages, `useLiveSuspenseQuery` for detail components under
|
|
32
|
-
suspense.
|
|
33
|
-
|
|
36
|
+
suspense. `.findOne()` still returns `T | undefined` after the loader's check, so keep
|
|
37
|
+
an `if (!data) return null` guard.
|
|
34
38
|
- Shape data in the query: filter, order, group and aggregate only the fields the
|
|
35
39
|
consumer needs. Do not load broad results and transform them in component code.
|
|
36
40
|
- Mutations go through `createOptimisticAction`: mirror the server write in `onMutate`,
|
|
@@ -39,24 +43,21 @@ metadata:
|
|
|
39
43
|
Await `transaction.isPersisted.promise` at the call site and surface failures with
|
|
40
44
|
`alert()`.
|
|
41
45
|
- `syncMode: "eager"` for top-level collections, `"on-demand"` for child data and anything expected past ~10k rows.
|
|
42
|
-
- Increment persisted `schemaVersion` whenever the row shape changes.
|
|
43
46
|
|
|
44
47
|
## Examples
|
|
45
48
|
|
|
46
49
|
```ts
|
|
47
50
|
// src/db/collections/<table>.ts
|
|
48
|
-
import { persistedCollectionOptions } from "@tanstack/browser-db-sqlite-persistence";
|
|
49
51
|
import { queryCollectionOptions } from "@tanstack/query-db-collection";
|
|
50
52
|
import { collectionOptions, useDbClient } from "@tanstack/react-db";
|
|
51
53
|
import type { QueryClient } from "@tanstack/react-query";
|
|
52
|
-
import { browserPersistence } from "../persistence";
|
|
53
54
|
import { TodoSchema } from "~/lib/schemas/todo";
|
|
54
55
|
import { selectTodos } from "~/server/actions/todo";
|
|
55
56
|
|
|
56
57
|
const TODOS_ID = "todos";
|
|
57
58
|
|
|
58
|
-
export const todoCollection = collectionOptions(TODOS_ID, (client) =>
|
|
59
|
-
|
|
59
|
+
export const todoCollection = collectionOptions(TODOS_ID, (client) =>
|
|
60
|
+
queryCollectionOptions({
|
|
60
61
|
id: TODOS_ID,
|
|
61
62
|
queryKey: [TODOS_ID],
|
|
62
63
|
queryFn: () => selectTodos(),
|
|
@@ -64,17 +65,8 @@ export const todoCollection = collectionOptions(TODOS_ID, (client) => {
|
|
|
64
65
|
schema: TodoSchema,
|
|
65
66
|
queryClient: client.requireDependency<QueryClient>("queryClient"),
|
|
66
67
|
syncMode: "eager",
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
const persistence = browserPersistence();
|
|
70
|
-
if (!persistence) return options;
|
|
71
|
-
|
|
72
|
-
return persistedCollectionOptions({
|
|
73
|
-
...options,
|
|
74
|
-
persistence,
|
|
75
|
-
schemaVersion: 1, // Increment when the persisted row shape changes.
|
|
76
|
-
}) as typeof options;
|
|
77
|
-
});
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
78
70
|
|
|
79
71
|
export const useTodoCollection = () => useDbClient().collection(todoCollection);
|
|
80
72
|
```
|
|
@@ -100,33 +92,45 @@ export const todoByIdQueryOptions = (id: string) => ({
|
|
|
100
92
|
```
|
|
101
93
|
|
|
102
94
|
```tsx
|
|
103
|
-
// route
|
|
95
|
+
// detail route: src/routes/todos/$id.tsx
|
|
104
96
|
export const Route = createFileRoute("/todos/$id")({
|
|
97
|
+
component: RouteComponent,
|
|
98
|
+
pendingComponent: TodoSkeleton,
|
|
105
99
|
beforeLoad: requireAuth("admin"),
|
|
106
|
-
loader: ({ context, params }) =>
|
|
107
|
-
context.dbClient.preloadLiveQuery(todoByIdQueryOptions(params.id))
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const { id } = Route.useParams();
|
|
111
|
-
const todos = useTodoCollection();
|
|
112
|
-
const { data } = useLiveSuspenseQuery(todoByIdQueryOptions(id));
|
|
113
|
-
|
|
114
|
-
const handleOnDelete = createOptimisticAction<string>({
|
|
115
|
-
onMutate: (id) => {
|
|
116
|
-
todos.delete(id);
|
|
117
|
-
},
|
|
118
|
-
mutationFn: async (id) => {
|
|
119
|
-
await deleteTodo({ data: { id } });
|
|
120
|
-
await todos.utils.refetch({ throwOnError: true });
|
|
100
|
+
loader: async ({ context, params }) => {
|
|
101
|
+
await context.dbClient.preloadLiveQuery(todoByIdQueryOptions(params.id));
|
|
102
|
+
if (!context.dbClient.collection(todoCollection).has(params.id)) throw notFound();
|
|
121
103
|
},
|
|
122
104
|
});
|
|
123
105
|
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
106
|
+
function RouteComponent() {
|
|
107
|
+
const { id } = Route.useParams();
|
|
108
|
+
const { alert } = useDialogs();
|
|
109
|
+
const navigate = useNavigate();
|
|
110
|
+
const todos = useTodoCollection();
|
|
111
|
+
const { data } = useLiveSuspenseQuery(todoByIdQueryOptions(id));
|
|
112
|
+
|
|
113
|
+
const handleOnDelete = createOptimisticAction<string>({
|
|
114
|
+
onMutate: (id) => {
|
|
115
|
+
todos.delete(id);
|
|
116
|
+
},
|
|
117
|
+
mutationFn: async (id) => {
|
|
118
|
+
await deleteTodos({ data: [id] });
|
|
119
|
+
await todos.utils.refetch({ throwOnError: true });
|
|
120
|
+
},
|
|
121
|
+
});
|
|
130
122
|
|
|
131
|
-
|
|
123
|
+
const handleDelete = async () => {
|
|
124
|
+
try {
|
|
125
|
+
const transaction = handleOnDelete(id);
|
|
126
|
+
await transaction.isPersisted.promise;
|
|
127
|
+
await navigate({ to: "/todos" });
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error instanceof Error) await alert(error.message);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
if (!data) return null;
|
|
134
|
+
// render data; call handleDelete from the delete button...
|
|
135
|
+
}
|
|
132
136
|
```
|
|
@@ -33,7 +33,9 @@ export const libraryTable = snakeCase.table("libraries", {
|
|
|
33
33
|
id: uuid().primaryKey(),
|
|
34
34
|
name: text().notNull(),
|
|
35
35
|
});
|
|
36
|
+
```
|
|
36
37
|
|
|
38
|
+
```ts
|
|
37
39
|
// src/server/db/schemas/book.ts
|
|
38
40
|
import { index, pgEnum, snakeCase, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
|
39
41
|
import { libraryTable } from "./library";
|
|
@@ -53,7 +55,9 @@ export const bookTable = snakeCase.table(
|
|
|
53
55
|
},
|
|
54
56
|
(table) => [index().on(table.libraryId)],
|
|
55
57
|
);
|
|
58
|
+
```
|
|
56
59
|
|
|
60
|
+
```ts
|
|
57
61
|
// src/server/db/schemas/relations.ts
|
|
58
62
|
import { defineRelations } from "drizzle-orm";
|
|
59
63
|
import { bookTable } from "./book";
|
|
@@ -70,7 +74,9 @@ export const relations = defineRelations(
|
|
|
70
74
|
},
|
|
71
75
|
}),
|
|
72
76
|
);
|
|
77
|
+
```
|
|
73
78
|
|
|
79
|
+
```ts
|
|
74
80
|
// src/lib/schemas/<table>.ts
|
|
75
81
|
import { createSelectSchema } from "drizzle-orm/zod";
|
|
76
82
|
import { t } from "wcz-layout/utils";
|
package/skills/dialogs/SKILL.md
CHANGED
|
@@ -22,14 +22,16 @@ metadata:
|
|
|
22
22
|
|
|
23
23
|
## Examples
|
|
24
24
|
|
|
25
|
-
```
|
|
25
|
+
```tsx
|
|
26
26
|
// confirmation dialog
|
|
27
27
|
const { confirm } = useDialogs();
|
|
28
28
|
const { t } = useTranslation();
|
|
29
29
|
|
|
30
30
|
const confirmed = await confirm(t("DeleteConfirmation", { count: selectedIds.length }));
|
|
31
31
|
if (confirmed) await deleteFeatures({ data: selectedIds });
|
|
32
|
+
```
|
|
32
33
|
|
|
34
|
+
```tsx
|
|
33
35
|
// alert dialog
|
|
34
36
|
const { alert } = useDialogs();
|
|
35
37
|
const { t } = useTranslation();
|
|
@@ -39,23 +41,23 @@ try {
|
|
|
39
41
|
} catch (error) {
|
|
40
42
|
await alert(error instanceof Error ? error.message : t("UnknownError"));
|
|
41
43
|
}
|
|
44
|
+
```
|
|
42
45
|
|
|
46
|
+
```tsx
|
|
43
47
|
// custom dialog that returns a result
|
|
44
48
|
const { open } = useDialogs();
|
|
45
49
|
|
|
46
50
|
const saved = await open(EditFeatureDialog, { id });
|
|
47
51
|
if (saved) await features.utils.refetch({ throwOnError: true });
|
|
52
|
+
```
|
|
48
53
|
|
|
54
|
+
```tsx
|
|
49
55
|
// custom dialog component
|
|
50
56
|
interface Payload {
|
|
51
57
|
id: string;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
export const EditFeatureDialog = ({
|
|
55
|
-
payload,
|
|
56
|
-
open,
|
|
57
|
-
onClose,
|
|
58
|
-
}: DialogProps<Payload, boolean>) => {
|
|
60
|
+
export const EditFeatureDialog = ({ payload, open, onClose }: DialogProps<Payload, boolean>) => {
|
|
59
61
|
const { t } = useTranslation();
|
|
60
62
|
|
|
61
63
|
return (
|
package/skills/forms/SKILL.md
CHANGED
|
@@ -27,7 +27,8 @@ metadata:
|
|
|
27
27
|
`dayjs(row.dueAt)` into `defaultValues`, `.toDate()` on the way out in `onSubmit`.
|
|
28
28
|
- Use translation for labels, helper text, validation messages and submit.
|
|
29
29
|
- Reset the form after a successful create, and let the submit handler reject on failure so
|
|
30
|
-
a failed save keeps what the user typed
|
|
30
|
+
a failed save keeps what the user typed: the route alerts, then rethrows (see the route
|
|
31
|
+
example). A handler that only alerts resolves, and the form resets anyway.
|
|
31
32
|
- `SubmitButton` calls `form.handleSubmit()` and owns its loading and disabled state.
|
|
32
33
|
- `reset()` restores the `defaultValues` captured when the form was constructed. If those
|
|
33
34
|
contain a generated `uuidv7()` id, pass a fresh one to `reset({ ...defaults, id: uuidv7() })`
|
|
@@ -102,3 +103,20 @@ export const Form: FC<FormProps> = ({ defaultValues, onSubmit }) => {
|
|
|
102
103
|
);
|
|
103
104
|
};
|
|
104
105
|
```
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
// Route rendering the form: alert, then rethrow so a failed save keeps the input
|
|
109
|
+
<Form
|
|
110
|
+
defaultValues={{ id: uuidv7(), property1: "" }}
|
|
111
|
+
onSubmit={async (value) => {
|
|
112
|
+
try {
|
|
113
|
+
const transaction = handleOnSubmit(value);
|
|
114
|
+
await transaction.isPersisted.promise;
|
|
115
|
+
await navigate({ to: "/features" });
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error instanceof Error) await alert(error.message);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
```
|
package/skills/general/SKILL.md
CHANGED
|
@@ -6,19 +6,17 @@ metadata:
|
|
|
6
6
|
library: wcz-layout
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
> This is the default skill. Reference it in combination with more specific skills (e.g., `forms`, `table`, `dialogs
|
|
9
|
+
> This is the default skill. Reference it in combination with more specific skills (e.g., `forms`, `table`, `dialogs`, etc.) for targeted tasks. For the full catalogue of every `wcz-layout` import subpath and what it exports, read [references/exports.md](references/exports.md).
|
|
10
10
|
|
|
11
11
|
## Preferred Technology Stack
|
|
12
12
|
|
|
13
13
|
Favor the established platform before introducing custom code or a new dependency:
|
|
14
14
|
|
|
15
|
-
- **TanStack ecosystem:** Reach for the TanStack library that owns the problem instead of hand-rolling it — Start for the full-stack app and server functions, Router for routing and route-level data loading, DB for client-side collections and live queries, AI for LLM-backed chat and streaming, Form for form state and validation, Hotkeys for keyboard shortcuts, Virtual for long lists and grids, Pacer for debouncing, throttling, rate limiting and queueing.
|
|
15
|
+
- **TanStack ecosystem:** Reach for the TanStack library that owns the problem instead of hand-rolling it — Start for the full-stack app and server functions, Router for routing and route-level data loading, DB for client-side collections and live queries, AI for LLM-backed chat and streaming, Form for form state and validation, Hotkeys for keyboard shortcuts, Virtual for long lists and grids, Pacer for debouncing, throttling, rate limiting and queueing or Charts for data visualization.
|
|
16
16
|
- **Vite+:** Use Vite+ for the development server, formatting, linting and testing.
|
|
17
|
-
- **Material UI:** Use Material UI for interface components and icons.
|
|
17
|
+
- **Material UI:** Use Material UI for interface components and icons.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
When the requirement is not covered above and a well-maintained, popular library solves it, use that library instead of writing your own implementation.
|
|
19
|
+
When the requirement is not covered above, look for an existing library before writing any logic. Prefer a well-maintained, widely adopted, typed library over custom implementations, even for seemingly simple functionality where a library can reduce edge cases and bugs. If a suitable library exists, install it and use it. Only implement the functionality yourself when it takes a few lines or no suitable library exists.
|
|
22
20
|
|
|
23
21
|
## Coding Conventions
|
|
24
22
|
|
|
@@ -32,18 +30,21 @@ When the requirement is not covered above and a well-maintained, popular library
|
|
|
32
30
|
|
|
33
31
|
- Translate every user-facing string via `useTranslation` (or `t` outside components).
|
|
34
32
|
- Format all client-side dates with `"L LT"` or `"L"`.
|
|
33
|
+
- When building UI, always design for both light and dark mode; this app uses `colorSchemeSelector: "data-mui-color-scheme"`, so prefer `theme.applyStyles("dark", ...)` for mode-specific styling.
|
|
34
|
+
- Always design for desktop and mobile, using responsive layouts and breakpoints to keep the UI usable on any screen.
|
|
35
35
|
- Build skeletons for loading states.
|
|
36
|
-
-
|
|
37
|
-
`colorSchemeSelector: "data-mui-color-scheme"`, so prefer `theme.applyStyles("dark", ...)`
|
|
38
|
-
for mode-specific styling.
|
|
36
|
+
- Success has no message. Animate the changed item where it lives: created enters, deleted collapses out, edited briefly tints. If the change isn't visible (e.g. before navigating), morph the trigger button to a check for ~400ms.
|
|
39
37
|
|
|
40
38
|
## Testing
|
|
41
39
|
|
|
42
|
-
-
|
|
40
|
+
- `vp test` runs `tests/unit` and `tests/integration`; import the test API from `vite-plus/test`.
|
|
41
|
+
- Server functions need a request context to run, so integration tests cover what they build on: the schema and constraints against the `DATABASE_URL` Postgres, and collections with the server function mocked.
|
|
42
|
+
- `npm run test:e2e` runs Playwright against the dev server, signed in as admin by `tests/e2e/auth.setup.ts`.
|
|
43
|
+
- Add or update tests for any new functionality or bug fixes where it matters, don't write tests just for the sake of having them.
|
|
43
44
|
|
|
44
45
|
## File Organization
|
|
45
46
|
|
|
46
|
-
Use this ownership model for new application code. Keep feature-specific code close to its route; promote it to a root directory only when it is shared across multiple features.
|
|
47
|
+
Use this ownership model for new application code. Keep feature-specific code close to its route; promote it to a root directory only when it is shared across multiple features.
|
|
47
48
|
|
|
48
49
|
```txt
|
|
49
50
|
src/ # client-first architecture
|
|
@@ -51,9 +52,8 @@ src/ # client-first architecture
|
|
|
51
52
|
├── db/ # TanStack DB
|
|
52
53
|
│ ├── collections/ # collection descriptors
|
|
53
54
|
│ │ └── <table>.ts
|
|
54
|
-
│
|
|
55
|
-
│
|
|
56
|
-
│ └── persistence.ts # browser SQLite persistence
|
|
55
|
+
│ └── queries/ # live query option objects
|
|
56
|
+
│ └── <table>.ts
|
|
57
57
|
├── env.ts # clientEnv + serverEnv via createEnv
|
|
58
58
|
├── hooks/ # shared hooks across multiple routes
|
|
59
59
|
│ └── useTheme.ts # MUI theme + color schemes
|
|
@@ -71,6 +71,7 @@ src/ # client-first architecture
|
|
|
71
71
|
│ ├── __root.tsx
|
|
72
72
|
│ ├── index.tsx
|
|
73
73
|
│ ├── login.tsx # required by requireAuth
|
|
74
|
+
│ ├── health.ts # Docker HEALTHCHECK, pings the database
|
|
74
75
|
│ ├── auth/ # OAuth handlers
|
|
75
76
|
│ │ ├── login.ts
|
|
76
77
|
│ │ ├── callback.ts
|
|
@@ -97,7 +98,6 @@ src/ # client-first architecture
|
|
|
97
98
|
│ │ └── index.ts # pool, search_path, auto-migrate
|
|
98
99
|
│ └── middleware/
|
|
99
100
|
│ └── databaseMiddleware.ts # app-local, not a library export
|
|
100
|
-
├── start.ts # request middleware, incl. CSRF
|
|
101
101
|
├── types/
|
|
102
102
|
│ ├── i18next.d.ts # types t() against en.json
|
|
103
103
|
│ └── wcz-layout.d.ts # declares virtual:wcz-layout
|
|
@@ -114,12 +114,14 @@ tests/
|
|
|
114
114
|
│ └── XCard.test.tsx
|
|
115
115
|
├── integration/
|
|
116
116
|
│ ├── server/
|
|
117
|
-
│ │ └──
|
|
117
|
+
│ │ └── db/ # real Postgres from DATABASE_URL
|
|
118
118
|
│ │ └── <table>.test.ts
|
|
119
119
|
│ └── db/
|
|
120
|
-
│ └── collections/
|
|
120
|
+
│ └── collections/ # server function mocked
|
|
121
121
|
│ └── <table>.test.ts
|
|
122
|
-
└── e2e/
|
|
122
|
+
└── e2e/ # Playwright
|
|
123
|
+
├── auth.setup.ts # signs in as admin, no Microsoft login
|
|
124
|
+
├── utils.ts # gotoHydrated
|
|
123
125
|
└── features/
|
|
124
|
-
└──
|
|
126
|
+
└── crud.spec.ts
|
|
125
127
|
```
|
|
@@ -70,9 +70,12 @@ The root subpath. Everything the application shell needs.
|
|
|
70
70
|
- `userMiddleware` — attaches the user without requiring one, as `User | null`
|
|
71
71
|
- `validationMiddleware` — validates API route input against a Zod schema. REST routes
|
|
72
72
|
only; server functions use `.validator()`.
|
|
73
|
-
- `csrfMiddleware` — CSRF protection
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
- `csrfMiddleware` — CSRF protection for server functions. Without a `src/start.ts`, Start
|
|
74
|
+
applies the same check by default, so the template has none. If the app adds
|
|
75
|
+
`src/start.ts` for its own request middleware, list `csrfMiddleware` there too —
|
|
76
|
+
`createStart(() => ({ requestMiddleware: [csrfMiddleware, ...] }))` — because a start
|
|
77
|
+
instance replaces that default. It is a **request** middleware, never part of a
|
|
78
|
+
`.middleware([])` array.
|
|
76
79
|
|
|
77
80
|
`databaseMiddleware` is **not** here. It is app-local; every app writes its own. See the
|
|
78
81
|
`server-functions` skill.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
https://mui.com/material-ui/react-number-field/
|
|
@@ -21,6 +21,7 @@ middleware arrays you need to eyeball vanish into the churn.
|
|
|
21
21
|
| Install | `@tanstack/react-table` | 9.x |
|
|
22
22
|
| Install | `@tanstack/react-virtual` | 3.x |
|
|
23
23
|
| Install | `@tanstack/react-hotkeys` | 0.x |
|
|
24
|
+
| Install | `@tanstack/react-pacer` | 0.x |
|
|
24
25
|
| Install | `@mui/x-date-pickers` | 9.x |
|
|
25
26
|
| Upgrade | `@tanstack/react-query` | **≥ 5.102** |
|
|
26
27
|
| Upgrade | `@tanstack/react-router-ssr-query` | latest 1.x |
|
|
@@ -28,7 +29,7 @@ middleware arrays you need to eyeball vanish into the churn.
|
|
|
28
29
|
| Delete | `@mui/x-date-pickers-pro` | — |
|
|
29
30
|
|
|
30
31
|
```bash
|
|
31
|
-
npm install @tanstack/react-table@9 @tanstack/react-virtual@3 @tanstack/react-hotkeys@0 @mui/x-date-pickers@9
|
|
32
|
+
npm install @tanstack/react-table@9 @tanstack/react-virtual@3 @tanstack/react-hotkeys@0 @tanstack/react-pacer@0 @mui/x-date-pickers@9
|
|
32
33
|
npm install @tanstack/react-query@latest @tanstack/react-router-ssr-query@latest
|
|
33
34
|
npm uninstall @mui/x-data-grid-premium @mui/x-date-pickers-pro
|
|
34
35
|
```
|
|
@@ -171,7 +172,7 @@ Check what the v9 middleware composed before touching any call site:
|
|
|
171
172
|
now serves anonymous callers unless you add `authMiddleware()` yourself.
|
|
172
173
|
|
|
173
174
|
| v9 call site | v9 meaning | v10 |
|
|
174
|
-
| ---------------------------------------------------------- | ------------------- |
|
|
175
|
+
| ---------------------------------------------------------- | ------------------- | ------------------------------------------------- |
|
|
175
176
|
| `databaseMiddleware({ optional: true })` | anonymous allowed | `[databaseMiddleware()]` |
|
|
176
177
|
| `databaseMiddleware()` over `authenticationMiddleware()` | user required | `[databaseMiddleware(), authMiddleware()]` |
|
|
177
178
|
| `[authorizationMiddleware("admin"), databaseMiddleware()]` | permission required | `[databaseMiddleware(), authMiddleware("admin")]` |
|
|
@@ -230,7 +231,7 @@ locale files is the library's.
|
|
|
230
231
|
|
|
231
232
|
**Merge it into the app's `Layout`, do not replace the block.** Apps add their own
|
|
232
233
|
keys inside that namespace (`Layout.Loading`, `Layout.NotProvided` in one app), and a
|
|
233
|
-
wholesale replace silently deletes them — which
|
|
234
|
+
wholesale replace silently deletes them — which _does_ break the build, because
|
|
234
235
|
`src/types/i18next.d.ts` types `t()` from `en.json` and the app's own
|
|
235
236
|
`t("Layout.Loading")` calls stop compiling. So: overlay the library's keys on top of
|
|
236
237
|
the app's, then look at what is left over. A leftover key the app's own code
|
|
@@ -285,26 +286,26 @@ Delete `src/components/DataGridToolbar.tsx`; `LayoutTable` renders the toolbar,
|
|
|
285
286
|
quick filter, columns panel and filter panel itself. In `useTheme.ts`, drop
|
|
286
287
|
`import { csCZ, enUS } from "@mui/x-data-grid/locales"` and its two entries.
|
|
287
288
|
|
|
288
|
-
| DataGridPremium | LayoutTable
|
|
289
|
-
| --------------------------------------------------- |
|
|
290
|
-
| `Array<GridColDef<Row>>` | `columnHelper.columns([...])` from `createLayoutColumnHelper`
|
|
291
|
-
| `field` / `headerName` | the accessor key / `header`
|
|
292
|
-
| `width`, `flex`, `minWidth` | `size`
|
|
293
|
-
| `renderCell` | `cell: ({ cell }) => <cell.ValueCell />`
|
|
294
|
-
| `valueGetter: (_v, row) => row.x.y` | `columnHelper.accessor((row) => row.x.y, { id: "..." })`
|
|
295
|
-
| `align` / `headerAlign` | `meta: { align }`
|
|
296
|
-
| `initialState.pinnedColumns.left` / `.right` | `initialState.columnPinning.start` / `.end`
|
|
297
|
-
| `initialState.sorting.sortModel` `{field, sort}` | `initialState.sorting` `[{ id, desc }]`
|
|
298
|
-
| `valueFormatter` on a date column | `cell.DateCell` or `cell.DateTimeCell`
|
|
299
|
-
| `valueFormatter` with an `Intl.NumberFormat` | `cell.NumberCell options={...}`, same options object
|
|
300
|
-
| `type: "singleSelect"` with `valueOptions` | `meta: { variant: "select", options }`
|
|
301
|
-
| `type: "number"` / `"date"` / `"boolean"` | `meta: { variant: "number" \| "date" \| "boolean" }`
|
|
302
|
-
| `rows` and `columns` props | `useLayoutTable({ data, columns })`, then `table={table}`
|
|
303
|
-
| `showToolbar` with `slots.toolbar` | `showToolbar` with `title` and `actions` on `LayoutTable`
|
|
304
|
-
| `ignoreDiacritics` | always on
|
|
305
|
-
| `rowSelectionModel` state | `table.getSelectedRowIds()`, `table.resetRowSelection()`
|
|
306
|
-
| `cellSelection` | always on, `Mod+C` copies the range as TSV
|
|
307
|
-
| `GridActionsCellItem` in a `type: "actions"` column | a `display` column rendering `cell.ActionsCell`
|
|
289
|
+
| DataGridPremium | LayoutTable |
|
|
290
|
+
| --------------------------------------------------- | ------------------------------------------------------------------ |
|
|
291
|
+
| `Array<GridColDef<Row>>` | `columnHelper.columns([...])` from `createLayoutColumnHelper` |
|
|
292
|
+
| `field` / `headerName` | the accessor key / `header` |
|
|
293
|
+
| `width`, `flex`, `minWidth` | `size` |
|
|
294
|
+
| `renderCell` | `cell: ({ cell }) => <cell.ValueCell />` |
|
|
295
|
+
| `valueGetter: (_v, row) => row.x.y` | `columnHelper.accessor((row) => row.x.y, { id: "..." })` |
|
|
296
|
+
| `align` / `headerAlign` | `meta: { align }` |
|
|
297
|
+
| `initialState.pinnedColumns.left` / `.right` | `initialState.columnPinning.start` / `.end` |
|
|
298
|
+
| `initialState.sorting.sortModel` `{field, sort}` | `initialState.sorting` `[{ id, desc }]` |
|
|
299
|
+
| `valueFormatter` on a date column | `cell.DateCell` or `cell.DateTimeCell` |
|
|
300
|
+
| `valueFormatter` with an `Intl.NumberFormat` | `cell.NumberCell options={...}`, same options object |
|
|
301
|
+
| `type: "singleSelect"` with `valueOptions` | `meta: { variant: "select", options }` |
|
|
302
|
+
| `type: "number"` / `"date"` / `"boolean"` | `meta: { variant: "number" \| "date" \| "boolean" }` |
|
|
303
|
+
| `rows` and `columns` props | `useLayoutTable({ data, columns })`, then `table={table}` |
|
|
304
|
+
| `showToolbar` with `slots.toolbar` | `showToolbar` with `title` and `actions` on `LayoutTable` |
|
|
305
|
+
| `ignoreDiacritics` | always on |
|
|
306
|
+
| `rowSelectionModel` state | `table.getSelectedRowIds()`, `table.resetRowSelection()` |
|
|
307
|
+
| `cellSelection` | always on, `Mod+C` copies the range as TSV |
|
|
308
|
+
| `GridActionsCellItem` in a `type: "actions"` column | a `display` column rendering `cell.ActionsCell`, `showInMenu` kept |
|
|
308
309
|
|
|
309
310
|
**Every row needs an `id`.** `getRowId` is not an option — the library hardcodes
|
|
310
311
|
`row.id`. A table over a view or a natural-key table without an `id` column must add
|
|
@@ -325,7 +326,7 @@ with one effect on `table.state`. There is no `onStateChange` option.
|
|
|
325
326
|
**Shared generic column factories do not port.** A v9 helper like
|
|
326
327
|
`actionColumn<T>(): GridColDef<T>` reused across pages cannot be rewritten as
|
|
327
328
|
`(helper: ColumnHelper<T>) => ...` — `createLayoutColumnHelper` is invariant in its row
|
|
328
|
-
type, so a concrete helper will not satisfy a generic parameter. Share the
|
|
329
|
+
type, so a concrete helper will not satisfy a generic parameter. Share the _contents_
|
|
329
330
|
instead: a function returning `Array<RowAction<T>>` (that type is generic-friendly) or
|
|
330
331
|
a plain predicate, and let each page write its own five-line `display` column.
|
|
331
332
|
|
|
@@ -339,7 +340,7 @@ field errors itself.
|
|
|
339
340
|
|
|
340
341
|
**Bulk actions need a selection column.** A v9 page driving actions off
|
|
341
342
|
`Object.keys(cellSelectionModel)` has nothing to map onto: cell selection is always on
|
|
342
|
-
in v10 but exists for `Mod+C`. `table.getSelectedRowIds()` reads
|
|
343
|
+
in v10 but exists for `Mod+C`. `table.getSelectedRowIds()` reads _row_ selection,
|
|
343
344
|
which renders only if the columns start with a `select` display column
|
|
344
345
|
(`header.SelectAllCell` / `cell.SelectCell`, `size: 50`, `enableResizing: false`,
|
|
345
346
|
`enableCellSelection: false`). Ids come back as plain strings, so the `id.toString()`
|
package/skills/routing/SKILL.md
CHANGED
|
@@ -22,7 +22,8 @@ metadata:
|
|
|
22
22
|
- Use `Route.useRouteContext()` to access the authenticated user. `user` can be `null` if
|
|
23
23
|
the route doesn't include `requireAuth`.
|
|
24
24
|
- Preload the route's live queries in the loader and return the promise:
|
|
25
|
-
`loader: ({ context }) => context.dbClient.preloadLiveQuery(<x>QueryOptions)`.
|
|
25
|
+
`loader: ({ context }) => context.dbClient.preloadLiveQuery(<x>QueryOptions)`. Detail
|
|
26
|
+
routes await it and throw `notFound()` for a missing row; see the `client-db` skill.
|
|
26
27
|
- Literal URL segments and feature folders use kebab-case. Entity feature names are plural;
|
|
27
28
|
TanStack special route tokens retain their required syntax.
|
|
28
29
|
- If a feature contains only one route, create a single file route: `src/routes/<feature>s.tsx`
|
|
@@ -33,6 +34,8 @@ metadata:
|
|
|
33
34
|
- Root-level `components/` and `hooks/` are only for code shared across multiple routes.
|
|
34
35
|
- After creating a new route, add a navigation item with a unique icon from
|
|
35
36
|
`@mui/icons-material` in `src/routes/__root.tsx`.
|
|
37
|
+
- Hide a navigation entry from users who cannot open it: `hidden: !hasPermission(user, <key>)`
|
|
38
|
+
with the same key as its route's `requireAuth(<key>)`.
|
|
36
39
|
- For user-clickable in-app navigation, use the type-safe router components from
|
|
37
40
|
`wcz-layout/components` (`RouterButton`, `RouterIconButton`, `RouterLink`, `RouterFab`,
|
|
38
41
|
`RouterTab`, `RouterListItemButton`) rather than raw MUI with a manual `href` — they wrap
|
|
@@ -40,14 +43,13 @@ metadata:
|
|
|
40
43
|
|
|
41
44
|
## Examples
|
|
42
45
|
|
|
43
|
-
```
|
|
46
|
+
```tsx
|
|
44
47
|
// imports
|
|
45
48
|
import AccountTree from "@mui/icons-material/AccountTree";
|
|
46
49
|
import Code from "@mui/icons-material/Code";
|
|
47
50
|
import Home from "@mui/icons-material/Home";
|
|
48
51
|
import Widgets from "@mui/icons-material/Widgets";
|
|
49
52
|
import { createFileRoute } from "@tanstack/react-router";
|
|
50
|
-
import { z } from "zod";
|
|
51
53
|
import type { Navigation } from "wcz-layout";
|
|
52
54
|
import { useDialogs, useTranslation } from "wcz-layout/hooks";
|
|
53
55
|
import { hasPermission, requireAuth } from "wcz-layout/utils";
|
|
@@ -68,12 +70,13 @@ function RouteComponent() {
|
|
|
68
70
|
|
|
69
71
|
// __root.tsx navigation
|
|
70
72
|
const navigation: Navigation = [
|
|
71
|
-
{ kind: "item", to: "/", title: t("Home"), icon: <Home
|
|
73
|
+
{ kind: "item", to: "/", title: t("Home"), icon: <Home /> },
|
|
72
74
|
{ kind: "header", title: t("Documentation") },
|
|
73
75
|
{
|
|
74
76
|
kind: "group",
|
|
75
77
|
title: t("Components"),
|
|
76
78
|
icon: <Widgets />,
|
|
79
|
+
hidden: !hasPermission(user, "admin"),
|
|
77
80
|
children: [
|
|
78
81
|
{ kind: "item", to: "/components/navigation", title: t("Navigation"), icon: <AccountTree /> },
|
|
79
82
|
{ kind: "divider" },
|
|
@@ -26,7 +26,7 @@ metadata:
|
|
|
26
26
|
// src/server/actions/<table>.ts
|
|
27
27
|
import { createFileRoute } from "@tanstack/react-router";
|
|
28
28
|
import { createServerFn } from "@tanstack/react-start";
|
|
29
|
-
import { eq } from "drizzle-orm";
|
|
29
|
+
import { eq, inArray } from "drizzle-orm";
|
|
30
30
|
import { authMiddleware, validationMiddleware } from "wcz-layout/middleware";
|
|
31
31
|
import z from "zod";
|
|
32
32
|
import { FeatureSchema } from "~/lib/schemas/feature";
|
|
@@ -43,7 +43,10 @@ export const insertFeature = createServerFn({ method: "POST" })
|
|
|
43
43
|
.validator(FeatureSchema)
|
|
44
44
|
.middleware([databaseMiddleware(), authMiddleware("admin")])
|
|
45
45
|
.handler(async ({ data, context }) => {
|
|
46
|
-
await context.db
|
|
46
|
+
await context.db
|
|
47
|
+
.insert(featureTable)
|
|
48
|
+
.values(data)
|
|
49
|
+
.onConflictDoNothing({ target: featureTable.id });
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
export const updateFeature = createServerFn({ method: "POST" })
|
|
@@ -53,11 +56,11 @@ export const updateFeature = createServerFn({ method: "POST" })
|
|
|
53
56
|
await context.db.update(featureTable).set(data).where(eq(featureTable.id, data.id));
|
|
54
57
|
});
|
|
55
58
|
|
|
56
|
-
export const
|
|
57
|
-
.validator(z.uuid())
|
|
59
|
+
export const deleteFeatures = createServerFn({ method: "POST" })
|
|
60
|
+
.validator(z.array(z.uuid()))
|
|
58
61
|
.middleware([databaseMiddleware(), authMiddleware("admin")])
|
|
59
62
|
.handler(async ({ data, context }) => {
|
|
60
|
-
await context.db.delete(featureTable).where(
|
|
63
|
+
await context.db.delete(featureTable).where(inArray(featureTable.id, data));
|
|
61
64
|
});
|
|
62
65
|
|
|
63
66
|
// src/routes/api/<feature>s/index.ts
|
package/skills/services/SKILL.md
CHANGED
|
@@ -11,7 +11,7 @@ metadata:
|
|
|
11
11
|
You can read about each service in the links below. Services are categorized as either client or server exports, depending on their intended usage.
|
|
12
12
|
|
|
13
13
|
- **Client exports** — React Query option factories from `wcz-layout/data/client`.
|
|
14
|
-
- **Server exports** — Direct service operations from `wcz-layout/data/server`; import
|
|
14
|
+
- **Server exports** — Direct service operations from `wcz-layout/data/server`; import them only in server code.
|
|
15
15
|
- Invalidating mutation factories take `{ queryClient }`.
|
|
16
16
|
- Access `queryClient` with `Route.useRouteContext()` in a route file, or `useRouteContext({ from: "path" })` in a component.
|
|
17
17
|
- To read about a service, open the linked file in the **File** column directly.
|