From fc00dd0c07a2bc2c0da2e08c859895caa57abe22 Mon Sep 17 00:00:00 2001 From: Ben White Date: Mon, 26 Aug 2024 08:44:11 +0100 Subject: [PATCH] feat(cdp): Added docs links for hog functions (#24545) --- frontend/src/lib/lemon-ui/Link/Link.tsx | 23 ++++++++-- .../hogfunctions/HogFunctionConfiguration.tsx | 8 ++++ .../hogfunctions/HogFunctionInputs.tsx | 45 ++++++++++++------- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/frontend/src/lib/lemon-ui/Link/Link.tsx b/frontend/src/lib/lemon-ui/Link/Link.tsx index 08a37f4366add..a8ce49710e678 100644 --- a/frontend/src/lib/lemon-ui/Link/Link.tsx +++ b/frontend/src/lib/lemon-ui/Link/Link.tsx @@ -1,7 +1,6 @@ import './Link.scss' import clsx from 'clsx' -import { useActions } from 'kea' import { router } from 'kea-router' import { isExternalLink } from 'lib/utils' import { getCurrentTeamId } from 'lib/utils/getAppContext' @@ -96,8 +95,6 @@ export const Link: React.FC> = Reac href: typeof to === 'string' ? to : undefined, }) - const { openSidePanel } = useActions(sidePanelStateLogic) - const onClick = (event: React.MouseEvent): void => { if (event.metaKey || event.ctrlKey) { event.stopPropagation() @@ -111,8 +108,26 @@ export const Link: React.FC> = Reac return } - if (typeof to === 'string' && isPostHogComDocs(to)) { + const mountedSidePanelLogic = sidePanelStateLogic.findMounted() + + if (typeof to === 'string' && isPostHogComDocs(to) && mountedSidePanelLogic) { + // TRICKY: We do this instead of hooks as there is some weird cyclic issue in tests + const { sidePanelOpen } = mountedSidePanelLogic.values + const { openSidePanel } = mountedSidePanelLogic.actions + event.preventDefault() + + const target = event.currentTarget + const container = document.getElementsByTagName('main')[0] + const topBar = document.getElementsByClassName('TopBar3000')[0] + if (!sidePanelOpen && container.contains(target)) { + setTimeout(() => { + // Little delay to allow the rendering of the side panel + const y = container.scrollTop + target.getBoundingClientRect().top - topBar.clientHeight + container.scrollTo({ top: y }) + }, 50) + } + openSidePanel(SidePanelTab.Docs, to) return } diff --git a/frontend/src/scenes/pipeline/hogfunctions/HogFunctionConfiguration.tsx b/frontend/src/scenes/pipeline/hogfunctions/HogFunctionConfiguration.tsx index a1a055618386a..6057a4c81c91e 100644 --- a/frontend/src/scenes/pipeline/hogfunctions/HogFunctionConfiguration.tsx +++ b/frontend/src/scenes/pipeline/hogfunctions/HogFunctionConfiguration.tsx @@ -326,6 +326,14 @@ export function HogFunctionConfiguration({ templateId, id }: { templateId?: stri Hide source code + + This is the underlying Hog code that will run whenever the + filters match.{' '} + + See the docs + {' '} + for more info + ) : undefined} - {showSource ? ( - <> - - inputs.{schema.key} - -
- } - onClick={() => setEditing(true)} - /> - - ) : null} + {showSource && ( + + inputs.{schema.key} + + )} +
+ + {supportsTemplating && ( + } + noPadding + className=" opacity-0 group-hover:opacity-100 p-1 transition-opacity" + > + Supports templating + + )} + {showSource && ( + } + onClick={() => setEditing(true)} + /> + )}
{value?.secret ? (