feat(crew): add staffing calculator#529
Conversation
WalkthroughA new staffing calculator module ( ChangesCrew Staffing Calculator
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
zacjones93
left a comment
There was a problem hiding this comment.
sign-off: no remaining actionable blockers
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/crew/src/lib/crew-staffing-calculator.ts (1)
1-204:⚠️ Potential issue | 🟠 Major | ⚡ Quick winAdd required
@latconcept references in this TypeScript module.This file currently has no
//@lat: [[section-id]]annotations, which breaks the repo’s source-to-concept traceability rule.As per coding guidelines,
**/*.{js,ts,rs,go,c,h,py}must tie source code to concepts using//@lat: [[section-id]].🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/crew/src/lib/crew-staffing-calculator.ts` around lines 1 - 204, The crew-staffing-calculator.ts file is missing required `// `@lat`: [[section-id]]` concept reference annotations needed for source-to-concept traceability. Add `// `@lat`: [[section-id]]` comments above logical groupings of related code to tie each section to its corresponding concept identifier. Place these annotations before the type definitions block (StaffingRoleGroup, StaffingRoleBasis, StaffingRoleAssumption, etc.), before the constant definitions (defaultStaffingRoleAssumptions, defaultStaffingCalculatorInputs), before the main calculation function estimateCrewStaffing, before the formatting function formatStaffingDuration, and before the helper functions (normalizeStaffingCalculatorInputs, getRoleBasisUnits, sumRoleValue, clampWholeNumber, clampDecimal) using appropriate section identifiers that match your project's concept documentation.Source: Coding guidelines
🧹 Nitpick comments (1)
apps/crew/src/routes/calculator.tsx (1)
20-49: Migrate form state to React Hook Form + Zod for consistency with project standard.This calculator currently uses manual state management and validation. Align with the established pattern across the crew app by adopting React Hook Form with Zod schemas to reduce custom parsing logic and improve maintainability.
Applies to lines 20-49 (input state), 76-122 (number field handlers), and 244-285 (role updates).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/crew/src/routes/calculator.tsx` around lines 20 - 49, Replace the manual useState-based state management for the StaffingCalculatorInputs with React Hook Form's useForm hook and Zod schema validation. Create a Zod schema for StaffingCalculatorInputs that defines validation rules for all numeric fields (lanes, floors, heats, heatDurationMinutes, shiftLengthHours) and the roleAssumptions array. Update the updateNumberField and updateRole functions to use the form's field register and setValue methods instead of direct setInputs calls, and leverage Zod's validation instead of inline Number.isFinite checks. This aligns the component with the established React Hook Form + Zod pattern used elsewhere in the crew app.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/crew/test/lib/crew-staffing-calculator.test.ts`:
- Around line 45-105: The test file is missing required `@lat` reference
comments for test specifications. Add exactly one `// `@lat`: [[section-id]]`
comment adjacent to each of the five `it(...)` test blocks: the tests for
"scales lane judge assumptions by floors and lanes", "converts heat time into
shift slots for coverage", "keeps judge and volunteer estimates separated",
"normalizes invalid minimums without producing zero coverage", and "formats full
hours and mixed durations". Ensure each `@lat` comment is placed immediately
next to its corresponding `it()` declaration and that no section IDs are
duplicated across the different tests.
---
Outside diff comments:
In `@apps/crew/src/lib/crew-staffing-calculator.ts`:
- Around line 1-204: The crew-staffing-calculator.ts file is missing required
`// `@lat`: [[section-id]]` concept reference annotations needed for
source-to-concept traceability. Add `// `@lat`: [[section-id]]` comments above
logical groupings of related code to tie each section to its corresponding
concept identifier. Place these annotations before the type definitions block
(StaffingRoleGroup, StaffingRoleBasis, StaffingRoleAssumption, etc.), before the
constant definitions (defaultStaffingRoleAssumptions,
defaultStaffingCalculatorInputs), before the main calculation function
estimateCrewStaffing, before the formatting function formatStaffingDuration, and
before the helper functions (normalizeStaffingCalculatorInputs,
getRoleBasisUnits, sumRoleValue, clampWholeNumber, clampDecimal) using
appropriate section identifiers that match your project's concept documentation.
---
Nitpick comments:
In `@apps/crew/src/routes/calculator.tsx`:
- Around line 20-49: Replace the manual useState-based state management for the
StaffingCalculatorInputs with React Hook Form's useForm hook and Zod schema
validation. Create a Zod schema for StaffingCalculatorInputs that defines
validation rules for all numeric fields (lanes, floors, heats,
heatDurationMinutes, shiftLengthHours) and the roleAssumptions array. Update the
updateNumberField and updateRole functions to use the form's field register and
setValue methods instead of direct setInputs calls, and leverage Zod's
validation instead of inline Number.isFinite checks. This aligns the component
with the established React Hook Form + Zod pattern used elsewhere in the crew
app.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 507e309d-0725-4d0b-84d8-b27cefaa89ad
📒 Files selected for processing (6)
apps/crew/src/lib/crew-staffing-calculator.tsapps/crew/src/routeTree.gen.tsapps/crew/src/routes/__root.tsxapps/crew/src/routes/calculator.tsxapps/crew/src/routes/index.tsxapps/crew/test/lib/crew-staffing-calculator.test.ts
There was a problem hiding this comment.
2 issues found across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
zacjones93
left a comment
There was a problem hiding this comment.
sign-off: no remaining actionable blockers
Summary
/calculatorroute for estimating judges, volunteers, concurrent staffing, and shift slots.Validation
pnpm check:schema-ownershippassed.pnpm --filter crew type-checkpassed.pnpm --filter crew buildpassed after creating ignored validation-onlyapps/crew/.alchemy/local/wrangler.jsoncfrom the checked-in Crew wrangler config. No Alchemy/deploy command was run.pnpm --filter crew lintexited 0; it still reports existing repo warnings outside this slice.pnpm --filter crew exec vitest run test/lib/crew-staffing-calculator.test.tspassed: 5 tests.git diff --checkpassed.Notes
pnpm --filter crew testwas attempted and failed on pre-existing/unrelated suites: missing legacy imports underroutes/compete/...androutes/api/webhooks/stripe, plus existing invite permission timeout/assertion failures. The new calculator test passed during that full run.pnpm installcompleted, with the known optionalbetter-sqlite3native rebuild failure from Python 3.7 on this machine.Summary by cubic
Adds a public Crew staffing calculator at
/calculatorto estimate judges, volunteers, concurrent staffing, and shift slots from simple event inputs. Adds nav/home links, a helper library with defaults and normalization, and tests./calculatorroute with inputs for lanes, floors, heats, heat duration, and shift length; shows per‑role concurrent coverage and shift slots.estimateCrewStaffing,formatStaffingDuration,normalizeStaffingCalculatorInputs, and default role assumptions; supportsevent,floor,lane, andlanePerFloor; returns per‑role and group totals; covered byvitesttests for scaling, coverage, normalization, and formatting.@tanstack/react-router.lat.md/crew.md.Written for commit 99ec4b0. Summary will update on new commits.
Summary by CodeRabbit