wcz-layout 6.7.2 → 9.6.3
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/Approval-C-hF4jbT.mjs +194 -0
- package/dist/Approval-C-hF4jbT.mjs.map +1 -0
- package/dist/DialogsContext-DLqA8RJ_.mjs +7 -0
- package/dist/DialogsContext-DLqA8RJ_.mjs.map +1 -0
- package/dist/Email-BzQQkbe9.mjs +20 -0
- package/dist/Email-BzQQkbe9.mjs.map +1 -0
- package/dist/Email-CKUxOURX.d.mts +17 -0
- package/dist/Employee-iepWeWhO.d.mts +363 -0
- package/dist/FileMeta-Be9viU7D.d.mts +19 -0
- package/dist/FileMeta-DDqUju1Y.mjs +19 -0
- package/dist/FileMeta-DDqUju1Y.mjs.map +1 -0
- package/dist/NotificationContext-CgwUOeW0.mjs +7 -0
- package/dist/NotificationContext-CgwUOeW0.mjs.map +1 -0
- package/dist/QueryClientParam-Cbb0MIKg.d.mts +10 -0
- package/dist/RouterListItemButton-owZVvuC_.mjs +78 -0
- package/dist/RouterListItemButton-owZVvuC_.mjs.map +1 -0
- package/dist/User-1gKoYJvW.d.mts +12 -0
- package/dist/auth.d.mts +19 -0
- package/dist/auth.mjs +92 -0
- package/dist/auth.mjs.map +1 -0
- package/dist/authMiddleware-CKD6lG9v.mjs +49 -0
- package/dist/authMiddleware-CKD6lG9v.mjs.map +1 -0
- package/dist/components.d.mts +104 -0
- package/dist/components.mjs +1277 -0
- package/dist/components.mjs.map +1 -0
- package/dist/data/client.d.mts +3202 -0
- package/dist/data/client.mjs +211 -0
- package/dist/data/client.mjs.map +1 -0
- package/dist/data/server.d.mts +10 -0
- package/dist/data/server.mjs +16 -0
- package/dist/data/server.mjs.map +1 -0
- package/dist/entra-47nBhMK-.mjs +109 -0
- package/dist/entra-47nBhMK-.mjs.map +1 -0
- package/dist/env-CoveIivr.mjs +30 -0
- package/dist/env-CoveIivr.mjs.map +1 -0
- package/dist/file-Bcoxn1YA.mjs +154 -0
- package/dist/file-Bcoxn1YA.mjs.map +1 -0
- package/dist/file-DgooCXxX.mjs +171 -0
- package/dist/file-DgooCXxX.mjs.map +1 -0
- package/dist/hooks.d.mts +215 -0
- package/dist/hooks.mjs +1090 -0
- package/dist/hooks.mjs.map +1 -0
- package/dist/index.d.mts +50 -0
- package/dist/index.mjs +1951 -0
- package/dist/index.mjs.map +1 -0
- package/dist/middleware.d.mts +33 -0
- package/dist/middleware.mjs +27 -0
- package/dist/middleware.mjs.map +1 -0
- package/dist/models.d.mts +225 -0
- package/dist/models.mjs +74 -0
- package/dist/models.mjs.map +1 -0
- package/dist/msalServer-Ce9p7sTC.mjs +30 -0
- package/dist/msalServer-Ce9p7sTC.mjs.map +1 -0
- package/dist/peoplesoft-4pOmhLn5.d.mts +167 -0
- package/dist/peoplesoft-BdPHe6Ac.mjs +202 -0
- package/dist/peoplesoft-BdPHe6Ac.mjs.map +1 -0
- package/dist/useDialogs-BUzVrTSP.mjs +248 -0
- package/dist/useDialogs-BUzVrTSP.mjs.map +1 -0
- package/dist/user-Dzv0N9fj.d.mts +16 -0
- package/dist/utils-5x4uNxsX.d.mts +63 -0
- package/dist/utils-CqVAK5F8.mjs +238 -0
- package/dist/utils-CqVAK5F8.mjs.map +1 -0
- package/dist/utils-D39-w_ij.mjs +4 -0
- package/dist/utils.d.mts +5 -0
- package/dist/utils.mjs +3 -0
- package/dist/vite.d.mts +6 -0
- package/dist/vite.mjs +149 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +127 -62
- package/skills/client-db/SKILL.md +109 -0
- package/skills/data-grid/SKILL.md +142 -0
- package/skills/db-schema/SKILL.md +72 -0
- package/skills/dialogs/SKILL.md +78 -0
- package/skills/forms/SKILL.md +83 -0
- package/skills/general/SKILL.md +74 -0
- package/skills/routing/SKILL.md +94 -0
- package/skills/server-functions/SKILL.md +111 -0
- package/skills/services/SKILL.md +31 -0
- package/skills/services/docs/approval.md +257 -0
- package/skills/services/docs/email.md +32 -0
- package/skills/services/docs/file.md +108 -0
- package/skills/services/docs/peoplesoft.md +110 -0
- package/skills/start/SKILL.md +47 -0
- package/skills/start/steps/01-git-setup.md +11 -0
- package/skills/start/steps/02-project-name-setup.md +19 -0
- package/skills/start/steps/03-apm-setup.md +208 -0
- package/skills/start/steps/04-wicop-setup.md +80 -0
- package/skills/start/steps/05-database-setup.md +44 -0
- package/skills/start/steps/06-entra-setup.md +98 -0
- package/skills/start/steps/07-vault-setup.md +69 -0
- package/skills/start/steps/08-generate-favicon.md +8 -0
- package/skills/start/steps/09-commit.md +15 -0
- package/skills/start/steps/10-gitlab-ci.md +25 -0
- package/dist/src/components/Layout.d.ts +0 -16
- package/dist/src/components/Layout.js +0 -122
- package/dist/src/components/Layout.js.map +0 -1
- package/dist/src/components/dataGrid/ChipInputCell.d.ts +0 -9
- package/dist/src/components/dataGrid/ChipInputCell.js +0 -17
- package/dist/src/components/dataGrid/ChipInputCell.js.map +0 -1
- package/dist/src/components/dataGrid/EditableColumnHeader.d.ts +0 -2
- package/dist/src/components/dataGrid/EditableColumnHeader.js +0 -7
- package/dist/src/components/dataGrid/EditableColumnHeader.js.map +0 -1
- package/dist/src/components/dataGrid/GridToolbar.d.ts +0 -8
- package/dist/src/components/dataGrid/GridToolbar.js +0 -40
- package/dist/src/components/dataGrid/GridToolbar.js.map +0 -1
- package/dist/src/components/dataGrid/TableContainer.d.ts +0 -3
- package/dist/src/components/dataGrid/TableContainer.js +0 -32
- package/dist/src/components/dataGrid/TableContainer.js.map +0 -1
- package/dist/src/components/form/FormAutocomplete.d.ts +0 -7
- package/dist/src/components/form/FormAutocomplete.js +0 -10
- package/dist/src/components/form/FormAutocomplete.js.map +0 -1
- package/dist/src/components/form/FormCheckbox.d.ts +0 -7
- package/dist/src/components/form/FormCheckbox.js +0 -11
- package/dist/src/components/form/FormCheckbox.js.map +0 -1
- package/dist/src/components/form/FormDatePicker.d.ts +0 -9
- package/dist/src/components/form/FormDatePicker.js +0 -19
- package/dist/src/components/form/FormDatePicker.js.map +0 -1
- package/dist/src/components/form/FormDateTimePicker.d.ts +0 -9
- package/dist/src/components/form/FormDateTimePicker.js +0 -19
- package/dist/src/components/form/FormDateTimePicker.js.map +0 -1
- package/dist/src/components/form/FormNumberField.d.ts +0 -12
- package/dist/src/components/form/FormNumberField.js +0 -12
- package/dist/src/components/form/FormNumberField.js.map +0 -1
- package/dist/src/components/form/FormRadioGroup.d.ts +0 -13
- package/dist/src/components/form/FormRadioGroup.js +0 -11
- package/dist/src/components/form/FormRadioGroup.js.map +0 -1
- package/dist/src/components/form/FormSlider.d.ts +0 -7
- package/dist/src/components/form/FormSlider.js +0 -11
- package/dist/src/components/form/FormSlider.js.map +0 -1
- package/dist/src/components/form/FormSubmitButton.d.ts +0 -5
- package/dist/src/components/form/FormSubmitButton.js +0 -13
- package/dist/src/components/form/FormSubmitButton.js.map +0 -1
- package/dist/src/components/form/FormSwitch.d.ts +0 -7
- package/dist/src/components/form/FormSwitch.js +0 -11
- package/dist/src/components/form/FormSwitch.js.map +0 -1
- package/dist/src/components/form/FormTextField.d.ts +0 -7
- package/dist/src/components/form/FormTextField.js +0 -11
- package/dist/src/components/form/FormTextField.js.map +0 -1
- package/dist/src/components/layout/AccountMenu.d.ts +0 -9
- package/dist/src/components/layout/AccountMenu.js +0 -44
- package/dist/src/components/layout/AccountMenu.js.map +0 -1
- package/dist/src/components/layout/DevelopmentBanner.d.ts +0 -7
- package/dist/src/components/layout/DevelopmentBanner.js +0 -29
- package/dist/src/components/layout/DevelopmentBanner.js.map +0 -1
- package/dist/src/components/layout/ErrorPage.d.ts +0 -2
- package/dist/src/components/layout/ErrorPage.js +0 -25
- package/dist/src/components/layout/ErrorPage.js.map +0 -1
- package/dist/src/components/layout/LayoutDialog.d.ts +0 -12
- package/dist/src/components/layout/LayoutDialog.js +0 -12
- package/dist/src/components/layout/LayoutDialog.js.map +0 -1
- package/dist/src/components/layout/LayoutSnackbar.d.ts +0 -8
- package/dist/src/components/layout/LayoutSnackbar.js +0 -25
- package/dist/src/components/layout/LayoutSnackbar.js.map +0 -1
- package/dist/src/components/layout/NavigationDrawer.d.ts +0 -11
- package/dist/src/components/layout/NavigationDrawer.js +0 -70
- package/dist/src/components/layout/NavigationDrawer.js.map +0 -1
- package/dist/src/components/layout/NotificationMenu.d.ts +0 -8
- package/dist/src/components/layout/NotificationMenu.js +0 -26
- package/dist/src/components/layout/NotificationMenu.js.map +0 -1
- package/dist/src/components/layout/TypographyWithIcon.d.ts +0 -7
- package/dist/src/components/layout/TypographyWithIcon.js +0 -22
- package/dist/src/components/layout/TypographyWithIcon.js.map +0 -1
- package/dist/src/components/layout/Unauthorized.d.ts +0 -2
- package/dist/src/components/layout/Unauthorized.js +0 -26
- package/dist/src/components/layout/Unauthorized.js.map +0 -1
- package/dist/src/contexts/LayoutContext.d.ts +0 -40
- package/dist/src/contexts/LayoutContext.js +0 -60
- package/dist/src/contexts/LayoutContext.js.map +0 -1
- package/dist/src/contexts/UserContext.d.ts +0 -24
- package/dist/src/contexts/UserContext.js +0 -55
- package/dist/src/contexts/UserContext.js.map +0 -1
- package/dist/src/hooks/FormHooks.d.ts +0 -46
- package/dist/src/hooks/FormHooks.js +0 -31
- package/dist/src/hooks/FormHooks.js.map +0 -1
- package/dist/src/hooks/UseSnackbar.d.ts +0 -10
- package/dist/src/hooks/UseSnackbar.js +0 -23
- package/dist/src/hooks/UseSnackbar.js.map +0 -1
- package/dist/src/hooks/UseUser.d.ts +0 -10
- package/dist/src/hooks/UseUser.js +0 -25
- package/dist/src/hooks/UseUser.js.map +0 -1
- package/dist/src/index.d.ts +0 -20
- package/dist/src/index.js +0 -15
- package/dist/src/index.js.map +0 -1
- package/dist/src/models/Error.d.ts +0 -6
- package/dist/src/models/Error.js +0 -2
- package/dist/src/models/Error.js.map +0 -1
- package/dist/src/models/KeycloakSettings.d.ts +0 -8
- package/dist/src/models/KeycloakSettings.js +0 -2
- package/dist/src/models/KeycloakSettings.js.map +0 -1
- package/dist/src/models/LayoutPaletteColorOptions.d.ts +0 -6
- package/dist/src/models/LayoutPaletteColorOptions.js +0 -2
- package/dist/src/models/LayoutPaletteColorOptions.js.map +0 -1
- package/dist/src/models/LayoutRoute.d.ts +0 -14
- package/dist/src/models/LayoutRoute.js +0 -2
- package/dist/src/models/LayoutRoute.js.map +0 -1
- package/dist/src/models/Notification.d.ts +0 -9
- package/dist/src/models/Notification.js +0 -2
- package/dist/src/models/Notification.js.map +0 -1
- package/dist/src/models/PeoplesoftDepartment.d.ts +0 -14
- package/dist/src/models/PeoplesoftDepartment.js +0 -2
- package/dist/src/models/PeoplesoftDepartment.js.map +0 -1
- package/dist/src/models/PeoplesoftEmployee.d.ts +0 -34
- package/dist/src/models/PeoplesoftEmployee.js +0 -2
- package/dist/src/models/PeoplesoftEmployee.js.map +0 -1
- package/dist/src/models/Snackbar.d.ts +0 -15
- package/dist/src/models/Snackbar.js +0 -2
- package/dist/src/models/Snackbar.js.map +0 -1
- package/dist/src/models/User.d.ts +0 -27
- package/dist/src/models/User.js +0 -11
- package/dist/src/models/User.js.map +0 -1
- package/dist/src/models/types/EmployeeCategoryGroup.d.ts +0 -1
- package/dist/src/models/types/EmployeeCategoryGroup.js +0 -2
- package/dist/src/models/types/EmployeeCategoryGroup.js.map +0 -1
- package/dist/src/models/types/EmployeeStatus.d.ts +0 -1
- package/dist/src/models/types/EmployeeStatus.js +0 -2
- package/dist/src/models/types/EmployeeStatus.js.map +0 -1
- package/dist/src/utils/Auth.d.ts +0 -12
- package/dist/src/utils/Auth.js +0 -49
- package/dist/src/utils/Auth.js.map +0 -1
- package/dist/src/utils/Fetches.d.ts +0 -5
- package/dist/src/utils/Fetches.js +0 -66
- package/dist/src/utils/Fetches.js.map +0 -1
- package/dist/src/utils/FormUtils.d.ts +0 -7
- package/dist/src/utils/FormUtils.js +0 -9
- package/dist/src/utils/FormUtils.js.map +0 -1
- package/dist/src/utils/Helpers.d.ts +0 -11
- package/dist/src/utils/Helpers.js +0 -26
- package/dist/src/utils/Helpers.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/components/Layout.tsx +0 -183
- package/src/components/dataGrid/ChipInputCell.tsx +0 -31
- package/src/components/dataGrid/EditableColumnHeader.tsx +0 -7
- package/src/components/dataGrid/GridToolbar.tsx +0 -63
- package/src/components/dataGrid/TableContainer.tsx +0 -39
- package/src/components/form/FormAutocomplete.tsx +0 -34
- package/src/components/form/FormCheckbox.tsx +0 -32
- package/src/components/form/FormDatePicker.tsx +0 -34
- package/src/components/form/FormDateTimePicker.tsx +0 -34
- package/src/components/form/FormNumberField.tsx +0 -33
- package/src/components/form/FormRadioGroup.tsx +0 -43
- package/src/components/form/FormSlider.tsx +0 -28
- package/src/components/form/FormSubmitButton.tsx +0 -29
- package/src/components/form/FormSwitch.tsx +0 -32
- package/src/components/form/FormTextField.tsx +0 -26
- package/src/components/layout/AccountMenu.tsx +0 -160
- package/src/components/layout/DevelopmentBanner.tsx +0 -54
- package/src/components/layout/ErrorPage.tsx +0 -34
- package/src/components/layout/LayoutDialog.tsx +0 -50
- package/src/components/layout/LayoutSnackbar.tsx +0 -44
- package/src/components/layout/NavigationDrawer.tsx +0 -131
- package/src/components/layout/NotificationMenu.tsx +0 -76
- package/src/components/layout/TypographyWithIcon.tsx +0 -35
- package/src/components/layout/Unauthorized.tsx +0 -37
- package/src/contexts/LayoutContext.tsx +0 -127
- package/src/contexts/UserContext.tsx +0 -88
- package/src/hooks/FormHooks.ts +0 -33
- package/src/hooks/UseSnackbar.tsx +0 -28
- package/src/hooks/UseUser.tsx +0 -29
- package/src/index.ts +0 -27
- package/src/models/Error.tsx +0 -6
- package/src/models/KeycloakSettings.ts +0 -8
- package/src/models/LayoutPaletteColorOptions.tsx +0 -7
- package/src/models/LayoutRoute.ts +0 -15
- package/src/models/Notification.ts +0 -10
- package/src/models/PeoplesoftDepartment.ts +0 -15
- package/src/models/PeoplesoftEmployee.ts +0 -35
- package/src/models/Snackbar.ts +0 -16
- package/src/models/User.ts +0 -13
- package/src/models/types/EmployeeCategoryGroup.ts +0 -1
- package/src/models/types/EmployeeStatus.ts +0 -1
- package/src/utils/Auth.ts +0 -58
- package/src/utils/Fetches.ts +0 -83
- package/src/utils/FormUtils.ts +0 -22
- package/src/utils/Helpers.ts +0 -27
- package/tsconfig.json +0 -29
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import https from "node:https";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { loadEnv } from "vite";
|
|
7
|
+
//#region src/models/VaultConfig.ts
|
|
8
|
+
const VaultConfigSchema = z.object({
|
|
9
|
+
VAULT_ADDRESS: z.url(),
|
|
10
|
+
VAULT_USERNAME: z.string().min(1),
|
|
11
|
+
VAULT_PASSWORD: z.string().min(1),
|
|
12
|
+
VAULT_SECRET_PATH: z.string().min(1),
|
|
13
|
+
VAULT_MOUNT_POINT: z.string().default("release")
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/lib/vite-plugin.ts
|
|
17
|
+
async function fetchVaultSecrets(env) {
|
|
18
|
+
const { VAULT_ADDRESS, VAULT_USERNAME, VAULT_PASSWORD, VAULT_SECRET_PATH, VAULT_MOUNT_POINT } = VaultConfigSchema.parse(env);
|
|
19
|
+
const client = axios.create({
|
|
20
|
+
baseURL: VAULT_ADDRESS,
|
|
21
|
+
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
|
22
|
+
});
|
|
23
|
+
const { data: loginData } = await client.post(`/v1/auth/userpass/login/${VAULT_USERNAME}`, { password: VAULT_PASSWORD });
|
|
24
|
+
const { data: secretData } = await client.get(`/v1/${VAULT_MOUNT_POINT}/data/${VAULT_SECRET_PATH}`, { headers: { "X-Vault-Token": loginData.auth.client_token } });
|
|
25
|
+
const secrets = secretData?.data?.data;
|
|
26
|
+
if (!secrets) throw new Error("No secrets found");
|
|
27
|
+
return Object.fromEntries(Object.entries(secrets).map(([key, value]) => [key, typeof value === "string" ? value : JSON.stringify(value)]));
|
|
28
|
+
}
|
|
29
|
+
async function loadVaultSecrets(command) {
|
|
30
|
+
if (command !== "serve") return;
|
|
31
|
+
const env = loadEnv("development", process.cwd(), "");
|
|
32
|
+
if (!env.VAULT_ADDRESS) return;
|
|
33
|
+
try {
|
|
34
|
+
const secrets = await fetchVaultSecrets(env);
|
|
35
|
+
Object.entries(secrets).forEach(([key, value]) => {
|
|
36
|
+
process.env[key] = env[key]?.trim() ? env[key] : value;
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.warn("[vite:wcz-layout] Vault failed:", e instanceof Error ? e.message : e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function loadLocaleResources(localesPath, addWatchFile) {
|
|
43
|
+
if (!fs.existsSync(localesPath)) fs.mkdirSync(localesPath, { recursive: true });
|
|
44
|
+
const enPath = path.join(localesPath, "en.json");
|
|
45
|
+
if (!fs.existsSync(enPath)) fs.writeFileSync(enPath, JSON.stringify({}));
|
|
46
|
+
const files = fs.readdirSync(localesPath);
|
|
47
|
+
const resources = {};
|
|
48
|
+
for (const file of files.filter((f) => f.endsWith(".json"))) {
|
|
49
|
+
const lang = path.basename(file, ".json");
|
|
50
|
+
const filePath = path.join(localesPath, file);
|
|
51
|
+
try {
|
|
52
|
+
resources[lang] = { translation: JSON.parse(fs.readFileSync(filePath, "utf-8")) };
|
|
53
|
+
} catch {
|
|
54
|
+
resources[lang] = { translation: {} };
|
|
55
|
+
}
|
|
56
|
+
addWatchFile(filePath);
|
|
57
|
+
}
|
|
58
|
+
return resources;
|
|
59
|
+
}
|
|
60
|
+
function ensurePermissionsFile(permissionsPath, addWatchFile) {
|
|
61
|
+
const dir = path.dirname(permissionsPath);
|
|
62
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
63
|
+
if (!fs.existsSync(permissionsPath)) fs.writeFileSync(permissionsPath, "export const permissions = {\n admin: [\"wcz-developers\"]\n} as const;");
|
|
64
|
+
addWatchFile(permissionsPath);
|
|
65
|
+
}
|
|
66
|
+
function ensureScopesFile(scopesPath, addWatchFile) {
|
|
67
|
+
const dir = path.dirname(scopesPath);
|
|
68
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
69
|
+
if (!fs.existsSync(scopesPath)) fs.writeFileSync(scopesPath, "export const scopes = {\n} as const;");
|
|
70
|
+
addWatchFile(scopesPath);
|
|
71
|
+
}
|
|
72
|
+
function loadManifest(manifestPath, addWatchFile) {
|
|
73
|
+
addWatchFile(manifestPath);
|
|
74
|
+
try {
|
|
75
|
+
return JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
76
|
+
} catch {
|
|
77
|
+
return { name: "" };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function viteWczLayout() {
|
|
81
|
+
const virtualModuleId = "virtual:wcz-layout";
|
|
82
|
+
const resolvedVirtualModuleId = "\0virtual:wcz-layout";
|
|
83
|
+
let localesPath;
|
|
84
|
+
let permissionsPath;
|
|
85
|
+
let scopesPath;
|
|
86
|
+
let envPath;
|
|
87
|
+
let manifestPath;
|
|
88
|
+
return {
|
|
89
|
+
name: "vite:wcz-layout",
|
|
90
|
+
enforce: "pre",
|
|
91
|
+
configResolved(resolvedConfig) {
|
|
92
|
+
localesPath = path.resolve(resolvedConfig.root, "src/lib/locales");
|
|
93
|
+
permissionsPath = path.resolve(resolvedConfig.root, "src/lib/auth/permissions.ts");
|
|
94
|
+
scopesPath = path.resolve(resolvedConfig.root, "src/lib/auth/scopes.ts");
|
|
95
|
+
envPath = path.resolve(resolvedConfig.root, "src/env.ts");
|
|
96
|
+
manifestPath = path.resolve(resolvedConfig.root, "public/manifest.json");
|
|
97
|
+
},
|
|
98
|
+
async config(_, { command }) {
|
|
99
|
+
await loadVaultSecrets(command);
|
|
100
|
+
},
|
|
101
|
+
configureServer(server) {
|
|
102
|
+
const refresh = (filePath) => {
|
|
103
|
+
if (filePath.includes(localesPath) || filePath === permissionsPath || filePath === scopesPath || filePath === envPath || filePath === manifestPath) {
|
|
104
|
+
const module = server.moduleGraph.getModuleById(resolvedVirtualModuleId);
|
|
105
|
+
if (module) server.moduleGraph.invalidateModule(module);
|
|
106
|
+
server.ws.send({
|
|
107
|
+
type: "full-reload",
|
|
108
|
+
path: "*"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
server.watcher.add([
|
|
113
|
+
localesPath,
|
|
114
|
+
permissionsPath,
|
|
115
|
+
scopesPath,
|
|
116
|
+
envPath,
|
|
117
|
+
manifestPath
|
|
118
|
+
]);
|
|
119
|
+
server.watcher.on("add", refresh);
|
|
120
|
+
server.watcher.on("change", refresh);
|
|
121
|
+
server.watcher.on("unlink", refresh);
|
|
122
|
+
},
|
|
123
|
+
resolveId(id) {
|
|
124
|
+
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
125
|
+
return null;
|
|
126
|
+
},
|
|
127
|
+
load(id) {
|
|
128
|
+
if (id !== resolvedVirtualModuleId) return null;
|
|
129
|
+
const resources = loadLocaleResources(localesPath, this.addWatchFile.bind(this));
|
|
130
|
+
ensurePermissionsFile(permissionsPath, this.addWatchFile.bind(this));
|
|
131
|
+
ensureScopesFile(scopesPath, this.addWatchFile.bind(this));
|
|
132
|
+
const manifest = loadManifest(manifestPath, this.addWatchFile.bind(this));
|
|
133
|
+
const normalizedPermissionsPath = permissionsPath.split(path.sep).join(path.posix.sep);
|
|
134
|
+
const normalizedScopesPath = scopesPath.split(path.sep).join(path.posix.sep);
|
|
135
|
+
const normalizedEnvPath = envPath.split(path.sep).join(path.posix.sep);
|
|
136
|
+
return `
|
|
137
|
+
export const resources = ${JSON.stringify(resources)};
|
|
138
|
+
export const manifest = ${JSON.stringify(manifest)};
|
|
139
|
+
export { permissions } from "${normalizedPermissionsPath}";
|
|
140
|
+
export { scopes } from "${normalizedScopesPath}";
|
|
141
|
+
export { serverEnv } from "${normalizedEnvPath}";
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { viteWczLayout };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=vite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.mjs","names":["z","VaultConfigSchema","object","VAULT_ADDRESS","url","VAULT_USERNAME","string","min","VAULT_PASSWORD","VAULT_SECRET_PATH","VAULT_MOUNT_POINT","default","VaultConfig","infer","fs","https","path","axios","loadEnv","VaultConfigSchema","Resource","Plugin","fetchVaultSecrets","env","Record","Promise","config","parse","VAULT_ADDRESS","VAULT_USERNAME","VAULT_PASSWORD","VAULT_SECRET_PATH","VAULT_MOUNT_POINT","client","create","baseURL","httpsAgent","Agent","rejectUnauthorized","data","loginData","post","password","secretData","get","headers","auth","client_token","secrets","Error","Object","fromEntries","entries","map","key","value","JSON","stringify","loadVaultSecrets","command","process","cwd","forEach","trim","e","console","warn","message","loadLocaleResources","localesPath","addWatchFile","existsSync","mkdirSync","recursive","enPath","join","writeFileSync","files","readdirSync","resources","file","filter","f","endsWith","lang","basename","filePath","translation","readFileSync","ensurePermissionsFile","permissionsPath","dir","dirname","ensureScopesFile","scopesPath","loadManifest","manifestPath","name","viteWczLayout","virtualModuleId","resolvedVirtualModuleId","envPath","enforce","configResolved","resolvedConfig","resolve","root","_","configureServer","server","refresh","includes","module","moduleGraph","getModuleById","invalidateModule","ws","send","type","watcher","add","on","resolveId","id","load","bind","manifest","normalizedPermissionsPath","split","sep","posix","normalizedScopesPath","normalizedEnvPath"],"sources":["../src/models/VaultConfig.ts","../src/lib/vite-plugin.ts"],"sourcesContent":["import z from \"zod\";\n\nexport const VaultConfigSchema = z.object({\n VAULT_ADDRESS: z.url(),\n VAULT_USERNAME: z.string().min(1),\n VAULT_PASSWORD: z.string().min(1),\n VAULT_SECRET_PATH: z.string().min(1),\n VAULT_MOUNT_POINT: z.string().default(\"release\"),\n});\n\nexport type VaultConfig = z.infer<typeof VaultConfigSchema>;\n","import fs from \"node:fs\";\r\nimport https from \"node:https\";\r\nimport path from \"node:path\";\r\nimport axios from \"axios\";\r\nimport { loadEnv } from \"vite\";\r\nimport { VaultConfigSchema } from \"../models/VaultConfig\";\r\nimport type { Resource } from \"i18next\";\r\nimport type { Plugin } from \"vite\";\r\n\r\nasync function fetchVaultSecrets(env: Record<string, string>): Promise<Record<string, string>> {\r\n const config = VaultConfigSchema.parse(env);\r\n const { VAULT_ADDRESS, VAULT_USERNAME, VAULT_PASSWORD, VAULT_SECRET_PATH, VAULT_MOUNT_POINT } =\r\n config;\r\n\r\n const client = axios.create({\r\n baseURL: VAULT_ADDRESS,\r\n httpsAgent: new https.Agent({ rejectUnauthorized: false }),\r\n });\r\n\r\n const { data: loginData } = await client.post(`/v1/auth/userpass/login/${VAULT_USERNAME}`, {\r\n password: VAULT_PASSWORD,\r\n });\r\n\r\n const { data: secretData } = await client.get(\r\n `/v1/${VAULT_MOUNT_POINT}/data/${VAULT_SECRET_PATH}`,\r\n {\r\n headers: { \"X-Vault-Token\": loginData.auth.client_token },\r\n },\r\n );\r\n\r\n const secrets = secretData?.data?.data;\r\n if (!secrets) throw new Error(\"No secrets found\");\r\n\r\n return Object.fromEntries(\r\n Object.entries(secrets).map(([key, value]) => [\r\n key,\r\n typeof value === \"string\" ? value : JSON.stringify(value),\r\n ]),\r\n );\r\n}\r\n\r\nasync function loadVaultSecrets(command: string): Promise<void> {\r\n if (command !== \"serve\") return;\r\n\r\n const env = loadEnv(\"development\", process.cwd(), \"\");\r\n if (!env.VAULT_ADDRESS) return;\r\n\r\n try {\r\n const secrets = await fetchVaultSecrets(env);\r\n Object.entries(secrets).forEach(([key, value]) => {\r\n process.env[key] = env[key]?.trim() ? env[key] : value;\r\n });\r\n } catch (e) {\r\n console.warn(\"[vite:wcz-layout] Vault failed:\", e instanceof Error ? e.message : e);\r\n }\r\n}\r\n\r\nfunction loadLocaleResources(localesPath: string, addWatchFile: (path: string) => void): Resource {\r\n if (!fs.existsSync(localesPath)) fs.mkdirSync(localesPath, { recursive: true });\r\n\r\n const enPath = path.join(localesPath, \"en.json\");\r\n if (!fs.existsSync(enPath)) fs.writeFileSync(enPath, JSON.stringify({}));\r\n\r\n const files = fs.readdirSync(localesPath);\r\n const resources: Resource = {};\r\n\r\n for (const file of files.filter((f) => f.endsWith(\".json\"))) {\r\n const lang = path.basename(file, \".json\");\r\n const filePath = path.join(localesPath, file);\r\n try {\r\n resources[lang] = { translation: JSON.parse(fs.readFileSync(filePath, \"utf-8\")) };\r\n } catch {\r\n resources[lang] = { translation: {} };\r\n }\r\n addWatchFile(filePath);\r\n }\r\n\r\n return resources;\r\n}\r\n\r\nfunction ensurePermissionsFile(\r\n permissionsPath: string,\r\n addWatchFile: (path: string) => void,\r\n): void {\r\n const dir = path.dirname(permissionsPath);\r\n if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });\r\n if (!fs.existsSync(permissionsPath)) {\r\n fs.writeFileSync(\r\n permissionsPath,\r\n 'export const permissions = {\\n admin: [\"wcz-developers\"]\\n} as const;',\r\n );\r\n }\r\n addWatchFile(permissionsPath);\r\n}\r\n\r\nfunction ensureScopesFile(scopesPath: string, addWatchFile: (path: string) => void): void {\r\n const dir = path.dirname(scopesPath);\r\n if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });\r\n if (!fs.existsSync(scopesPath)) {\r\n fs.writeFileSync(scopesPath, \"export const scopes = {\\n} as const;\");\r\n }\r\n addWatchFile(scopesPath);\r\n}\r\n\r\nfunction loadManifest(\r\n manifestPath: string,\r\n addWatchFile: (path: string) => void,\r\n): { name: string } & Record<string, unknown> {\r\n addWatchFile(manifestPath);\r\n try {\r\n return JSON.parse(fs.readFileSync(manifestPath, \"utf-8\"));\r\n } catch {\r\n return { name: \"\" };\r\n }\r\n}\r\n\r\nexport function viteWczLayout(): Plugin {\r\n const virtualModuleId = \"virtual:wcz-layout\";\r\n const resolvedVirtualModuleId = \"\\0\" + virtualModuleId;\r\n\r\n let localesPath: string;\r\n let permissionsPath: string;\r\n let scopesPath: string;\r\n let envPath: string;\r\n let manifestPath: string;\r\n\r\n return {\r\n name: \"vite:wcz-layout\",\r\n enforce: \"pre\",\r\n configResolved(resolvedConfig) {\r\n localesPath = path.resolve(resolvedConfig.root, \"src/lib/locales\");\r\n permissionsPath = path.resolve(resolvedConfig.root, \"src/lib/auth/permissions.ts\");\r\n scopesPath = path.resolve(resolvedConfig.root, \"src/lib/auth/scopes.ts\");\r\n envPath = path.resolve(resolvedConfig.root, \"src/env.ts\");\r\n manifestPath = path.resolve(resolvedConfig.root, \"public/manifest.json\");\r\n },\r\n async config(_, { command }) {\r\n await loadVaultSecrets(command);\r\n },\r\n configureServer(server) {\r\n const refresh = (filePath: string) => {\r\n if (\r\n filePath.includes(localesPath) ||\r\n filePath === permissionsPath ||\r\n filePath === scopesPath ||\r\n filePath === envPath ||\r\n filePath === manifestPath\r\n ) {\r\n const module = server.moduleGraph.getModuleById(resolvedVirtualModuleId);\r\n if (module) server.moduleGraph.invalidateModule(module);\r\n server.ws.send({ type: \"full-reload\", path: \"*\" });\r\n }\r\n };\r\n\r\n server.watcher.add([localesPath, permissionsPath, scopesPath, envPath, manifestPath]);\r\n server.watcher.on(\"add\", refresh);\r\n server.watcher.on(\"change\", refresh);\r\n server.watcher.on(\"unlink\", refresh);\r\n },\r\n resolveId(id) {\r\n if (id === virtualModuleId) return resolvedVirtualModuleId;\r\n return null;\r\n },\r\n load(id) {\r\n if (id !== resolvedVirtualModuleId) return null;\r\n\r\n const resources = loadLocaleResources(localesPath, this.addWatchFile.bind(this));\r\n ensurePermissionsFile(permissionsPath, this.addWatchFile.bind(this));\r\n ensureScopesFile(scopesPath, this.addWatchFile.bind(this));\r\n const manifest = loadManifest(manifestPath, this.addWatchFile.bind(this));\r\n\r\n const normalizedPermissionsPath = permissionsPath.split(path.sep).join(path.posix.sep);\r\n const normalizedScopesPath = scopesPath.split(path.sep).join(path.posix.sep);\r\n const normalizedEnvPath = envPath.split(path.sep).join(path.posix.sep);\r\n return `\r\n export const resources = ${JSON.stringify(resources)};\r\n export const manifest = ${JSON.stringify(manifest)};\r\n export { permissions } from \"${normalizedPermissionsPath}\";\r\n export { scopes } from \"${normalizedScopesPath}\";\r\n export { serverEnv } from \"${normalizedEnvPath}\";\r\n `;\r\n },\r\n };\r\n}\r\n"],"mappings":";;;;;;;AAEA,MAAaC,oBAAoBD,EAAEE,OAAO;CACxCC,eAAeH,EAAEI,IAAI;CACrBC,gBAAgBL,EAAEM,OAAO,CAAC,CAACC,IAAI,CAAC;CAChCC,gBAAgBR,EAAEM,OAAO,CAAC,CAACC,IAAI,CAAC;CAChCE,mBAAmBT,EAAEM,OAAO,CAAC,CAACC,IAAI,CAAC;CACnCG,mBAAmBV,EAAEM,OAAO,CAAC,CAACK,QAAQ,SAAS;AACjD,CAAC;;;ACCD,eAAeW,kBAAkBC,KAA8D;CAE7F,MAAM,EAAEK,eAAeC,gBAAgBC,gBAAgBC,mBAAmBC,sBAD3Db,kBAAkBQ,MAAMJ,GAErCG;CAEF,MAAMO,SAAShB,MAAMiB,OAAO;EAC1BC,SAASP;EACTQ,YAAY,IAAIrB,MAAMsB,MAAM,EAAEC,oBAAoB,MAAM,CAAC;CAC3D,CAAC;CAED,MAAM,EAAEC,MAAMC,cAAc,MAAMP,OAAOQ,KAAK,2BAA2BZ,kBAAkB,EACzFa,UAAUZ,eACZ,CAAC;CAED,MAAM,EAAES,MAAMI,eAAe,MAAMV,OAAOW,IACxC,OAAOZ,kBAAiB,QAASD,qBACjC,EACEc,SAAS,EAAE,iBAAiBL,UAAUM,KAAKC,aAAa,EAC1D,CACF;CAEA,MAAMC,UAAUL,YAAYJ,MAAMA;CAClC,IAAI,CAACS,SAAS,MAAM,IAAIC,MAAM,kBAAkB;CAEhD,OAAOC,OAAOC,YACZD,OAAOE,QAAQJ,OAAO,C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|
+
"version": "9.6.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tanstack-intent"
|
|
7
|
+
],
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://gitlab.wistron.com/wcz/it-developers/layout/tanstack.git"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"skills",
|
|
15
|
+
"!skills/_artifacts"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./dist/index.mjs"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"import": "./dist/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./components": {
|
|
28
|
+
"types": "./dist/components.d.mts",
|
|
29
|
+
"import": "./dist/components.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./hooks": {
|
|
32
|
+
"types": "./dist/hooks.d.mts",
|
|
33
|
+
"import": "./dist/hooks.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./middleware": {
|
|
36
|
+
"types": "./dist/middleware.d.mts",
|
|
37
|
+
"import": "./dist/middleware.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./models": {
|
|
40
|
+
"types": "./dist/models.d.mts",
|
|
41
|
+
"import": "./dist/models.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./data/client": {
|
|
44
|
+
"types": "./dist/data/client.d.mts",
|
|
45
|
+
"import": "./dist/data/client.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./data/server": {
|
|
48
|
+
"types": "./dist/data/server.d.mts",
|
|
49
|
+
"import": "./dist/data/server.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./utils": {
|
|
52
|
+
"types": "./dist/utils.d.mts",
|
|
53
|
+
"import": "./dist/utils.mjs"
|
|
54
|
+
},
|
|
55
|
+
"./auth": {
|
|
56
|
+
"types": "./dist/auth.d.mts",
|
|
57
|
+
"import": "./dist/auth.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./vite": {
|
|
60
|
+
"types": "./dist/vite.d.mts",
|
|
61
|
+
"import": "./dist/vite.mjs"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"dev": "vp dev",
|
|
66
|
+
"check": "vp check",
|
|
67
|
+
"typecheck": "tsc --noEmit --watch --preserveWatchOutput",
|
|
68
|
+
"build": "vp pack",
|
|
69
|
+
"prepublishOnly": "npm run build"
|
|
70
|
+
},
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"@azure/msal-node": "^5.4.3",
|
|
73
|
+
"@t3-oss/env-core": "^0.13.11",
|
|
74
|
+
"i18next": "^26.3.6",
|
|
75
|
+
"i18next-browser-languagedetector": "^8.2.1",
|
|
76
|
+
"jose": "^6.2.5",
|
|
77
|
+
"react-dropzone": "^19.1.1",
|
|
78
|
+
"react-i18next": "^17.0.11",
|
|
79
|
+
"react-intersection-observer": "^10.1.0",
|
|
80
|
+
"react-number-format": "^5.4.5",
|
|
81
|
+
"tus-js-client": "^4.3.1",
|
|
82
|
+
"uuidv7": "^1.2.1"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@arethetypeswrong/core": "^0.18.5",
|
|
86
|
+
"@rolldown/plugin-babel": "^0.2.3",
|
|
87
|
+
"@tanstack/ai": "^0.42.0",
|
|
88
|
+
"@tanstack/ai-client": "^0.22.1",
|
|
89
|
+
"@tanstack/ai-openai": "^0.17.1",
|
|
90
|
+
"@tanstack/highlight": "^0.0.9",
|
|
91
|
+
"@types/node": "^26.1.1",
|
|
92
|
+
"@types/react": "^19.2.17",
|
|
93
|
+
"@types/react-dom": "^19.2.3",
|
|
94
|
+
"@vitejs/plugin-react": "^6.0.5",
|
|
95
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
96
|
+
"nitro": "npm:nitro-nightly@latest",
|
|
97
|
+
"publint": "^0.3.22",
|
|
98
|
+
"typescript": "^7.0.2",
|
|
99
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.6",
|
|
100
|
+
"vite-plus": "0.2.6"
|
|
101
|
+
},
|
|
102
|
+
"peerDependencies": {
|
|
103
|
+
"@emotion/cache": "11.x",
|
|
104
|
+
"@emotion/react": "11.x",
|
|
105
|
+
"@emotion/styled": "11.x",
|
|
106
|
+
"@mui/icons-material": "9.x",
|
|
107
|
+
"@mui/material": "9.x",
|
|
108
|
+
"@mui/x-data-grid-premium": "9.x",
|
|
109
|
+
"@mui/x-date-pickers-pro": "9.x",
|
|
110
|
+
"@tanstack/query-db-collection": "1.x",
|
|
111
|
+
"@tanstack/react-db": "0.x",
|
|
112
|
+
"@tanstack/react-form": "1.x",
|
|
113
|
+
"@tanstack/react-query": "5.x",
|
|
114
|
+
"@tanstack/react-router": "1.x",
|
|
115
|
+
"@tanstack/react-router-ssr-query": "1.x",
|
|
116
|
+
"@tanstack/react-start": "1.x",
|
|
117
|
+
"axios": "1.x",
|
|
118
|
+
"dayjs": "1.x",
|
|
119
|
+
"react": "19.x",
|
|
120
|
+
"react-dom": "19.x",
|
|
121
|
+
"zod": "4.x"
|
|
122
|
+
},
|
|
123
|
+
"overrides": {
|
|
124
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.6"
|
|
125
|
+
},
|
|
126
|
+
"packageManager": "npm@12.0.2"
|
|
127
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: client-db
|
|
3
|
+
description: "Use when: creating or modifying TanStack DB collections, live queries, optimistic collection writes, subset loading, collection preloading."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
> Mechanics (`createCollection`, `queryCollectionOptions`, the live-query builder, `createOptimisticAction`) are covered by TanStack's own skills — load `@tanstack/db#db-core/live-queries`, `#db-core/mutations-optimistic`, and `@tanstack/react-db` for the API details. This skill adds only the wcz-layout conventions on top.
|
|
7
|
+
|
|
8
|
+
## Rules
|
|
9
|
+
|
|
10
|
+
- Use `eager` syncMode for top-level collections, `on-demand` for child/relational data.
|
|
11
|
+
- Always preload every `eager` collection used by a route, including collections used only by components rendered under that route. Do not preload `on-demand` collections.
|
|
12
|
+
- Use `useLiveQuery` for list/grid pages and `useLiveSuspenseQuery` for detail components wrapped in suspense.
|
|
13
|
+
- Shape data in the collection query whenever possible: filter, order, group and aggregate only the fields the consumer needs. Do not load broad results and further filter or transform them in component code.
|
|
14
|
+
- For mutations use `createOptimisticAction` — mirror the server mutation in `onMutate`, then call the server function and `collection.utils.refetch()` in `mutationFn`.
|
|
15
|
+
- For on-demand subset loading, convert `meta.loadSubsetOptions` with `fromTanDb()` (from `agnostic-query/tanstack-db`) before passing it to the server fn, and set `autoIndex: "eager"` with `defaultIndexType: BasicIndex` (from `@tanstack/react-db`).
|
|
16
|
+
|
|
17
|
+
## File Placement
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
src/db-collections/ — DB collections
|
|
21
|
+
src/server/actions/ — server functions (select/update/insert/delete)
|
|
22
|
+
src/lib/schemas/ — Zod schemas (shared between client and server)
|
|
23
|
+
src/lib/auth/scopes.ts — API scope keys
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Examples
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// src/db-collections/<feature>.ts
|
|
30
|
+
export const librariesCollection = createCollection(
|
|
31
|
+
queryCollectionOptions({
|
|
32
|
+
queryKey: ["libraries"],
|
|
33
|
+
queryFn: () => selectLibraries(),
|
|
34
|
+
getKey: ({ id }) => id,
|
|
35
|
+
schema: LibrarySchema,
|
|
36
|
+
queryClient: queryClient,
|
|
37
|
+
syncMode: "eager",
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// src/db-collections/<feature>.ts — child/relational (on-demand)
|
|
42
|
+
import { BasicIndex } from "@tanstack/react-db";
|
|
43
|
+
import { fromTanDb } from "agnostic-query/tanstack-db";
|
|
44
|
+
|
|
45
|
+
export const bookCollection = createCollection(
|
|
46
|
+
queryCollectionOptions({
|
|
47
|
+
queryKey: ["books"],
|
|
48
|
+
queryFn: ({ meta }) => selectBooks({ data: fromTanDb(meta?.loadSubsetOptions) }),
|
|
49
|
+
getKey: ({ id }) => id,
|
|
50
|
+
schema: BookSchema,
|
|
51
|
+
queryClient: queryClient,
|
|
52
|
+
syncMode: "on-demand",
|
|
53
|
+
autoIndex: "eager",
|
|
54
|
+
defaultIndexType: BasicIndex,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Preload
|
|
59
|
+
export const Route = createFileRoute("/")({
|
|
60
|
+
loader: () => {
|
|
61
|
+
void librariesCollection.preload();
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// simple query
|
|
66
|
+
const { data, isLoading } = useLiveQuery((q) =>
|
|
67
|
+
q.from({ library: libraryCollection }).orderBy(({ library }) => library.name, "asc"),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
// advanced query with relational data
|
|
71
|
+
const { data } = useLiveQuery((q) =>
|
|
72
|
+
q
|
|
73
|
+
.from({ library: libraryCollection })
|
|
74
|
+
.where(({ library }) => eq(library.id, id))
|
|
75
|
+
.findOne()
|
|
76
|
+
.select(({ library }) => ({
|
|
77
|
+
...library,
|
|
78
|
+
books: toArray(
|
|
79
|
+
q
|
|
80
|
+
.from({ book: bookCollection })
|
|
81
|
+
.where(({ book }) => eq(book.libraryId, library.id))
|
|
82
|
+
.orderBy(({ book }) => book.title, "asc")
|
|
83
|
+
.select(({ book }) => ({
|
|
84
|
+
id: book.id,
|
|
85
|
+
title: book.title,
|
|
86
|
+
})),
|
|
87
|
+
),
|
|
88
|
+
})),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// form submission handler
|
|
92
|
+
const handleOnSubmit = createOptimisticAction<Library>({
|
|
93
|
+
onMutate: (formValues) => {
|
|
94
|
+
libraryCollection.update(id, (prev) => Object.assign(prev, formValues));
|
|
95
|
+
},
|
|
96
|
+
mutationFn: async (formValues) => {
|
|
97
|
+
await updateLibrary({ data: formValues });
|
|
98
|
+
await libraryCollection.utils.refetch();
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// calling the handler
|
|
103
|
+
try {
|
|
104
|
+
const transaction = handleOnSubmit(formValues);
|
|
105
|
+
await transaction.isPersisted.promise;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (error instanceof Error) alert(error.message);
|
|
108
|
+
}
|
|
109
|
+
```
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: data-grid
|
|
3
|
+
description: "Use when: building or configuring MUI X DataGrid tables."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Rules
|
|
7
|
+
|
|
8
|
+
- Wrap DataGrid in `Fullscreen` when it is the only content on the page.
|
|
9
|
+
- Type columns as `Array<GridColDef<RowType>>` with the row interface.
|
|
10
|
+
- Use translation for all `headerName` values.
|
|
11
|
+
- Use `rows`, `columns`, `showToolbar`, `loading`, `ignoreDiacritics`, `cellSelection`, and `disableRowSelectionOnClick` on grids.
|
|
12
|
+
- For enums use `type: "singleSelect"` with `{ value, label }` options array used from enumObject.
|
|
13
|
+
- For editable columns, pair `editable: true` with `renderHeader: EditableColumnHeader`.
|
|
14
|
+
- Use `EditableColumnHeader`, and router button/grid action components from `wcz-layout/components` when they fit.
|
|
15
|
+
- Always apply a `valueFormatter` for columns with type `dateTime` or `date`.
|
|
16
|
+
|
|
17
|
+
## File Placement
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
@mui/x-data-grid-premium — GridColDef, DataGridPremium
|
|
21
|
+
src/db-collections/ - TanStack DB collections to get data
|
|
22
|
+
@tanstack/react-db - useLiveQuery, useLiveSuspenseQuery
|
|
23
|
+
src/server/actions/ - server functions and enums
|
|
24
|
+
wcz-layout/components - EditableColumnHeader, Fullscreen
|
|
25
|
+
wcz-layout/hooks - useTranslation
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Examples
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
// src/routes/<feature>s/index.tsx
|
|
32
|
+
const { t } = useTranslation();
|
|
33
|
+
const { confirm, alert } = useDialogs();
|
|
34
|
+
const navigate = useNavigate();
|
|
35
|
+
const [cellSelectionModel, setCellSelectionModel] = useState<GridCellSelectionModel>({});
|
|
36
|
+
|
|
37
|
+
const { data, isLoading } = useLiveQuery((q) =>
|
|
38
|
+
q.from({ feature: featureCollection }).orderBy(({ feature }) => feature.name, "asc"),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const columns: Array<GridColDef<Feature>> = [
|
|
42
|
+
{
|
|
43
|
+
field: "name",
|
|
44
|
+
headerName: t("Feature.Name"),
|
|
45
|
+
width: 200,
|
|
46
|
+
editable: true,
|
|
47
|
+
renderHeader: EditableColumnHeader,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
field: "status",
|
|
51
|
+
headerName: t("Feature.Status"),
|
|
52
|
+
width: 200,
|
|
53
|
+
type: "singleSelect",
|
|
54
|
+
valueOptions: featureStatusEnum.enumValues.map((status) => ({
|
|
55
|
+
value: status,
|
|
56
|
+
label: t(`FeatureStatus.${status}`),
|
|
57
|
+
})),
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
const handleOnDelete = createOptimisticAction<Array<string>>({
|
|
62
|
+
onMutate: (ids) => {
|
|
63
|
+
ids.forEach((id) => {
|
|
64
|
+
featureCollection.delete(id);
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
mutationFn: async (ids) => {
|
|
68
|
+
deleteFeatures({ data: ids });
|
|
69
|
+
await featureCollection.utils.refetch();
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Fullscreen>
|
|
75
|
+
<DataGridPremium
|
|
76
|
+
rows={data}
|
|
77
|
+
columns={columns}
|
|
78
|
+
showToolbar
|
|
79
|
+
loading={isLoading}
|
|
80
|
+
ignoreDiacritics
|
|
81
|
+
onRowDoubleClick={({ row }) => navigate({ to: "/features/$id", params: { id: row.id } })}
|
|
82
|
+
cellSelection
|
|
83
|
+
disableRowSelectionOnClick
|
|
84
|
+
cellSelectionModel={cellSelectionModel}
|
|
85
|
+
onCellSelectionModelChange={(newModel) => setCellSelectionModel(newModel)}
|
|
86
|
+
slots={{ toolbar: DataGridToolbar }}
|
|
87
|
+
slotProps={{
|
|
88
|
+
toolbar: {
|
|
89
|
+
title: t("Feature.Features"),
|
|
90
|
+
actions: [
|
|
91
|
+
<Tooltip key="create" title={t("Create")}>
|
|
92
|
+
<RouterIconButton to="/features/create">
|
|
93
|
+
<Add fontSize="small" />
|
|
94
|
+
</RouterIconButton>
|
|
95
|
+
</Tooltip>,
|
|
96
|
+
Object.keys(cellSelectionModel).length === 1 && (
|
|
97
|
+
<Tooltip key="edit" title={t("Edit")}>
|
|
98
|
+
<RouterIconButton
|
|
99
|
+
to="/features/edit/$id"
|
|
100
|
+
params={{ id: Object.keys(cellSelectionModel)[0].toString() }}
|
|
101
|
+
>
|
|
102
|
+
<Edit fontSize="small" />
|
|
103
|
+
</RouterIconButton>
|
|
104
|
+
</Tooltip>
|
|
105
|
+
),
|
|
106
|
+
Object.keys(cellSelectionModel).length > 0 && (
|
|
107
|
+
<Tooltip key="delete" title={t("Delete")}>
|
|
108
|
+
<IconButton
|
|
109
|
+
onClick={async () => {
|
|
110
|
+
const confirmed = await confirm(
|
|
111
|
+
t("DeleteConfirmation", { count: Object.keys(cellSelectionModel).length }),
|
|
112
|
+
);
|
|
113
|
+
if (confirmed) {
|
|
114
|
+
try {
|
|
115
|
+
const transaction = handleOnDelete(
|
|
116
|
+
Object.keys(cellSelectionModel).map((id) => id.toString()),
|
|
117
|
+
);
|
|
118
|
+
await transaction.isPersisted.promise;
|
|
119
|
+
setCellSelectionModel({});
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error instanceof Error) await alert(error.message);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
<Badge
|
|
127
|
+
badgeContent={Object.keys(cellSelectionModel).length}
|
|
128
|
+
invisible={Object.keys(cellSelectionModel).length <= 1}
|
|
129
|
+
color="error"
|
|
130
|
+
>
|
|
131
|
+
<Delete fontSize="small" />
|
|
132
|
+
</Badge>
|
|
133
|
+
</IconButton>
|
|
134
|
+
</Tooltip>
|
|
135
|
+
),
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
</Fullscreen>
|
|
141
|
+
);
|
|
142
|
+
```
|