:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(workflows): make creating an email template quicker (#113833)
Meikel Ratz9ddc445be7fa
diff --git a/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx b/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsxindex d9d600830a1e..caa737b6b7e8 100644--- a/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx+++ b/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx@@ -132,9 +132,9 @@ export function MessageTemplate(props: MessageTemplateSceneLogicProps): JSX.ElemhtmlType="submit"form="template"onClick={submitTemplate}- loading={isTemplateSubmitting}+ loading={isTemplateSubmitting || templateLoading}disabledReason={- !templateChanged+ !templateChanged && props.id !== 'new'? 'No changes to save': !template.name? 'Name is required'diff --git a/products/workflows/frontend/TemplateLibrary/MessageTemplatesTable.tsx b/products/workflows/frontend/TemplateLibrary/MessageTemplatesTable.tsxindex 6a59e580210b..92ade950cab2 100644--- a/products/workflows/frontend/TemplateLibrary/MessageTemplatesTable.tsx+++ b/products/workflows/frontend/TemplateLibrary/MessageTemplatesTable.tsx@@ -4,7 +4,7 @@ import { useActions, useMountedLogic, useValues } from 'kea'import { router } from 'kea-router'import * as readingIsMagicPng from '@posthog/brand/hoggies/png/reading-is-magic'-import { IconTrash } from '@posthog/icons'+import { IconPlus, IconTrash } from '@posthog/icons'import { pngHoggie } from 'lib/brand/hoggies'import { MemberSelect } from 'lib/components/MemberSelect'@@ -13,9 +13,12 @@ import { More } from 'lib/lemon-ui/LemonButton/More'import { LemonInput } from 'lib/lemon-ui/LemonInput'import { LemonMenuOverlay } from 'lib/lemon-ui/LemonMenu/LemonMenu'import { Spinner } from 'lib/lemon-ui/Spinner'+import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'import MaxTool from 'scenes/max/MaxTool'import { urls } from 'scenes/urls'+import { AccessControlLevel, AccessControlResourceType } from '~/types'+import { MessageTemplateCard } from './MessageTemplateCard'import { messageTemplatesLogic } from './messageTemplatesLogic'import { newTemplateAgentLogic } from './newTemplateAgentLogic'@@ -30,6 +33,11 @@ export function MessageTemplatesTable(): JSX.Element {const { startNewTemplate } = useActions(newTemplateAgentLogic)const showProductIntroduction = !templatesLoading && templates.length === 0+ // Same check as the "New template" button in the header: the template API needs Editor access.+ const newTemplateDisabledReason = getAccessControlDisabledReason(+ AccessControlResourceType.Workflow,+ AccessControlLevel.Editor+ )return (<div className="templates-section" data-attr="message-templates-table">@@ -69,6 +77,28 @@ export function MessageTemplatesTable(): JSX.Element {<Spinner className="text-6xl" />) : (<div className="MessageTemplatesGrid">+ {!showProductIntroduction && (+ <button+ type="button"+ className={+ newTemplateDisabledReason+ ? 'MessageTemplateItem cursor-not-allowed'+ : 'MessageTemplateItem cursor-pointer'+ }+ onClick={startNewTemplate}+ disabled={!!newTemplateDisabledReason}+ title={newTemplateDisabledReason ?? undefined}+ data-attr="message-templates-new-card"+ >+ <div className="MessageTemplateItemInner flex flex-col items-center justify-center gap-2 rounded border border-dashed bg-surface-primary px-4 text-center text-secondary hover:text-primary">+ <IconPlus className="text-3xl" />+ <span className="font-semibold">New template</span>+ {newTemplateDisabledReason && (+ <span className="text-xs">{newTemplateDisabledReason}</span>+ )}+ </div>+ </button>+ )}{filteredTemplates.map((template, index) => (<MessageTemplateCardkey={template.id}diff --git a/products/workflows/frontend/TemplateLibrary/constants.ts b/products/workflows/frontend/TemplateLibrary/constants.tsindex d28173ae58aa..a1920c3fcebc 100644--- a/products/workflows/frontend/TemplateLibrary/constants.ts+++ b/products/workflows/frontend/TemplateLibrary/constants.ts@@ -2,14 +2,14 @@ import { MessageTemplate } from './types'export const NEW_TEMPLATE: MessageTemplate = {id: 'new',- name: '',+ name: 'Untitled email',description: '',content: {templating: 'liquid' as const,email: {from: '',to: '',- subject: '',+ subject: 'Hello from PostHog',html: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head>\n<!--[if gte mso 9]>\n<xml>\n <o:OfficeDocumentSettings>\n <o:AllowPNG/>\n <o:PixelsPerInch>96</o:PixelsPerInch>\n </o:OfficeDocumentSettings>\n</xml>\n<![endif]-->\n <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <meta name="x-apple-disable-message-reformatting" />\n <!--[if !mso]><!--><meta http-equiv="X-UA-Compatible" content="IE=edge" /><!--<![endif]-->\n <title></title>\n \n <style type="text/css">\n \n @media only screen and (min-width: 520px) \\{\n .u-row \\{\n width: 500px !important;\n }\n\n .u-row .u-col \\{\n vertical-align: top;\n }\n\n \n .u-row .u-col-100 \\{\n width: 500px !important;\n }\n \n }\n\n @media only screen and (max-width: 520px) \\{\n .u-row-container \\{\n max-width: 100% !important;\n padding-left: 0px !important;\n padding-right: 0px !important;\n }\n\n .u-row \\{\n width: 100% !important;\n }\n\n .u-row .u-col \\{\n display: block !important;\n width: 100% !important;\n min-width: 320px !important;\n max-width: 100% !important;\n }\n\n .u-row .u-col > div \\{\n margin: 0 auto;\n }\n\n\n}\n \nbody \\{\n margin: 0;\n padding: 0;\n}\n\ntable,\ntr,\ntd \\{\n vertical-align: top;\n border-collapse: collapse;\n}\n\np \\{\n margin: 0;\n}\n\n.ie-container table,\n.mso-container table \\{\n table-layout: fixed;\n}\n\n* \\{\n line-height: inherit;\n}\n\na[x-apple-data-detectors=\'true\'] \\{\n color: inherit !important;\n text-decoration: none !important;\n}\n\n\n\ntable, td \\{ color: #000000; } #u_body a \\{ color: #0000ee; text-decoration: underline; }\n </style>\n \n \n\n</head>\n\n<body class="clean-body u_body" style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #F7F8F9;color: #000000">\n <!--[if IE]><div class="ie-container"><![endif]-->\n <!--[if mso]><div class="mso-container"><![endif]-->\n <table id="u_body" style="border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;min-width: 320px;Margin: 0 auto;background-color: #F7F8F9;width:100%" cellpadding="0" cellspacing="0">\n <tbody>\n <tr style="vertical-align: top">\n <td style="word-break: break-word;border-collapse: collapse !important;vertical-align: top">\n <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" style="background-color: #F7F8F9;"><![endif]-->\n \n \n \n<div class="u-row-container" style="padding: 0px;background-color: transparent">\n <div class="u-row" style="margin: 0 auto;min-width: 320px;max-width: 500px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">\n <div style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">\n <!--[if (mso)|(IE)]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td style="padding: 0px;background-color: transparent;" align="center"><table cellpadding="0" cellspacing="0" border="0" style="width:500px;"><tr style="background-color: transparent;"><![endif]-->\n \n<!--[if (mso)|(IE)]><td align="center" width="500" style="width: 500px;padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;" valign="top"><![endif]-->\n<div class="u-col u-col-100" style="max-width: 320px;min-width: 500px;display: table-cell;vertical-align: top;">\n <div style="height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">\n <!--[if (!mso)&(!IE)]><!--><div style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;"><!--<![endif]-->\n \n<table style="font-family:arial,helvetica,sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">\n <tbody>\n <tr>\n <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;" align="left">\n \n <div style="font-size: 14px; line-height: 140%; text-align: left; word-wrap: break-word;">\n <p style="line-height: 140%;">Hello from PostHog!</p>\n </div>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style="font-family:arial,helvetica,sans-serif;" role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">\n <tbody>\n <tr>\n <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;" align="left">\n \n <!--[if mso]><style>.v-button \\{background: transparent !important;}</style><![endif]-->\n<div align="center">\n <!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://posthog.com/" style="height:37px; v-text-anchor:middle; width:112px;" arcsize="11%" stroke="f" fillcolor="#3AAEE0"><w:anchorlock/><center style="color:#FFFFFF;"><![endif]-->\n <a href="https://posthog.com/" target="_blank" class="v-button" style="box-sizing: border-box;display: inline-block;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #3AAEE0; border-radius: 4px;-webkit-border-radius: 4px; -moz-border-radius: 4px; width:auto; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;font-size: 14px;">\n <span style="display:block;padding:10px 20px;line-height:120%;">Learn more</span>\n </a>\n <!--[if mso]></center></v:roundrect><![endif]-->\n</div>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n <!--[if (!mso)&(!IE)]><!--></div><!--<![endif]-->\n </div>\n</div>\n<!--[if (mso)|(IE)]></td><![endif]-->\n <!--[if (mso)|(IE)]></tr></table></td></tr></table><![endif]-->\n </div>\n </div>\n </div>\n \n\n\n <!--[if (mso)|(IE)]></td></tr></table><![endif]-->\n </td>\n </tr>\n </tbody>\n </table>\n <!--[if mso]></div><![endif]-->\n <!--[if IE]></div><![endif]-->\n\n\n\n</body></html>',design: {body: {diff --git a/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.test.ts b/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.test.tsindex f8712dd9475e..f0596e88d22f 100644--- a/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.test.ts+++ b/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.test.ts@@ -79,21 +79,13 @@ describe('messageTemplateLogic', () => {})it.each([- {- missing: 'name',- prefill: { key: 'content.email.subject', value: 'Welcome' },- toast: 'Name is required',- },- {- missing: 'subject',- prefill: { key: 'name', value: 'Welcome email' },- toast: 'Subject is required',- },- ])('toasts when the $missing is missing', async ({ prefill, toast }) => {+ { missing: 'name', key: 'name', toast: 'Name is required' },+ { missing: 'subject', key: 'content.email.subject', toast: 'Subject is required' },+ ])('toasts when the $missing is missing', async ({ key, toast }) => {logic = messageTemplateLogic({ id: 'new' })logic.mount()- logic.actions.setTemplateValue(prefill.key, prefill.value)+ logic.actions.setTemplateValue(key, '')await expectLogic(logic, () => {logic.actions.submitTemplate()}).toDispatchActions(['submitTemplateFailure'])diff --git a/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.ts b/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.tsindex 8ffc9a303654..75cacfc134c8 100644--- a/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.ts+++ b/products/workflows/frontend/TemplateLibrary/messageTemplateLogic.ts@@ -504,12 +504,16 @@ export const messageTemplateLogic = kea<messageTemplateLogicType>([lemonToast.error('Failed to save template. Please try again.')},saveTemplateSuccess: async ({ template }) => {- lemonToast.success('Template saved')+ lemonToast.success(props.id === 'new' ? 'Template created' : 'Template saved')// Clear the unsaved-changes state before navigating so the beforeUnload guard// does not intercept the post-save redirect.actions.resetTemplate(template)actions.setOriginalTemplate(template)- template.id && router.actions.replace(urls.workflowsLibraryTemplate(template.id))+ if (props.id === 'new') {+ router.actions.push(urls.workflows('library'))+ } else if (template.id) {+ router.actions.replace(urls.workflowsLibraryTemplate(template.id))+ }actions.replayDeferredExternalEdit()},loadMessageSuccess: async ({ message }) => {