-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fix: resolve strange behaviors in amount levels #7018
Conversation
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.
@JasonTheAdams Great work! Almost everything worked as expected, except for one little detail which I left a comment about.
As a note, this component isn't the same as FFM, it was copied, pasted, and adapted from there. The addon uses its own component as you can check here: https://github.com/impress-org/give-form-field-manager/blob/develop/src/FormExtension/FormBuilder/Blocks/components/OptionsPanel/index.tsx
src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/inspector/index.tsx
Show resolved
Hide resolved
@glaubersilva That's good to know for FFM. I mounted the |
@glaubersilva This is ready for review, again! |
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.
@JasonTheAdams I found a problem related to the components mounted on the window global object and left a comment with more details about it.
|
||
export {default as Header} from './header'; | ||
export {SecondarySidebar, Sidebar} from './sidebar'; | ||
|
||
export default function registerComponents() { | ||
window.givewp.form.components = window.givewp.form.components || {}; | ||
window.givewp.form.components.CurrencyControl = CurrencyControl; | ||
window.givewp.form.components.DraggableOptionsControl = Options; |
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.
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.
@glaubersilva I ended up removing the exporting of components as we're going to go about this a different way by introducing an NPM package of Form Builder components in a later PR.
@glaubersilva This is ready for review, again! |
src/FormBuilder/resources/js/form-builder/src/components/OptionsPanel/index.tsx
Show resolved
Hide resolved
@jonwaldstein This is ready for review again! |
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.
Looks good 👍
Passed manual QA tests. |
Description
The primary goal of this PR is to resolve this feedback: https://feedback.givewp.com/next-gen/p/donation-levels-should-obey-selections-and-deletions
In working on this, I also found that dragging options around would have a strange result if a lower amount value was moved above a high amount value — it was over-writing the moved amount.
Upon further inspection, I found there were two main issues at play:
<Draggable>
key was not guaranteed to map to the corresponding value/selection. Since the values can be dragged and deleted, the given row was not guaranteed uniqueness during the lifecycle of theOptionsList
component, and no value (index, value, selection) could guarantee this without causing too many re-renders.Options
component only has a singlesetOptions
callback, which is too vague. It can be triggered when any events occur (see list below). As such, thesetOptions
was trying to do too much and couldn't make any assumptions based on the event. So it was doing things like doubling the last option, even when an option was removed.On top of this, the
Option
component is used in many places (including FFM), and I didn't want to have to break backwards-compatibility.To handle the key issue, I added an optional
Option.id
property, which is assumed to be unique. If not present, it falls back on previous behavior. In the amount field I'm generating a unique integer for the id. I thought about having theOptions
component apply a unique id, but it's designed to be controlled, so the implementing component manages the options state.Next, I defined two new event props:
If these event props are used, they will be preferred in
Options
over thesetOptions
callback, given implementing components a more granular event, allowing them to assume that specific event won't triggersetOptions
. This helped to clean up the code and prevent some strange behaviors.Affects
Mostly the amount levels settings, but it does affect any setting using the
Options
component — though it should be backwards-compatible.Testing Instructions
Mess around with the amount levels. Add, remove, change values, drag-n-drop, and so forth. Make sure there are not strange or counter-intuitive behaviors.
Pre-review Checklist