@thepalaceproject/circulation-admin 1.40.0 → 1.41.0-post.6
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/CLAUDE.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
Admin interface for The Palace Project Circulation Manager. A React/Redux single-page application built with TypeScript that manages library circulation systems—collections, lanes, custom lists, patron management, and book metadata. Published to npm as `@thepalaceproject/circulation-admin` and consumed by the Circulation Manager backend (Python).
|
|
8
|
+
|
|
9
|
+
Built on `@thepalaceproject/web-opds-client` which provides the base OPDS catalog React component.
|
|
10
|
+
|
|
11
|
+
## Build & Development Commands
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm run dev # Watch build (for use with local Circulation Manager)
|
|
15
|
+
npm run dev-server -- --env=backend=https://your-cm-url # Dev server against remote backend
|
|
16
|
+
npm run prod # Production build
|
|
17
|
+
npm run lint # Run tslint + sass-lint
|
|
18
|
+
npm test # Full test suite (mocha legacy + jest)
|
|
19
|
+
npm run test-jest # Jest tests only
|
|
20
|
+
npm run test-jest-file <path> # Single jest test: npm run test-jest-file tests/jest/components/MyTest.test.tsx
|
|
21
|
+
npm run test-file-ts <path> # Single mocha test: npm run test-file-ts src/components/__tests__/MyTest-test.tsx
|
|
22
|
+
npm run dev-test-axe # Dev build with react-axe accessibility checking (output in browser console)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The dev server can also read the backend URL from `.env` or `.env.local` with `BACKEND=https://...`.
|
|
26
|
+
|
|
27
|
+
## Architecture
|
|
28
|
+
|
|
29
|
+
### State Management (Dual System)
|
|
30
|
+
|
|
31
|
+
**Legacy Redux (majority of app):** `src/reducers/` contains ~30+ reducers combined in `src/reducers/index.ts`. Most follow the `createFetchEditReducer` factory pattern (`src/reducers/createFetchEditReducer.ts`) which generates standard CRUD state: `isFetching`, `isEditing`, `fetchError`, `formError`, `isLoaded` with `REQUEST/SUCCESS/FAILURE/LOAD/CLEAR` action types. Action creators are in `src/actions.ts`, extending `ActionCreator` from web-opds-client.
|
|
32
|
+
|
|
33
|
+
**Modern RTK (newer code):** `src/features/` uses Redux Toolkit slices and RTK Query. The API base is `src/features/api/apiSlice.ts`. The store (`src/store.ts`) combines both systems:
|
|
34
|
+
|
|
35
|
+
- `editor` — legacy reducers
|
|
36
|
+
- `catalog` — web-opds-client reducers
|
|
37
|
+
- `bookEditor` — RTK slice
|
|
38
|
+
- `api` — RTK Query
|
|
39
|
+
|
|
40
|
+
**React Query:** `@tanstack/react-query` is also used for server state in some newer components.
|
|
41
|
+
|
|
42
|
+
### App Context
|
|
43
|
+
|
|
44
|
+
`src/context/appContext.ts` provides configuration via React Context. Key hooks: `useAppContext()`, `useCsrfToken()`, `useAppAdmin()`, `useAppFeatureFlags()`. The context carries CSRF tokens, admin user info, feature flags, and support contact configuration.
|
|
45
|
+
|
|
46
|
+
### Component Patterns
|
|
47
|
+
|
|
48
|
+
- Mix of class components (legacy) and functional components (newer)
|
|
49
|
+
- React Router v3 (`react-router@^3.2.0`) — uses older API style
|
|
50
|
+
- React 16.8 — hooks are available but many components predate hooks
|
|
51
|
+
- Bootstrap 3 via react-bootstrap for UI primitives
|
|
52
|
+
- SCSS stylesheets in `src/stylesheets/`
|
|
53
|
+
|
|
54
|
+
### Key Entry Points
|
|
55
|
+
|
|
56
|
+
- `src/index.tsx` — Main entry, `CirculationAdmin` class that sets up all providers (Redux, Router, Context, QueryClient)
|
|
57
|
+
- `src/store.ts` — Redux store configuration
|
|
58
|
+
- `src/actions.ts` — All legacy action creators
|
|
59
|
+
- `src/interfaces.ts` — Core TypeScript types
|
|
60
|
+
- `src/reducers/index.ts` — Root reducer
|
|
61
|
+
|
|
62
|
+
## Testing
|
|
63
|
+
|
|
64
|
+
**Two test systems coexist:**
|
|
65
|
+
|
|
66
|
+
1. **Jest** (for all new tests): Tests in `tests/jest/` mirroring `src/` structure. Uses React Testing Library, jest-dom, and MSW for API mocking. Test utilities in `tests/jest/testUtils/withProviders.tsx` provide `renderWithProviders()` and `componentWithProviders()` to wrap components with Redux, Context, and QueryClient.
|
|
67
|
+
|
|
68
|
+
2. **Mocha** (legacy): Tests in `src/*/__tests__/` directories. Uses Enzyme with React 16 adapter. Do not add new mocha tests.
|
|
69
|
+
|
|
70
|
+
## Code Style
|
|
71
|
+
|
|
72
|
+
- Prettier: double quotes, semicolons, trailing commas (es5), 80 char width
|
|
73
|
+
- ESLint with `jsx-a11y/strict` — accessibility rules are enforced via the husky pre-commit hook (not `npm run lint`, which runs tslint + sass-lint)
|
|
74
|
+
- `@typescript-eslint/no-explicit-any` is disabled (any is allowed)
|
|
75
|
+
- Prefer template literals over string concatenation for building strings with variables
|
|
76
|
+
- When an arrow function only passes its arguments through to another function with the same signature, pass the function directly instead of wrapping it (e.g., `onClick: this.handleClick` not `onClick: (e) => this.handleClick(e)`)
|
|
77
|
+
- Husky pre-commit hooks run eslint and prettier on staged files
|
|
78
|
+
|
|
79
|
+
## Output
|
|
80
|
+
|
|
81
|
+
Webpack builds to `dist/circulation-admin.js` (UMD library, global `CirculationAdmin`) and `dist/circulation-admin.css`. Node.js 20+ required.
|
|
82
|
+
|
|
83
|
+
## Code Conventions
|
|
84
|
+
|
|
85
|
+
- **Component names should reflect DOM role.** If a component renders an `<li>`, name it `FooListItem`, not `Foo`. The name should hint at what it produces in the DOM.
|
|
86
|
+
- **Put the component definition at the top of the file** (after imports and interfaces). Helper functions (`renderDetails`, `renderValue`, etc.) go below. This makes the component's shape immediately visible when opening the file.
|
|
87
|
+
- **Extract closure helpers into standalone functions** that take explicit parameters rather than closing over component variables. This makes data flow clear and keeps the component body concise.
|
|
88
|
+
- **Handle empty states with user-facing feedback.** When a list/collection can legitimately be empty in production (e.g., a library with no auth integrations), show a helpful alert or message rather than rendering a blank or empty form.
|
|
89
|
+
- **Keep type guards consistent with actual types.** Don't check for `undefined` when the type union doesn't include it — only guard against values the type actually allows.
|
|
90
|
+
|
|
91
|
+
## Pull Requests
|
|
92
|
+
|
|
93
|
+
When creating a PR, use the repository's PR template at `.github/pull_request_template.md`. Fill in all sections: Description, Motivation and Context, How Has This Been Tested, and the Checklist.
|