-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
feat: add unique handlebar helper #3717
Conversation
NV-2482 unique items in array helper in handlebars
If I send an array with duplicate items in payload and in email (or any other channel) editor, loop through this payload variable, all duplicate items will be considered. There should be a helper to consider only unique values (take duplicate values only once) related:- https://stackoverflow.com/a/23733207 David suggested to create process of adding new handlebar helpers easy for community. |
Pull reviewers statsStats of the last 30 days for novu:
|
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.
⭐
|
||
return array | ||
.map((item) => { | ||
if (item[property]) { |
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.
@jainpawan21 wdyt of also making it work for unique values of an array of strings?
|
||
return array | ||
.map((item) => { | ||
if (item[property]) { |
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.
If the object doesn't have that property we should handle it somehow
return array | ||
.map((item) => { | ||
if (item[property]) { | ||
return item[property]; | ||
} | ||
}) | ||
.filter((value, index, self) => self.indexOf(value) === 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.
If I am getting it right, we will return an array of only the property we filtered the distinct of. I feel we should return the whole object.
For example:
array: [{name:1,var:1},{name:1,var:1},{name:2,var:1}]
should return
[{name:1,var:1},{name:2,var:1}]`
instead of ['1','2']
what do you think?
feat: add unique handlebar helper
What change does this PR introduce?
unique
handlebar helper and its test.Why was this change needed?
To remove duplicates in array iteration
Other information (Screenshots)
Usage Example:-
Custom code
Input:-
HTML output:-
--Name 1----Name 2--