From 239258ffb996d626ccedcb521f3145b6211d0c5e Mon Sep 17 00:00:00 2001 From: Optio Agent Date: Fri, 24 Jul 2026 10:19:42 +0000 Subject: [PATCH] fix(logging): don't overwrite a contact's NULL power with 0 on edit A contact loaded without power arrives as JSON `null`. The edit-dialog submit guard only mapped `undefined`/'' to null, so `null` fell through to `Number(null) === 0` and rewrote the column from NULL to 0 on any save. That also defeated the export's COALESCE(c.tx_pwr, s.power_watts) station-power fallback. Treat null/undefined/blank/NaN uniformly as "clear to NULL". Co-Authored-By: Claude Opus 4.8 (1M context) --- src/components/EditContactDialog.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/EditContactDialog.tsx b/src/components/EditContactDialog.tsx index 221a7f9..82ee2d0 100644 --- a/src/components/EditContactDialog.tsx +++ b/src/components/EditContactDialog.tsx @@ -248,10 +248,16 @@ export default function EditContactDialog({ contact, isOpen, onClose, onSave, on body: JSON.stringify({ ...formData, datetime: formData.datetime ? new Date(formData.datetime).toISOString() : undefined, - // Blank power clears the field (null), not an empty string a numeric - // column would reject. + // Blank/absent power clears the field (null), not an empty string a + // numeric column would reject. `== null` catches both a cleared input + // (undefined/'') and a contact loaded with no power (JSON null) — the + // latter must stay null, not become Number(null) === 0, which would + // otherwise overwrite NULL with 0 and defeat the export's + // COALESCE(c.tx_pwr, s.power_watts) station-power fallback. tx_pwr: - formData.tx_pwr === undefined || (formData.tx_pwr as unknown) === '' + formData.tx_pwr == null || + (formData.tx_pwr as unknown) === '' || + Number.isNaN(Number(formData.tx_pwr)) ? null : Number(formData.tx_pwr), }),