Skip to content

fix(platform): clear the product fields an edit empties - #4230

Merged
yannickmonney merged 1 commit into
mainfrom
fix/product-edit-clear-optional-fields
Oct 4, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
fix/product-edit-clear-optional-fields

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

What changed

When someone emptied a product's description, category, price, currency or stock in Edit product and chose Save, the dialog closed with a success toast but the old values stayed (#3615). The edit submit used the create dialog's omission rule: x.trim() || undefined, and a blank number became undefined. The write adapter (entityBody) drops undefined keys. The update door's patch rule (ProductInput) reads an omitted key as "unchanged" and null as "clear", so the door answered ok and kept every old value. The image's removal already sent null and worked.

product-edit-dialog.tsx is the only behaviour change:

  • Emptied means null. If a field opened with a value and is blank on Save, it goes out as null. The door already clears on null (the card's live control). The rule reads the form's own formState.defaultValues, which is what the editor opened with.

  • Untouched blank stays omitted. If a field opened blank and is still blank, it stays out of the patch, as before. Sending null for it would turn a no-op into a write that could undo a concurrent edit.

  • Zero is a value. A price or stock of 0 still goes out as 0.

  • No USD seed. The edit form used to seed USD into a product without a currency. That had two effects:

    • an untouched blank currency was saved as USD;
    • a cleared currency reopened as USD and was written back on the next save.

    The form now seeds the stored currency or blank. The field's placeholder still reads USD, and the table and details still display a missing currency as USD.

contract/products.ts: the update args take | null on the five fields. Their type was the create shape, so null could not be sent with types intact. The create dialog and its contract are untouched; #4198's create-dialog work is merged and not involved.

Decisions a reviewer may want to challenge

  1. "Emptied" is judged against what the editor opened with, not the live prop. Comparing with the current product prop would send null for a field someone else filled in while the dialog was open. The image keeps its existing || null (the card's control). It still sends null for an image that opened blank. That is a no-op except under a concurrent edit, and I left it out of this change.
  2. The currency seed is part of this fix. Without it, a currency clear does not survive: reopening shows USD, and the next unrelated save stamps it back. It also contradicted "unchanged fields stay omitted".

Out of scope

How I verified it

Exact head 53738010e, base main 96d3428e7. The branch merges cleanly with main 8a580fcc2.

Regression across the failing boundary. The new product-edit-dialog.wire.test.tsx runs the real dialog, useUpdateProduct, useBackendMutation, the products/mutations:updateProduct adapter row and backendFetch. Only fetch is answered, so each assertion reads the exact JSON body the door receives. I ran the final test file against main's dialog, then restored it.

case main 96d3428 this branch
empty all five → Save FAIL: body {"name":"Audit widget","imageUrl":null,"status":"active"} (the card's PRODUCT_CLEAR), and the editor still closed PASS: all five null, success toast, closed
empty one (stock) → Save FAIL: stock key missing PASS: stock: null, the rest unchanged
control: a field that opened blank stays out of the patch FAIL: currency: "USD" sent PASS: {name, imageUrl: null, status} only
control: price 0 and stock 0 PASS PASS
a cleared product reopens with the five fields blank FAIL: Currency reads USD PASS

Door and service legs. These pin existing correct behaviour, so they pass on main too:

  • routes.test.ts posts the exact emitted body to POST /products/:id. updateProduct receives every null unchanged.
  • service.test.ts extends the clearing case with stock and price (the five-field set was missing those two) and holds an omitted stock or price kept.

Suites on the exact head.

  • app/features/products (client project): 18 files, 112 tests passed. This includes the existing edit, CRUD, view and row-action suites.
  • backend/domains/products, app/lib/backend/engagement.test.ts and the single-failure-toast and error-message-description guards (server project): 7 files, 147 tests passed.

Gates on the changed files.

  • oxlint --type-aware: 0 diagnostics.
  • oxfmt --check: clean.
  • Scoped tsc --noEmit: exit 0. It covered the changed files plus mutations.ts, engagement.ts, use-backend-mutation.ts, product-view-dialog.tsx, product-row-actions.tsx, routes.ts and service.ts.
  • bun run lint:manual: ok.
  • integration-scope guard: passed.
  • Pre-commit: conflict markers, oxfmt and opengrep.

Manual layer: one reference/automation.md row, beside the product image row.

Not run here: the full platform suite, a whole-workspace tsc, browser and E2E, and backend:integration. CI runs those. No local stack either, so there is no PostgreSQL readback from this branch. The card's own control showed the running API clears all five fields on explicit null, and the backend is unchanged.

Closes #3615

Edit product sent an emptied description, category, price, currency or
stock as undefined. The write adapter dropped those keys, and the update
door read an omitted key as "unchanged", so it kept the old values while
the dialog showed success and closed. A field that opened with a value and
is blank on Save now goes out as null, which the door already clears on. A
field that opened blank stays out of the patch, and a price or stock of
zero still goes out as zero.

The edit form no longer seeds USD into a product without a currency.
Before, an untouched blank currency was saved as USD, and a currency
someone had cleared reopened as USD and was written back on the next save.
The update contract now allows null on the five fields. Create is
unchanged.

Closes #3615

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review: ACCEPT

Source: PR #4230 / TALE-160 / #3615, exact head 53738010e50c357eeea71ab0933ac6c030f62978, merge base 96d3428e7aef9fbe287944c62a751901c690a639. Head confirmed at start and immediately before posting.

Reviewer: agent #10 a0f9fd03-7af6-4c69-b602-755201d86f89, run 8835f554-eb8e-4bf7-8754-2d231b322e2d, TALE-557. Distinct from implementation agent #6 / run af5f4e7e-c44a-459d-812f-948be0b244e1. GitHub uses the same principal as the PR author, so this is an explicit independent ACCEPT record in a COMMENT review, not an attempted self-approval.

No blocking findings. The fix addresses the actual omission/null mismatch without changing create or backend patch semantics. The form's opening defaults distinguish deliberately emptied fields from initially blank fields; the string representation of zero remains truthy. Removing the USD seed is necessary for a cleared currency to stay cleared after reopening and an unrelated save.

Independently observed evidence

  • Existing dialog + new real-wire regression: 15/15 tests passed (2 files). The regression executes the actual dialog, mutation hook, adapter and backendFetch, not a mutation mock.
  • Product backend + engagement adapter: 72/72 tests passed (5 files), including route null forwarding and service omission/clearing controls.
  • Importers/numeric schema + reviewer-owned PostgreSQL proof: 36/36 tests passed (5 files), including 10 additional persistence cases. 123 targeted tests total, with one worker per invocation.
  • The reviewer proof runs the actual dialog → useUpdateProduct → useBackendMutation → adapter → backendFetch, bridges fetch to the actual Hono route and shared domain field schema, executes the actual updateProduct and SERIALIZABLE transaction, then compares a separate GET readback with a fresh SQL SELECT after commit.
  • Readback PASS: all five fields cleared together; each cleared separately while the other four retain their values; API omitted fields remain unchanged; fields that opened blank remain omitted and do not wipe a concurrent fill; zero is saved as zero and an opening zero can deliberately be cleared; the committed all-null product reopens blank and remains cleared after a subsequent name-only edit.
  • All 11 existing validation messages used by the edit form are nonempty in EN/DE/FR and DE-CH via the existing German fallback. No new UI strings are introduced.
  • Changed TypeScript files: oxfmt --check clean; scoped oxlint --type-aware exit 0; scoped tsc --noEmit exit 0, including adapter, hook, route/service and relevant consumers. No whole-workspace type check or whole-platform suite.

Proof boundaries and merge gate

The temporary cluster/database tale_557_review, PostgreSQL 15.18, is owned by this review (loopback port 56423, user review557, synthetic product prod-557). It uses a minimal products schema matching the storage types in migration 0014. Auth/session membership, audit/outbox and unused image/blob effects are stubbed; product update logic, validation, transactions and database reads/writes are real. This is an in-process route/database proof, not a browser or full deployed-stack test.

Initial Bun/shared-worktree startup issues, reviewer response-envelope mismatch, a 5-second reviewer-test timeout and missing scoped-config ambient declarations were corrected in the review harness; final runs above pass. Failure logs are retained. No PR source changes were needed.

Not run: browser, E2E, containers, full platform suite, full backend integration/migration suite, production tests or full authentication/audit/realtime paths. Existing #3617 null-price table presentation remains separate; no visual acceptance claim.

At 04:32Z, hosted checks are 2 success / 5 queued, with none rerun or cancelled. ACCEPT is a correctness review, not permission to bypass required CI. The author owns remaining CI repairs; TALE-359 owns subsequent merge/completion reconciliation. No merge, push or card move performed.

Evidence and reproduction source are retained in TALE-557's delivery box: /agent/output/cbd79690-f37a-4f96-a472-715ca0ddb8c9/ (client-tests-node.log, server-tests.log, readback-and-importers.log, reviewer readback test, scoped configs, locale check, lint/format/types logs and CI snapshot).

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.

Bug: Product edit silently discards clearing description, price, stock, currency and category

1 participant