Skip to content

: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.

fix(workflows): show block settings on select and guard the link dialog (#124702)

Meikel Ratz4f52fec5ddb7
diff --git a/frontend/src/scenes/hog-functions/email-templater/EmailTemplater.tsx b/frontend/src/scenes/hog-functions/email-templater/EmailTemplater.tsx
index 0d8638e7da28..b2f719f334d6 100644
--- a/frontend/src/scenes/hog-functions/email-templater/EmailTemplater.tsx
+++ b/frontend/src/scenes/hog-functions/email-templater/EmailTemplater.tsx
@@ -42,6 +42,7 @@ import { filterMessageTemplates } from 'products/workflows/frontend/TemplateLibr
import { MessageTemplateCard } from 'products/workflows/frontend/TemplateLibrary/MessageTemplateCard'
import { collapseToolsPanelCustomJs } from './custom-tools/collapseToolsPanel'
+import { linkDialogFocusCustomJs } from './custom-tools/linkDialogFocus'
import { previewLinkTargetCustomJs } from './custom-tools/previewLinkTarget'
import { unsubscribeLinkToolCustomJs } from './custom-tools/unsubscribeLinkTool'
import { EmailSenderSummary } from './EmailSenderSummary'
@@ -229,7 +230,7 @@ function DestinationEmailTemplaterForm({
// paid credits from our Unlayer workspace, so keep them all off.
ai: false,
},
- customJS: [previewLinkTargetCustomJs],
+ customJS: [previewLinkTargetCustomJs, linkDialogFocusCustomJs],
}}
/>
</div>
@@ -811,8 +812,13 @@ function NativeEmailTemplaterForm({
unsubscribeLinkToolCustomJs,
collapseToolsPanelCustomJs,
previewLinkTargetCustomJs,
+ linkDialogFocusCustomJs,
]
- : [unsubscribeLinkToolCustomJs, previewLinkTargetCustomJs],
+ : [
+ unsubscribeLinkToolCustomJs,
+ previewLinkTargetCustomJs,
+ linkDialogFocusCustomJs,
+ ],
fonts: unlayerEditorProjectId
? {
showDefaultFonts: true,
diff --git a/frontend/src/scenes/hog-functions/email-templater/custom-tools/collapseToolsPanel.ts b/frontend/src/scenes/hog-functions/email-templater/custom-tools/collapseToolsPanel.ts
index 55b6a3432e9c..f20fa770f236 100644
--- a/frontend/src/scenes/hog-functions/email-templater/custom-tools/collapseToolsPanel.ts
+++ b/frontend/src/scenes/hog-functions/email-templater/custom-tools/collapseToolsPanel.ts
@@ -1,8 +1,10 @@
/**
* Unlayer has no supported option to start with the right-hand tools panel collapsed
* (only `collapsible`), so this customJS runs inside the editor iframe and clicks the
- * panel's collapse toggle once on load. DOM-coupled by necessity: if unlayer renames
- * `.collapse-tools-panel-button`, the panel silently stays open (the retry loop bails
+ * panel's collapse toggle once on load. A collapsed panel also hides the selected block's
+ * properties, such as a button's link, so selecting a block opens the panel again.
+ * DOM-coupled by necessity: if unlayer renames `.collapse-tools-panel-button` or
+ * `.blockbuilder-layer-selected`, the panel silently stays as it is (the retry loop bails
* out after ~10s, nothing breaks).
*/
export const collapseToolsPanelCustomJs = `
@@ -18,7 +20,32 @@ export const collapseToolsPanelCustomJs = `
if (toggle) {
clearInterval(timer)
toggle.click()
+ openPanelOnSelect()
}
}, 250)
+
+ function openPanelOnSelect() {
+ var lastSelected = null
+ new MutationObserver(function () {
+ var selected = document.querySelector('.blockbuilder-layer-selected')
+ if (selected === lastSelected) {
+ return
+ }
+ lastSelected = selected
+ var toggle = document.querySelector('button.collapse-tools-panel-button.collapsed')
+ if (selected && toggle) {
+ // Opening the panel clears the selection, so select the block again to show its properties.
+ toggle.click()
+ setTimeout(function () {
+ // A block selected in the meantime is the newer choice, so keep it.
+ if (selected.isConnected && !document.querySelector('.blockbuilder-layer-selected')) {
+ ;['mousedown', 'mouseup', 'click'].forEach(function (type) {
+ selected.dispatchEvent(new MouseEvent(type, { bubbles: true, cancelable: true, view: window }))
+ })
+ }
+ }, 200)
+ }
+ }).observe(document.body, { subtree: true, attributes: true, attributeFilter: ['class'], childList: true })
+ }
})()
`
diff --git a/frontend/src/scenes/hog-functions/email-templater/custom-tools/linkDialogFocus.ts b/frontend/src/scenes/hog-functions/email-templater/custom-tools/linkDialogFocus.ts
new file mode 100644
index 000000000000..2160a83b45ac
--- /dev/null
+++ b/frontend/src/scenes/hog-functions/email-templater/custom-tools/linkDialogFocus.ts
@@ -0,0 +1,54 @@
+/**
+ * The link dialog only takes keyboard input in its fields. A click on the dimmed overlay or on
+ * the dialog outside its fields moves focus out of the URL field, and a second overlay click
+ * closes the dialog and puts the cursor in the email body, so a paste lands in the email.
+ * This customJS keeps focus in the dialog for those clicks and keeps an overlay click from
+ * closing it. It acts only on dialogs with a text field. Cancel, Save and Escape still close the dialog. Unlayer opens the dialog in its
+ * own modal or in a TinyMCE dialog, depending on the editor state. DOM-coupled by necessity:
+ * if unlayer renames those classes, clicks behave as before.
+ */
+export const linkDialogFocusCustomJs = `
+(function () {
+ var DIALOG = '.ReactModal__Overlay, .tox-dialog-wrap'
+ var CONTENT = '.ReactModal__Content > *, .tox-dialog'
+ var CONTROLS = 'input, textarea, select, button, a, [role="button"], [role="combobox"], [role="listbox"], [role="option"], [contenteditable="true"]'
+
+ var FIELDS = 'input:not([type="hidden"]), textarea'
+ var lastField = null
+
+ function guard(event) {
+ var target = event.target
+ var dialog = target && target.closest && target.closest(DIALOG)
+ if (!dialog || target.closest(CONTROLS)) {
+ return
+ }
+ // Only dialogs with a text field, so the preview and other modals still close on an overlay click.
+ var field = lastField && dialog.contains(lastField) ? lastField : dialog.querySelector(FIELDS)
+ if (!field) {
+ return
+ }
+ event.preventDefault()
+ if (!target.closest(CONTENT)) {
+ event.stopImmediatePropagation()
+ }
+ // The editor moves focus after this handler runs, so restore it once that has happened.
+ setTimeout(function () {
+ if (field && !(document.activeElement && document.activeElement.closest && document.activeElement.closest(CONTROLS))) {
+ field.focus()
+ }
+ }, 0)
+ }
+
+ document.addEventListener(
+ 'focusin',
+ function (event) {
+ if (event.target.closest && event.target.closest(DIALOG) && event.target.matches(FIELDS)) {
+ lastField = event.target
+ }
+ },
+ true
+ )
+ window.addEventListener('mousedown', guard, true)
+ window.addEventListener('click', guard, true)
+})()
+`