Skip to content

Refactor project management in adminJs: add and remove QF Round actions#2328

Merged
RamRamez merged 2 commits into
stagingfrom
add-and-remove-QF-Round-actions
Jun 3, 2026
Merged

Refactor project management in adminJs: add and remove QF Round actions#2328
RamRamez merged 2 commits into
stagingfrom
add-and-remove-QF-Round-actions

Conversation

@RamRamez
Copy link
Copy Markdown
Member

@RamRamez RamRamez commented Jun 3, 2026

Summary by CodeRabbit

  • Bug Fixes

    • More robust QF round project list parsing, sync and validation to prevent invalid IDs.
    • Improved cache handling and view refreshes after QF round edits, with safer error handling.
  • Refactor

    • QF project assignment UI/actions removed from the Projects tab and consolidated into the QF Round administration workflow.
    • Edit flow now pre-fills related projects and avoids persisting the virtual project-list field.

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.
@RamRamez RamRamez requested review from ae2079 and kkatusic June 3, 2026 21:39
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 27b0da9b-b83c-4bec-b73f-4a2ac68dcf1d

📥 Commits

Reviewing files that changed from the base of the PR and between a2df2c9 and 80fb896.

📒 Files selected for processing (1)
  • src/server/adminJs/tabs/qfRoundTab.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/server/adminJs/tabs/qfRoundTab.ts

Walkthrough

This 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.

Changes

QF-round project management consolidation

Layer / File(s) Summary
Remove QF-round handlers from Projects tab
src/server/adminJs/tabs/projectsTab.ts
Removes exported action handlers addProjectsToQfRound and addSingleProjectToQfRound, along with their action entries. Includes import reordering and relocation of the extractCategoryIds helper with no implementation changes.
Implement consolidated QF-round project management
src/server/adminJs/tabs/qfRoundTab.ts
validateQfRound parses projectIdsList with robust trim/NaN filtering and syncs relations via database-based diffing of existing vs submitted project IDs. The edit handler GET path pre-fills the textarea from current related projects, payload processing skips the virtual field, and post-update code clears the active-round cache and refreshes materialized views. refreshMaterializedViews now derives and sets projectIdsList from fetched related projects.

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A project shuffle, swift and clean,
From panels many to one serene!
The Projects tab says its last goodbye,
As QF Rounds take the lead on high—
Diffing, syncing, views refresh with glee! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title mentions 'add and remove QF Round actions' but the summary shows these actions were removed from projectsTab.ts, not added or refactored in a bidirectional way. Clarify the title to accurately reflect that QF Round actions are being removed from the Projects tab and refactored in the QF Round tab, or confirm the intended meaning of 'add and remove'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-and-remove-QF-Round-actions

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f0aa023 and a2df2c9.

📒 Files selected for processing (2)
  • src/server/adminJs/tabs/projectsTab.ts
  • src/server/adminJs/tabs/qfRoundTab.ts
💤 Files with no reviewable changes (1)
  • src/server/adminJs/tabs/projectsTab.ts

Comment thread src/server/adminJs/tabs/qfRoundTab.ts
Comment thread src/server/adminJs/tabs/qfRoundTab.ts
Comment thread src/server/adminJs/tabs/qfRoundTab.ts
Copy link
Copy Markdown
Collaborator

@kkatusic kkatusic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @RamRamez

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.
@RamRamez RamRamez merged commit 78dbf17 into staging Jun 3, 2026
13 checks passed
@RamRamez RamRamez deleted the add-and-remove-QF-Round-actions branch June 3, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants