fix: denormalize module data when a show page is recieved, unit test#862
fix: denormalize module data when a show page is recieved, unit test#862
Conversation
…ests Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughCentralized page-module normalization/denormalization into Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/reducers/sponsors/show-pages-list-reducer.js (1)
152-165: Extract the DOCUMENT denormalization into a shared helper.This branch now mirrors
src/reducers/sponsors_inventory/page-template-reducer.js:60-85, so the next document-shape change will have to land in two reducers. A small shared helper for the file/type rewrite would keep the receive flows from drifting.♻️ Refactor sketch
- if (module.kind === PAGES_MODULE_KINDS.DOCUMENT) { - if (module.file) { - tmpModule.file = [ - { - ...module.file, - file_path: module.file.storage_key, - public_url: module.file.file_url - } - ]; - tmpModule.type = PAGE_MODULES_DOWNLOAD.FILE; - } else { - tmpModule.type = PAGE_MODULES_DOWNLOAD.URL; - } - } + Object.assign(tmpModule, denormalizeDocumentModule(module));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/reducers/sponsors/show-pages-list-reducer.js` around lines 152 - 165, Extract the DOCUMENT denormalization logic into a shared helper to avoid duplication: move the block that checks module.kind === PAGES_MODULE_KINDS.DOCUMENT and rewrites module.file -> tmpModule.file (including file_path: module.file.storage_key and public_url: module.file.file_url) and sets tmpModule.type to PAGE_MODULES_DOWNLOAD.FILE or PAGE_MODULES_DOWNLOAD.URL into a new utility function (e.g., normalizeDocumentModule(module) or denormalizeDocumentFile(module, tmpModule)); replace the inlined logic in show-pages-list-reducer (and mirror change in sponsors_inventory/page-template-reducer) to call that helper so future document-shape changes are implemented once.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/reducers/sponsors/show-pages-list-reducer.js`:
- Around line 152-165: Extract the DOCUMENT denormalization logic into a shared
helper to avoid duplication: move the block that checks module.kind ===
PAGES_MODULE_KINDS.DOCUMENT and rewrites module.file -> tmpModule.file
(including file_path: module.file.storage_key and public_url:
module.file.file_url) and sets tmpModule.type to PAGE_MODULES_DOWNLOAD.FILE or
PAGE_MODULES_DOWNLOAD.URL into a new utility function (e.g.,
normalizeDocumentModule(module) or denormalizeDocumentFile(module, tmpModule));
replace the inlined logic in show-pages-list-reducer (and mirror change in
sponsors_inventory/page-template-reducer) to call that helper so future
document-shape changes are implemented once.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6728e2ce-4a59-4cb2-8326-61268074ce99
📒 Files selected for processing (2)
src/reducers/sponsors/__tests__/show-pages-list-reducer.test.jssrc/reducers/sponsors/show-pages-list-reducer.js
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/utils/page-template.js (1)
14-21: Consider validatingepochToMomentTimeZonereturn value.Based on usage patterns elsewhere in the codebase (e.g.,
src/utils/methods.js:315-325),epochToMomentTimeZonemay return invalid values when conversion fails. The existing pattern usesmoment.isMoment()to validate before proceeding. Here, no such validation occurs, which could result in an invalid moment object being assigned toupload_deadline.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/page-template.js` around lines 14 - 21, The assignment to upload_deadline should validate epochToMomentTimeZone's return like other usages: when timeZone is provided call epochToMomentTimeZone(module.upload_deadline, timeZone) and check with moment.isMoment() (or fall back to moment(module.upload_deadline * MILLISECONDS_IN_SECOND) or omit the field) so that an invalid moment is never assigned; update the ternary/conditional creating upload_deadline to perform this validation and fallback logic referencing epochToMomentTimeZone, moment.isMoment, timeZone, module.upload_deadline and MILLISECONDS_IN_SECOND.src/actions/show-pages-actions.js (1)
129-142: Consider passing summit timezone for consistency.
normalizePageTemplateModulesis called without thetimeZoneparameter, causing it to usemoment.utc().unix()for deadline conversion. Whilemoment.unix()returns the same epoch regardless of timezone display, passing the summit timezone would maintain consistency with howdenormalizePageModulesis called in the reducer (withstate.summitTZ).♻️ Optional fix for consistency
-const normalizeShowPage = (entity) => { +const normalizeShowPage = (entity, timeZone) => { const normalizedEntity = { ...entity }; normalizedEntity.apply_to_all_types = false; if (entity.sponsorship_types?.includes("all")) { normalizedEntity.apply_to_all_types = true; delete normalizedEntity.sponsorship_types; } - normalizedEntity.modules = normalizePageTemplateModules(entity.modules); + normalizedEntity.modules = normalizePageTemplateModules(entity.modules, timeZone); return normalizedEntity; };Then update the call site in
saveShowPage:- const normalizedShowPage = normalizeShowPage(entity); + const summitTZ = currentSummit.time_zone?.name; + const normalizedShowPage = normalizeShowPage(entity, summitTZ);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/actions/show-pages-actions.js` around lines 129 - 142, The normalizeShowPage function calls normalizePageTemplateModules without a timezone, causing inconsistent deadline handling; update normalizeShowPage to accept and forward the summit timezone into normalizePageTemplateModules (e.g., add a timeZone parameter and call normalizePageTemplateModules(entity.modules, timeZone)); also ensure saveShowPage (where normalizeShowPage is invoked) passes state.summitTZ through to normalizeShowPage so the same summitTZ used by denormalizePageModules in the reducer is used here as well.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/utils/page-template.js`:
- Around line 10-11: denormalizePageModules and normalizePageTemplateModules
call .map() on the modules parameter without guarding against null/undefined;
update both functions (denormalizePageModules and normalizePageTemplateModules)
to defensively handle falsy modules by treating modules as an empty array (e.g.,
defaulting modules to [] before mapping or returning [] when modules is falsy)
so the .map() call never throws; preserve existing parameters (like timeZone)
and behavior for non-empty arrays.
---
Nitpick comments:
In `@src/actions/show-pages-actions.js`:
- Around line 129-142: The normalizeShowPage function calls
normalizePageTemplateModules without a timezone, causing inconsistent deadline
handling; update normalizeShowPage to accept and forward the summit timezone
into normalizePageTemplateModules (e.g., add a timeZone parameter and call
normalizePageTemplateModules(entity.modules, timeZone)); also ensure
saveShowPage (where normalizeShowPage is invoked) passes state.summitTZ through
to normalizeShowPage so the same summitTZ used by denormalizePageModules in the
reducer is used here as well.
In `@src/utils/page-template.js`:
- Around line 14-21: The assignment to upload_deadline should validate
epochToMomentTimeZone's return like other usages: when timeZone is provided call
epochToMomentTimeZone(module.upload_deadline, timeZone) and check with
moment.isMoment() (or fall back to moment(module.upload_deadline *
MILLISECONDS_IN_SECOND) or omit the field) so that an invalid moment is never
assigned; update the ternary/conditional creating upload_deadline to perform
this validation and fallback logic referencing epochToMomentTimeZone,
moment.isMoment, timeZone, module.upload_deadline and MILLISECONDS_IN_SECOND.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 24657e69-6cf7-45e4-96c3-9d2379950506
📒 Files selected for processing (6)
src/actions/page-template-actions.jssrc/actions/show-pages-actions.jssrc/actions/sponsor-pages-actions.jssrc/reducers/sponsors/show-pages-list-reducer.jssrc/reducers/sponsors_inventory/page-template-reducer.jssrc/utils/page-template.js
✅ Files skipped from review due to trivial changes (1)
- src/actions/sponsor-pages-actions.js
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
ref:
Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com
Summary by CodeRabbit
Tests
Bug Fixes
Refactor