Skip to content

fix: use denormalize function for modules for sponsor managed pages#940

Merged
smarcet merged 3 commits into
masterfrom
fix/sponsor-managed-pages-modules-denormalize
Jun 9, 2026
Merged

fix: use denormalize function for modules for sponsor managed pages#940
smarcet merged 3 commits into
masterfrom
fix/sponsor-managed-pages-modules-denormalize

Conversation

@tomrndom

@tomrndom tomrndom commented May 15, 2026

Copy link
Copy Markdown

ref: https://app.clickup.com/t/86b9x7fbm

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

Summary by CodeRabbit

  • Refactor

    • Centralized page-module normalization/denormalization to a shared utility for consistent module payloads.
    • Removed duplicated timezone and document/module transformation logic so managed and customized pages are prepared and stored uniformly.
    • Made the page-normalization helper available for reuse across actions/reducers.
  • Tests

    • Added tests covering document vs URL handling and media upload-deadline timezone conversion to ensure consistent behavior.

@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a65e6a72-e5cc-4b6c-922b-e17990379e1c

📥 Commits

Reviewing files that changed from the base of the PR and between d41be10 and ac1938d.

📒 Files selected for processing (2)
  • src/actions/__tests__/sponsor-pages-actions.test.js
  • src/actions/sponsor-pages-actions.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/actions/sponsor-pages-actions.js

📝 Walkthrough

Walkthrough

Actions now export and call normalizePageTemplateModules(entity.modules); the reducer calls denormalizePageModules(modules, state.summitTZ || "UTC") for RECEIVE_SPONSOR_MANAGED_PAGE and RECEIVE_SPONSOR_CUSTOMIZED_PAGE. Local timezone/epoch and inline per-module reshaping were removed; corresponding tests were added/updated.

Changes

Module Normalization Refactoring

Layer / File(s) Summary
Dependency imports and constants cleanup
src/actions/sponsor-pages-actions.js, src/reducers/sponsors/sponsor-page-pages-list-reducer.js
Removed moment-timezone and epochToMomentTimeZone imports; action no longer imports PAGES_MODULE_KINDS; reducer now imports PAGES_MODULE_KINDS and denormalizePageModules.
Action: export & delegate modules normalization
src/actions/sponsor-pages-actions.js
Exported normalizeSponsorManagedPageToCustomize and replaced inline per-module conversions with normalizePageTemplateModules(entity.modules).
Reducer: delegate modules denormalization
src/reducers/sponsors/sponsor-page-pages-list-reducer.js
RECEIVE_SPONSOR_MANAGED_PAGE and RECEIVE_SPONSOR_CUSTOMIZED_PAGE now call `denormalizePageModules(..., state.summitTZ
Tests: add/update action and reducer tests
src/actions/__tests__/sponsor-pages-actions.test.js, src/reducers/sponsors/__tests__/sponsor-page-pages-list-reducer.test.js
Adds tests for normalizeSponsorManagedPageToCustomize (DOCUMENT FILE vs FILE-existing vs URL) and updates reducer tests to assert DOCUMENT module wrapping/type and MEDIA upload_deadline timezone conversion with UTC fallback.

Sequence Diagram:

sequenceDiagram
  participant SponsorPagesAction
  participant PageTemplateUtils
  participant SponsorPageReducer
  SponsorPagesAction->>PageTemplateUtils: normalizePageTemplateModules(entity.modules)
  PageTemplateUtils-->>SponsorPagesAction: normalized modules
  SponsorPagesAction->>SponsorPageReducer: dispatch page with normalized modules
  SponsorPageReducer->>PageTemplateUtils: denormalizePageModules(modules, summitTZ)
  PageTemplateUtils-->>SponsorPageReducer: denormalized modules
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • smarcet
  • santipalenque

Poem

🐰 I hop through modules, tidy each line,
Files trimmed, deadlines set to time.
One shared path now shapes URL and file,
Reducer and action walk the same mile.
🌱📦

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring to use a denormalize function for modules in sponsor-managed pages, which is the core purpose reflected in all modified files.
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-managed-pages-modules-denormalize

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

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

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)

205-206: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Pass summitTZ through the managed-page module normalization path.

This save path now calls normalizePageTemplateModules(entity.modules) without the summit timezone, while the customized-page save path passes summitTZ and the reducer denormalizes module deadlines with that timezone. In non-UTC summits, managed-page edits can round-trip upload_deadline incorrectly.

Suggested fix
 export const saveSponsorManagedPage =
   (entity) => async (dispatch, getState) => {
     const { currentSummitState, currentSponsorState } = getState();
     const { currentSummit } = currentSummitState;
+    const summitTZ = currentSummit.time_zone.name;
     const {
       entity: { id: sponsorId }
     } = currentSponsorState;
     const accessToken = await getAccessTokenSafely();
@@
     if (entity.id) {
-      const normalizedEntity = normalizeSponsorManagedPageToCustomize(entity);
+      const normalizedEntity = normalizeSponsorManagedPageToCustomize(
+        entity,
+        summitTZ
+      );
@@
-const normalizeSponsorManagedPageToCustomize = (entity) => {
+const normalizeSponsorManagedPageToCustomize = (entity, summitTZ) => {
   const normalizedEntity = {
     ...entity,
     ...normalizeSelectAllField(
       entity.allowed_add_ons,
       "apply_to_all_add_ons",
       "allowed_add_ons"
     )
   };
 
-  normalizedEntity.modules = normalizePageTemplateModules(entity.modules);
+  normalizedEntity.modules = normalizePageTemplateModules(
+    entity.modules,
+    summitTZ
+  );

Also applies to: 300-310

🤖 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/actions/sponsor-pages-actions.js` around lines 205 - 206, The
managed-page save path is calling normalizeSponsorManagedPageToCustomize(entity)
which in turn calls normalizePageTemplateModules(entity.modules) without passing
summitTZ, causing module deadlines to be denormalized with the wrong timezone;
update normalizeSponsorManagedPageToCustomize (and any other managed-page
normalization call sites around the other occurrence at ~300-310) to accept and
forward summitTZ into normalizePageTemplateModules (i.e., call
normalizePageTemplateModules(entity.modules, summitTZ)) so the same summitTZ
used by the customized-page path is used for denormalizing upload_deadline.
🤖 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.

