Skip to content

fix: add delete on sponsor form managed table - #1035

Open
tomrndom wants to merge 3 commits into
masterfrom
fix/sponsor-managed-form-delete
Open

fix: add delete on sponsor form managed table#1035
tomrndom wants to merge 3 commits into
masterfrom
fix/sponsor-managed-form-delete

Conversation

@tomrndom

@tomrndom tomrndom commented Aug 5, 2026

Copy link
Copy Markdown
  • new actions, constants and tests

ref: https://app.clickup.com/t/9014802374/86bb8wb20

Summary by CodeRabbit

  • New Features

    • Added the ability to delete explicitly assigned managed sponsor forms.
    • Customized and managed form lists now refresh automatically after deletion.
    • Managed form assignment details are retained for accurate display and actions.
    • Successful deletions now display a confirmation notification.
  • Bug Fixes

    • Managed form counts and lists update correctly after deletion.
    • Deletion is hidden for forms that are not explicitly assigned.
    • Cancelled or failed deletions leave forms and list counts unchanged.
  • Tests

    • Added coverage for deletion, cancellation, visibility, failure handling, and list refresh behavior.

… and tests

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The sponsor forms flow now tracks managed-form assignment types. Explicitly assigned managed forms can be deleted through the API. Redux removes deleted forms, and the tab refreshes both form lists after successful deletion.

Sponsor-managed form deletion

Layer / File(s) Summary
Assignment contract and managed-form state
src/utils/constants.js, src/actions/sponsor-forms-actions.js, src/reducers/sponsors/sponsor-page-forms-list-reducer.js
Managed-form requests include assignment_type. Shared constants define explicit and implicit assignments. Reducer state preserves assignment data and handles the deletion action.
Managed-form deletion flow
src/actions/sponsor-forms-actions.js, src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/index.js, src/reducers/sponsors/sponsor-page-forms-list-reducer.js
The thunk sends the DELETE request, dispatches the deletion action, shows a success notification, and stops loading. The tab allows deletion only for explicit assignments and refreshes both lists.
Deletion behavior validation
src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/__tests__/sponsor-forms-tab.test.js
Tests cover deletion visibility, confirmation, successful and failed requests, list refreshes, cancellation, and customized-form deletion.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SponsorFormsTab
  participant deleteSponsorManagedForm
  participant SponsorFormsAPI
  participant ReduxReducer
  SponsorFormsTab->>deleteSponsorManagedForm: Confirm managed-form deletion
  deleteSponsorManagedForm->>SponsorFormsAPI: Send DELETE request
  SponsorFormsAPI-->>deleteSponsorManagedForm: Return deletion result
  deleteSponsorManagedForm->>ReduxReducer: Dispatch SPONSOR_MANAGED_FORM_DELETED
  SponsorFormsTab->>SponsorFormsAPI: Refresh managed and customized lists
Loading

Possibly related PRs

Suggested reviewers: smarcet

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding delete functionality to the sponsor managed forms table.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 fix/sponsor-managed-form-delete

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

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/__tests__/sponsor-forms-tab.test.js (3)

235-239: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Select form 2 by row, not by icon index.

getAllByTestId("DeleteIcon")[1] assumes the table order and action count. If either changes, the test can click a different row while still appearing to validate form 2. Query the row containing "Managed Form 2" and then find its delete button.

Proposed test selection
-      const deleteButtons = screen.getAllByTestId("DeleteIcon");
-      const secondDeleteButton = deleteButtons[1].closest("button");
+      const targetRow = screen.getByText("Managed Form 2").closest("tr");
+      const deleteButton = within(targetRow).getByTestId("DeleteIcon").closest("button");

       await act(async () => {
-        await userEvent.click(secondDeleteButton);
+        await userEvent.click(deleteButton);
       });

Based on learnings, MuiTable.onDelete passes the primitive row identifier, so keep the existing ID assertion while making the target-row lookup explicit.

🤖 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
`@src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/__tests__/sponsor-forms-tab.test.js`
around lines 235 - 239, Update the test around the delete-button interaction to
locate the table row containing “Managed Form 2,” then query that row’s delete
button instead of selecting the second DeleteIcon globally. Keep the existing
click flow and primitive row-ID assertion unchanged.

Source: Learnings


313-315: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Await the rejected request instead of using a fixed delay.

The 50 ms timeout is not tied to the request lifecycle. Store the rejected promise and await it before asserting the unchanged state. This removes arbitrary timing from the test.

Proposed deterministic wait
+      let requestPromise;
       deleteRequest.mockImplementation(
-        () => () => () => Promise.reject(new Error("delete failed"))
+        () => () => () => {
+          requestPromise = Promise.reject(new Error("delete failed"));
+          return requestPromise;
+        }
       );
...
-      await act(async () => {
-        await new Promise((resolve) => {
-          setTimeout(resolve, 50);
-        });
-      });
+      await waitFor(() => expect(requestPromise).toBeDefined());
+      await act(async () => {
+        await expect(requestPromise).rejects.toThrow("delete failed");
+      });

Also applies to: 342-350

🤖 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
`@src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/__tests__/sponsor-forms-tab.test.js`
around lines 313 - 315, Update the test’s delete-request setup and assertions
around deleteRequest.mockImplementation so the rejected request promise is
stored and explicitly awaited before checking the unchanged state. Apply the
same deterministic waiting pattern to the additional occurrence, and remove the
fixed 50 ms delay.

301-309: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Check both list refresh actions after cancellation.

The cancellation test checks only getSponsorManagedForms. Add the customized-list assertion so an accidental refresh of getSponsorCustomizedForms also fails the test.

Proposed assertion
       expect(deleteRequest).not.toHaveBeenCalled();
       expect(getSponsorManagedForms).toHaveBeenCalledTimes(1); // mount only
+      expect(getSponsorCustomizedForms).toHaveBeenCalledTimes(1); // mount only
       expect(screen.getByText("Managed Form 1")).toBeInTheDocument();
🤖 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
`@src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/__tests__/sponsor-forms-tab.test.js`
around lines 301 - 309, Add an assertion in the cancellation test after the
cancel action verifying getSponsorCustomizedForms was called only once for the
initial mount, alongside the existing getSponsorManagedForms assertion. Keep the
existing no-delete and rendered-form checks unchanged.
🤖 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.

Nitpick comments:
In
`@src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/__tests__/sponsor-forms-tab.test.js`:
- Around line 235-239: Update the test around the delete-button interaction to
locate the table row containing “Managed Form 2,” then query that row’s delete
button instead of selecting the second DeleteIcon globally. Keep the existing
click flow and primitive row-ID assertion unchanged.
- Around line 313-315: Update the test’s delete-request setup and assertions
around deleteRequest.mockImplementation so the rejected request promise is
stored and explicitly awaited before checking the unchanged state. Apply the
same deterministic waiting pattern to the additional occurrence, and remove the
fixed 50 ms delay.
- Around line 301-309: Add an assertion in the cancellation test after the
cancel action verifying getSponsorCustomizedForms was called only once for the
initial mount, alongside the existing getSponsorManagedForms assertion. Keep the
existing no-delete and rendered-form checks unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 285c21ee-5996-4420-be53-b128da7676ff

📥 Commits

Reviewing files that changed from the base of the PR and between f1382fa and 751dad7.

📒 Files selected for processing (1)
  • src/pages/sponsors/sponsor-page/tabs/sponsor-forms-tab/__tests__/sponsor-forms-tab.test.js

@tomrndom
tomrndom requested a review from smarcet August 5, 2026 22:00
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.

1 participant