fix(SDK-1284): persist 0 when an additional-earning field is cleared - #2649
Draft
krisxcrash wants to merge 1 commit into
Draft
fix(SDK-1284): persist 0 when an additional-earning field is cleared#2649krisxcrash wants to merge 1 commit into
krisxcrash wants to merge 1 commit into
Conversation
buildCompensationFromFormData skipped any fixed compensation whose form value was an empty string, so clearing a field dropped the entry from the payload entirely. The payroll update API leaves anything it is not sent untouched, so the previously saved amount survived: the box looked empty, the save appeared to succeed, and the old value came back on refetch. Typing an explicit 0 worked because that took the existing-compensation branch. An entry that already has a saved amount now resolves a cleared field to '0', so clearing behaves exactly like typing 0. Entries with no saved compensation stay omitted -- there is nothing to zero out. This also fixes the live gross-pay preview, which runs through the same builder, so the total now drops the moment the field is cleared instead of showing the stale amount. Note for reviewers: the ticket attributed this to the gws-flows NumberInput adapter forwarding NaN. That component is not on this path -- additional earnings render as TextInputField type="number", so the values are strings and the cause is entirely in this builder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes SDK-1284 (High, Pay v2 / RRoP Test Fest).
Correction to the ticket
The ticket attributes this to the gws-flows
NumberInputadapter forwardingNaN. That component is not on this path. Additional earnings render asTextInputField type="number" min={0}, so the values are strings andNumberInputnever enters the picture. No adapter change is needed; the cause is entirely in this component.Root cause
buildCompensationFromFormDatagated onformAmount !== '':A cleared field is
'', so the entry was skipped entirely and never added toupdatedFixedCompensations.PayrollEditEmployeethen spreads that object into thepayrollUpdate, so the API received afixed_compensationsarray with the entry absent — and the payroll update API leaves anything it is not sent untouched. The previously saved amount survived: the box looked empty, the save appeared to succeed, and the old value came back on refetch. That is exactly the reporter's "the pre and post are ultimately the same screenshot."Typing an explicit
0worked because that took theexistingFixedCompensationbranch and sentamount: "0".Nothing caught it client-side either: the field is marked
isRequired, but the schema isz.record(z.string(), z.string().optional()), so empty passes. (Field-levelrulesare ignored when a resolver is present, soisRequiredis presentational here.)Fix
An entry that already has a saved compensation now resolves a cleared field to
'0', so clearing behaves exactly like typing 0 — the path testers already know works. Entries with no saved compensation stay omitted; there is nothing to zero out.This also fixes the live gross-pay preview, which runs through the same builder, so the total drops the moment the field is cleared instead of showing the stale amount.
Testing
Two new cases in
PayrollEditEmployeePresentation.test.tsx, sitting next to the existing "submits existing compensations even when set to zero":amount: '0'and leaves Commission untouchednpx vitest run src/components/Payroll/PayrollEditEmployee— 70 pass. Both new tests also pass in isolation (-t), not just when an earlier test has warmed the i18n namespace.npm run tsc, eslint, prettier — clean.Merge note
SDK-1285 touches the same file and the same schema/builder block. Whichever of the two merges second needs a small rebase there.