mirror of
https://github.com/zuiidea/antd-admin.git
synced 2026-10-19 16:14:37 +00:00
- Add second sample resource (orders): API, schemas, MSW, routes, menu, Lingui, and E2E. - Introduce useCrudToasts, useUrlSearchState, useTableFitHeight; extend useResourceCRUD with optimistic updates; add Vitest coverage for hooks and createHandler. - Implement token refresh in http layer, RouteError, and new E2E specs (auth-refresh, rbac, url-state). - Replace gen-resource codegen with English add-resource.instructions.md; fix Copilot instruction YAML in with-lingui and basic. - Add with-lingui CI workflow, Cursor thin rules, optimization plan doc, and refresh README/AGENTS. - Bump packages/create and lockfile where applicable. Made-with: Cursor
3.7 KiB
3.7 KiB
applyTo, description
| applyTo | description |
|---|---|
| src/api/**/*.ts,src/mocks/**/*.ts,src/routes/_auth/**/*.tsx,e2e/**/*.spec.ts | Use when adding a new CRUD resource (orders, roles, tenants, etc.). Keywords: add resource, new resource, scaffold, CRUD page. |
Add Resource Recipe
Add a list CRUD flow in apps/with-lingui that mirrors Users (TanStack Router + Query + MSW + Lingui). There is no codegen script: copy and adapt by hand using the steps below, or have an Agent follow this checklist. Primary references: src/routes/_auth/users/, the sample src/routes/_auth/orders/, and the matching e2e/*.spec.ts files.
0. Verification commands (after your changes)
cd apps/with-lingui
pnpm run build # refresh TanStack routeTree when routes change
pnpm exec vp check --no-fmt
pnpm run test:e2e -- e2e/<slug>.spec.ts
1. Zod and types (src/api/schemas.ts)
- Define
<Entity>Schema,Create<Entity>RequestSchema,Update<Entity>RequestSchema(Update=Create.partial()). - Reuse
PaginatedResponseSchema(<Entity>Schema)for list responses. - Export
type <Entity> = z.infer<typeof ...>.
2. Endpoint constants (src/api/<slug>.ts)
- Export
<SLUG_UPPER>_ENDPOINTS:list/create/update(id)/delete(id)with paths like/api/<slug>.
3. Mock data (src/mocks/data.ts)
- Append a
MOCK_<ENTITIES>array. For admin users,permissionsmust include<slug>:view(and create/edit/delete if you add writes), aligned withGET /api/auth/permissions.
4. MSW (src/mocks/handlers/<slug>.ts + handlers/index.ts)
- Follow
handlers/user.ts/handlers/orders.ts: paginatedGET+ optionalkeyword,POST/PUT/DELETE; usesuccessWithSchema/paginatedWithSchema/successWithNullBodyfor success anderrorResponsefor errors. - Register
...<slug>Handlersinhandlers/index.ts.
5. Route page (src/routes/_auth/<slug>/)
createFileRoute("/_auth/<slug>/"), wiringuseResourceCRUD(recommended:optimistic: { update: true, delete: true }),useCrudToasts,useUrlSearchState,useTableFitHeight(seeusers/for splitting-Toolbar/-FormModal).- Lingui: run
pnpm run i18n:extract && pnpm run i18n:compilefor new copy (orvp exec lingui …).
6. Menu and permissions (src/utils/appMenu.ts)
- Add a menu entry to
APP_MENU_TREE:path: "/<slug>",permissions: ["<slug>:view"],iconusing a Sidebar-registered key such asIconLucidePackage(see existingIconLucide*entries inSidebar). - Keep behavior consistent with
canAccessPath/ 403.
6b. Sidebar labels and icons (src/components/Layout/Sidebar/index.tsx)
- In
MENU_LABELS, add a Linguimsgentry for the menu itemname(must match thenamestring fromappMenu). - In
MENU_ICON_MAP, map the newiconkey to alucide-reacticon and add the matchingimport. - Then run
pnpm run i18n:extract && pnpm run i18n:compileand fill inzh(and other locale) translations.
In this template repo, the
orderssample is already aligned with the Sidebar next toappMenu. When adding a resource from scratch, double-check this section.
7. E2E (e2e/<slug>.spec.ts)
- Copy structure from
users.spec.ts/orders.spec.ts:loginAsAdmin→goto /<slug>, assert headers / search placeholder, etc.
8. Verification
pnpm exec vp check --no-fmtpnpm run test:e2e:core(if you add the new spec to core) orpnpm exec playwright test e2e/<slug>.spec.tspnpm run buildand watch chunk sizes in the log
Notes
- Before adding or renaming files, confirm nothing already exists at that path so you do not overwrite hand-written code.
- After manual schema edits, treat the diff as source of truth; there is no automatic merge.