Skip to content

fix bug in isNullOrWhiteSpace utility#3943

Merged
James-Baloyi merged 1 commit intoshesha-io:mainfrom
James-Baloyi:james/b/69774
Oct 8, 2025
Merged

fix bug in isNullOrWhiteSpace utility#3943
James-Baloyi merged 1 commit intoshesha-io:mainfrom
James-Baloyi:james/b/69774

Conversation

@James-Baloyi
Copy link
Copy Markdown
Contributor

@James-Baloyi James-Baloyi commented Oct 8, 2025

Summary by CodeRabbit

  • Bug Fixes
    • High-precision number fields now handle decimal input reliably, preserving user-entered values without unwanted integer parsing or loss of precision.
    • Enhanced blank-value detection to only treat whitespace in text inputs as empty, avoiding errors when non-string values are evaluated. This prevents sporadic runtime issues and improves overall form stability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 8, 2025

Walkthrough

Updates numeric parsing in NumberFieldComponent for high-precision mode to parse strings with parseFloat and leave non-strings unchanged. Adjusts isNullOrWhiteSpace to only trim when the value is a string, avoiding trim calls on non-strings. No public API changes.

Changes

Cohort / File(s) Summary
NumberField high-precision parsing
shesha-reactjs/src/designer-components/numberField/numberField.tsx
Alters onChange handling for highPrecision: parse string inputs with parseFloat; pass through non-string values unchanged (replaces prior parseInt for all).
Utilities: nullable checks
shesha-reactjs/src/utils/nullables.ts
Refines isNullOrWhiteSpace: only trims when value is a string; null/undefined unchanged; avoids runtime trim on non-strings.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as NumberFieldComponent
  participant Util as nullables.ts

  User->>UI: Type input (string/number)
  UI->>UI: highPrecision?
  alt highPrecision enabled
    alt input is string
      UI->>UI: value = parseFloat(input)
    else input is non-string
      UI->>UI: value = input (unchanged)
    end
  else highPrecision disabled
    UI->>UI: (existing path, unchanged)
  end
  UI->>Util: isNullOrWhiteSpace(value)
  Note right of Util: Trim only if typeof value === "string"
  Util-->>UI: boolean
  UI-->>User: Update state/propagate onChange
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A nibble of numbers, a hop of delight,
I parse with finesse in the soft moonlight.
Strings get a float, non-strings glide through,
Whitespace behaves as strings ought to do.
Thump-thump—clean inputs, precise and bright! 🐇✨

Pre-merge checks and finishing touches

✅ 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 clearly describes the bug fix in the isNullOrWhiteSpace utility and refers to a real part of the changeset, even though it does not mention the unrelated numberField parsing update.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39d5eca and 838387b.

📒 Files selected for processing (2)
  • shesha-reactjs/src/designer-components/numberField/numberField.tsx (1 hunks)
  • shesha-reactjs/src/utils/nullables.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
shesha-reactjs/src/utils/nullables.ts (1)
shesha-reactjs/src/providers/auth/authenticator.ts (1)
  • r (210-210)
shesha-reactjs/src/designer-components/numberField/numberField.tsx (2)
shesha-reactjs/src/designer-components/inputComponent/index.tsx (1)
  • v (102-105)
shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx (1)
  • localValue (82-90)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-attempt
🔇 Additional comments (2)
shesha-reactjs/src/designer-components/numberField/numberField.tsx (1)

92-98: LGTM! High-precision parsing improved.

The conditional parsing logic correctly handles high-precision values:

  • Preserves decimals by using parseFloat instead of parseInt
  • Avoids unnecessary string coercion when val is already numeric
  • The null/undefined check on line 93 ensures falsy numeric values like 0 are handled correctly
shesha-reactjs/src/utils/nullables.ts (1)

10-12: LGTM! Defensive type guard prevents runtime errors.

The typeof value === 'string' check before calling trim() is a good defensive practice. While the type signature restricts inputs to string | null | undefined, this runtime guard:

  • Prevents errors if non-string values are passed (e.g., through JavaScript interop or type assertions)
  • Returns false for non-string values, which aligns with the function's semantics (non-strings aren't "null or whitespace")
  • Complements the numberField changes where mixed-type values may be handled

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.

@James-Baloyi James-Baloyi merged commit 1e0eefb into shesha-io:main Oct 8, 2025
2 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.

1 participant