Refactor project management in adminJs: add and remove QF Round actions#2328
Conversation
Eliminated the `addProjectsToQfRound` and `addSingleProjectToQfRound` functions from the projects tab, along with their associated action handlers. Updated the `qfRoundTab` to streamline project relation management by directly syncing project IDs during QF Round edits. Enhanced the validation logic to handle project relations more effectively, ensuring proper updates to the active QF Round's project associations.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR consolidates QF-round project association management by removing dedicated handlers from the Projects tab and implementing integrated project list editing within the QF Round tab. Validation now uses database-based diffing to sync project relations, with pre-fill logic for existing projects and post-update materialized view refresh. ChangesQF-round project management consolidation
Sequence DiagramsequenceDiagram
participant Editor as Editor<br/>(Admin UI)
participant Handler as edit handler
participant DB as Database
participant Views as Materialized<br/>Views
Editor->>Handler: GET edit form for QF Round
Handler->>DB: Fetch related projects
DB-->>Handler: Current project IDs
Handler-->>Editor: Pre-fill projectIdsList textarea
Editor->>Handler: Submit form with projectIdsList
Handler->>Handler: Parse & trim projectIdsList
Handler->>DB: Fetch existing related project IDs
DB-->>Handler: Existing IDs
Handler->>Handler: Diff submitted vs existing
Handler->>DB: Add/remove project relations
Handler->>DB: Update QF Round record
Handler->>Views: Clear active-round cache
Handler->>Views: Refresh estimated/actual matching views
Views-->>Handler: Done
Handler-->>Editor: Success
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@src/server/adminJs/tabs/qfRoundTab.ts`:
- Around line 232-260: The relation sync in validateQfRound (using
getRelatedProjectsOfQfRound and relateManyProjectsToQfRound) can succeed while
the later QfRound.update fails, leaving state inconsistent; wrap the project
relation diffing/relating and the later QfRound.update into a single DB
transaction: start a transaction, pass the transaction object into
getRelatedProjectsOfQfRound/relateManyProjectsToQfRound (and any other DB calls
in validateQfRound), perform added/removed relateManyProjectsToQfRound calls
within the transaction, then perform the QfRound.update inside the same
transaction, committing on success and rolling back on error; if helper
functions do not accept a transaction param, add an optional tx argument to
those functions and thread it through so all DB operations participate in the
same transaction.
- Around line 212-217: currentProjectIds parsing turns empty tokens into 0
because Number("") === 0; change the parsing to first split and trim tokens,
filter out empty tokens (token.trim() !== ''), then map to Number and filter out
NaN and zero values so admins submitting an empty/whitespace/comma-only
payload.projectIdsList won't produce a project ID 0. Update the logic that
builds currentProjectIds (referenced where payload.projectIdsList is used) and
keep relateManyProjectsToQfRound behaviour unchanged.
- Around line 619-626: Validate the qfRoundId extracted in the prefill GET
branch before calling getRelatedProjectsOfQfRound: when request.method === 'get'
compute qfRoundId from Number(request.params?.recordId), check
Number.isInteger(qfRoundId) (or that it's a finite positive integer) and return
the record immediately (record.toJSON(currentAdmin)) if invalid; only call
getRelatedProjectsOfQfRound(qfRoundId) when the id passes validation to avoid
passing NaN into the SQL interpolation inside getRelatedProjectsOfQfRound.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 94525282-439a-4f7c-958e-7cc568b3d02e
📒 Files selected for processing (2)
src/server/adminJs/tabs/projectsTab.tssrc/server/adminJs/tabs/qfRoundTab.ts
💤 Files with no reviewable changes (1)
- src/server/adminJs/tabs/projectsTab.ts
Updated the `validateQfRound` function to improve project ID handling by trimming whitespace and filtering out invalid IDs, ensuring only positive integers are processed. Added error handling for invalid `qfRoundId` in the GET request to prevent SQL injection risks. This change strengthens data integrity and security during QF Round edits.
Summary by CodeRabbit
Bug Fixes
Refactor