-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add default values for discount widgets, apply them on dropdown change #2207
Conversation
Original task is a bit changed, in discussion with @alexanderfc. Instead of preserving modified values for each possible discount field, its just need to reset it to default everytime a user changes offer or qualifier type. |
👀 |
const setType = (type: any) => { | ||
const defaultDiscountParams = _.find(props.descriptions, (item) => { | ||
if (item.type == type) return true; |
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.
Why?! I think it can be just return item.type == type
or even:
const defaultDiscountParams = _.find(props.descriptions, { type });
if (item.type == type) return true; | ||
}); | ||
const key = _.get(defaultDiscountParams, 'content[0].[1].name'); | ||
const value = _.get(defaultDiscountParams, 'content[0].[1].value', {}); | ||
props.onChange({ |
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.
I think we have to check if type
and key
are defined. Otherwise we can receive an onChange
with {null: {null: smth}}
payload.
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.
it's totally weird behavior -- using content[0][1] for business logic which aims to be a template. I'll prepare commit soon which fixes it
439f0ea
to
34c7599
Compare
discountChilds.push(<DiscountAttrs | ||
blockId={'promo-qualifier-block-' + index} | ||
dropdownId={'promo-qualifier-dd-' + index} | ||
const discountChildren = discounts.reduce ((acc, disc, index) => { |
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.
Extra space after reduce
, and probably we should use _.reduce
?
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 will be array for sure, so we can use native reduce method then
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.
https://jsperf.com/reduce-lodash-vs-underscore-js-vs-native
Very interesting results
instead of accessing to concrete item description in |
…m/highlander into bug/promotions-validation
Thx Andrey, @alexanderfc while I was testing @anru changes, I saw that promotion object fails to save in several offer types case. E.G. Discounted Shipping, Set Price shiping. Its same on stage. |
looks good, except excess |
fixed |
No description provided.