-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(cdp): Add mailgun destination #24137
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
83065de
Fixes
benjackwhite 16b9f33
Fix up choices
benjackwhite 1039d74
Fix up property mappings
benjackwhite 587ef25
Fix tests
benjackwhite 2ec589e
Updated to include the right events
benjackwhite 07c668d
Fixes
benjackwhite 2bc00d4
Merge branch 'master' into fix/cdp-customerio
benjackwhite a7af2af
Fixes
benjackwhite 62cb346
Merge branch 'fix/cdp-customerio' of github.com:PostHog/posthog into …
benjackwhite 17ac4d1
Fixes
benjackwhite 029bb9b
Fixes
benjackwhite 460c944
Fixed tests
benjackwhite 3794f72
Fix
benjackwhite 0fced3f
Fixes
benjackwhite b9aa75e
Update UI snapshots for `chromium` (1)
github-actions[bot] d758635
Update UI snapshots for `chromium` (1)
github-actions[bot] cbf6c53
Merge branch 'master' into fix/cdp-customerio
benjackwhite 6356a55
Added email templating
benjackwhite 6dafa21
Fixes
benjackwhite 2fc4fb5
Fixed validation
benjackwhite e29cd45
Updated values
benjackwhite f834cde
Fix templates
benjackwhite e7cbefa
Fixes
benjackwhite 16fa07f
Fixes
benjackwhite c90adaf
Merge branch 'master' into fix/cdp-customerio
benjackwhite 92a70d3
Merge branch 'fix/cdp-customerio' into feat/cdp-mailgun
benjackwhite a14f0e0
Fixes
benjackwhite 2df46dc
Fixes
benjackwhite 4461680
Merge branch 'fix/cdp-customerio' into feat/cdp-mailgun
benjackwhite 535fab6
Fixes
benjackwhite 0c93764
Merge branch 'master' into feat/cdp-mailgun
benjackwhite 83d1228
Fixes
benjackwhite b85a118
Added failing tests
benjackwhite ee75a7a
Merge branch 'master' into feat/cdp-mailgun
benjackwhite 9b8cf25
escape curlies in style/script tags in the generated HTML
mariusandra 297f5e7
Update UI snapshots for `chromium` (1)
github-actions[bot] 21bd63d
Merge branch 'master' into feat/cdp-mailgun
mariusandra c0cfb5d
Merge branch 'feat/cdp-mailgun' of github.com:PostHog/posthog into fe…
mariusandra 39a9ee9
Update UI snapshots for `chromium` (1)
github-actions[bot] b980a57
fix test
mariusandra 5db2a0e
Merge branch 'feat/cdp-mailgun' of github.com:PostHog/posthog into fe…
mariusandra 41f34fb
Update UI snapshots for `chromium` (1)
github-actions[bot] 6e79f6d
Update UI snapshots for `chromium` (1)
github-actions[bot] fd504e7
Update UI snapshots for `chromium` (1)
github-actions[bot] 467a7b8
Update UI snapshots for `chromium` (1)
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
frontend/src/scenes/pipeline/hogfunctions/email-templater/EmailTemplater.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { LemonButton, LemonLabel, LemonModal } from '@posthog/lemon-ui' | ||
import { useActions, useValues } from 'kea' | ||
import { Form } from 'kea-forms' | ||
import { LemonField } from 'lib/lemon-ui/LemonField' | ||
import { CodeEditorInline } from 'lib/monaco/CodeEditorInline' | ||
import { capitalizeFirstLetter } from 'lib/utils' | ||
import EmailEditor from 'react-email-editor' | ||
|
||
import { emailTemplaterLogic, EmailTemplaterLogicProps } from './emailTemplaterLogic' | ||
|
||
function EmailTemplaterForm({ | ||
mode, | ||
...props | ||
}: EmailTemplaterLogicProps & { | ||
mode: 'full' | 'preview' | ||
}): JSX.Element { | ||
const { setEmailEditorRef, emailEditorReady, setIsModalOpen } = useActions(emailTemplaterLogic(props)) | ||
|
||
return ( | ||
<Form | ||
className="flex flex-col border rounded overflow-hidden flex-1" | ||
logic={props.formLogic} | ||
props={props.formLogicProps} | ||
formKey={props.formKey} | ||
> | ||
{['from', 'to', 'subject'].map((field) => ( | ||
<LemonField | ||
key={field} | ||
name={`${props.formFieldsPrefix ? props.formFieldsPrefix + '.' : ''}${field}`} | ||
className="border-b shrink-0 gap-1 pl-2" | ||
// We will handle the error display ourselves | ||
renderError={() => null} | ||
> | ||
{({ value, onChange, error }) => ( | ||
<div className="flex items-center"> | ||
<LemonLabel className={error ? 'text-danger' : ''}> | ||
{capitalizeFirstLetter(field)} | ||
</LemonLabel> | ||
<CodeEditorInline | ||
embedded | ||
className="flex-1" | ||
globals={props.globals} | ||
value={value} | ||
onChange={onChange} | ||
/> | ||
</div> | ||
)} | ||
</LemonField> | ||
))} | ||
|
||
{mode === 'full' ? ( | ||
<EmailEditor ref={(r) => setEmailEditorRef(r)} onReady={() => emailEditorReady()} /> | ||
) : ( | ||
<LemonField | ||
name={`${props.formFieldsPrefix ? props.formFieldsPrefix + '.' : ''}html`} | ||
className="relative flex flex-col" | ||
> | ||
{({ value }) => ( | ||
<> | ||
<div className="absolute inset-0 p-2 flex items-end justify-center transition-opacity opacity-0 hover:opacity-100"> | ||
<div className="opacity-50 bg-bg-light absolute inset-0" /> | ||
<LemonButton type="primary" size="small" onClick={() => setIsModalOpen(true)}> | ||
Click to modify content | ||
</LemonButton> | ||
</div> | ||
|
||
<iframe srcDoc={value} className="flex-1" /> | ||
</> | ||
)} | ||
</LemonField> | ||
)} | ||
</Form> | ||
) | ||
} | ||
|
||
export function EmailTemplaterModal({ ...props }: EmailTemplaterLogicProps): JSX.Element { | ||
const { isModalOpen } = useValues(emailTemplaterLogic(props)) | ||
const { setIsModalOpen, onSave } = useActions(emailTemplaterLogic(props)) | ||
|
||
return ( | ||
<LemonModal isOpen={isModalOpen} width="90vw" onClose={() => setIsModalOpen(false)}> | ||
<div className="h-[80vh] flex"> | ||
<div className="flex flex-col flex-1"> | ||
<div className="shrink-0"> | ||
<h2>Editing email template</h2> | ||
</div> | ||
<EmailTemplaterForm {...props} mode="full" /> | ||
<div className="flex items-center mt-2 gap-2"> | ||
<div className="flex-1" /> | ||
<LemonButton onClick={() => setIsModalOpen(false)}>Cancel</LemonButton> | ||
<LemonButton type="primary" onClick={() => onSave()}> | ||
Save | ||
</LemonButton> | ||
</div> | ||
</div> | ||
</div> | ||
</LemonModal> | ||
) | ||
} | ||
|
||
export function EmailTemplater(props: EmailTemplaterLogicProps): JSX.Element { | ||
return ( | ||
<div className="flex flex-col flex-1"> | ||
<EmailTemplaterForm {...props} mode="preview" /> | ||
<EmailTemplaterModal {...props} /> | ||
</div> | ||
) | ||
} |
120 changes: 120 additions & 0 deletions
120
frontend/src/scenes/pipeline/hogfunctions/email-templater/emailTemplaterLogic.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { actions, connect, kea, listeners, LogicWrapper, path, props, reducers } from 'kea' | ||
import { capitalizeFirstLetter } from 'lib/utils' | ||
import { EditorRef as _EditorRef } from 'react-email-editor' | ||
|
||
import type { emailTemplaterLogicType } from './emailTemplaterLogicType' | ||
|
||
// Helping kea-typegen navigate the exported type | ||
export interface EditorRef extends _EditorRef {} | ||
|
||
export type EmailTemplate = { | ||
design: any | ||
html: string | ||
subject: string | ||
text: string | ||
from: string | ||
to: string | ||
} | ||
|
||
export interface EmailTemplaterLogicProps { | ||
formLogic: LogicWrapper | ||
formLogicProps: any | ||
formKey: string | ||
formFieldsPrefix?: string | ||
globals?: Record<string, any> | ||
} | ||
|
||
export const emailTemplaterLogic = kea<emailTemplaterLogicType>([ | ||
props({} as EmailTemplaterLogicProps), | ||
connect({ | ||
// values: [teamLogic, ['currentTeam'], groupsModel, ['groupTypes'], userLogic, ['hasAvailableFeature']], | ||
}), | ||
path(() => ['scenes', 'pipeline', 'hogfunctions', 'emailTemplaterLogic']), | ||
actions({ | ||
onSave: true, | ||
setEmailEditorRef: (emailEditorRef: EditorRef | null) => ({ emailEditorRef }), | ||
emailEditorReady: true, | ||
setIsModalOpen: (isModalOpen: boolean) => ({ isModalOpen }), | ||
}), | ||
reducers({ | ||
emailEditorRef: [ | ||
null as EditorRef | null, | ||
{ | ||
setEmailEditorRef: (_, { emailEditorRef }) => emailEditorRef, | ||
}, | ||
], | ||
isModalOpen: [ | ||
false, | ||
{ | ||
setIsModalOpen: (_, { isModalOpen }) => isModalOpen, | ||
}, | ||
], | ||
}), | ||
|
||
listeners(({ props, values, actions }) => ({ | ||
onSave: async () => { | ||
const editor = values.emailEditorRef?.editor | ||
if (!editor) { | ||
return | ||
} | ||
const data = await new Promise<any>((res) => editor.exportHtml(res)) | ||
|
||
// TRICKY: We have to build the action we need in order to nicely callback to the form field | ||
const setFormValue = props.formLogic.findMounted(props.formLogicProps)?.actions?.[ | ||
`set${capitalizeFirstLetter(props.formKey)}Value` | ||
] | ||
|
||
const pathParts = props.formFieldsPrefix ? props.formFieldsPrefix.split('.') : [] | ||
|
||
setFormValue(pathParts.concat('design'), data.design) | ||
setFormValue(pathParts.concat('html'), escapeHTMLStringCurlies(data.html)) | ||
|
||
// Load the logic and set the property... | ||
actions.setIsModalOpen(false) | ||
}, | ||
|
||
emailEditorReady: () => { | ||
const pathParts = (props.formFieldsPrefix ? props.formFieldsPrefix.split('.') : []).concat('design') | ||
|
||
let value = props.formLogic.findMounted(props.formLogicProps)?.values?.[props.formKey] | ||
|
||
// Get the value from the form and set it in the editor | ||
while (pathParts.length && value) { | ||
value = value[pathParts.shift()!] | ||
} | ||
|
||
if (value) { | ||
values.emailEditorRef?.editor?.loadDesign(value) | ||
} | ||
}, | ||
})), | ||
]) | ||
|
||
function escapeHTMLStringCurlies(htmlString: string): string { | ||
const parser = new DOMParser() | ||
const doc = parser.parseFromString(htmlString, 'text/html') | ||
|
||
function escapeCurlyBraces(text: string): string { | ||
return text.replace(/{/g, '\\{') | ||
} | ||
|
||
function processNode(node: Node): void { | ||
if (node.nodeType === Node.ELEMENT_NODE) { | ||
const element = node as HTMLElement | ||
if (element.tagName === 'STYLE' || element.tagName === 'SCRIPT') { | ||
element.textContent = escapeCurlyBraces(element.textContent || '') | ||
} else { | ||
Array.from(node.childNodes).forEach(processNode) | ||
} | ||
} else if (node.nodeType === Node.COMMENT_NODE) { | ||
const commentContent = (node as Comment).nodeValue || '' | ||
;(node as Comment).nodeValue = escapeCurlyBraces(commentContent) | ||
} | ||
} | ||
|
||
processNode(doc.head) | ||
processNode(doc.body) | ||
|
||
const serializer = new XMLSerializer() | ||
return serializer.serializeToString(doc) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
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 seems like a false positive. We're not trying to escape backslashes 🤷♂️. We're also doing all that the "show more details" text says to do for global matching, so dunno. Dismiss?