Skip to content
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

Draft
wants to merge 11 commits into
base: tasker-scan-workflow-templates
Choose a base branch
from

Conversation

joeauyeung
Copy link
Contributor

@joeauyeung joeauyeung commented Feb 3, 2025

Stacked on #18822

What does this PR do?

  • Abstracts logic to get a workflow template body when passing the workflow action and template enum
  • For the scanning workflow body task, checks if the reminder body is the default template

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • In the workflow editing screen, change the action and template
    • The body should change
  • Trigger the scanning workflow body task on a step that has the default body and one that does not

Copy link

vercel bot commented Feb 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cal-com-ui-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2025 5:29pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Feb 3, 2025 5:29pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Feb 3, 2025 5:29pm

Copy link
Contributor

github-actions bot commented Feb 3, 2025

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:

No release type found in pull request title "Abstract getting workflow templates". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@keithwillcode keithwillcode added consumer core area: core, team members only labels Feb 3, 2025
@joeauyeung joeauyeung changed the title Abstract getting workflow templates refactor: Abstract getting workflow templates Feb 3, 2025
@joeauyeung joeauyeung changed the title refactor: Abstract getting workflow templates refactor: Compare workflow reminder bodies to default template Feb 3, 2025
@joeauyeung joeauyeung changed the title refactor: Compare workflow reminder bodies to default template feat: Compare workflow reminder bodies to default template Feb 3, 2025

if (step && form.getValues(`steps.${step.stepNumber - 1}.template`) === WorkflowTemplates.REMINDER) {
Copy link
Contributor Author

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({
Copy link
Contributor Author

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 (
Copy link
Contributor Author

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({
Copy link
Contributor Author

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

Copy link
Contributor Author

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(/&amp;/g, "&");
Copy link
Contributor Author

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 =
Copy link
Contributor Author

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 = ({
Copy link
Contributor Author

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 })
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consumer core area: core, team members only ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants