Skip to content

fix: adjust format on form items from inventary popup#817

Merged
smarcet merged 2 commits intomasterfrom
fix/form-items-popup-currency
Mar 9, 2026
Merged

fix: adjust format on form items from inventary popup#817
smarcet merged 2 commits intomasterfrom
fix/form-items-popup-currency

Conversation

@tomrndom
Copy link

@tomrndom tomrndom commented Mar 9, 2026

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

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved currency formatting for event rates (early bird, standard, and onsite) across inventory and form-template displays so amounts are shown consistently and correctly as currency.
  • Tests
    • Updated tests to mock the currency utility so rate formatting is covered and stable in automated tests.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@tomrndom tomrndom requested a review from smarcet March 9, 2026 14:52
@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

Replaced inline "$ " and toFixed-based formatting with the currencyAmountFromCents utility for early_bird_rate, standard_rate, and onsite_rate in two UI components; added a test mock for the money utility.

Changes

Cohort / File(s) Summary
Rate column formatting (UI components)
src/pages/sponsors-global/form-templates/add-form-template-item-popup.js, src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-add-item-from-inventory-popup.js
Imported currencyAmountFromCents and replaced inline "$ " and toFixed() formatting with currencyAmountFromCents(...) in renderers for early_bird_rate, standard_rate, and onsite_rate. No control-flow changes.
Tests — money util mock
src/pages/sponsors/sponsor-form-item-list-page/components/__test__/inventory-popup.test.js
Added a Jest mock for openstack-uicore-foundation/lib/utils/money exporting currencyAmountFromCents as a jest.fn() to support the new formatting usage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • smarcet

Poem

🐰 I hopped through cents and tiny sums,
Swapped to helpers, neat and plumb,
Numbers now in proper dress,
No more rounding, no more stress,
Hooray — the ledger's feeling yum! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title mentions 'adjust format on form items from inventary popup' which directly aligns with the changes: applying currency formatting to rate columns (early_bird_rate, standard_rate, onsite_rate) in inventory popup components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/form-items-popup-currency

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

Copy link

@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: 1

