Skip to content

Conversation

@Sartoric
Copy link
Contributor

@Sartoric Sartoric commented Oct 1, 2025

Avoid disappearing field and undefined Pump mode if Pump Power is empty

  • Replaced isNumber with a new isNumeric utility for better type checks including NaN.
  • Added handleSave to normalize pump values in both forms and ensure NaN values are converted to 0 to avoid potential issues.

#445

Summary by CodeRabbit

  • Bug Fixes

    • Prevents invalid (NaN) pump values from being saved by defaulting them to 0 during profile save.
    • Ensures consistent detection of numeric pump inputs, improving pump power and mode calculations.
    • Reduces unexpected behavior when editing and saving phases in both Standard and Extended profile forms.
  • Improvements

    • More reliable profile editing with better input normalization and validation for pump-related fields.

… if Pump Power is empty**

- Replaced `isNumber` with a new `isNumeric` utility for better type checks (NaN).
- Added `handleSave` to normalize `pump` values in both forms and ensure `NaN` values are converted to `0` to avoid potential issues.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

Walkthrough

Adds pump numeric-check helper and replaces isNumber with isNumeric in pump-related logic. Introduces handleSave in profile forms to normalize phases by converting NaN pump values to 0 before invoking onSave. Updates submission flow to route through normalization.

Changes

Cohort / File(s) Summary
Pump numeric check refactor
web/src/pages/ProfileEdit/ExtendedPhase.jsx, web/src/pages/ProfileEdit/StandardProfileForm.jsx
Introduced local isNumeric helper and replaced isNumber(phase.pump) usages for pumpPower and mode derivation, aligning logic paths to a consistent numeric check.
Save normalization flow
web/src/pages/ProfileEdit/ExtendedProfileForm.jsx, web/src/pages/ProfileEdit/StandardProfileForm.jsx
Added handleSave to map phases and coerce NaN pump values to 0, invoking onSave with normalized data; updated form submission to use handleSave.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Form as Profile Form (Extended/Standard)
  participant Normalizer as handleSave (normalize phases)
  participant Store as onSave (consumer)

  User->>Form: Submit
  Form->>Normalizer: handleSave(data)
  Note right of Normalizer: For each phase: if pump is NaN -> set to 0
  Normalizer-->>Form: normalizedData
  Form->>Store: onSave(normalizedData)
  Store-->>Form: ack
Loading
sequenceDiagram
  autonumber
  participant UI as Phase UI
  participant Logic as Pump Logic

  UI->>Logic: compute pumpPower/mode
  alt pump is numeric (isNumeric)
    Logic-->>UI: derive from numeric pump
  else pump not numeric
    Logic-->>UI: derive from phase.pump.target / defaults
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A bunny taps save with careful cheer,
Normalized pumps—no NaNs left here.
Numbers checked with nimble nick,
isNumeric does the hopping trick.
Profiles primed, the flows align—
Carrots up! The code’s just fine. 🥕✨

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title “Bug #445 - Pump Power empty field” clearly reflects the primary issue addressed by the changeset, namely the missing Pump Power field behavior and defaulting logic for empty inputs. It concisely indicates that the pull request fixes a specific bug related to Pump Power being empty, aligning with the PR objectives. Although it includes the issue number, this common convention does not obscure the change’s focus. The phrasing is direct and informative enough for team members scanning history to understand the purpose without examining the diff.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 1, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
5.1% Duplication on New Code (required ≤ 4%)

See analysis details on SonarQube Cloud

Copy link
Contributor

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

🧹 Nitpick comments (2)
web/src/pages/ProfileEdit/ExtendedPhase.jsx (1)

48-48: Mixing isNumber and isNumeric helpers is inconsistent.

Line 48 uses isNumber from chart.js while lines 47 and 50 use the new isNumeric helper. This creates inconsistency in how numeric checks are performed.

For consistency, consider using isNumeric throughout:

-  const pressure = !isNumber(phase.pump) ? phase.pump.pressure : 0;
+  const pressure = !isNumeric(phase.pump) ? phase.pump.pressure : 0;

And remove the unused import:

-import { isNumber } from 'chart.js/helpers';
web/src/pages/ProfileEdit/StandardProfileForm.jsx (1)

219-219: Mixing isNumber and isNumeric helpers is inconsistent.

Line 219 uses isNumber from chart.js while lines 218 and 221 use the new isNumeric helper. This creates inconsistency in how numeric checks are performed.

For consistency, consider using isNumeric throughout:

-  const pressure = !isNumber(phase.pump) ? phase.pump.pressure : 0;
+  const pressure = !isNumeric(phase.pump) ? phase.pump.pressure : 0;

And if isNumber is no longer used elsewhere in the file, remove the unused import:

-import { isNumber } from 'chart.js/helpers';
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30cfe34 and aa080d4.

