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.

chore(hog-functions): thread returnTo through HogFunctionList (#59988)

Rafael Audibertdf1e1f7e9828
diff --git a/frontend/src/scenes/hog-functions/list/HogFunctionsList.test.ts b/frontend/src/scenes/hog-functions/list/HogFunctionsList.test.ts
new file mode 100644
index 000000000000..125fe83445e6
--- /dev/null
+++ b/frontend/src/scenes/hog-functions/list/HogFunctionsList.test.ts
@@ -0,0 +1,25 @@
+import { HogFunctionType } from '~/types'
+
+import { urlForHogFunction } from './HogFunctionsList'
+
+const makeFn = (id: string): HogFunctionType => ({ id }) as HogFunctionType
+
+describe('urlForHogFunction', () => {
+ it('returns the bare hog function path when returnTo is undefined', () => {
+ expect(urlForHogFunction(makeFn('abc123'))).toBe('/functions/abc123')
+ })
+
+ it('appends returnTo as a query param for a hog function id', () => {
+ expect(urlForHogFunction(makeFn('abc123'), '/health/sdk-doctor')).toBe(
+ '/functions/abc123?returnTo=%2Fhealth%2Fsdk-doctor'
+ )
+ })
+
+ it('does not append returnTo for plugin- prefix IDs', () => {
+ expect(urlForHogFunction(makeFn('plugin-7'), '/health/sdk-doctor')).toBe('/pipeline/plugins/7')
+ })
+
+ it('does not append returnTo for batch-export- prefix IDs', () => {
+ expect(urlForHogFunction(makeFn('batch-export-9'), '/health/sdk-doctor')).toBe('/pipeline/batch-exports/9')
+ })
+})
diff --git a/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx b/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
index 282de17fb02e..59595c6d6100 100644
--- a/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
+++ b/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
@@ -1,5 +1,5 @@
import { BindLogic, useActions, useValues } from 'kea'
-import { router } from 'kea-router'
+import { combineUrl, router } from 'kea-router'
import { useCallback, useMemo } from 'react'
import { IconBell } from '@posthog/icons'
@@ -90,14 +90,17 @@ function NotificationContextTag({ hogFunction }: { hogFunction: HogFunctionType
)
}
-const urlForHogFunction = (hogFunction: HogFunctionType): string => {
+// `returnTo` only applies to the canonical hog-function path; legacy plugin and
+// batch-export scenes don't read it.
+export const urlForHogFunction = (hogFunction: HogFunctionType, returnTo?: string): string => {
if (hogFunction.id.startsWith('plugin-')) {
return urls.legacyPlugin(hogFunction.id.replace('plugin-', ''))
}
if (hogFunction.id.startsWith('batch-export-')) {
return urls.batchExport(hogFunction.id.replace('batch-export-', ''))
}
- return urls.hogFunction(hogFunction.id)
+ const path = urls.hogFunction(hogFunction.id)
+ return returnTo ? combineUrl(path, { returnTo }).url : path
}
export function HogFunctionList({
@@ -106,6 +109,7 @@ export function HogFunctionList({
emptyText,
onDeleteHogFunction,
onEditHogFunction,
+ returnTo,
...props
}: HogFunctionListLogicProps & {
extraControls?: JSX.Element
@@ -113,6 +117,7 @@ export function HogFunctionList({
emptyText?: string
onDeleteHogFunction?: (hogFunction: HogFunctionType) => void
onEditHogFunction?: (hogFunction: HogFunctionType) => void
+ returnTo?: string
}): JSX.Element {
const { loading, filteredHogFunctions, filters, hogFunctions, hiddenHogFunctions } = useValues(
hogFunctionsListLogic(props)
@@ -152,7 +157,7 @@ export function HogFunctionList({
render: (_, hogFunction) => {
return (
<LemonTableLink
- to={urlForHogFunction(hogFunction)}
+ to={urlForHogFunction(hogFunction, returnTo)}
onClick={onEditHogFunction ? () => onEditHogFunction(hogFunction) : undefined}
title={
<>
@@ -239,7 +244,7 @@ export function HogFunctionList({
// TRICKY: Hack for now to just link out to the full view
{
label: 'View & configure',
- to: urlForHogFunction(hogFunction),
+ to: urlForHogFunction(hogFunction, returnTo),
},
]
: [
@@ -295,6 +300,7 @@ export function HogFunctionList({
isManualFunction,
onDeleteHogFunction,
onEditHogFunction,
+ returnTo,
]) // oxlint-disable-line react-hooks/exhaustive-deps
return (