Skip to content

Commit 83a8479

Browse files
fix(dashboard): coerce numeric quota values in parseSize
Address review feedback from gemini-code-assist on ResourceQuotasField.tsx: parseSize coerces val to a string first so a numeric quota from user-authored YAML (e.g. cpu: 10) no longer crashes the edit form with "val.endsWith is not a function". Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent fbbcc2e commit 83a8479

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎packages/system/dashboard/images/console/apps/console/src/components/ResourceQuotasField.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ const KNOWN_KEYS = new Set(KNOWN_ROWS.map((r) => r.key))
2525
// Accepts count/<resource> and extended resource patterns like <resource>.<group>
2626
const VALID_CUSTOM_KEY = /^(?:count\/[a-z0-9]([a-z0-9._-]*[a-z0-9])?|[a-z0-9]([a-z0-9._/-]*[a-z0-9])?)$/
2727

28-
function parseSize(val: string, units: readonly string[]): { num: string; unit: string } {
28+
function parseSize(val: string | number, units: readonly string[]): { num: string; unit: string } {
29+
// val can arrive as a number from user-authored YAML (e.g. `cpu: 10`)
30+
const valStr = String(val)
2931
// Match longest suffix first to avoid partial matches
3032
const sorted = [...units].sort((a, b) => b.length - a.length)
3133
for (const u of sorted) {
32-
if (val.endsWith(u)) return { num: val.slice(0, -u.length), unit: u }
34+
if (valStr.endsWith(u)) return { num: valStr.slice(0, -u.length), unit: u }
3335
}
3436
// Strip any trailing alphabetic chars so we don't corrupt data on save
35-
const numericPart = val.replace(/[A-Za-z]+$/, "")
36-
return { num: numericPart || val, unit: units[0] ?? "" }
37+
const numericPart = valStr.replace(/[A-Za-z]+$/, "")
38+
return { num: numericPart || valStr, unit: units[0] ?? "" }
3739
}
3840

3941
function formatSize(num: string, unit: string): string {

0 commit comments

Comments
 (0)