: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): hide workflow suggestions when the org has not approved AI processing (#116260)
Daniel Marchukfb1d16210f57
diff --git a/products/workflows/frontend/Workflows/WorkflowScene.tsx b/products/workflows/frontend/Workflows/WorkflowScene.tsxindex fc0481601565..3a189371949b 100644--- a/products/workflows/frontend/Workflows/WorkflowScene.tsx+++ b/products/workflows/frontend/Workflows/WorkflowScene.tsx@@ -7,10 +7,8 @@ import { SpinnerOverlay } from '@posthog/lemon-ui'import { ActivityLog } from 'lib/components/ActivityLog/ActivityLog'import { NotFound } from 'lib/components/NotFound'-import { FEATURE_FLAGS } from 'lib/constants'import { useDebouncedValue } from 'lib/hooks/useDebouncedValue'import { LemonTab, LemonTabs } from 'lib/lemon-ui/LemonTabs'-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'import { AI_FIRST_COMPOSER_OVERRIDE } from 'scenes/max/aiFirstCreate/aiFirstMode'import { sceneAgentPanelLogic } from 'scenes/max/sceneAgentPanelLogic'@@ -28,6 +26,7 @@ import { batchWorkflowJobsLogic } from './batchWorkflowJobsLogic'import { NewWorkflowAgent } from './NewWorkflowAgent'import { newWorkflowLogic } from './newWorkflowLogic'import { WorkflowSuggestions } from './suggestions/WorkflowSuggestions'+import { workflowSuggestionsAvailabilityLogic } from './suggestions/workflowSuggestionsAvailabilityLogic'import { WorkflowSuggestionsNotice } from './suggestions/WorkflowSuggestionsNotice'import { WorkflowSuggestionsTabLabel } from './suggestions/WorkflowSuggestionsTabLabel'import { Workflow } from './Workflow'@@ -105,8 +104,7 @@ export function WorkflowScene(props: WorkflowSceneLogicProps): JSX.Element {useMemo(() => ({ workflow, id: workflowSceneProps.id ?? 'new' }), [workflow, workflowSceneProps.id]),500)- const { featureFlags } = useValues(featureFlagLogic)- const selfOptimisingEnabled = !!featureFlags[FEATURE_FLAGS.SELF_OPTIMISING_WORKFLOWS]+ const { suggestionsAvailable } = useValues(workflowSuggestionsAvailabilityLogic)const isSavedWorkflow = !!props.id && props.id !== 'new'const { sceneIntegrationEnabled } = useValues(sceneAgentPanelLogic)const { aiComposerAvailable } = useValues(newWorkflowLogic)@@ -188,7 +186,7 @@ export function WorkflowScene(props: WorkflowSceneLogicProps): JSX.Element {*/content: <WorkflowMetrics id={workflowSceneProps.id!} />,},- selfOptimisingEnabled+ suggestionsAvailable? {label: <WorkflowSuggestionsTabLabel id={workflowSceneProps.id!} />,key: 'self-driving',@@ -231,7 +229,7 @@ export function WorkflowScene(props: WorkflowSceneLogicProps): JSX.Element {<BindLogic logic={workflowLogic} props={workflowProps}><WorkflowSceneHeader {...props} /><WorkflowEmailPauseBanner />- {selfOptimisingEnabled && isSavedWorkflow && <WorkflowSuggestionsNotice id={props.id!} />}+ {suggestionsAvailable && isSavedWorkflow && <WorkflowSuggestionsNotice id={props.id!} />}{/* Only show Logs and Metrics tabs if the workflow has already been created */}{!props.id || props.id === 'new' ? (<Workflow {...workflowProps} />diff --git a/products/workflows/frontend/Workflows/WorkflowSceneHeader.tsx b/products/workflows/frontend/Workflows/WorkflowSceneHeader.tsxindex e1d7254eb7b9..d9bcfc97317a 100644--- a/products/workflows/frontend/Workflows/WorkflowSceneHeader.tsx+++ b/products/workflows/frontend/Workflows/WorkflowSceneHeader.tsx@@ -24,6 +24,7 @@ import { ScenePanel, ScenePanelActionsSection, ScenePanelDivider } from '~/layouimport { AccessControlLevel, AccessControlResourceType } from '~/types'import { HogFlowManualTriggerButton } from './hogflows/HogFlowManualTriggerButton'+import { workflowSuggestionsAvailabilityLogic } from './suggestions/workflowSuggestionsAvailabilityLogic'import { WorkflowSuggestionsMenuItem } from './suggestions/WorkflowSuggestionsMenuItem'import { WorkflowSuggestionsPanelToggle } from './suggestions/WorkflowSuggestionsPanelToggle'import { SaveAsTemplateModal } from './templates/SaveAsTemplateModal'@@ -68,7 +69,7 @@ export const WorkflowSceneHeader = (props: WorkflowSceneLogicProps = {}): JSX.Elconst isManualWorkflow = ['manual', 'batch'].includes(workflow?.trigger?.type || '')const { featureFlags } = useValues(featureFlagLogic)const sceneMenuBarEnabled = !!featureFlags[FEATURE_FLAGS.SCENE_MENU_BAR]- const selfOptimisingEnabled = !!featureFlags[FEATURE_FLAGS.SELF_OPTIMISING_WORKFLOWS]+ const { suggestionsAvailable } = useValues(workflowSuggestionsAvailabilityLogic)const [displayStatus, setDisplayStatus] = useState(workflow?.status)const [isTransitioning, setIsTransitioning] = useState(false)const prevStatusRef = useRef(workflow?.status)@@ -189,7 +190,7 @@ export const WorkflowSceneHeader = (props: WorkflowSceneLogicProps = {}): JSX.El<IconClock />Version history</SceneMenuBarItem>- {selfOptimisingEnabled && (+ {suggestionsAvailable && (<><SceneMenuBarSeparator /><WorkflowSuggestionsMenuItem id={props.id!} />@@ -243,7 +244,7 @@ export const WorkflowSceneHeader = (props: WorkflowSceneLogicProps = {}): JSX.El</AccessControlAction><LemonDivider vertical /><ScenePanel>- {selfOptimisingEnabled && (+ {suggestionsAvailable && (<><ScenePanelActionsSection><WorkflowSuggestionsPanelToggle id={props.id!} />diff --git a/products/workflows/frontend/Workflows/WorkflowsTable.tsx b/products/workflows/frontend/Workflows/WorkflowsTable.tsxindex 8402a82ca81a..f5e1438e3c74 100644--- a/products/workflows/frontend/Workflows/WorkflowsTable.tsx+++ b/products/workflows/frontend/Workflows/WorkflowsTable.tsx@@ -15,7 +15,6 @@ import {import { AccessControlAction } from 'lib/components/AccessControlAction'import { AppMetricsSparkline } from 'lib/components/AppMetrics/AppMetricsSparkline'import { MemberSelect } from 'lib/components/MemberSelect'-import { FEATURE_FLAGS } from 'lib/constants'import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'import { LemonButton } from 'lib/lemon-ui/LemonButton'import { More } from 'lib/lemon-ui/LemonButton/More'@@ -23,7 +22,6 @@ import { LemonTable, LemonTableColumn, LemonTableColumns } from 'lib/lemon-ui/Leimport { updatedAtColumn } from 'lib/lemon-ui/LemonTable/columnUtils'import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture'-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { capitalizeFirstLetter } from 'lib/utils/strings'import { urls } from 'scenes/urls'@@ -34,6 +32,7 @@ import { AutomationSuggestionBanner } from '../setupGuide/AutomationSuggestionBaimport { MessagingSetupReminderBanner } from '../setupGuide/MessagingSetupReminderBanner'import { getHogFlowStep } from './hogflows/steps/HogFlowSteps'import { HogFlow } from './hogflows/types'+import { workflowSuggestionsAvailabilityLogic } from './suggestions/workflowSuggestionsAvailabilityLogic'import { workflowLogic } from './workflowLogic'import { findMatchingWorkflowSteps } from './workflowSearchMatches'import {@@ -116,8 +115,7 @@ function WorkflowActionsSummary({ workflow }: { workflow: HogFlow }): JSX.Elemen}export function WorkflowsTable(): JSX.Element {- const { featureFlags } = useValues(featureFlagLogic)- const selfOptimisingEnabled = !!featureFlags[FEATURE_FLAGS.SELF_OPTIMISING_WORKFLOWS]+ const { suggestionsAvailable } = useValues(workflowSuggestionsAvailabilityLogic)const logic = workflowsLogic()const {workflowsLoading,@@ -207,7 +205,7 @@ export function WorkflowsTable(): JSX.Element {title={<span className="flex items-center gap-2 flex-wrap">{item.name}- {selfOptimisingEnabled &&+ {suggestionsAvailable &&item.status === 'active' &&item.suggestions_enabled && (// Reads only: the row link already renders an anchor, and andiff --git a/products/workflows/frontend/Workflows/suggestions/workflowSuggestionsAvailabilityLogic.test.ts b/products/workflows/frontend/Workflows/suggestions/workflowSuggestionsAvailabilityLogic.test.tsnew file mode 100644index 000000000000..739259a868ab--- /dev/null+++ b/products/workflows/frontend/Workflows/suggestions/workflowSuggestionsAvailabilityLogic.test.ts@@ -0,0 +1,41 @@+import { MOCK_DEFAULT_ORGANIZATION } from 'lib/api.mock'++import { FEATURE_FLAGS } from 'lib/constants'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { organizationLogic } from 'scenes/organizationLogic'++import { initKeaTests } from '~/test/init'+import { OrganizationType } from '~/types'++import { workflowSuggestionsAvailabilityLogic } from './workflowSuggestionsAvailabilityLogic'++describe('workflowSuggestionsAvailabilityLogic', () => {+ beforeEach(() => {+ initKeaTests()+ })++ test.each([+ { flagOn: true, approved: true, hasOrg: true, expected: true },+ { flagOn: true, approved: false, hasOrg: true, expected: false },+ { flagOn: true, approved: null, hasOrg: true, expected: false },+ { flagOn: true, approved: undefined, hasOrg: true, expected: false },+ { flagOn: true, approved: true, hasOrg: false, expected: false },+ { flagOn: false, approved: true, hasOrg: true, expected: false },+ ])(+ 'flag on $flagOn, approved $approved, has org $hasOrg -> $expected',+ ({ flagOn, approved, hasOrg, expected }) => {+ const flags = flagOn ? [FEATURE_FLAGS.SELF_OPTIMISING_WORKFLOWS] : []+ featureFlagLogic.actions.setFeatureFlags(flags, Object.fromEntries(flags.map((flag) => [flag, true])))+ const organization = {+ ...MOCK_DEFAULT_ORGANIZATION,+ is_ai_data_processing_approved: approved,+ } as OrganizationType+ organizationLogic.actions.loadCurrentOrganizationSuccess(hasOrg ? organization : null)++ const logic = workflowSuggestionsAvailabilityLogic()+ logic.mount()++ expect(logic.values.suggestionsAvailable).toBe(expected)+ }+ )+})diff --git a/products/workflows/frontend/Workflows/suggestions/workflowSuggestionsAvailabilityLogic.ts b/products/workflows/frontend/Workflows/suggestions/workflowSuggestionsAvailabilityLogic.tsnew file mode 100644index 000000000000..8d890f0232f4--- /dev/null+++ b/products/workflows/frontend/Workflows/suggestions/workflowSuggestionsAvailabilityLogic.ts@@ -0,0 +1,43 @@+import { MakeLogicType, connect, kea, path, selectors } from 'kea'++import { FEATURE_FLAGS } from 'lib/constants'+import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { organizationLogic } from 'scenes/organizationLogic'++import { OrganizationType } from '~/types'++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface workflowSuggestionsAvailabilityLogicValues {+ featureFlags: FeatureFlagsSet // featureFlagLogic+ currentOrganization: OrganizationType | null // organizationLogic+ suggestionsAvailable: boolean+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface workflowSuggestionsAvailabilityLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ suggestionsAvailable: (featureFlags: FeatureFlagsSet, currentOrganization: OrganizationType | null) => boolean+ }+}++export type workflowSuggestionsAvailabilityLogicType = MakeLogicType<+ workflowSuggestionsAvailabilityLogicValues,+ {},+ Record<string, any>,+ workflowSuggestionsAvailabilityLogicMeta+>++export const workflowSuggestionsAvailabilityLogic = kea<workflowSuggestionsAvailabilityLogicType>([+ path(['products', 'workflows', 'frontend', 'workflowSuggestionsAvailabilityLogic']),+ connect(() => ({+ values: [featureFlagLogic, ['featureFlags'], organizationLogic, ['currentOrganization']],+ })),+ selectors({+ suggestionsAvailable: [+ (s) => [s.featureFlags, s.currentOrganization],+ (featureFlags: FeatureFlagsSet, currentOrganization: OrganizationType | null): boolean =>+ !!featureFlags[FEATURE_FLAGS.SELF_OPTIMISING_WORKFLOWS] &&+ currentOrganization?.is_ai_data_processing_approved === true,+ ],+ }),+])