🤖 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/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-add-item-from-inventory-popup.js`:
- Around line 125-126: Update the RECEIVE_INVENTORY_ITEMS branch in the
inventory-item-list-reducer.js reducer to import currencyAmountFromCents from
"openstack-uicore-foundation/lib/utils/money" and map each incoming item so
early_bird_rate, standard_rate, and onsite_rate are set to
currencyAmountFromCents(a.early_bird_rate),
currencyAmountFromCents(a.standard_rate), and
currencyAmountFromCents(a.onsite_rate) respectively (keep other fields like id,
code, name, images, is_archived, checked as before); then remove the
currencyAmountFromCents calls from the render functions in
sponsor-form-add-item-from-inventory-popup.js so the component renders the
already-formatted early_bird_rate, standard_rate, and onsite_rate values
directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c1dbfddc-e1d7-40ff-9407-b5d15b2b5ca2

📥 Commits

Reviewing files that changed from the base of the PR and between 827fd4a and 15eb327.

📒 Files selected for processing (2)
  • src/pages/sponsors-global/form-templates/add-form-template-item-popup.js
  • src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-add-item-from-inventory-popup.js

Comment on lines +125 to +126
sortable: false,
render: (row) => currencyAmountFromCents(row.early_bird_rate)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check how inventory items are normalized/transformed to understand the rate format

# Search for inventory item normalizer or entity definition
rg -n -B2 -A10 'INVENTORY_ITEM' --type=js -g '*normalizer*'

# Check the API response handling for inventory items
rg -n -C5 'getInventoryItems' --type=js -g '*actions*'

Repository: fntechgit/summit-admin

Length of output: 952


🏁 Script executed:

# Get the full implementation of getInventoryItems
rg -n -A30 'export const getInventoryItems' src/actions/inventory-item-actions.js

Repository: fntechgit/summit-admin

Length of output: 969


🏁 Script executed:

# Find the currencyAmountFromCents function definition
fd -t f -e js | xargs rg -l 'currencyAmountFromCents' | head -5

Repository: fntechgit/summit-admin

Length of output: 407


🏁 Script executed:

# Look at the component itself to understand the data context
cat -n src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-add-item-from-inventory-popup.js | head -150

Repository: fntechgit/summit-admin

Length of output: 4975


🏁 Script executed:

# Search for other usages of currencyAmountFromCents to understand the expected input
rg -n 'currencyAmountFromCents' --type=js -B2 -A1 | head -60

Repository: fntechgit/summit-admin

Length of output: 6308


🏁 Script executed:

# Check the inventory items reducer to see how data is handled
cat -n src/reducers/inventory-items-reducer.js | head -100

Repository: fntechgit/summit-admin

Length of output: 137


🏁 Script executed:

# Look for other rate field usage in the codebase
rg -n 'early_bird_rate|standard_rate|onsite_rate' --type=js -B1 -A1 | head -80

Repository: fntechgit/summit-admin

Length of output: 7049


🏁 Script executed:

# Check which reducer is connected to the inventoryItems state
rg -n "inventoryItems" src/reducers/sponsors_inventory/inventory-item-list-reducer.js -B5 -A15 | head -80

Repository: fntechgit/summit-admin

Length of output: 2200


🏁 Script executed:

# Look at the root reducer to understand the state structure
fd -t f -e js "*root*reducer*" | xargs rg -l "inventoryItems" 2>/dev/null | head -3

Repository: fntechgit/summit-admin

Length of output: 609


🏁 Script executed:

# Check the component's mapStateToProps to see which reducer it uses
cat -n src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-add-item-from-inventory-popup.js | tail -30

Repository: fntechgit/summit-admin

Length of output: 1096


🏁 Script executed:

# Check amountFromCents definition to understand the transformation
rg -n "export.*amountFromCents|export.*currencyAmountFromCents" --type=js

Repository: fntechgit/summit-admin

Length of output: 48


🏁 Script executed:

# Search for how rates are used when they come from the API - look for any conversion in inventory-item-actions
cat -n src/actions/inventory-item-actions.js | sed -n '98,180p'

Repository: fntechgit/summit-admin

Length of output: 2775


🏁 Script executed:

# Check if there's documentation about the rate fields or API response format
rg -n "rate" src/actions/inventory-item-actions.js -B2 -A2 | grep -E "(comment|doc|Rate|RATE)" | head -20

Repository: fntechgit/summit-admin

Length of output: 48


🏁 Script executed:

# Look for test files or examples showing the rate field format
fd -t f -e js "*test*" -o -e spec | xargs rg -l "early_bird_rate" 2>/dev/null | head -3

Repository: fntechgit/summit-admin

Length of output: 437


🏁 Script executed:

# Check if amountFromCents is the inverse of currencyAmountFromCents
rg -n "export.*amountFromCents\|const.*amountFromCents" src/reducers/sponsors/sponsor-form-items-list-reducer.js -B2 -A5

Repository: fntechgit/summit-admin

Length of output: 48


🏁 Script executed:

# Find where amountFromCents is imported from
rg -n "import.*amountFromCents" --type=js | head -10

Repository: fntechgit/summit-admin

Length of output: 768


🏁 Script executed:

# Look at the reducer file that uses amountFromCents
head -20 src/reducers/sponsors_inventory/inventory-item-reducer.js

Repository: fntechgit/summit-admin

Length of output: 933


🏁 Script executed:

# Check if there's any transformation happening in the reducer for the inventory-item-list
rg -n "RECEIVE_INVENTORY_ITEMS" src/reducers/sponsors_inventory/inventory-item-list-reducer.js -A20

Repository: fntechgit/summit-admin

Length of output: 1314


🏁 Script executed:

# Look for what openstack-uicore-foundation exports
find . -name "package.json" | xargs grep -l "openstack-uicore-foundation" | head -1

Repository: fntechgit/summit-admin

Length of output: 80


🏁 Script executed:

# Check package.json to see the version of openstack-uicore-foundation
cat package.json | grep -A2 -B2 "openstack-uicore-foundation"

Repository: fntechgit/summit-admin

Length of output: 229


🏁 Script executed:

# Compare how other similar components handle the same situation
cat -n src/pages/sponsors-global/form-templates/add-form-template-item-popup.js | sed -n '1,160p' | tail -80

Repository: fntechgit/summit-admin

Length of output: 2561


🏁 Script executed:

# Check the inventory-item-reducer for a single item to see how it transforms rates
cat -n src/reducers/sponsors_inventory/inventory-item-reducer.js | sed -n '60,100p'

Repository: fntechgit/summit-admin

Length of output: 1556


🏁 Script executed:

# Look for any transformation happening after RECEIVE_INVENTORY_ITEMS in the list reducer
cat -n src/reducers/sponsors_inventory/inventory-item-list-reducer.js | sed -n '78,110p'

Repository: fntechgit/summit-admin

Length of output: 1192


🏁 Script executed:

# Check what format other reducers expect from the inventory item API
cat -n src/reducers/sponsors_inventory/form-template-item-reducer.js | sed -n '60,100p'

Repository: fntechgit/summit-admin

Length of output: 1581


🏁 Script executed:

# Look at how sponsor-customized-form-items-list-reducer handles the transformation
cat -n src/reducers/sponsors/sponsor-customized-form-items-list-reducer.js | sed -n '78,110p'

Repository: fntechgit/summit-admin

Length of output: 1126


🏁 Script executed:

# Check if inventory-item-list-reducer should apply amountFromCents like the single-item reducer does
rg -n "import.*amountFromCents" src/reducers/sponsors_inventory/inventory-item-list-reducer.js

Repository: fntechgit/summit-admin

Length of output: 48


🏁 Script executed:

# Check if inventory-item-list-reducer should be importing and using amountFromCents
head -25 src/reducers/sponsors_inventory/inventory-item-list-reducer.js

Repository: fntechgit/summit-admin

Length of output: 1048


🏁 Script executed:

# Look at how the component in form-templates handles the same situation - check if it also fails or uses different data
rg -n "mapStateToProps" src/pages/sponsors-global/form-templates/add-form-template-item-popup.js -A5

Repository: fntechgit/summit-admin

Length of output: 373


🏁 Script executed:

# Check what state is being used by the form-templates component
rg -n "currentFormTemplateItemListState\|currentInventoryItemListState" src/reducers --type=js | head -10

Repository: fntechgit/summit-admin

Length of output: 48


Fix the rate field transformation in the reducer, not the component.

The inventory-item-list-reducer.js is missing the rate field transformation that other similar reducers apply. When inventory items are received from the API (lines 87-89), the early_bird_rate, standard_rate, and onsite_rate fields should be transformed in the reducer—not in the component's render function.

Compare with sponsor-customized-form-items-list-reducer.js (lines 95-97), which correctly applies the transformation at the reducer level. The component render functions should receive already-formatted data.

Update src/reducers/sponsors_inventory/inventory-item-list-reducer.js to import currencyAmountFromCents and transform the rate fields in the RECEIVE_INVENTORY_ITEMS case:

import { currencyAmountFromCents } from "openstack-uicore-foundation/lib/utils/money";

// In RECEIVE_INVENTORY_ITEMS case:
const inventoryItems = payload.response.data.map((a) => ({
  id: a.id,
  code: a.code,
  name: a.name,
  images: a.images,
  is_archived: a.is_archived,
  early_bird_rate: currencyAmountFromCents(a.early_bird_rate),
  standard_rate: currencyAmountFromCents(a.standard_rate),
  onsite_rate: currencyAmountFromCents(a.onsite_rate),
  checked: false
}));

Then remove the formatting calls from the component's render functions (lines 126, 134, 142) and render the values directly.

🧰 Tools
🪛 GitHub Actions: jest

[error] 126-126: cents must be an integer number. Error originates from money.js when rendering currency via currencyAmountFromCents(row.early_bird_rate). Likely a non-integer value is being passed to currency formatter during inventory popup render.

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

In
`@src/pages/sponsors/sponsor-form-item-list-page/components/sponsor-form-add-item-from-inventory-popup.js`
around lines 125 - 126, Update the RECEIVE_INVENTORY_ITEMS branch in the
inventory-item-list-reducer.js reducer to import currencyAmountFromCents from
"openstack-uicore-foundation/lib/utils/money" and map each incoming item so
early_bird_rate, standard_rate, and onsite_rate are set to
currencyAmountFromCents(a.early_bird_rate),
currencyAmountFromCents(a.standard_rate), and
currencyAmountFromCents(a.onsite_rate) respectively (keep other fields like id,
code, name, images, is_archived, checked as before); then remove the
currencyAmountFromCents calls from the render functions in
sponsor-form-add-item-from-inventory-popup.js so the component renders the
already-formatted early_bird_rate, standard_rate, and onsite_rate values
directly.

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

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

🧹 Nitpick comments (1)
src/pages/sponsors/sponsor-form-item-list-page/components/__test__/inventory-popup.test.js (1)

41-43: Make the money mock partial and deterministic.

A bare jest.fn() returns undefined for every amount, so this spec can still pass with blank price cells. It also replaces the entire money module, which is brittle if InventoryPopup or one of its children uses another export from that file.

Suggested mock
-jest.mock("openstack-uicore-foundation/lib/utils/money", () => ({
-  currencyAmountFromCents: jest.fn()
-}));
+jest.mock("openstack-uicore-foundation/lib/utils/money", () => {
+  const actual = jest.requireActual(
+    "openstack-uicore-foundation/lib/utils/money"
+  );
+
+  return {
+    ...actual,
+    currencyAmountFromCents: jest.fn(
+      amount => `$ ${(amount / 100).toFixed(2)}`
+    )
+  };
+});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/pages/sponsors/sponsor-form-item-list-page/components/__test__/inventory-popup.test.js`
around lines 41 - 43, The current jest.mock call replaces the whole money module
and makes currencyAmountFromCents a noop; update the mock to be partial by
calling jest.requireActual for the real module and override only
currencyAmountFromCents with a deterministic implementation (e.g., convert cents
to dollars and return a formatted string or object as the component expects) so
InventoryPopup and its children still get other real exports; modify the
jest.mock in inventory-popup.test.js to merge the actual module with a defined
currencyAmountFromCents mock that returns predictable output for assertions.
🤖 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/pages/sponsors/sponsor-form-item-list-page/components/__test__/inventory-popup.test.js`:
- Around line 41-43: The current jest.mock call replaces the whole money module
and makes currencyAmountFromCents a noop; update the mock to be partial by
calling jest.requireActual for the real module and override only
currencyAmountFromCents with a deterministic implementation (e.g., convert cents
to dollars and return a formatted string or object as the component expects) so
InventoryPopup and its children still get other real exports; modify the
jest.mock in inventory-popup.test.js to merge the actual module with a defined
currencyAmountFromCents mock that returns predictable output for assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c1d387e6-8f59-4cbf-b5fc-43d77ee880ac

📥 Commits

Reviewing files that changed from the base of the PR and between 15eb327 and 8f16fa9.

📒 Files selected for processing (1)
  • src/pages/sponsors/sponsor-form-item-list-page/components/__test__/inventory-popup.test.js

Copy link

@smarcet smarcet left a comment

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 2a59473 into master Mar 9, 2026
9 checks passed
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