-
Notifications
You must be signed in to change notification settings - Fork 780
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
Added support for dynamicTemplateData #691
Conversation
@thinkingserious As we're on a time crunch, we published the new packages with this version to our private npm org and we'll be using it until this PR gets reviewed/merged. Hope its okay. |
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.
Thanks for the PR, it mostly looks good to me, just a few comments and recommendations, plus some code style issues to make sure we keep our code base consistent.
If you could look at these and make the necessary changes this should be good to go!
packages/helpers/classes/mail.js
Outdated
@@ -247,7 +273,7 @@ class Mail { | |||
) { | |||
throw new Error('Provide at least one of to, cc or bcc'); | |||
} | |||
this.addPersonalization(new Personalization({to, cc, bcc})); |
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.
The code style in this package doesn't use leading/trailing spaces after/before curly brackets, could you revert this change?
packages/helpers/classes/mail.js
Outdated
@@ -21,6 +21,7 @@ class Mail { | |||
constructor(data) { | |||
|
|||
//Initialize array and object properties | |||
this._isDynamic = false; |
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'm thinking just us this.isDynamic
for the flag, e.g. without the underscore.
packages/helpers/classes/mail.js
Outdated
} | ||
|
||
/** | ||
* Set substitutions |
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.
Fix comment to avoid confusion
@@ -8,10 +8,10 @@ const Mail = require('./mail'); | |||
/** | |||
* Tests | |||
*/ | |||
describe('Mail', function() { | |||
describe('Mail', function () { |
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.
Can you also undo these style corrections? Please respect the code style as indicated by the editor config and eslint config. If you enable ESLint in your editor it should automatically fix these issues.
/** | ||
* Reverse merge dynamic template data, preserving existing ones | ||
*/ | ||
reverseMergeDynamicTemplateData(dynamicTemplateData) { |
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.
Can we call this method deepMergeDynamicTemplateData
instead? I think that's what's happening here, so that description would be a bit clearer and a better fit imo.
} = this; | ||
|
||
//Initialize with mandatory values | ||
const json = {to}; | ||
const json = { to }; |
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.
Code style
@@ -0,0 +1,33 @@ | |||
'use strict'; |
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.
Can we use the existing and proven package deepmerge for this instead of rolling our own helper? From experience, this can be a tricky beast to get right, so I'd rather use an existing package which is being downloaded and used a lot, rather than try to replicate and have to maintain this part of the logic ourselves.
In particular merging of arrays can be tricky, which this package handles very flexibly.
@adamreisnz @mvpspl619 You both friggin rock! Thanks so much for your contributions here! |
@adamreisnz Can you take a look one more time? Sorry about the delay, I couldn't figure out why my VSCode kept overriding the trailingSpaces config, and then realized it was in my userSettings, so turned it off and voila. |
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.
Thanks for making the changes, looks good to me!
Hello @mvpspl619, |
Hey, may I ask what is dynamic templating and what's the difference between that and the standard "Transactional Templating"? |
@ron23 yes I think that's correct. See #221 (comment) for more information on what dynamic templates are (going to be). Essentially it adds support for handlebars style templates with additional templating language syntax, like loops and conditional statements etc. |
@ron23 Adam nailed it, I just wanted to add, we are running a beta of this right now, which is why/how Adam and Raju have access to this functionality and you don't yet. If you'd like to participate just drop me an email @ ben@sendgrid.com and include your username. Cheers! |
Thanks guys. But yea, this issue #221 totally explained everything. |
I cannot believe how long it took me to find this buried in the release notes. This info needs to be in the main READMEs. These dynamic transactional templates are apparently the default now, and I lost almost two hours tracking this down. |
I lost 3 hours looking for this |
It's great work from @mvpspl619, but it's pretty unfortunate that the maintainers here apparently do not require front-facing documentation to accompany new features. I'm happy to submit a PR which updates the docs if it will be accepted. Is there an explanation why |
FYI, here is a repost of the announcement made this morning: Hey all! Great news–– Dynamic content for Transactional Templates is here!This morning, our team publicly launched dynamic content for transactional templates. It is now available for all customers sending over v3 of our Mail Send API. Iterate over lists, handle conditionals and more, thanks to native support for a subset of Handlebars syntax! More information can be found in our blog post announcement. Documentation: Thank you, on behalf of the entire SendGrid team, for all of the feedback throughout the beta program. 🙌🏻 |
My apologies for the poor experience. I've created this issue and added it to our backlog to improve usability. Please feel free to add to that issue if you feel I missed anything. Thanks! With Best Regards, Elmer |
Fixes
Fixes #689
Checklist
Short description of what this PR does:
templateId
, and decides whether it is dynamic template or not. (Dynamic template ids start withd-
.substitutions
if thetemplateId
is for a dynamic templatedynamicTemplateData
in the mail object directly and merges withdynamicTemplateData
in eachpersonalization
object