Outside diff comments:
In `@src/actions/sponsor-pages-actions.js`:
- Around line 205-206: The managed-page save path is calling
normalizeSponsorManagedPageToCustomize(entity) which in turn calls
normalizePageTemplateModules(entity.modules) without passing summitTZ, causing
module deadlines to be denormalized with the wrong timezone; update
normalizeSponsorManagedPageToCustomize (and any other managed-page normalization
call sites around the other occurrence at ~300-310) to accept and forward
summitTZ into normalizePageTemplateModules (i.e., call
normalizePageTemplateModules(entity.modules, summitTZ)) so the same summitTZ
used by the customized-page path is used for denormalizing upload_deadline.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d99d5b2-8404-4a1e-a24c-d39e3ed3ca79

📥 Commits

Reviewing files that changed from the base of the PR and between 81351ea and 5aa44f9.

📒 Files selected for processing (2)
  • src/actions/sponsor-pages-actions.js
  • src/reducers/sponsors/sponsor-page-pages-list-reducer.js

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom force-pushed the fix/sponsor-managed-pages-modules-denormalize branch from 5aa44f9 to 6853676 Compare June 9, 2026 13:50
state.summitTZ || "UTC"
);

return { ...state, currentEditPage: { ...editPage, modules } };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing regression tests for this new delegation to denormalizePageModules.

Suggested test cases in src/reducers/sponsors/__tests__/sponsor-page-pages-list-reducer.test.js:

  • MEDIA module with upload_deadline → verify timezone conversion is applied via epochToMomentTimeZone
  • DOCUMENT module with file present → verify file is array-wrapped and type is set to FILE
  • DOCUMENT module without file → verify type is set to URL

state.summitTZ || "UTC"
);

return { ...state, currentEditPage: { ...customizedPage, modules } };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing regression test for this new delegation to denormalizePageModules.

Suggested test case in src/reducers/sponsors/__tests__/sponsor-page-pages-list-reducer.test.js:

  • DOCUMENT module with file present → verify the file is array-wrapped with file_path and public_url mapped, and type is set to FILE


return normalizedModule;
});
normalizedEntity.modules = normalizePageTemplateModules(entity.modules);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

normalizePageTemplateModules is now shared with the customized-page flow. The old inline code sent every file unconditionally; this shared helper only sends a file if it lacks an id/file_id (the isNewFile guard) — a silent behavioral change for the managed-page PUT path.

