: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
feat(workflows): regroup the workflows tabs behind a flag (#113834)
Meikel Ratz9c0f5cbfcef2
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 8a6f2bdfb982..90bdbed4e7ed 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -636,6 +636,7 @@ export const FEATURE_FLAGS = {WORKFLOWS_INTERNAL_EVENT_FILTERS: 'workflows-internal-event-filters', // owner: @haven #team-workflowsWORKFLOWS_ISP_SENDING_HEALTH: 'workflows-isp-sending-health', // owner: #team-workflowsWORKFLOWS_LINEAR_VIEW: 'workflows-linear-view', // owner: #team-workflows+ WORKFLOWS_NEW_NAVIGATION: 'workflows-new-navigation', // owner: #team-workflows, groups the workflows tabs into Workflows, Templates and MessagingWORKFLOWS_PUSH_NOTIFICATIONS: 'workflows-push-notifications', // owner: #team-workflowsWORKFLOWS_TRIGGER_VOLUME_ESTIMATE: 'workflows-trigger-volume-estimate', // owner: @mayteio #team-workflowsXAA_AUTHENTICATION: 'xaa-authentication', // owner: @reecejones #team-platform-featuresdiff --git a/products/workflows/backend/models/hog_flow/hog_flow.py b/products/workflows/backend/models/hog_flow/hog_flow.pyindex 8802b946338b..071bdae91ca8 100644--- a/products/workflows/backend/models/hog_flow/hog_flow.py+++ b/products/workflows/backend/models/hog_flow/hog_flow.py@@ -82,8 +82,8 @@ BILLABLE_ACTION_TYPES: Final[set[str]] = {# Action types that send a message to a person. A workflow containing at least one of these is a# "messaging" workflow; everything else is an "automation". Keep in sync with the frontend's-# WorkflowTypeTag (products/workflows/frontend/Workflows/WorkflowsTable.tsx), which renders the-# same split, and the list API's `type` filter, which queries on it.+# MESSAGING_ACTION_TYPES (products/workflows/frontend/Workflows/workflowTypeFilters.ts), which the list's+# type tag and the template type filter use, and the list API's `type` filter, which queries on it.MESSAGING_ACTION_TYPES: Final[list[str]] = ["function_email","function_sms",diff --git a/products/workflows/frontend/Broadcasts/BroadcastsScene.tsx b/products/workflows/frontend/Broadcasts/BroadcastsScene.tsxindex bfdca806835a..04155fe2b456 100644--- a/products/workflows/frontend/Broadcasts/BroadcastsScene.tsx+++ b/products/workflows/frontend/Broadcasts/BroadcastsScene.tsx@@ -4,7 +4,9 @@ import { router } from 'kea-router'import { LemonButton } from '@posthog/lemon-ui'import { AccessControlAction } from 'lib/components/AccessControlAction'+import { FEATURE_FLAGS } from 'lib/constants'import { LemonTabs } from 'lib/lemon-ui/LemonTabs'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { SceneExport } from 'scenes/sceneTypes'import { urls } from 'scenes/urls'@@ -14,8 +16,15 @@ import { ProductKey } from '~/queries/schema/schema-general'import { AccessControlLevel, AccessControlResourceType } from '~/types'import { EmailSuspensionBanner } from '../EmailSuspensionBanner'+import { MessagingSetup } from '../MessagingSetup'import { MessagingTabActions } from '../MessagingTabActions'-import { MESSAGING_NAV_TAB_KEYS, MessagingNavTabKey, messagingNavTabs } from '../messagingTabs'+import {+ MESSAGING_NAV_TAB_KEYS,+ MESSAGING_TAB_CONTENT,+ MessagingNavTabKey,+ isMessagingSetupTab,+ messagingNavTabs,+} from '../messagingTabs'import { BroadcastsFeaturePreview } from './BroadcastsFeaturePreview'import { BroadcastsTable } from './BroadcastsTable'import { newBroadcastAgentLogic } from './newBroadcastAgentLogic'@@ -33,6 +42,20 @@ export function BroadcastsScene(): JSX.Element {const currentTab: MessagingNavTabKey | 'broadcasts' = MESSAGING_NAV_TAB_KEYS.includes(lastSegment)? lastSegment: 'broadcasts'+ const { featureFlags } = useValues(featureFlagLogic)+ const newNavigationEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_NEW_NAVIGATION]++ const broadcastsTab = {+ label: 'Broadcasts',+ key: 'broadcasts' as const,+ link: urls.broadcasts(),+ content: (+ <>+ <BroadcastsFeaturePreview />+ <BroadcastsTable />+ </>+ ),+ }return (<SceneContent>@@ -61,24 +84,38 @@ export function BroadcastsScene(): JSX.Element {}/><EmailSuspensionBanner />- <LemonTabs- activeKey={currentTab}- tabs={[- {- label: 'Broadcasts',- key: 'broadcasts',- link: urls.broadcasts(),- content: (- <>- <BroadcastsFeaturePreview />- <BroadcastsTable />- </>- ),- },- ...messagingNavTabs((tab) => urls.broadcasts(tab)),- ]}- sceneInset- />+ {newNavigationEnabled ? (+ <LemonTabs<'broadcasts' | 'library' | 'messaging-setup'>+ activeKey={currentTab === 'broadcasts' || currentTab === 'library' ? currentTab : 'messaging-setup'}+ tabs={[+ broadcastsTab,+ {+ label: 'Templates',+ key: 'library',+ link: urls.broadcasts('library'),+ content: MESSAGING_TAB_CONTENT.library,+ },+ {+ label: 'Messaging',+ key: 'messaging-setup',+ link: urls.broadcasts('channels'),+ content: (+ <MessagingSetup+ tab={isMessagingSetupTab(currentTab) ? currentTab : 'channels'}+ linkFor={(tab) => urls.broadcasts(tab)}+ />+ ),+ },+ ]}+ sceneInset+ />+ ) : (+ <LemonTabs+ activeKey={currentTab}+ tabs={[broadcastsTab, ...messagingNavTabs((tab) => urls.broadcasts(tab))]}+ sceneInset+ />+ )}</SceneContent>)}diff --git a/products/workflows/frontend/Channels/ChannelCatalog.tsx b/products/workflows/frontend/Channels/ChannelCatalog.tsxnew file mode 100644index 000000000000..4dfa0205512a--- /dev/null+++ b/products/workflows/frontend/Channels/ChannelCatalog.tsx@@ -0,0 +1,47 @@+import { useValues } from 'kea'++import { LemonBanner, LemonSkeleton } from '@posthog/lemon-ui'++import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'+import { TeamMembershipLevel } from 'lib/constants'++import { ChannelCatalogCard } from './ChannelCatalogCard'+import { channelCatalogLogic } from './channelCatalogLogic'+import { CATALOG_CHANNELS } from './channelSummary'++const GRID_CLASS = 'grid gap-2 grid-cols-1 @min-[44rem]/main-content:grid-cols-2 @min-[72rem]/main-content:grid-cols-3'++/** Every channel a workflow can send through, with whether this project has it set up. */+export function ChannelCatalog(): JSX.Element {+ const { channels, activeCount, integrationsLoadFailed } = useValues(channelCatalogLogic)+ const restrictedReason = useRestrictedArea({+ scope: RestrictionScope.Project,+ minimumAccessLevel: TeamMembershipLevel.Admin,+ })++ return (+ <section className="flex flex-col gap-2" data-attr="workflows-channel-catalog">+ <div className="flex flex-wrap items-baseline justify-between gap-2">+ <h3 className="mb-0 text-base font-semibold">Available channels</h3>+ {channels && (+ <span className="text-secondary text-sm">{`${activeCount} of ${channels.length} active`}</span>+ )}+ </div>+ {channels ? (+ <div className={GRID_CLASS}>+ {channels.map((channel) => (+ <ChannelCatalogCard key={channel.kind} channel={channel} disabledReason={restrictedReason} />+ ))}+ </div>+ ) : integrationsLoadFailed ? (+ <LemonBanner type="error">Couldn't load your channels. Refresh the page to try again.</LemonBanner>+ ) : (+ <div className={GRID_CLASS}>+ {CATALOG_CHANNELS.map((kind) => (+ <LemonSkeleton key={kind} className="h-20" />+ ))}+ </div>+ )}+ </section>+ )+}diff --git a/products/workflows/frontend/Channels/ChannelCatalogCard.tsx b/products/workflows/frontend/Channels/ChannelCatalogCard.tsxnew file mode 100644index 000000000000..d726f667a9d3--- /dev/null+++ b/products/workflows/frontend/Channels/ChannelCatalogCard.tsx@@ -0,0 +1,72 @@+import { useActions } from 'kea'++import { IconAndroid, IconApple, IconLetter } from '@posthog/icons'+import { LemonButton, LemonCard, LemonTag, LemonTagType } from '@posthog/lemon-ui'++import { IconSlack, IconTwilio } from 'lib/lemon-ui/icons'++import { channelCatalogLogic } from './channelCatalogLogic'+import { CHANNEL_COPY, ChannelStatus, ChannelSummary } from './channelSummary'+import type { ChannelType } from './MessageChannels'++const CHANNEL_ICONS: Record<ChannelType, JSX.Element> = {+ email: <IconLetter />,+ slack: <IconSlack />,+ twilio: <IconTwilio />,+ firebase: <IconAndroid />,+ apns: <IconApple />,+}++const STATUS_TAGS: Record<ChannelStatus, { label: string; type: LemonTagType }> = {+ active: { label: 'Active', type: 'success' },+ 'needs-verification': { label: 'Verify domain', type: 'warning' },+ 'needs-attention': { label: 'Needs attention', type: 'danger' },+ 'not-set-up': { label: 'Not set up', type: 'muted' },+}++export function ChannelCatalogCard({+ channel,+ disabledReason,+}: {+ channel: ChannelSummary+ disabledReason: string | null+}): JSX.Element {+ const { startChannelSetup } = useActions(channelCatalogLogic)+ const { name, description } = CHANNEL_COPY[channel.kind]+ const tag = STATUS_TAGS[channel.status]+ const isSetUp = channel.status !== 'not-set-up'++ return (+ <LemonCard+ hoverEffect={false}+ className="flex items-start gap-3 p-3"+ data-attr={`workflows-channel-catalog-${channel.kind}`}+ >+ <span className="text-xl shrink-0 mt-0.5">{CHANNEL_ICONS[channel.kind]}</span>+ <div className="flex flex-col gap-1 flex-1 min-w-0">+ <div className="flex flex-wrap items-center gap-2">+ <span className="font-semibold">{name}</span>+ <LemonTag size="small" type={tag.type}>+ {tag.label}+ </LemonTag>+ </div>+ <span className="text-secondary text-sm">{description}</span>+ {isSetUp && (+ <span className="text-secondary text-xs">+ {channel.count === 1 ? '1 connection' : `${channel.count} connections`}+ </span>+ )}+ </div>+ <LemonButton+ size="small"+ type={isSetUp ? 'secondary' : 'primary'}+ className="shrink-0"+ onClick={() => startChannelSetup(channel.kind)}+ disabledReason={disabledReason}+ data-attr={`workflows-channel-catalog-connect-${channel.kind}`}+ >+ {isSetUp ? 'Add another' : 'Connect'}+ </LemonButton>+ </LemonCard>+ )+}diff --git a/products/workflows/frontend/Channels/MessageChannels.tsx b/products/workflows/frontend/Channels/MessageChannels.tsxindex 3836e47d18dd..f4d55e086b3b 100644--- a/products/workflows/frontend/Channels/MessageChannels.tsx+++ b/products/workflows/frontend/Channels/MessageChannels.tsx@@ -6,10 +6,13 @@ import { LemonSkeleton } from '@posthog/lemon-ui'import { pngHoggie } from 'lib/brand/hoggies'import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'import { SetupTaskId } from 'lib/components/ProductSetup'+import { FEATURE_FLAGS } from 'lib/constants'import { EmailIntegrationsList } from 'lib/integrations/EmailIntegrationsList'import { IntegrationsList } from 'lib/integrations/IntegrationsList'import { integrationsLogic } from 'lib/integrations/integrationsLogic'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { ChannelCatalog } from './ChannelCatalog'import { ChannelSetupModal } from './ChannelSetupModal'const HedgehogReporter = pngHoggie(reporterPng)@@ -21,11 +24,13 @@ export function MessageChannels(): JSX.Element {const { setupModalOpen, integrations, integrationsLoading, setupModalType, selectedIntegration } =useValues(integrationsLogic)const { openSetupModal, closeSetupModal, markTaskAsCompleted } = useActions(integrationsLogic)+ const { featureFlags } = useValues(featureFlagLogic)+ const showCatalog = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_NEW_NAVIGATION]const allWorkflowIntegrations =integrations?.filter((integration) => MESSAGING_CHANNEL_TYPES.includes(integration.kind as ChannelType)) ?? []- const showProductIntroduction = !integrationsLoading && !allWorkflowIntegrations.length+ const showProductIntroduction = !showCatalog && !integrationsLoading && !allWorkflowIntegrations.lengthreturn (<>@@ -41,7 +46,11 @@ export function MessageChannels(): JSX.Element {/><div className="flex flex-col gap-4" data-attr="message-channels">- {integrationsLoading && !integrations?.length && (+ {showCatalog && <ChannelCatalog />}+ {showCatalog && allWorkflowIntegrations.length > 0 && (+ <h3 className="mb-0 text-base font-semibold">Your connections</h3>+ )}+ {!showCatalog && integrationsLoading && !integrations?.length && (<><LemonSkeleton className="h-20" /><LemonSkeleton className="h-20" />diff --git a/products/workflows/frontend/Channels/channelCatalogLogic.ts b/products/workflows/frontend/Channels/channelCatalogLogic.tsnew file mode 100644index 000000000000..842e323f374c--- /dev/null+++ b/products/workflows/frontend/Channels/channelCatalogLogic.ts@@ -0,0 +1,123 @@+import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'+import { router } from 'kea-router'+import posthog from 'posthog-js'++import api from 'lib/api'+import { FEATURE_FLAGS } from 'lib/constants'+import { integrationsLogic } from 'lib/integrations/integrationsLogic'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { removeProjectIdIfPresent } from 'lib/utils/kea-router'++import type { FeatureFlagsSet } from '../../../../frontend/src/lib/logic/featureFlagLogic'+import type { IntegrationType } from '../../../../frontend/src/types'+import { CATALOG_CHANNELS, ChannelSummary, PUSH_CHANNELS, summarizeChannel } from './channelSummary'+import type { ChannelType } from './MessageChannels'++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface channelCatalogLogicValues {+ featureFlags: FeatureFlagsSet // featureFlagLogic+ integrations: IntegrationType[] | null // integrationsLogic+ activeCount: number+ channels: ChannelSummary[] | null+ integrationsLoadFailed: boolean+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface channelCatalogLogicActions {+ loadIntegrationsFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ } // integrationsLogic+ loadIntegrationsSuccess: (+ integrations: IntegrationType[],+ payload?: any+ ) => {+ integrations: IntegrationType[]+ payload?: any+ } // integrationsLogic+ openSetupModal: (+ integration?: IntegrationType | undefined,+ channelType?: 'apns' | 'email' | 'firebase' | 'slack' | 'twilio' | undefined+ ) => {+ channelType: 'apns' | 'email' | 'firebase' | 'slack' | 'twilio' | undefined+ integration: IntegrationType | undefined+ } // integrationsLogic+ startChannelSetup: (kind: ChannelType) => {+ kind: 'apns' | 'email' | 'firebase' | 'slack' | 'twilio'+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface channelCatalogLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ channels: (integrations: IntegrationType[] | null, featureFlags: FeatureFlagsSet) => ChannelSummary[] | null+ activeCount: (channels: ChannelSummary[] | null) => number+ }+}++export type channelCatalogLogicType = MakeLogicType<+ channelCatalogLogicValues,+ channelCatalogLogicActions,+ Record<string, any>,+ channelCatalogLogicMeta+>++export const channelCatalogLogic = kea<channelCatalogLogicType>([+ path(['products', 'workflows', 'frontend', 'Channels', 'channelCatalogLogic']),+ connect(() => ({+ values: [integrationsLogic, ['integrations'], featureFlagLogic, ['featureFlags']],+ actions: [integrationsLogic, ['openSetupModal', 'loadIntegrationsFailure', 'loadIntegrationsSuccess']],+ })),+ actions({+ startChannelSetup: (kind: ChannelType) => ({ kind }),+ }),+ reducers({+ integrationsLoadFailed: [+ false,+ {+ loadIntegrationsFailure: () => true,+ loadIntegrationsSuccess: () => false,+ },+ ],+ }),+ selectors({+ /** `null` until the integrations load, so the catalog never shows a channel as not set up by mistake. */+ channels: [+ (s) => [s.integrations, s.featureFlags],+ (integrations: IntegrationType[] | null, featureFlags: FeatureFlagsSet): ChannelSummary[] | null =>+ integrations === null+ ? null+ : CATALOG_CHANNELS.filter(+ (kind) =>+ !PUSH_CHANNELS.includes(kind) ||+ !!featureFlags[FEATURE_FLAGS.WORKFLOWS_PUSH_NOTIFICATIONS]+ ).map((kind) => summarizeChannel(kind, integrations)),+ ],+ activeCount: [+ (s) => [s.channels],+ (channels: ChannelSummary[] | null): number =>+ channels?.filter((channel) => channel.status === 'active').length ?? 0,+ ],+ }),+ listeners(({ actions, values }) => ({+ startChannelSetup: ({ kind }) => {+ // pinned: analytics event name - renaming breaks dashboards+ posthog.capture('workflows channel setup started', {+ kind,+ status: values.channels?.find((channel) => channel.kind === kind)?.status,+ })+ if (kind === 'slack') {+ // Slack connects through OAuth on slack.com, so `next` returns the person to the tab they left.+ window.location.href = api.integrations.authorizeUrl({+ kind: 'slack',+ next: removeProjectIdIfPresent(router.values.location.pathname),+ })+ return+ }+ actions.openSetupModal(undefined, kind)+ },+ })),+])diff --git a/products/workflows/frontend/Channels/channelSummary.test.ts b/products/workflows/frontend/Channels/channelSummary.test.tsnew file mode 100644index 000000000000..da3118f48f50--- /dev/null+++ b/products/workflows/frontend/Channels/channelSummary.test.ts@@ -0,0 +1,25 @@+import { ChannelStatus, summarizeChannel } from './channelSummary'+import type { ChannelType } from './MessageChannels'++const email = (verified: boolean): any => ({ kind: 'email', config: { verified } })+const slack = (errors?: string): any => ({ kind: 'slack', config: {}, errors })+const github: any = { kind: 'github', config: {} }++describe('summarizeChannel', () => {+ test.each<[string, ChannelType, any[], ChannelStatus, number]>([+ ['nothing connected', 'email', [], 'not-set-up', 0],+ ['other kinds do not count', 'slack', [github, email(true)], 'not-set-up', 0],+ ['an unverified email address needs verification', 'email', [email(false)], 'needs-verification', 1],+ ['one verified address makes email active', 'email', [email(false), email(true)], 'active', 2],+ ['a connected slack workspace is active', 'slack', [slack()], 'active', 1],+ [+ 'a connection with an error needs attention',+ 'slack',+ [slack(), slack('TOKEN_REFRESH_FAILED')],+ 'needs-attention',+ 2,+ ],+ ])('%s', (_, kind, integrations, status, count) => {+ expect(summarizeChannel(kind, integrations)).toEqual({ kind, status, count })+ })+})diff --git a/products/workflows/frontend/Channels/channelSummary.ts b/products/workflows/frontend/Channels/channelSummary.tsnew file mode 100644index 000000000000..1b32d0d360f9--- /dev/null+++ b/products/workflows/frontend/Channels/channelSummary.ts@@ -0,0 +1,46 @@+import type { IntegrationType } from '~/types'++import type { ChannelType } from './MessageChannels'++// pinned: integration kinds, also sent as the `kind` property of the channel setup event - renaming breaks dashboards+export const CATALOG_CHANNELS: ChannelType[] = ['email', 'slack', 'twilio', 'firebase', 'apns']+export const PUSH_CHANNELS: ChannelType[] = ['firebase', 'apns']++// pinned: analytics property values of the channel setup event - renaming breaks dashboards+export type ChannelStatus = 'not-set-up' | 'active' | 'needs-verification' | 'needs-attention'++export interface ChannelSummary {+ kind: ChannelType+ status: ChannelStatus+ count: number+}++export const CHANNEL_COPY: Record<ChannelType, { name: string; description: string }> = {+ email: { name: 'Email', description: 'Send email from your own domain.' },+ slack: { name: 'Slack', description: "Post messages to your team's Slack channels." },+ twilio: { name: 'Twilio', description: 'Send SMS messages to your users.' },+ firebase: { name: 'Firebase Cloud Messaging', description: 'Send push notifications to Android apps.' },+ apns: { name: 'Apple Push Notifications', description: 'Send push notifications to iOS apps.' },+}++/**+ * An email channel sends only after its domain is verified, so a connected but unverified address is not active.+ * Any connection with an error marks the whole channel, because a step that uses it can fail.+ */+export function summarizeChannel(+ kind: ChannelType,+ integrations: Pick<IntegrationType, 'kind' | 'config' | 'errors'>[]+): ChannelSummary {+ const connected = integrations.filter((integration) => integration.kind === kind)+ const count = connected.length+ if (count === 0) {+ return { kind, status: 'not-set-up', count }+ }+ if (connected.some((integration) => !!integration.errors)) {+ return { kind, status: 'needs-attention', count }+ }+ if (kind === 'email' && !connected.some((integration) => integration.config?.verified === true)) {+ return { kind, status: 'needs-verification', count }+ }+ return { kind, status: 'active', count }+}diff --git a/products/workflows/frontend/MessagingSetup.tsx b/products/workflows/frontend/MessagingSetup.tsxnew file mode 100644index 000000000000..ba300ba8af44--- /dev/null+++ b/products/workflows/frontend/MessagingSetup.tsx@@ -0,0 +1,41 @@+import { LemonButton } from '@posthog/lemon-ui'++import {+ MESSAGING_SETUP_TAB_KEYS,+ MESSAGING_TAB_CONTENT,+ MESSAGING_TAB_LABELS,+ MessagingNavTabKey,+ MessagingSetupTabKey,+} from './messagingTabs'++export interface MessagingSetupProps {+ tab: MessagingSetupTabKey+ linkFor: (tab: MessagingNavTabKey) => string+}++/** The sending setup tabs behind one "Messaging" tab, with a side menu that keeps each tab's own URL. */+export function MessagingSetup({ tab, linkFor }: MessagingSetupProps): JSX.Element {+ return (+ <>+ <div className="flex flex-col gap-4 @min-[48rem]/main-content:flex-row">+ <nav+ className="flex flex-row flex-wrap gap-1 shrink-0 @min-[48rem]/main-content:flex-col @min-[48rem]/main-content:w-52"+ aria-label="Messaging"+ >+ {MESSAGING_SETUP_TAB_KEYS.map((key) => (+ <LemonButton+ key={key}+ size="small"+ to={linkFor(key)}+ active={key === tab}+ data-attr={`messaging-setup-menu-${key}`}+ >+ {MESSAGING_TAB_LABELS[key]}+ </LemonButton>+ ))}+ </nav>+ <div className="flex-1 min-w-0">{MESSAGING_TAB_CONTENT[tab]}</div>+ </div>+ </>+ )+}diff --git a/products/workflows/frontend/Workflows/NewWorkflowModal.tsx b/products/workflows/frontend/Workflows/NewWorkflowModal.tsxindex 281549232f94..37dd5eb1c71a 100644--- a/products/workflows/frontend/Workflows/NewWorkflowModal.tsx+++ b/products/workflows/frontend/Workflows/NewWorkflowModal.tsx@@ -2,17 +2,23 @@ import { useActions, useValues } from 'kea'import { LemonInput, LemonSelect } from '@posthog/lemon-ui'+import { FEATURE_FLAGS } from 'lib/constants'import { LemonModal } from 'lib/lemon-ui/LemonModal'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { isMobile } from 'lib/utils/dom'import { newWorkflowLogic } from './newWorkflowLogic'import { WorkflowTemplateChooser } from './templates/WorkflowTemplateChooser'import { workflowTemplatesLogic } from './templates/workflowTemplatesLogic'+import { WorkflowTemplateTypePicker } from './templates/WorkflowTemplateTypePicker'export function NewWorkflowModal(): JSX.Element {const { hideNewWorkflowModal } = useActions(newWorkflowLogic)const { newWorkflowModalVisible } = useValues(newWorkflowLogic)+ const { featureFlags } = useValues(featureFlagLogic)+ const newNavigationEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_NEW_NAVIGATION]+const { templateFilter, tagFilter, availableTags } = useValues(workflowTemplatesLogic)const { setTemplateFilter, setTagFilter } = useActions(workflowTemplatesLogic)@@ -41,6 +47,7 @@ export function NewWorkflowModal(): JSX.Element {// A focused input makes iOS pan the viewport on swipe instead of scrolling the list.autoFocus={!isMobile()}/>+ {newNavigationEnabled && <WorkflowTemplateTypePicker />}{availableTags.length > 0 && (<LemonSelectclassName="shrink-0 min-w-56 whitespace-nowrap"diff --git a/products/workflows/frontend/Workflows/WorkflowsTable.tsx b/products/workflows/frontend/Workflows/WorkflowsTable.tsxindex cb049c676017..93e771344590 100644--- a/products/workflows/frontend/Workflows/WorkflowsTable.tsx+++ b/products/workflows/frontend/Workflows/WorkflowsTable.tsx@@ -1,7 +1,16 @@import { useActions, useValues } from 'kea'import { useMemo } from 'react'-import { LemonCheckbox, LemonDivider, LemonInput, LemonSelect, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'+import {+ LemonCheckbox,+ LemonDivider,+ LemonInput,+ LemonSegmentedButton,+ LemonSelect,+ LemonTag,+ Link,+ Tooltip,+} from '@posthog/lemon-ui'import { AccessControlAction } from 'lib/components/AccessControlAction'import { AppMetricsSparkline } from 'lib/components/AppMetrics/AppMetricsSparkline'@@ -32,6 +41,7 @@ import {workflowsLogic,} from './workflowsLogic'import { WorkflowStepMatches } from './WorkflowStepMatches'+import { hasMessagingAction } from './workflowTypeFilters'const STATUS_CONFIG: Record<string, { label: string; type: 'success' | 'default' | 'muted' }> = {active: { label: 'Active', type: 'success' },@@ -40,13 +50,7 @@ const STATUS_CONFIG: Record<string, { label: string; type: 'success' | 'default'}function WorkflowTypeTag({ workflow }: { workflow: HogFlow }): JSX.Element {- const hasMessagingAction = useMemo(() => {- // Keep in sync with MESSAGING_ACTION_TYPES in products/workflows/backend/models/hog_flow/hog_flow.py,- // which the list API's `type` filter uses - the tag and the filter must agree on what "Messaging" is.- return workflow.actions.some((action) => {- return ['function_email', 'function_sms', 'function_push'].includes(action.type)- })- }, [workflow.actions])+ const isMessaging = useMemo(() => hasMessagingAction(workflow.actions), [workflow.actions])if (workflow.origin_product === 'loops') {return (@@ -55,7 +59,7 @@ function WorkflowTypeTag({ workflow }: { workflow: HogFlow }): JSX.Element {</Link>)}- if (hasMessagingAction) {+ if (isMessaging) {return <LemonTag type="completion">Messaging</LemonTag>}return <LemonTag type="default">Automation</LemonTag>@@ -111,6 +115,7 @@ function WorkflowActionsSummary({ workflow }: { workflow: HogFlow }): JSX.Elemenexport function WorkflowsTable(): JSX.Element {const { featureFlags } = useValues(featureFlagLogic)const selfOptimisingEnabled = !!featureFlags[FEATURE_FLAGS.SELF_OPTIMISING_WORKFLOWS]+ const newNavigationEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_NEW_NAVIGATION]const logic = workflowsLogic()const {workflowsLoading,@@ -130,6 +135,7 @@ export function WorkflowsTable(): JSX.Element {deleteWorkflow,deleteSelectedWorkflows,setFilters,+ selectTypeTab,toggleArchivedWorkflowSelection,selectAllArchivedWorkflows,clearArchivedWorkflowSelection,@@ -386,6 +392,25 @@ export function WorkflowsTable(): JSX.Element {return (<div className="workflows-section" data-attr="workflows-table" data-loading={workflowsLoading}><>+ {newNavigationEnabled && (+ <div className="mb-3">+ <LemonSegmentedButton<WorkflowTypeFilter>+ size="small"+ value={filters.type}+ onChange={selectTypeTab}+ options={[+ { value: 'all', label: 'All', 'data-attr': 'workflows-type-tab-all' },+ { value: 'messaging', label: 'Messaging', 'data-attr': 'workflows-type-tab-messaging' },+ {+ value: 'automation',+ label: 'Automations',+ 'data-attr': 'workflows-type-tab-automation',+ },+ { value: 'loop', label: 'Loops', 'data-attr': 'workflows-type-tab-loop' },+ ]}+ />+ </div>+ )}<div className="flex justify-between gap-2 flex-wrap mb-4"><LemonInputtype="search"@@ -409,21 +434,25 @@ export function WorkflowsTable(): JSX.Element {]}value={filters.status}/>- <span className="ml-1">- <b>Type</b>- </span>- <LemonSelect- dropdownMatchSelectWidth={false}- size="small"- onChange={(value) => setFilters({ type: value as WorkflowTypeFilter })}- options={[- { label: 'All', value: 'all' },- { label: 'Messaging', value: 'messaging' },- { label: 'Automation', value: 'automation' },- { label: 'Loop', value: 'loop' },- ]}- value={filters.type}- />+ {!newNavigationEnabled && (+ <>+ <span className="ml-1">+ <b>Type</b>+ </span>+ <LemonSelect+ dropdownMatchSelectWidth={false}+ size="small"+ onChange={(value) => setFilters({ type: value as WorkflowTypeFilter })}+ options={[+ { label: 'All', value: 'all' },+ { label: 'Messaging', value: 'messaging' },+ { label: 'Automation', value: 'automation' },+ { label: 'Loop', value: 'loop' },+ ]}+ value={filters.type}+ />+ </>+ )}<span className="ml-1"><b>Trigger</b></span>diff --git a/products/workflows/frontend/Workflows/templates/WorkflowTemplateTypePicker.tsx b/products/workflows/frontend/Workflows/templates/WorkflowTemplateTypePicker.tsxnew file mode 100644index 000000000000..745b4c06b9d2--- /dev/null+++ b/products/workflows/frontend/Workflows/templates/WorkflowTemplateTypePicker.tsx@@ -0,0 +1,24 @@+import { useActions, useValues } from 'kea'++import { LemonSegmentedButton } from '@posthog/lemon-ui'++import type { WorkflowTemplateTypeFilter } from '../workflowTypeFilters'+import { workflowTemplatesLogic } from './workflowTemplatesLogic'++export function WorkflowTemplateTypePicker(): JSX.Element {+ const { typeFilter } = useValues(workflowTemplatesLogic)+ const { setTypeFilter } = useActions(workflowTemplatesLogic)++ return (+ <LemonSegmentedButton<WorkflowTemplateTypeFilter>+ size="small"+ value={typeFilter}+ onChange={setTypeFilter}+ options={[+ { value: 'all', label: 'All', 'data-attr': 'workflow-template-type-all' },+ { value: 'messaging', label: 'Messaging', 'data-attr': 'workflow-template-type-messaging' },+ { value: 'automation', label: 'Automation', 'data-attr': 'workflow-template-type-automation' },+ ]}+ />+ )+}diff --git a/products/workflows/frontend/Workflows/templates/WorkflowTemplatesBrowser.tsx b/products/workflows/frontend/Workflows/templates/WorkflowTemplatesBrowser.tsxnew file mode 100644index 000000000000..6a6eb77c8acf--- /dev/null+++ b/products/workflows/frontend/Workflows/templates/WorkflowTemplatesBrowser.tsx@@ -0,0 +1,46 @@+import { useActions, useValues } from 'kea'++import { LemonInput, LemonSelect } from '@posthog/lemon-ui'++import { WorkflowTemplateChooser } from './WorkflowTemplateChooser'+import { workflowTemplatesLogic } from './workflowTemplatesLogic'+import { WorkflowTemplateTypePicker } from './WorkflowTemplateTypePicker'++/** Workflow templates as a page of their own, for browsing outside the "New workflow" modal. */+export function WorkflowTemplatesBrowser(): JSX.Element {+ const { templateFilter, tagFilter, availableTags } = useValues(workflowTemplatesLogic)+ const { setTemplateFilter, setTagFilter } = useActions(workflowTemplatesLogic)++ const tagOptions = [+ { value: null as string | null, label: 'All categories' },+ ...availableTags.map((tag) => ({ value: tag as string | null, label: tag })),+ ]++ return (+ <div className="flex flex-col gap-4">+ <div className="flex flex-wrap gap-2 items-center justify-between">+ <LemonInput+ type="search"+ placeholder="Search templates"+ onChange={setTemplateFilter}+ value={templateFilter}+ className="max-w-80"+ />+ <div className="flex flex-wrap gap-2 items-center">+ <WorkflowTemplateTypePicker />+ {availableTags.length > 0 && (+ <LemonSelect+ className="shrink-0 min-w-56 whitespace-nowrap"+ options={tagOptions}+ value={tagFilter}+ onChange={(value) => setTagFilter(value)}+ dropdownMatchSelectWidth={false}+ data-attr="workflow-templates-category"+ />+ )}+ </div>+ </div>+ <WorkflowTemplateChooser />+ </div>+ )+}diff --git a/products/workflows/frontend/Workflows/templates/workflowTemplatesLogic.ts b/products/workflows/frontend/Workflows/templates/workflowTemplatesLogic.tsindex e60725bd13e5..131a8edd8cd2 100644--- a/products/workflows/frontend/Workflows/templates/workflowTemplatesLogic.ts+++ b/products/workflows/frontend/Workflows/templates/workflowTemplatesLogic.ts@@ -6,6 +6,7 @@ import api from 'lib/api'import { createFuse, Fuse } from 'lib/utils/fuseSearch'import type { HogFlowTemplate } from '../hogflows/types'+import { WorkflowTemplateTypeFilter, matchesTemplateType } from '../workflowTypeFilters'// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface workflowTemplatesLogicValues {@@ -13,6 +14,7 @@ export interface workflowTemplatesLogicValues {filteredTemplates: HogFlowTemplate[]tagFilter: string | nulltemplateFilter: string+ typeFilter: WorkflowTemplateTypeFilterworkflowTemplateFuse: Fuse<HogFlowTemplate>workflowTemplates: HogFlowTemplate[]workflowTemplatesLoading: boolean@@ -62,6 +64,9 @@ export interface workflowTemplatesLogicActions {setTemplateFilter: (search: string) => {search: string}+ setTypeFilter: (typeFilter: WorkflowTemplateTypeFilter) => {+ typeFilter: WorkflowTemplateTypeFilter+ }}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -72,6 +77,7 @@ export interface workflowTemplatesLogicMeta {workflowTemplates: HogFlowTemplate[],templateFilter: string,tagFilter: string | null,+ typeFilter: WorkflowTemplateTypeFilter,workflowTemplateFuse: Fuse<HogFlowTemplate>) => HogFlowTemplate[]availableTags: (workflowTemplates: HogFlowTemplate[]) => string[]@@ -90,6 +96,7 @@ export const workflowTemplatesLogic = kea<workflowTemplatesLogicType>([actions({setTemplateFilter: (search: string) => ({ search }),setTagFilter: (tag: string | null) => ({ tag }),+ setTypeFilter: (typeFilter: WorkflowTemplateTypeFilter) => ({ typeFilter }),deleteHogflowTemplate: (template: HogFlowTemplate) => ({ template }),}),reducers({@@ -105,6 +112,12 @@ export const workflowTemplatesLogic = kea<workflowTemplatesLogicType>([setTagFilter: (_, { tag }) => tag,},],+ typeFilter: [+ 'all' as WorkflowTemplateTypeFilter,+ {+ setTypeFilter: (_, { typeFilter }) => typeFilter,+ },+ ],}),loaders(({ values }) => ({workflowTemplates: [@@ -133,11 +146,12 @@ export const workflowTemplatesLogic = kea<workflowTemplatesLogicType>([},],filteredTemplates: [- (s) => [s.workflowTemplates, s.templateFilter, s.tagFilter, s.workflowTemplateFuse],+ (s) => [s.workflowTemplates, s.templateFilter, s.tagFilter, s.typeFilter, s.workflowTemplateFuse],(workflowTemplates: HogFlowTemplate[],templateFilter: string,tagFilter: string | null,+ typeFilter: WorkflowTemplateTypeFilter,workflowTemplateFuse: Fuse<HogFlowTemplate>): HogFlowTemplate[] => {let filtered = workflowTemplates@@ -157,7 +171,7 @@ export const workflowTemplatesLogic = kea<workflowTemplatesLogicType>([}}- return filtered+ return filtered.filter((template) => matchesTemplateType(template.actions, typeFilter))},],availableTags: [@@ -171,16 +185,20 @@ export const workflowTemplatesLogic = kea<workflowTemplatesLogicType>([},],}),- urlToAction(({ actions }) => ({- '/workflows': (_, searchParams) => {+ urlToAction(({ actions }) => {+ const applySearchParams = (searchParams: Record<string, any>): void => {if (searchParams.templateFilter) {actions.setTemplateFilter(searchParams.templateFilter)}if (searchParams.tagFilter) {actions.setTagFilter(searchParams.tagFilter)}- },- })),+ }+ return {+ '/workflows': (_, searchParams) => applySearchParams(searchParams),+ '/workflows/templates': (_, searchParams) => applySearchParams(searchParams),+ }+ }),actionToUrl(({ values }) => ({setTemplateFilter: () => {const searchParams = { ...router.values.searchParams }@@ -188,7 +206,7 @@ export const workflowTemplatesLogic = kea<workflowTemplatesLogicType>([if (!values.templateFilter) {delete searchParams.templateFilter}- return ['/workflows', searchParams, router.values.hashParams, { replace: true }]+ return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]},setTagFilter: () => {const searchParams = { ...router.values.searchParams }@@ -197,7 +215,7 @@ export const workflowTemplatesLogic = kea<workflowTemplatesLogicType>([} else {delete searchParams.tagFilter}- return ['/workflows', searchParams, router.values.hashParams, { replace: true }]+ return [router.values.location.pathname, searchParams, router.values.hashParams, { replace: true }]},})),afterMount(({ actions }) => {diff --git a/products/workflows/frontend/Workflows/workflowTypeFilters.test.ts b/products/workflows/frontend/Workflows/workflowTypeFilters.test.tsnew file mode 100644index 000000000000..5575605a1b2d--- /dev/null+++ b/products/workflows/frontend/Workflows/workflowTypeFilters.test.ts@@ -0,0 +1,29 @@+import { WorkflowTemplateTypeFilter, matchesTemplateType, templateTypeForListType } from './workflowTypeFilters'++describe('workflowTypeFilters', () => {+ test.each<[string, string[], WorkflowTemplateTypeFilter, boolean]>([+ ['email is messaging', ['trigger', 'function_email'], 'messaging', true],+ ['sms is messaging', ['trigger', 'function_sms'], 'messaging', true],+ ['push is messaging', ['trigger', 'delay', 'function_push'], 'messaging', true],+ ['slack-only is not messaging', ['trigger', 'function'], 'messaging', false],+ ['slack-only is automation', ['trigger', 'function'], 'automation', true],+ ['slack plus email is not automation', ['trigger', 'function', 'function_email'], 'automation', false],+ ['all matches everything', ['trigger', 'function_email'], 'all', true],+ ])('%s', (_, actionTypes, typeFilter, expected) => {+ expect(+ matchesTemplateType(+ actionTypes.map((type) => ({ type }) as any),+ typeFilter+ )+ ).toBe(expected)+ })++ test.each([+ ['messaging', 'messaging'],+ ['automation', 'automation'],+ ['loop', 'all'],+ ['all', 'all'],+ ] as const)('list type %s opens templates filtered to %s', (listType, expected) => {+ expect(templateTypeForListType(listType)).toBe(expected)+ })+})diff --git a/products/workflows/frontend/Workflows/workflowTypeFilters.ts b/products/workflows/frontend/Workflows/workflowTypeFilters.tsnew file mode 100644index 000000000000..55ad280d3013--- /dev/null+++ b/products/workflows/frontend/Workflows/workflowTypeFilters.ts@@ -0,0 +1,28 @@+import type { HogFlowAction } from './hogflows/types'+import type { WorkflowTypeFilter } from './workflowsLogic'++// Keep in sync with MESSAGING_ACTION_TYPES in products/workflows/backend/models/hog_flow/hog_flow.py,+// which the list API's `type` filter uses - the tag, the template filter, and the list filter must+// agree on what "Messaging" is.+const MESSAGING_ACTION_TYPES: string[] = ['function_email', 'function_sms', 'function_push']++export type WorkflowTemplateTypeFilter = 'all' | 'messaging' | 'automation'++export function hasMessagingAction(actions: Pick<HogFlowAction, 'type'>[]): boolean {+ return actions.some((action) => MESSAGING_ACTION_TYPES.includes(action.type))+}++export function matchesTemplateType(+ actions: Pick<HogFlowAction, 'type'>[],+ typeFilter: WorkflowTemplateTypeFilter+): boolean {+ if (typeFilter === 'all') {+ return true+ }+ return hasMessagingAction(actions) === (typeFilter === 'messaging')+}++/** The template filter that matches a type tab on the workflows list. Loops have no templates, so they show all. */+export function templateTypeForListType(listType: WorkflowTypeFilter): WorkflowTemplateTypeFilter {+ return listType === 'messaging' || listType === 'automation' ? listType : 'all'+}diff --git a/products/workflows/frontend/Workflows/workflowsLogic.ts b/products/workflows/frontend/Workflows/workflowsLogic.tsindex 4375238fd7f3..cae00bb36dfe 100644--- a/products/workflows/frontend/Workflows/workflowsLogic.ts+++ b/products/workflows/frontend/Workflows/workflowsLogic.ts@@ -1,6 +1,7 @@import { MakeLogicType, actions, kea, key, listeners, path, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'import { actionToUrl, router, urlToAction } from 'kea-router'+import posthog from 'posthog-js'import { LemonDialog, PaginationManual, lemonToast } from '@posthog/lemon-ui'@@ -199,6 +200,9 @@ export interface workflowsLogicActions {selectAllArchivedWorkflows: (ids: string[]) => {ids: string[]}+ selectTypeTab: (type: WorkflowTypeFilter) => {+ type: WorkflowTypeFilter+ }setFilters: (filters: Partial<WorkflowsFilters>,replace?: boolean@@ -262,6 +266,7 @@ export const workflowsLogic = kea<workflowsLogicType>([deleteSelectedWorkflows: true,loadWorkflows: () => ({}),setFilters: (filters: Partial<WorkflowsFilters>, replace?: boolean) => ({ filters, replace }),+ selectTypeTab: (type: WorkflowTypeFilter) => ({ type }),toggleArchivedWorkflowSelection: (id: string) => ({ id }),selectAllArchivedWorkflows: (ids: string[]) => ({ ids }),clearArchivedWorkflowSelection: true,@@ -456,6 +461,11 @@ export const workflowsLogic = kea<workflowsLogicType>([],}),listeners(({ actions, values }) => ({+ selectTypeTab: ({ type }) => {+ actions.setFilters({ type })+ // pinned: analytics event name - renaming breaks dashboards+ posthog.capture('workflows type tab selected', { type })+ },setFilters: async (_, breakpoint) => {// Debounce so typing in the search box doesn't fire a request per keystroke.await breakpoint(300)diff --git a/products/workflows/frontend/WorkflowsScene.tsx b/products/workflows/frontend/WorkflowsScene.tsxindex 7aba15ff2148..61e5a4c4557d 100644--- a/products/workflows/frontend/WorkflowsScene.tsx+++ b/products/workflows/frontend/WorkflowsScene.tsx@@ -1,11 +1,14 @@import { MakeLogicType, actions, kea, path, props, reducers, selectors, useActions, useValues } from 'kea'-import { urlToAction } from 'kea-router'+import { router, urlToAction } from 'kea-router'import { LemonButton } from '@posthog/lemon-ui'import { AccessControlAction } from 'lib/components/AccessControlAction'-import { LemonTab, LemonTabs } from 'lib/lemon-ui/LemonTabs'+import { FEATURE_FLAGS } from 'lib/constants'+import { LemonTabs } from 'lib/lemon-ui/LemonTabs'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { trackedActionToUrl } from 'lib/logic/scenes/trackedActionToUrl'+import { removeProjectIdIfPresent } from 'lib/utils/kea-router'import { addProductIntent } from 'lib/utils/product-intents'import { capitalizeFirstLetter } from 'lib/utils/strings'import { sceneConfigurations } from 'scenes/scenes'@@ -19,13 +22,27 @@ import { AccessControlLevel, AccessControlResourceType, Breadcrumb } from '~/typimport { EmailSuspensionBanner } from './EmailSuspensionBanner'import { workflowsEmptyState } from './emptyState/workflowsEmptyState'+import { MessagingSetup } from './MessagingSetup'import { MessagingTabActions } from './MessagingTabActions'-import { messagingNavTabs } from './messagingTabs'+import { isMessagingSetupTab, messagingNavTabs } from './messagingTabs'import { newWorkflowLogic } from './Workflows/newWorkflowLogic'import { NewWorkflowModal } from './Workflows/NewWorkflowModal'+import { workflowTemplatesLogic } from './Workflows/templates/workflowTemplatesLogic'+import { workflowsLogic } from './Workflows/workflowsLogic'import { WorkflowsTable } from './Workflows/WorkflowsTable'+import { templateTypeForListType } from './Workflows/workflowTypeFilters'+import { WorkflowsTemplates } from './WorkflowsTemplates'-const WORKFLOW_SCENE_TABS = ['workflows', 'library', 'channels', 'opt-outs', 'suppression', 'reputation'] as const+// pinned: URL path segments under /workflows - renaming breaks bookmarks+const WORKFLOW_SCENE_TABS = [+ 'workflows',+ 'templates',+ 'library',+ 'channels',+ 'opt-outs',+ 'suppression',+ 'reputation',+] as constexport type WorkflowsSceneTab = (typeof WORKFLOW_SCENE_TABS)[number]export type WorkflowsSceneProps = {@@ -42,7 +59,7 @@ export interface workflowsSceneLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface workflowsSceneLogicActions {setCurrentTab: (tab: WorkflowsSceneTab) => {- tab: 'channels' | 'library' | 'opt-outs' | 'reputation' | 'suppression' | 'workflows'+ tab: 'channels' | 'library' | 'opt-outs' | 'reputation' | 'suppression' | 'templates' | 'workflows'}}@@ -51,7 +68,7 @@ export interface workflowsSceneLogicMeta {__keaTypeGenInternalSelectorTypes: {logicProps: (arg: any) => anybreadcrumbs: (- currentTab: 'channels' | 'library' | 'opt-outs' | 'reputation' | 'suppression' | 'workflows'+ currentTab: 'channels' | 'library' | 'opt-outs' | 'reputation' | 'suppression' | 'templates' | 'workflows') => Breadcrumb[]}}@@ -93,7 +110,13 @@ export const workflowsSceneLogic = kea<workflowsSceneLogicType>([],}),trackedActionToUrl(({ values }) => ({- setCurrentTab: () => [urls.workflows(values.currentTab)],+ setCurrentTab: () => {+ const target = urls.workflows(values.currentTab)+ // A tab set from the URL keeps that URL's params, such as a template search.+ return removeProjectIdIfPresent(router.values.location.pathname) === target+ ? [target, router.values.searchParams, router.values.hashParams]+ : [target]+ },})),urlToAction(({ actions, values }) => {return {@@ -122,18 +145,32 @@ export const scene: SceneExport<WorkflowsSceneProps> = {emptyState: workflowsEmptyState,}+type WorkflowsTopTab = 'workflows' | 'templates' | 'messaging-setup'++function topTabFor(tab: WorkflowsSceneTab): WorkflowsTopTab {+ if (tab === 'templates' || tab === 'library') {+ return 'templates'+ }+ return isMessagingSetupTab(tab) ? 'messaging-setup' : 'workflows'+}+export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {- const { currentTab } = useValues(workflowsSceneLogic(props))+ const { currentTab: routeTab } = useValues(workflowsSceneLogic(props))+ const { featureFlags } = useValues(featureFlagLogic)+ const newNavigationEnabled = !!featureFlags[FEATURE_FLAGS.WORKFLOWS_NEW_NAVIGATION]+ // The workflow templates page exists only in the new navigation.+ const currentTab: WorkflowsSceneTab = !newNavigationEnabled && routeTab === 'templates' ? 'workflows' : routeTabconst { startNewWorkflow } = useActions(newWorkflowLogic)- const tabs: LemonTab<WorkflowsSceneTab>[] = [- {- label: 'Workflows',- key: 'workflows',- content: <WorkflowsTable />,- link: urls.workflows(),- },- ...messagingNavTabs((tab) => urls.workflows(tab)),- ]+ const { setTypeFilter } = useActions(workflowTemplatesLogic)+ const { filters } = useValues(workflowsLogic)++ const workflowsTab = {+ label: 'Workflows',+ key: 'workflows' as const,+ content: <WorkflowsTable />,+ link: urls.workflows(),+ }+ const showsNewWorkflowButton = currentTab === 'workflows' || currentTab === 'templates'return (<SceneContent className="workflows">@@ -145,7 +182,7 @@ export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {}}actions={<>- {currentTab === 'workflows' && (+ {showsNewWorkflowButton && (<AccessControlActionresourceType={AccessControlResourceType.Workflow}minAccessLevel={AccessControlLevel.Editor}@@ -157,6 +194,13 @@ export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {product_type: ProductKey.WORKFLOWS,intent_context: ProductIntentContext.WORKFLOW_CREATED,})+ // Open the template chooser on the type the list shows, so a person on the+ // Messaging tab sees messaging templates first.+ setTypeFilter(+ newNavigationEnabled && currentTab === 'workflows'+ ? templateTypeForListType(filters.type)+ : 'all'+ )startNewWorkflow()}}type="primary"@@ -166,14 +210,47 @@ export function WorkflowsScene(props: WorkflowsSceneProps = {}): JSX.Element {</LemonButton></AccessControlAction>)}- {currentTab !== 'workflows' && (+ {currentTab !== 'workflows' && currentTab !== 'templates' && (<MessagingTabActions tab={currentTab} channelsUrl={urls.workflows('channels')} />)}</>}/><EmailSuspensionBanner />- <LemonTabs activeKey={currentTab} tabs={tabs} sceneInset data-attr="workflows-scene-tabs" />+ {newNavigationEnabled ? (+ <LemonTabs<WorkflowsTopTab>+ activeKey={topTabFor(currentTab)}+ tabs={[+ workflowsTab,+ {+ label: 'Templates',+ key: 'templates',+ link: urls.workflows('library'),+ content: <WorkflowsTemplates tab={currentTab === 'templates' ? 'templates' : 'library'} />,+ },+ {+ label: 'Messaging',+ key: 'messaging-setup',+ link: urls.workflows('channels'),+ content: (+ <MessagingSetup+ tab={isMessagingSetupTab(currentTab) ? currentTab : 'channels'}+ linkFor={(tab) => urls.workflows(tab)}+ />+ ),+ },+ ]}+ sceneInset+ data-attr="workflows-scene-tabs"+ />+ ) : (+ <LemonTabs+ activeKey={currentTab}+ tabs={[workflowsTab, ...messagingNavTabs((tab) => urls.workflows(tab))]}+ sceneInset+ data-attr="workflows-scene-tabs"+ />+ )}<NewWorkflowModal /></SceneContent>)diff --git a/products/workflows/frontend/WorkflowsTemplates.tsx b/products/workflows/frontend/WorkflowsTemplates.tsxnew file mode 100644index 000000000000..a79940f501e2--- /dev/null+++ b/products/workflows/frontend/WorkflowsTemplates.tsx@@ -0,0 +1,29 @@+import { router } from 'kea-router'++import { LemonSegmentedButton } from '@posthog/lemon-ui'++import { urls } from 'scenes/urls'++import { MESSAGING_TAB_CONTENT } from './messagingTabs'+import { WorkflowTemplatesBrowser } from './Workflows/templates/WorkflowTemplatesBrowser'++// pinned: URL path segments under /workflows. `library` keeps the email templates it always showed.+export type WorkflowsTemplatesTab = 'templates' | 'library'++/** Everything a person reuses: the email templates that steps start from, and whole workflow templates. */+export function WorkflowsTemplates({ tab }: { tab: WorkflowsTemplatesTab }): JSX.Element {+ return (+ <div className="flex flex-col gap-4">+ <LemonSegmentedButton<WorkflowsTemplatesTab>+ size="small"+ value={tab}+ onChange={(value) => router.actions.push(urls.workflows(value))}+ options={[+ { value: 'library', label: 'Email templates', 'data-attr': 'workflows-library-emails' },+ { value: 'templates', label: 'Workflow templates', 'data-attr': 'workflows-library-templates' },+ ]}+ />+ {tab === 'templates' ? <WorkflowTemplatesBrowser /> : MESSAGING_TAB_CONTENT.library}+ </div>+ )+}diff --git a/products/workflows/frontend/messagingTabs.tsx b/products/workflows/frontend/messagingTabs.tsxindex 236b6cece920..aa0023a98d88 100644--- a/products/workflows/frontend/messagingTabs.tsx+++ b/products/workflows/frontend/messagingTabs.tsx@@ -10,6 +10,18 @@ import { WorkflowsReputation } from './Workflows/Reputation/WorkflowsReputation'export const MESSAGING_NAV_TAB_KEYS = ['library', 'channels', 'opt-outs', 'suppression', 'reputation'] as constexport type MessagingNavTabKey = (typeof MESSAGING_NAV_TAB_KEYS)[number]+/** The tabs that configure sending. The new navigation groups them under one "Messaging" tab. */+export const MESSAGING_SETUP_TAB_KEYS = ['channels', 'opt-outs', 'suppression', 'reputation'] as const+export type MessagingSetupTabKey = (typeof MESSAGING_SETUP_TAB_KEYS)[number]++export const MESSAGING_TAB_LABELS: Record<MessagingNavTabKey, string> = {+ library: 'Library',+ channels: 'Channels',+ 'opt-outs': 'Opt-outs',+ suppression: 'Suppression list',+ reputation: 'Reputation',+}+export const MESSAGING_TAB_CONTENT: Record<MessagingNavTabKey, JSX.Element> = {library: <MessageTemplatesTable />,channels: <MessageChannels />,@@ -18,31 +30,19 @@ export const MESSAGING_TAB_CONTENT: Record<MessagingNavTabKey, JSX.Element> = {reputation: <WorkflowsReputation />,}+export function isMessagingSetupTab(tab: string): tab is MessagingSetupTabKey {+ return (MESSAGING_SETUP_TAB_KEYS as readonly string[]).includes(tab)+}+/*** Sending setup that every messaging surface shares: templates, senders, and who may be sent to.* Each surface renders them under its own URL, so switching tabs never leaves the surface.*/export function messagingNavTabs(linkFor: (tab: MessagingNavTabKey) => string): LemonTab<MessagingNavTabKey>[] {- return [- { 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: 'Reputation',- key: 'reputation',- link: linkFor('reputation'),- content: MESSAGING_TAB_CONTENT.reputation,- },- ]+ return MESSAGING_NAV_TAB_KEYS.map((key) => ({+ label: MESSAGING_TAB_LABELS[key],+ key,+ link: linkFor(key),+ content: MESSAGING_TAB_CONTENT[key],+ }))}