: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
fix(workflows): keep the shared messaging tabs inside the broadcasts page (#105744)
Daniel Marchukb81ad60c827f
diff --git a/frontend/src/products.tsx b/frontend/src/products.tsxindex beac6286daff..bd771be72825 100644--- a/frontend/src/products.tsx+++ b/frontend/src/products.tsx@@ -43,6 +43,7 @@ import type {import type { SourceSceneTab } from '../../products/data_warehouse/frontend/scenes/SourceScene/SourceScene'import { configurationRedirect, resolveSettingSlug } from '../../products/error_tracking/frontend/settingsRedirects'import type { InboxTabKey } from '../../products/signals/frontend/inbox/types'+import type { MessagingNavTabKey } from '../../products/workflows/frontend/messagingTabs'import type { WorkflowsSceneTab } from '../../products/workflows/frontend/WorkflowsScene'import {ActionType,@@ -294,6 +295,11 @@ export const productRoutes: Record<string, [string, string]> = {'workflowsLibraryTemplateFromMessage',],'/broadcasts': ['Broadcasts', 'broadcasts'],+ '/broadcasts/library': ['Broadcasts', 'broadcasts'],+ '/broadcasts/channels': ['Broadcasts', 'broadcasts'],+ '/broadcasts/opt-outs': ['Broadcasts', 'broadcasts'],+ '/broadcasts/suppression': ['Broadcasts', 'broadcasts'],+ '/broadcasts/reputation': ['Broadcasts', 'broadcasts'],'/broadcasts/new': ['Broadcast', 'broadcast'],'/broadcasts/:id': ['Broadcast', 'broadcast'],}@@ -1675,7 +1681,7 @@ export const productUrls = {workflowsLibraryTemplate: (id?: string): string => `/workflows/library/templates/${id}`,workflowsLibraryTemplateNew: (): string => '/workflows/library/templates/new',workflowsLibraryTemplateFromMessage: (id?: string): string => `/workflows/library/templates/new?messageId=${id}`,- broadcasts: (): string => '/broadcasts',+ broadcasts: (tab?: MessagingNavTabKey): string => `/broadcasts${tab ? `/${tab}` : ''}`,broadcast: (id: string): string => `/broadcasts/${id}`,broadcastNew: (): string => '/broadcasts/new',}diff --git a/products/workflows/frontend/Broadcasts/BroadcastsScene.tsx b/products/workflows/frontend/Broadcasts/BroadcastsScene.tsxindex 4106c6274a3b..65cc17c8e09d 100644--- a/products/workflows/frontend/Broadcasts/BroadcastsScene.tsx+++ b/products/workflows/frontend/Broadcasts/BroadcastsScene.tsx@@ -1,3 +1,6 @@+import { useValues } from 'kea'+import { router } from 'kea-router'+import { LemonButton } from '@posthog/lemon-ui'import { AccessControlAction } from 'lib/components/AccessControlAction'@@ -11,7 +14,8 @@ import { ProductKey } from '~/queries/schema/schema-general'import { AccessControlLevel, AccessControlResourceType } from '~/types'import { EmailSuspensionBanner } from '../EmailSuspensionBanner'-import { messagingNavTabs } from '../messagingTabs'+import { MessagingTabActions } from '../MessagingTabActions'+import { MESSAGING_NAV_TAB_KEYS, MessagingNavTabKey, messagingNavTabs } from '../messagingTabs'import { BroadcastsFeaturePreview } from './BroadcastsFeaturePreview'import { BroadcastsTable } from './BroadcastsTable'@@ -21,6 +25,13 @@ export const scene: SceneExport = {}export function BroadcastsScene(): JSX.Element {+ const { location } = useValues(router)+ // The tab routes are literal paths, so the tab is the last path segment rather than a route param.+ const lastSegment = location.pathname.split('/').pop() as MessagingNavTabKey+ const currentTab: MessagingNavTabKey | 'broadcasts' = MESSAGING_NAV_TAB_KEYS.includes(lastSegment)+ ? lastSegment+ : 'broadcasts'+return (<SceneContent><SceneTitleSection@@ -28,24 +39,39 @@ export function BroadcastsScene(): JSX.Element {description="Send a one-time or scheduled email to a group of people"resourceType={{ type: 'broadcasts' }}actions={- <AccessControlAction- resourceType={AccessControlResourceType.Workflow}- minAccessLevel={AccessControlLevel.Editor}- >- <LemonButton data-attr="new-broadcast" to={urls.broadcastNew()} type="primary" size="small">- New broadcast- </LemonButton>- </AccessControlAction>+ currentTab === 'broadcasts' ? (+ <AccessControlAction+ resourceType={AccessControlResourceType.Workflow}+ minAccessLevel={AccessControlLevel.Editor}+ >+ <LemonButton data-attr="new-broadcast" to={urls.broadcastNew()} type="primary" size="small">+ New broadcast+ </LemonButton>+ </AccessControlAction>+ ) : (+ <MessagingTabActions tab={currentTab} channelsUrl={urls.broadcasts('channels')} />+ )}/><EmailSuspensionBanner /><LemonTabs- activeKey="broadcasts"- tabs={[{ label: 'Broadcasts', key: 'broadcasts', link: urls.broadcasts() }, ...messagingNavTabs()]}+ activeKey={currentTab}+ tabs={[+ {+ label: 'Broadcasts',+ key: 'broadcasts',+ link: urls.broadcasts(),+ content: (+ <>+ <BroadcastsFeaturePreview />+ <BroadcastsTable />+ </>+ ),+ },+ ...messagingNavTabs((tab) => urls.broadcasts(tab)),+ ]}sceneInset/>- <BroadcastsFeaturePreview />- <BroadcastsTable /></SceneContent>)}diff --git a/products/workflows/frontend/Broadcasts/broadcastsRoutes.test.ts b/products/workflows/frontend/Broadcasts/broadcastsRoutes.test.tsnew file mode 100644index 000000000000..d61905473ee4--- /dev/null+++ b/products/workflows/frontend/Broadcasts/broadcastsRoutes.test.ts@@ -0,0 +1,50 @@+import { kea, path } from 'kea'+import { router, urlToAction } from 'kea-router'++import { productRoutes } from '~/products'+import { initKeaTests } from '~/test/init'++describe('broadcasts routes', () => {+ // The tab paths are literal segments under /broadcasts, and kea-router takes the first route that+ // matches. Listed after '/broadcasts/:id', a tab would open as a broadcast with that id.+ let resolvedScene: string | null = null++ const routeLogic = kea([+ path(['products', 'workflows', 'frontend', 'Broadcasts', 'broadcastsRoutesTest']),+ urlToAction(() =>+ Object.fromEntries(+ Object.entries(productRoutes)+ .filter(([route]) => route.startsWith('/broadcasts'))+ .map(([route, [scene]]) => [+ route,+ () => {+ resolvedScene = scene+ },+ ])+ )+ ),+ ])++ beforeEach(() => {+ resolvedScene = null+ initKeaTests(false)+ routeLogic.mount()+ })++ afterEach(() => routeLogic.unmount())++ it.each([+ ['/broadcasts', 'Broadcasts'],+ ['/broadcasts/library', 'Broadcasts'],+ ['/broadcasts/channels', 'Broadcasts'],+ ['/broadcasts/opt-outs', 'Broadcasts'],+ ['/broadcasts/suppression', 'Broadcasts'],+ ['/broadcasts/reputation', 'Broadcasts'],+ ['/broadcasts/new', 'Broadcast'],+ ['/broadcasts/01a05e5e-38c2-0000-b81a-21fe48581914', 'Broadcast'],+ ])('opens %s in the %s scene', (url, scene) => {+ router.actions.push(url)++ expect(resolvedScene).toBe(scene)+ })+})diff --git a/products/workflows/frontend/MessagingTabActions.tsx b/products/workflows/frontend/MessagingTabActions.tsxnew file mode 100644index 000000000000..c61891ba5d24--- /dev/null+++ b/products/workflows/frontend/MessagingTabActions.tsx@@ -0,0 +1,149 @@+import { useActions, useValues } from 'kea'++import { IconApple, IconAndroid, IconLetter, IconPlusSmall } from '@posthog/icons'+import { LemonButton, LemonMenu, LemonMenuItems } from '@posthog/lemon-ui'++import api from 'lib/api'+import { AccessControlAction } from 'lib/components/AccessControlAction'+import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'+import { FEATURE_FLAGS, TeamMembershipLevel } from 'lib/constants'+import { integrationsLogic } from 'lib/integrations/integrationsLogic'+import { IconSlack, IconTwilio } from 'lib/lemon-ui/icons'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { urls } from 'scenes/urls'++import { AccessControlLevel, AccessControlResourceType } from '~/types'++import type { MessagingNavTabKey } from './messagingTabs'+import { optOutCategoriesLogic } from './OptOuts/optOutCategoriesLogic'++/** The scene-header action for a shared messaging tab, the same on every surface that shows the tab. */+export function MessagingTabActions({+ tab,+ channelsUrl,+}: {+ tab: MessagingNavTabKey+ /** Where the Slack authorization flow returns to, so it lands back on the surface it left. */+ channelsUrl: string+}): JSX.Element | null {+ // One component per action, so a tab mounts (and loads) only the logic its own button needs.+ if (tab === 'library') {+ return <NewTemplateButton />+ }+ if (tab === 'channels') {+ return <NewChannelButton channelsUrl={channelsUrl} />+ }+ if (tab === 'opt-outs') {+ return <NewCategoryButton />+ }+ return null+}++function NewTemplateButton(): JSX.Element {+ return (+ <AccessControlAction+ resourceType={AccessControlResourceType.Workflow}+ minAccessLevel={AccessControlLevel.Editor}+ >+ <LemonButton+ data-attr="new-message-button"+ to={urls.workflowsLibraryTemplateNew()}+ type="primary"+ size="small"+ >+ New template+ </LemonButton>+ </AccessControlAction>+ )+}++function NewChannelButton({ channelsUrl }: { channelsUrl: string }): JSX.Element {+ const { featureFlags } = useValues(featureFlagLogic)+ const { openSetupModal } = useActions(integrationsLogic)+ const newChannelRestrictedReason = useRestrictedArea({+ scope: RestrictionScope.Project,+ minimumAccessLevel: TeamMembershipLevel.Admin,+ })++ const newChannelMenuItems: LemonMenuItems = [+ {+ label: (+ <div className="flex gap-1 items-center">+ <IconLetter /> Email+ </div>+ ),+ onClick: () => openSetupModal(undefined, 'email'),+ },++ {+ label: (+ <div className="flex gap-1 items-center">+ <IconSlack /> Slack+ </div>+ ),+ disableClientSideRouting: true,+ to: api.integrations.authorizeUrl({+ kind: 'slack',+ next: channelsUrl,+ }),+ },+ {+ label: (+ <div className="flex gap-1 items-center">+ <IconTwilio /> Twilio+ </div>+ ),+ onClick: () => openSetupModal(undefined, 'twilio'),+ },+ ...(featureFlags[FEATURE_FLAGS.WORKFLOWS_PUSH_NOTIFICATIONS]+ ? [+ {+ label: (+ <div className="flex gap-1 items-center">+ <IconAndroid /> Firebase Cloud Messaging+ </div>+ ),+ onClick: () => openSetupModal(undefined, 'firebase'),+ },+ {+ label: (+ <div className="flex gap-1 items-center">+ <IconApple /> Apple Push Notifications+ </div>+ ),+ onClick: () => openSetupModal(undefined, 'apns'),+ },+ ]+ : []),+ ]++ return (+ <LemonMenu items={newChannelMenuItems} matchWidth>+ <LemonButton+ data-attr="new-channel-button"+ icon={<IconPlusSmall />}+ size="small"+ type="primary"+ disabledReason={newChannelRestrictedReason}+ >+ New channel+ </LemonButton>+ </LemonMenu>+ )+}++function NewCategoryButton(): JSX.Element {+ const { openNewCategoryModal } = useActions(optOutCategoriesLogic)++ return (+ <LemonButton+ data-attr="new-optout-category"+ icon={<IconPlusSmall />}+ size="small"+ type="primary"+ onClick={() => openNewCategoryModal()}+ >+ New category+ </LemonButton>+ )+}diff --git a/products/workflows/frontend/WorkflowsScene.tsx b/products/workflows/frontend/WorkflowsScene.tsxindex 147dc5b6ed06..7aba15ff2148 100644--- a/products/workflows/frontend/WorkflowsScene.tsx+++ b/products/workflows/frontend/WorkflowsScene.tsx@@ -1,17 +1,10 @@import { MakeLogicType, actions, kea, path, props, reducers, selectors, useActions, useValues } from 'kea'import { urlToAction } from 'kea-router'-import { IconApple, IconAndroid, IconLetter, IconPlusSmall } from '@posthog/icons'-import { LemonButton, LemonMenu, LemonMenuItems } from '@posthog/lemon-ui'+import { LemonButton } from '@posthog/lemon-ui'-import api from 'lib/api'import { AccessControlAction } from 'lib/components/AccessControlAction'-import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'-import { FEATURE_FLAGS, TeamMembershipLevel } from 'lib/constants'-import { integrationsLogic } from 'lib/integrations/integrationsLogic'-import { IconSlack, IconTwilio } from 'lib/lemon-ui/icons'import { LemonTab, LemonTabs } from 'lib/lemon-ui/LemonTabs'-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { trackedActionToUrl } from 'lib/logic/scenes/trackedActionToUrl'import { addProductIntent } from 'lib/utils/product-intents'import { capitalizeFirstLetter } from 'lib/utils/strings'@@ -24,17 +17,12 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'import { ProductIntentContext, ProductKey } from '~/queries/schema/schema-general'import { AccessControlLevel, AccessControlResourceType, Breadcrumb } from '~/types'-import { MessageChannels } from './Channels/MessageChannels'import { EmailSuspensionBanner } from './EmailSuspensionBanner'import { workflowsEmptyState } from './emptyState/workflowsEmptyState'-import { MessagingNavTabKey, messagingNavTabs } from './messagingTabs'-import { optOutCategoriesLogic } from './OptOuts/optOutCategoriesLogic'-import { OptOutScene } from './OptOuts/OptOutScene'-import { SuppressionScene } from './Suppression/SuppressionScene'-import { MessageTemplatesTable } from './TemplateLibrary/MessageTemplatesTable'+import { MessagingTabActions } from './MessagingTabActions'+import { messagingNavTabs } from './messagingTabs'import { newWorkflowLogic } from './Workflows/newWorkflowLogic'import { NewWorkflowModal } from './Workflows/NewWorkflowModal'-import { WorkflowsReputation } from './Workflows/Reputation/WorkflowsReputation'import { WorkflowsTable } from './Workflows/WorkflowsTable'const WORKFLOW_SCENE_TABS = ['workflows', 'library', 'channels', 'opt-outs', 'suppression', 'reputation'] as const@@ -134,77 +122,9 @@ export const scene: SceneExport<WorkflowsSceneProps> = {emptyState: workflowsEmptyState,}-const MESSAGING_TAB_CONTENT: Record<MessagingNavTabKey, JSX.Element> = {- library: <MessageTemplatesTable />,- channels: <MessageChannels />,- 'opt-outs': <OptOutScene />,- suppression: <SuppressionScene />,- reputation: <WorkflowsReputation />,-}-export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {const { currentTab } = useValues(workflowsSceneLogic(props))- const { featureFlags } = useValues(featureFlagLogic)- const { openSetupModal } = useActions(integrationsLogic)- const { openNewCategoryModal } = useActions(optOutCategoriesLogic)const { startNewWorkflow } = useActions(newWorkflowLogic)- const newChannelRestrictedReason = useRestrictedArea({- scope: RestrictionScope.Project,- minimumAccessLevel: TeamMembershipLevel.Admin,- })-- const newChannelMenuItems: LemonMenuItems = [- {- label: (- <div className="flex gap-1 items-center">- <IconLetter /> Email- </div>- ),- onClick: () => openSetupModal(undefined, 'email'),- },-- {- label: (- <div className="flex gap-1 items-center">- <IconSlack /> Slack- </div>- ),- disableClientSideRouting: true,- to: api.integrations.authorizeUrl({- kind: 'slack',- next: urls.workflows('channels'),- }),- },- {- label: (- <div className="flex gap-1 items-center">- <IconTwilio /> Twilio- </div>- ),- onClick: () => openSetupModal(undefined, 'twilio'),- },- ...(featureFlags[FEATURE_FLAGS.WORKFLOWS_PUSH_NOTIFICATIONS]- ? [- {- label: (- <div className="flex gap-1 items-center">- <IconAndroid /> Firebase Cloud Messaging- </div>- ),- onClick: () => openSetupModal(undefined, 'firebase'),- },- {- label: (- <div className="flex gap-1 items-center">- <IconApple /> Apple Push Notifications- </div>- ),- onClick: () => openSetupModal(undefined, 'apns'),- },- ]- : []),- ]-const tabs: LemonTab<WorkflowsSceneTab>[] = [{label: 'Workflows',@@ -212,8 +132,7 @@ export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {content: <WorkflowsTable />,link: urls.workflows(),},- // Shared with the broadcasts scene; the content lives here because this is where they open.- ...messagingNavTabs().map((tab) => ({ ...tab, content: MESSAGING_TAB_CONTENT[tab.key] })),+ ...messagingNavTabs((tab) => urls.workflows(tab)),]return (@@ -247,44 +166,8 @@ export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {</LemonButton></AccessControlAction>)}- {currentTab === 'library' && (- <AccessControlAction- resourceType={AccessControlResourceType.Workflow}- minAccessLevel={AccessControlLevel.Editor}- >- <LemonButton- data-attr="new-message-button"- to={urls.workflowsLibraryTemplateNew()}- type="primary"- size="small"- >- New template- </LemonButton>- </AccessControlAction>- )}- {currentTab === 'channels' && (- <LemonMenu items={newChannelMenuItems} matchWidth>- <LemonButton- data-attr="new-channel-button"- icon={<IconPlusSmall />}- size="small"- type="primary"- disabledReason={newChannelRestrictedReason}- >- New channel- </LemonButton>- </LemonMenu>- )}- {currentTab === 'opt-outs' && (- <LemonButton- data-attr="new-optout-category"- icon={<IconPlusSmall />}- size="small"- type="primary"- onClick={() => openNewCategoryModal()}- >- New category- </LemonButton>+ {currentTab !== 'workflows' && (+ <MessagingTabActions tab={currentTab} channelsUrl={urls.workflows('channels')} />)}</>}diff --git a/products/workflows/frontend/messagingTabs.tsx b/products/workflows/frontend/messagingTabs.tsxindex 38386b5293cf..2af94d2ecedc 100644--- a/products/workflows/frontend/messagingTabs.tsx+++ b/products/workflows/frontend/messagingTabs.tsx@@ -1,21 +1,45 @@import { LemonTag } from '@posthog/lemon-ui'import { LemonTab } from 'lib/lemon-ui/LemonTabs'-import { urls } from 'scenes/urls'++import { MessageChannels } from './Channels/MessageChannels'+import { OptOutScene } from './OptOuts/OptOutScene'+import { SuppressionScene } from './Suppression/SuppressionScene'+import { MessageTemplatesTable } from './TemplateLibrary/MessageTemplatesTable'+import { WorkflowsReputation } from './Workflows/Reputation/WorkflowsReputation'++// pinned: URL path segments under /workflows and /broadcasts - renaming breaks bookmarks+export const MESSAGING_NAV_TAB_KEYS = ['library', 'channels', 'opt-outs', 'suppression', 'reputation'] as const+export type MessagingNavTabKey = (typeof MESSAGING_NAV_TAB_KEYS)[number]++export const MESSAGING_TAB_CONTENT: Record<MessagingNavTabKey, JSX.Element> = {+ library: <MessageTemplatesTable />,+ channels: <MessageChannels />,+ 'opt-outs': <OptOutScene />,+ suppression: <SuppressionScene />,+ reputation: <WorkflowsReputation />,+}/*** Sending setup that every messaging surface shares: templates, senders, and who may be sent to.- * Workflows renders these with their content; Broadcasts renders them as links back to it, so a- * sender or a suppression rule is one click away from either surface rather than only from one.+ * Each surface renders them under its own URL, so switching tabs never leaves the surface.*/-export type MessagingNavTabKey = 'library' | 'channels' | 'opt-outs' | 'suppression' | 'reputation'--export function messagingNavTabs(): LemonTab<MessagingNavTabKey>[] {+export function messagingNavTabs(linkFor: (tab: MessagingNavTabKey) => string): LemonTab<MessagingNavTabKey>[] {return [- { label: 'Library', key: 'library', link: urls.workflows('library') },- { label: 'Channels', key: 'channels', link: urls.workflows('channels') },- { label: 'Opt-outs', key: 'opt-outs', link: urls.workflows('opt-outs') },- { label: 'Suppression list', key: 'suppression', link: urls.workflows('suppression') },+ { label: 'Library', key: 'library', link: linkFor('library'), content: MESSAGING_TAB_CONTENT.library },+ { label: 'Channels', key: 'channels', link: linkFor('channels'), content: MESSAGING_TAB_CONTENT.channels },+ {+ label: 'Opt-outs',+ key: 'opt-outs',+ link: linkFor('opt-outs'),+ content: MESSAGING_TAB_CONTENT['opt-outs'],+ },+ {+ label: 'Suppression list',+ key: 'suppression',+ link: linkFor('suppression'),+ content: MESSAGING_TAB_CONTENT.suppression,+ },{label: (<>@@ -26,7 +50,8 @@ export function messagingNavTabs(): LemonTab<MessagingNavTabKey>[] {</>),key: 'reputation',- link: urls.workflows('reputation'),+ link: linkFor('reputation'),+ content: MESSAGING_TAB_CONTENT.reputation,},]}diff --git a/products/workflows/manifest.tsx b/products/workflows/manifest.tsxindex 7dd38c578925..07c5a39f80ba 100644--- a/products/workflows/manifest.tsx+++ b/products/workflows/manifest.tsx@@ -3,6 +3,7 @@ import { urls } from 'scenes/urls'import { ProductItemCategory, ProductKey } from '~/queries/schema/schema-general'import { FileSystemIconColor, ProductManifest } from '../../frontend/src/types'+import type { MessagingNavTabKey } from './frontend/messagingTabs'import type { WorkflowsSceneTab } from './frontend/WorkflowsScene'export const manifest: ProductManifest = {@@ -55,6 +56,12 @@ export const manifest: ProductManifest = {'workflowsLibraryTemplateFromMessage',],'/broadcasts': ['Broadcasts', 'broadcasts'],+ // Literal tab paths, listed before '/broadcasts/:id' so a tab never opens as a broadcast id.+ '/broadcasts/library': ['Broadcasts', 'broadcasts'],+ '/broadcasts/channels': ['Broadcasts', 'broadcasts'],+ '/broadcasts/opt-outs': ['Broadcasts', 'broadcasts'],+ '/broadcasts/suppression': ['Broadcasts', 'broadcasts'],+ '/broadcasts/reputation': ['Broadcasts', 'broadcasts'],// kea-router matches in declaration order, so the literal 'new' comes before ':id'.'/broadcasts/new': ['Broadcast', 'broadcast'],'/broadcasts/:id': ['Broadcast', 'broadcast'],@@ -68,7 +75,7 @@ export const manifest: ProductManifest = {workflowsLibraryTemplateNew: (): string => '/workflows/library/templates/new',workflowsLibraryTemplateFromMessage: (id?: string): string =>`/workflows/library/templates/new?messageId=${id}`,- broadcasts: (): string => '/broadcasts',+ broadcasts: (tab?: MessagingNavTabKey): string => `/broadcasts${tab ? `/${tab}` : ''}`,broadcast: (id: string): string => `/broadcasts/${id}`,broadcastNew: (): string => '/broadcasts/new',},