📒 Files selected for processing (3)
  • web/src/pages/ProfileEdit/ExtendedPhase.jsx (2 hunks)
  • web/src/pages/ProfileEdit/ExtendedProfileForm.jsx (1 hunks)
  • web/src/pages/ProfileEdit/StandardProfileForm.jsx (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
web/src/pages/ProfileEdit/ExtendedProfileForm.jsx (2)
web/src/pages/ProfileEdit/StandardProfileForm.jsx (1)
  • handleSave (57-69)
web/src/pages/ProfileEdit/index.jsx (2)
  • data (21-21)
  • onSave (85-94)
web/src/pages/ProfileEdit/StandardProfileForm.jsx (3)
web/src/pages/ProfileEdit/ExtendedProfileForm.jsx (1)
  • handleSave (68-80)
web/src/pages/ProfileEdit/index.jsx (2)
  • data (21-21)
  • onSave (85-94)
web/src/pages/ProfileEdit/ExtendedPhase.jsx (5)
  • isNumeric (8-8)
  • pumpPower (47-47)
  • pressure (48-48)
  • flow (49-49)
  • mode (50-50)
web/src/pages/ProfileEdit/ExtendedPhase.jsx (2)
web/src/pages/ProfileEdit/StandardProfileForm.jsx (5)
  • isNumeric (188-188)
  • pumpPower (218-218)
  • pressure (219-219)
  • flow (220-220)
  • mode (221-221)
web/src/pages/ProfileList/utils.js (1)
  • phase (36-48)
🔇 Additional comments (4)
web/src/pages/ProfileEdit/ExtendedProfileForm.jsx (2)

68-80: LGTM! NaN normalization prevents invalid pump states.

The normalization logic correctly identifies NaN values and converts them to 0 before saving, which should resolve the disappearing field issue mentioned in the PR objectives.


89-89: LGTM! Submission now routes through normalization.

Form submission correctly invokes handleSave to ensure pump values are normalized before persisting.

web/src/pages/ProfileEdit/StandardProfileForm.jsx (2)

57-69: LGTM! NaN normalization prevents invalid pump states.

The normalization logic correctly identifies NaN values and converts them to 0 before saving, consistent with the implementation in ExtendedProfileForm.


75-75: LGTM! Submission now routes through normalization.

Form submission correctly invokes handleSave to ensure pump values are normalized before persisting.

import { faPlus } from '@fortawesome/free-solid-svg-icons/faPlus';

export function ExtendedPhase({ phase, index, onChange, onRemove, pressureAvailable }) {
const isNumeric = v => typeof v === 'number';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

isNumeric doesn't filter out NaN as described in PR objectives.

The helper returns true for NaN since typeof NaN === 'number' in JavaScript. This contradicts the PR description stating it "handles NaN" to improve type checks.

Apply this diff to properly exclude NaN:

-  const isNumeric = v => typeof v === 'number';
+  const isNumeric = v => typeof v === 'number' && !Number.isNaN(v);

Without this fix, lines 47 and 50 will incorrectly treat NaN pump values as valid numbers, causing:

  • Line 47: pumpPower will be NaN instead of defaulting to 100
  • Line 50: mode will be 'power' when pump is NaN (undefined behavior)

While handleSave in the form normalizes NaN to 0 before saving, the UI will still display incorrectly when pump becomes NaN during editing.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isNumeric = v => typeof v === 'number';
const isNumeric = v => typeof v === 'number' && !Number.isNaN(v);
🤖 Prompt for AI Agents
In web/src/pages/ProfileEdit/ExtendedPhase.jsx around line 8, the isNumeric
helper currently returns true for NaN because it only checks typeof v ===
'number'; change it to exclude NaN by using Number.isFinite(v) (or equivalently
typeof v === 'number' && !Number.isNaN(v)) so NaN is treated as non-numeric;
update the helper accordingly so downstream logic at lines ~47 and ~50 will
default correctly (pumpPower -> 100 and mode selection) when the value is NaN.

}

function Phase({ phase, index, onChange, onRemove, pressureAvailable }) {
const isNumeric = v => typeof v === 'number';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

isNumeric doesn't filter out NaN as described in PR objectives.

The helper returns true for NaN since typeof NaN === 'number' in JavaScript. This contradicts the PR description stating it "handles NaN" to improve type checks.

Apply this diff to properly exclude NaN:

-  const isNumeric = v => typeof v === 'number';
+  const isNumeric = v => typeof v === 'number' && !Number.isNaN(v);

Without this fix, lines 218 and 221 will incorrectly treat NaN pump values as valid numbers, causing:

  • Line 218: pumpPower will be NaN instead of defaulting to 100
  • Line 221: mode will be 'power' when pump is NaN (undefined behavior)

While handleSave normalizes NaN to 0 before saving, the UI will still display incorrectly when pump becomes NaN during editing.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isNumeric = v => typeof v === 'number';
const isNumeric = v => typeof v === 'number' && !Number.isNaN(v);
🤖 Prompt for AI Agents
In web/src/pages/ProfileEdit/StandardProfileForm.jsx around line 188, the
isNumeric helper currently returns true for NaN because it only checks typeof
=== 'number'; update it to exclude NaN (use Number.isFinite(v) or (typeof v ===
'number' && !Number.isNaN(v))) so NaN is treated as non-numeric; this ensures
downstream logic on lines ~218 and ~221 will default pumpPower to 100 and not
switch mode to 'power' when the value is NaN.

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