Missing regression tests for normalizeSponsorManagedPageToCustomize in src/actions/__tests__/:

  • DOCUMENT module with a new file (no id/file_id) → verify file is included in the PUT payload
  • DOCUMENT module with an existing file (id present) → verify file is NOT included in the PUT payload (isNewFile guard fires)
  • DOCUMENT/URL module → verify no file appears in the PUT payload

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

@tomrndom please review comments

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 (2)
src/reducers/sponsors/__tests__/sponsor-page-pages-list-reducer.test.js (2)

81-81: 💤 Low value

Test description could be more precise.

The description says "when summitTZ is not set" but the test uses summitTZ: "" (an empty string). Consider updating to "falls back to UTC when summitTZ is falsy" or "when summitTZ is empty" for accuracy.

🤖 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/reducers/sponsors/__tests__/sponsor-page-pages-list-reducer.test.js` at
line 81, Update the test description to accurately reflect the input being
asserted: change the it(...) string in sponsor-page-pages-list-reducer.test.js
(the test block with description "falls back to UTC when summitTZ is not set")
to either "falls back to UTC when summitTZ is falsy" or "falls back to UTC when
summitTZ is empty" to match the test data where summitTZ is an empty string;
leave the test body and assertions (the reducer call and expected UTC behavior)
unchanged.

93-134: 💤 Low value

Consider adding UTC fallback test for consistency.

The RECEIVE_SPONSOR_CUSTOMIZED_PAGE suite lacks a UTC fallback test (present in the RECEIVE_SPONSOR_MANAGED_PAGE suite at lines 81-90). While the reducer code path is identical for both actions, adding it would ensure symmetric test coverage.

🤖 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/reducers/sponsors/__tests__/sponsor-page-pages-list-reducer.test.js`
around lines 93 - 134, Add a new test in the RECEIVE_SPONSOR_CUSTOMIZED_PAGE
block that mirrors the UTC-fallback test from the RECEIVE_SPONSOR_MANAGED_PAGE
suite: call dispatchReceiveCustomizedPage with a MEDIA module (use
PAGES_MODULE_KINDS.MEDIA and upload_deadline: 1700000000) while creating state
without a summitTZ (e.g., createInitialState({}) or omit summitTZ), then assert
that the resulting module's upload_deadline equals "moment-1700000000-UTC";
place it alongside the existing MEDIA test and reference
dispatchReceiveCustomizedPage and PAGES_MODULE_KINDS.MEDIA to locate where to
add it.
🤖 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/reducers/sponsors/__tests__/sponsor-page-pages-list-reducer.test.js`:
- Line 81: Update the test description to accurately reflect the input being
asserted: change the it(...) string in sponsor-page-pages-list-reducer.test.js
(the test block with description "falls back to UTC when summitTZ is not set")
to either "falls back to UTC when summitTZ is falsy" or "falls back to UTC when
summitTZ is empty" to match the test data where summitTZ is an empty string;
leave the test body and assertions (the reducer call and expected UTC behavior)
unchanged.
- Around line 93-134: Add a new test in the RECEIVE_SPONSOR_CUSTOMIZED_PAGE
block that mirrors the UTC-fallback test from the RECEIVE_SPONSOR_MANAGED_PAGE
suite: call dispatchReceiveCustomizedPage with a MEDIA module (use
PAGES_MODULE_KINDS.MEDIA and upload_deadline: 1700000000) while creating state
without a summitTZ (e.g., createInitialState({}) or omit summitTZ), then assert
that the resulting module's upload_deadline equals "moment-1700000000-UTC";
place it alongside the existing MEDIA test and reference
dispatchReceiveCustomizedPage and PAGES_MODULE_KINDS.MEDIA to locate where to
add it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 942e4a9c-9ed4-452d-b0a9-e2896b8c0153

📥 Commits

Reviewing files that changed from the base of the PR and between 6853676 and d41be10.

📒 Files selected for processing (1)
  • src/reducers/sponsors/__tests__/sponsor-page-pages-list-reducer.test.js

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

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

LGTM

@smarcet smarcet merged commit 49d8491 into master Jun 9, 2026
9 checks passed
smarcet pushed a commit that referenced this pull request Jun 11, 2026
…940)

* fix: use denormalize function for modules for sponsor managed pages

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

* fix: add test cases for pages modules checking files and dates

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

* fix: add sponsor-pages-actions unit test to check file payload

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

---------

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
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