Fix: prevent duplicate donation amount levels from selecting together#8236
Fix: prevent duplicate donation amount levels from selecting together#8236pramodjodhani wants to merge 8 commits into
Conversation
When two or more amount levels shared the same value, selection was derived directly from `level.value === amount`, so clicking one level highlighted every level with that value. This made it impossible to distinguish which duplicate level the donor actually chose. To solve this problem: 1. Added `checked` key to the `levels` array returned by ConvertDonationAmountBlockToFieldsApi::prepareLevelsArray(). 2. In DonationAmountLevels, use the `checked` flag to determine the selected level index. 3. In DonationAmountLevels, use a `getSelectedLevelIndex` helper that resolves the active level. It prefers the level flagged as `checked` in the form builder (the configured default) only when that level's value matches the current amount, and otherwise selects a level only when exactly one matches — avoiding an ambiguous highlight across duplicates.
|
Great and thanks for your help |
glaubersilva
left a comment
There was a problem hiding this comment.
@pramodjodhani In general, the code looks good and is working well, but there is a file in this PR that seems to have been added by accident, so please remove it before we move forward to QA.
glaubersilva
left a comment
There was a problem hiding this comment.
@pramodjodhani Nice work! Ready for QA.
|
@pramodjodhani @glaubersilva FYI we're moving to |
|
Thank you so much for your great service |
…unts in V3 forms - Add a hidden 'levelId' field to the 'donationAmount' Fields API group - Set and update the 'levelId' form value in index.tsx when preset options are selected or custom amounts are entered - Add a $levelId property to DonateControllerData and map it to Donation models during V3 form checkout - Correct the array search logic in UpdateDonationLevelId.php listener to properly handle the associative levels schema - Update give_get_donation_form_title to look up option values by level ID (price_id) first before falling back to amount-based matching - Add unit tests for the UpdateDonationLevelId listener
|
@glaubersilva Victor found a issue during QA (correct label not showing in the email). I fixed it in the latest commit. Can you please review that? |
|
@pramodjodhani The code looks good. Just remember to add the |
|
@glaubersilva My bad! This is corrected now |
|
@pramodjodhani Sorry, I think my last comment wasn't clear. I was talking more about the changes made on this commit: Fix: prevent duplicate donation amount levels from selecting together by pramodjodhani · Pull Request #8236 · impress-org/givewp For example, there are no |
|
Thanks for clarification @glaubersilva. I have added the |
|
@pramodjodhani Thanks for the changes! It's all good. Ready for another QA round. |
Resolves #SMTNC-294
Description
When two or more amount levels shared the same value, selection was derived directly from
level.value === amount, so clicking one level highlighted every level with that value. This made it impossible to distinguish which duplicate level the donor actually chose.To solve this problem:
checkedkey to thelevelsarray returned by ConvertDonationAmountBlockToFieldsApi::prepareLevelsArray().checkedflag to determine the selected level index.getSelectedLevelIndexhelper that resolves the active level. It prefers the level flagged ascheckedin the form builder (the configured default) only when that level's value matches the current amount, and otherwise selects a level only when exactly one matches — avoiding an ambiguous highlight across duplicates.Visuals
https://www.loom.com/share/27722b6ba37142d0b1683497e3655e7e
Testing Instructions
Pre-review Checklist
@unreleasedtags included in DocBlocks