Skip to content

fix(dashboard): handle empty input for min and max values (#3410, #3411)#334

Open
YUDONGLING wants to merge 1 commit intocloudreve:masterfrom
YUDONGLING:fix-rating-setting-nan-20260403.1
Open

fix(dashboard): handle empty input for min and max values (#3410, #3411)#334
YUDONGLING wants to merge 1 commit intocloudreve:masterfrom
YUDONGLING:fix-rating-setting-nan-20260403.1

Conversation

@YUDONGLING
Copy link
Copy Markdown
Member

Copilot AI review requested due to automatic review settings April 2, 2026 17:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the dashboard Custom Props editor to properly treat empty min/max numeric inputs as “unset” instead of attempting to parse them, addressing issues #3410 and #3411.

Changes:

  • Update min numeric input handler to set min to undefined when the input is emptied.
  • Update max numeric input handler to set max to undefined when the input is emptied.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 120 to 123
type="number"
value={editProps?.min || ""}
onChange={(e) => setEditProps({ ...editProps, min: parseInt(e.target.value) } as CustomProps)}
onChange={(e) => setEditProps({ ...editProps, min: e.target.value === "" ? undefined : parseInt(e.target.value) } as CustomProps)}
/>
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

value={editProps?.min || ""} will render 0 (and also NaN) as an empty string because of the || fallback. That makes the UI inconsistent with the underlying state (e.g., min=0 looks cleared) and can mask invalid values. Use a nullish check (e.g., ??) and/or explicitly handle NaN so only undefined/null becomes empty.

Copilot uses AI. Check for mistakes.
Comment on lines 121 to 123
value={editProps?.min || ""}
onChange={(e) => setEditProps({ ...editProps, min: parseInt(e.target.value) } as CustomProps)}
onChange={(e) => setEditProps({ ...editProps, min: e.target.value === "" ? undefined : parseInt(e.target.value) } as CustomProps)}
/>
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The new handler maps empty string to undefined, but parseInt(...) can still yield NaN for certain transient/invalid inputs (and it also truncates decimals / ignores exponent notation). Saving NaN here can later serialize to null and break min/max constraints. Consider using e.target.valueAsNumber (or Number(...)) and treating NaN as undefined; if you keep parseInt, pass an explicit radix.

Copilot uses AI. Check for mistakes.
Comment on lines 132 to 136
type="number"
required={fieldType.maxRequired}
value={editProps?.max || ""}
onChange={(e) => setEditProps({ ...editProps, max: parseInt(e.target.value) } as CustomProps)}
onChange={(e) => setEditProps({ ...editProps, max: e.target.value === "" ? undefined : parseInt(e.target.value) } as CustomProps)}
/>
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

value={editProps?.max || ""} has the same issue as min: it will display 0 (and NaN) as empty due to ||, which can confuse users and hide invalid state. Prefer a nullish fallback (??) and/or sanitize NaN before storing/displaying.

Copilot uses AI. Check for mistakes.
Comment on lines 133 to 136
required={fieldType.maxRequired}
value={editProps?.max || ""}
onChange={(e) => setEditProps({ ...editProps, max: parseInt(e.target.value) } as CustomProps)}
onChange={(e) => setEditProps({ ...editProps, max: e.target.value === "" ? undefined : parseInt(e.target.value) } as CustomProps)}
/>
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

Same parsing concern for max: parseInt(...) can produce NaN (or silently truncate) and that value will be persisted in editProps. Treat NaN as undefined (and consider valueAsNumber) to ensure you never save an invalid numeric constraint.

Copilot uses AI. Check for mistakes.
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.

The page crashes when creating a new custom attribute

2 participants