Skip to content

fix: adjust normalize managed pages function, add dependency#907

Open
tomrndom wants to merge 1 commit intomasterfrom
fix/sponsor-pages-action-fixes
Open

fix: adjust normalize managed pages function, add dependency#907
tomrndom wants to merge 1 commit intomasterfrom
fix/sponsor-pages-action-fixes

Conversation

@tomrndom
Copy link
Copy Markdown

@tomrndom tomrndom commented Apr 29, 2026

ref:

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

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced timezone support to improve date/time accuracy across the platform.
    • Resolved an issue with add-on availability on sponsor-managed pages to ensure correct add-on options are presented to users.

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

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

The sponsor-pages-actions.js module adds timezone-aware date/time support via moment-timezone import and extends sponsor-managed page normalization to include an allowed_add_ons field derived from entity.add_ons, enabling downstream logic to validate add-ons correctly.

Changes

Cohort / File(s) Summary
Timezone and Add-Ons Normalization Update
src/actions/sponsor-pages-actions.js
Added moment-timezone import for timezone handling. Updated sponsor page normalization to include allowed_add_ons field derived from entity.add_ons in payload construction for downstream add-on validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • smarcet

Poem

🐰 A tiny import hops in place,
Timezones dance across the space,
Add-ons sprouting left and right,
Sponsor pages now shine bright! ✨

🚥 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 directly addresses the main changes: adjusting the normalize managed pages function and adding a dependency (moment-timezone).
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.

✏️ 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 fix/sponsor-pages-action-fixes

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

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

Copy link
Copy Markdown

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/actions/sponsor-pages-actions.js (1)

285-294: ⚠️ Potential issue | 🟠 Major

Use the normalizeSelectAllField helper consistently in the create flow to avoid crashes and improve maintainability.

At lines 286–294, the function manually implements add-ons normalization without null checks or the shared helper. This differs from the update flow (normalizeSponsorManagedPageToCustomize at line 300), which correctly uses normalizeSelectAllField. If entity.add_ons is missing or falsy, .includes() at line 289 and .map() at line 293 will throw.

Refactor to use the helper function with a safe fallback:

const normalizeSponsorManagedPage = (entity) => {
+  const addOns = entity.add_ons ?? entity.allowed_add_ons ?? [];
   const normalizedEntity = {
     show_page_ids: entity.pages,
-    allowed_add_ons: entity.add_ons
+    ...normalizeSelectAllField(
+      addOns,
+      "apply_to_all_add_ons",
+      "allowed_add_ons"
+    )
   };
-
-  if (normalizedEntity.allowed_add_ons.includes("all")) {
-    normalizedEntity.apply_to_all_add_ons = true;
-    normalizedEntity.allowed_add_ons = [];
-  } else {
-    normalizedEntity.allowed_add_ons = entity.add_ons.map((a) => a.id);
-    normalizedEntity.apply_to_all_add_ons = false;
-  }
 
   return normalizedEntity;
 };

This aligns with the pattern used in the update flow and similar functions like normalizeSponsorManagedForm, eliminating code duplication and defensive logic gaps.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/actions/sponsor-pages-actions.js` around lines 285 - 294, The create-flow
block that manually handles add-ons (using normalizedEntity and entity.add_ons)
should be replaced with the shared normalizeSelectAllField helper to avoid
null/undefined crashes and duplicate logic; instead of calling
.includes()/.map() on entity.add_ons directly, pass (entity.add_ons || []) into
normalizeSelectAllField (so normalizeSponsorManagedPageToCustomize and
normalizeSponsorManagedForm patterns are matched) and use its returned values to
set normalizedEntity.allowed_add_ons and normalizedEntity.apply_to_all_add_ons.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/actions/sponsor-pages-actions.js`:
- Around line 285-294: The create-flow block that manually handles add-ons
(using normalizedEntity and entity.add_ons) should be replaced with the shared
normalizeSelectAllField helper to avoid null/undefined crashes and duplicate
logic; instead of calling .includes()/.map() on entity.add_ons directly, pass
(entity.add_ons || []) into normalizeSelectAllField (so
normalizeSponsorManagedPageToCustomize and normalizeSponsorManagedForm patterns
are matched) and use its returned values to set normalizedEntity.allowed_add_ons
and normalizedEntity.apply_to_all_add_ons.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e8abb547-e8de-4cc3-939e-c75623a5a46e

📥 Commits

Reviewing files that changed from the base of the PR and between d3edaee and 152752a.

📒 Files selected for processing (1)
  • src/actions/sponsor-pages-actions.js

@tomrndom tomrndom requested a review from smarcet May 7, 2026 15:01
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