-
Notifications
You must be signed in to change notification settings - Fork 8.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: Compare workflow reminder bodies to default template #19060
base: tasker-scan-workflow-templates
Are you sure you want to change the base?
feat: Compare workflow reminder bodies to default template #19060
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details:
|
…orkflow-templates
|
||
if (step && form.getValues(`steps.${step.stepNumber - 1}.template`) === WorkflowTemplates.REMINDER) { |
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.
This type of logic was repeated through out the component. I decided to abstract this to getTemplateBodyForAction
so it can be be used in other parts of the codebase
const templateBody = getWhatsappTemplateForAction(step.action, i18n.language, step.template, timeFormat); | ||
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, templateBody); | ||
if (step && !form.getValues(`steps.${step.stepNumber - 1}.emailSubject`)) { | ||
const subjectTemplate = emailReminderTemplate({ |
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.
Emails are the only one with subjects so keeping it as is
@@ -492,65 +484,6 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) { | |||
setIsEmailSubjectNeeded(true); | |||
} | |||
|
|||
if ( |
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.
Handled with getTemplateBodyForAction
@@ -95,3 +109,28 @@ export function getWhatsappTemplateForAction( | |||
const templateFunction = getWhatsappTemplateFunction(template); | |||
return templateFunction(true, locale, action, timeFormat); | |||
} | |||
|
|||
export function getTemplateBodyForAction({ |
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.
This function is used in WorkflowStepContainer
when changing the template or action. Also used in tasker to grab the default template
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 found that the workflow editor was adding HTML tags that weren't in the standard template. I decided that to compare if the workflow body was the same as the template is to stripe all of the HTML tags out of the reminder body and template and compare the content.
reminderBody: string; | ||
template: string; | ||
}) => { | ||
const stripHTML = (html: string) => html.replace(/<[^>]+>/g, "").replace(/&/g, "&"); |
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.
&
is encoded / not encoded between the editor and the template. Decided to keep both templates the same by adding &
@@ -79,3 +79,6 @@ const emailRatingTemplate = ({ | |||
}; | |||
|
|||
export default emailRatingTemplate; | |||
|
|||
export const plainTextTemplate = |
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.
For tests, it wouldn't make sense to strip the templates twice with the same function since it would always pass. By adding the plain text templates, we can detect whether the template was changed or something changed with the comparison function.
name?: string, | ||
isBrandingDisabled?: boolean | ||
) => { | ||
const emailReminderTemplate = ({ |
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.
Refactored this function to take in an object as a param for readability and to align with other template functions.
}); | ||
|
||
if ( | ||
compareReminderBodyToTemplate({ reminderBody: workflowStep.reminderBody, template: defaultTemplate }) |
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.
Only call Akismet for spam detection if the reminder body is not a default template
Stacked on #18822
What does this PR do?
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?