-
Notifications
You must be signed in to change notification settings - Fork 1
add buffer numeric text before canonicalizing it. #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import React from "react"; | ||
|
|
||
| interface NumberFieldProps | ||
| extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onchange'>{ | ||
| value : number | ||
| onCommit : (n:number) => void | ||
| fallback ?: number | ||
| allowNegative ? :boolean | ||
| } | ||
|
|
||
| export const NumberField : React.FC<NumberFieldProps> = ({ | ||
| value, onCommit, fallback, allowNegative | ||
| }) => { | ||
| const [draft,setDraft] = React.useState<string | null> (null) | ||
|
|
||
| const pattern = allowNegative ? /^-?\d*\.?\d*$/ : /^\d*\.?\d*$/; | ||
|
|
||
| const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const text = e.target.value | ||
| if(!pattern.test(text)) return | ||
| setDraft(text) | ||
| const n = Number(text) | ||
| if(text != '' && !isNaN(n)) onCommit(n); | ||
|
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate and inspect the file in question.
git ls-files src/components/ui/NumberField.tsx
wc -l src/components/ui/NumberField.tsx
cat -n src/components/ui/NumberField.tsx | sed -n '1,220p'Repository: iTeebot/flow Length of output: 1804 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find local usages of NumberField and inspect the call sites.
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
'NumberField' src
# Also inspect the component's immediate neighbors for context if any.
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
'onCommit\(|fallback|allowNegative|inputMode="decimal"' src/components src | sed -n '1,200p'Repository: iTeebot/flow Length of output: 3087 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Search for local call sites to understand whether Infinity would affect money/quantity flows.
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
'<NumberField|NumberField\\s*\\(' src
# Show surrounding lines for each hit.
for f in $(rg -l --hidden --glob '!node_modules' --glob '!dist' --glob '!build' \
'<NumberField|NumberField\\s*\\(' src); do
echo "===== $f ====="
cat -n "$f" | sed -n '1,240p'
doneRepository: iTeebot/flow Length of output: 263 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Probe the number semantics that drive the bug claim.
node - <<'JS'
const samples = [
'9'.repeat(307),
'9'.repeat(308),
'1e309',
'',
'123.45',
'-123',
'abc',
];
for (const s of samples) {
const n = Number(s);
console.log(JSON.stringify({s, n, isNaN: isNaN(n), finite: Number.isFinite(n)}));
}
JS
# Find every local reference to NumberField to understand impact.
rg -n --hidden --glob '!node_modules' --glob '!dist' --glob '!build' 'NumberField' srcRepository: iTeebot/flow Length of output: 1873 🏁 Script executed: #!/bin/bash
set -euo pipefail
node - <<'JS'
for (const len of [308, 309, 310, 320]) {
const s = '9'.repeat(len);
const n = Number(s);
console.log(len, String(n), Number.isFinite(n), isNaN(n));
}
JSRepository: iTeebot/flow Length of output: 247 Reject non-finite numeric values. 🤖 Prompt for AI Agents |
||
| } | ||
| const handleBlur = () =>{ | ||
| const n = Number(draft ?? '') | ||
| if( draft == '' || draft == null || isNaN(n)){ | ||
| if(fallback !== undefined){ | ||
| onCommit(fallback) | ||
| } | ||
| } | ||
|
|
||
| setDraft(null); | ||
| } | ||
|
|
||
| return( | ||
| <input | ||
| type="text" | ||
| inputMode="decimal" | ||
| onChange={handleChange} | ||
| onBlur={handleBlur} | ||
| value={draft ?? (value === 0 ? '' : String(value))} | ||
| /> | ||
|
|
||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import { CreateProductModal } from "../../components/modals/CreateProductModal"; | |
| import { CreateCustomerModal } from "../../components/modals/CreateCustomerModal"; | ||
| import { useUiStore } from "../../store/uiStore"; | ||
| import { Input } from "../../components/ui/Input"; | ||
| import { NumberField } from "../../components/ui/NumberField"; | ||
|
|
||
| type ChallanItem = { | ||
| product_id: number; | ||
|
|
@@ -442,10 +443,10 @@ export function CreateDeliveryChallanModule() { | |
| </div> | ||
| <div className="flex items-center gap-0 border border-border rounded-lg overflow-hidden bg-background"> | ||
| <button onClick={() => handleUpdateItemQty(item.product_id, -1)} className="h-6 w-6 flex items-center justify-center border-r border-border hover:bg-surface"><Minus className="h-2.5 w-2.5" /></button> | ||
| <input | ||
| value={item.quantity === 0 ? '' : item.quantity} | ||
| onChange={e => handleSetItemQty(item.product_id, Number(e.target.value))} | ||
| onBlur={() => { if (item.quantity < 1) handleSetItemQty(item.product_id, 1); }} | ||
| <NumberField | ||
| value={item.quantity} | ||
| onCommit={(n) => handleSetItemQty(item.product_id, n)} | ||
| fallback={1} | ||
|
Comment on lines
+446
to
+449
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Map the relevant files and inspect the shared component plus the caller.
git ls-files 'src/components/ui/NumberField.tsx' 'src/modules/deliveryChallan/CreateDeliveryChallanModule.tsx'
echo
echo '--- NumberField outline ---'
ast-grep outline src/components/ui/NumberField.tsx --view expanded || true
echo
echo '--- CreateDeliveryChallanModule outline (focused) ---'
ast-grep outline src/modules/deliveryChallan/CreateDeliveryChallanModule.tsx --view expanded | sed -n '1,220p'
echo
echo '--- NumberField source ---'
wc -l src/components/ui/NumberField.tsx
cat -n src/components/ui/NumberField.tsx
echo
echo '--- Caller lines around usage ---'
sed -n '430,470p' src/modules/deliveryChallan/CreateDeliveryChallanModule.tsxRepository: iTeebot/flow Length of output: 5341 Forward native input props in 🤖 Prompt for AI Agents |
||
| className="w-10 h-6 text-center text-[10px] font-black border-0 bg-transparent focus:ring-0" | ||
| /> | ||
| <button onClick={() => handleUpdateItemQty(item.product_id, 1)} className="h-6 w-6 flex items-center justify-center border-l border-border hover:bg-surface"><Plus className="h-2.5 w-2.5" /></button> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: iTeebot/flow
Length of output: 9237
🏁 Script executed:
Repository: iTeebot/flow
Length of output: 2746
Forward native input props from
NumberField. The component drops caller-supplied props because it never captures or spreads the rest ofReact.InputHTMLAttributes, sorequired,placeholder,className, and similar attributes never reach the DOM input.type="number"is also ignored because the field is hardcoded totype="text"for draft editing.src/components/ui/NumberField.tsx: fix the prop type omit to useonChange(notonchange), capture the remaining input props, and spread them onto<input />.typeprop explicit or remove it from callers that expect native number input behavior.📍 Affects 4 files
src/components/ui/NumberField.tsx#L3-L8(this comment)src/components/ui/NumberField.tsx#L11-L13src/components/ui/NumberField.tsx#L36-L43src/modules/deliveryChallan/CreateDeliveryChallanModule.tsx#L446-L449src/modules/inventory/InventoryModule.tsx#L236-L241src/modules/invoices/CreateInvoiceModule.tsx#L521-L524🤖 Prompt for AI Agents