: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(shortcuts): show a sidebar banner while out of the posthog team cohort (#109783)
Rafael Audiberte142e811d2c6
diff --git a/frontend/jest.setup.ts b/frontend/jest.setup.tsindex 12411d0d7295..d88b163c4e37 100644--- a/frontend/jest.setup.ts+++ b/frontend/jest.setup.ts@@ -193,6 +193,7 @@ jest.mock('posthog-js', () => {unregister: jest.fn(),reset: jest.fn(),group: jest.fn(),+ setPersonProperties: jest.fn(),updateEarlyAccessFeatureEnrollment: jest.fn(),people: { set: jest.fn() },featureFlags: { override: jest.fn() },diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex e45a32cb1cc9..8a0865fb49c0 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -3960,6 +3960,14 @@ snapshots:hash: v1.k794b7964.d4e69a3d1504fadf1b4056c6b7f84dd8e94a1a44d9cc83ae46d2c023f9b5788a.1wbkpRs6-VqVJGd9C-utXO-kA7rQN7JPvJ_SZ6W9cAclayout-navigation-sidebar--density-comparison--light:hash: v1.k794b7964.1ce2fdf015cbe4fefcaabc64af3bd2d8e671b8d502b3cf96bd07afea725d9fd1.zybM8RjBCVWcX5OYJ9MyNfMiwuu7HL9EgySs48INc_U+ layout-navigation-sidebar-posthog-team-cohort-banner--collapsed--dark:+ hash: v1.k794b7964.3ba80798b00d6b9a48ddcd8134bdcba754412fb34017a5497688f1c3dc9bb7a4.W9JGvxWo3Sgl8WDUqJaoDzkpZIhqM79UxeivhoBfFcc+ layout-navigation-sidebar-posthog-team-cohort-banner--collapsed--light:+ hash: v1.k794b7964.01a59be3c92957e5582b5287800a6ed7dfad3592143ece95c458dc762a718c31.c1gB9_ntPXR-87XaIZQqnqNvloJOut-TZ5jio-mHYKA+ layout-navigation-sidebar-posthog-team-cohort-banner--expanded--dark:+ hash: v1.k794b7964.ea064be94dddea97d646b701c5f61b81c62ca80baa60ce0463f2f084e5116c86.98-WnBtxpdJ6y8O8NbOBLf4-gHKPTfqDYzCv3qRdfzw+ layout-navigation-sidebar-posthog-team-cohort-banner--expanded--light:+ hash: v1.k794b7964.9971f304eb6c5667987493fdfe02c1b14041ef8f10cee0574323f30bb805aad4.C8LaYfcDBoSrYolf36VTMITLsAP3ZaGLlF90AeHXSIMlayout-products-and-files--chat--dark:hash: v1.k794b7964.8fe0ef68f9f51c97987697cd41c0f90f047f36468086fb58dba53da457298777.S15LWTVbxxB728U348RP2XuOaV_KOVeAiQELXFL50pIlayout-products-and-files--chat--light:diff --git a/frontend/src/layout/panel-layout/navbar/NavBar.tsx b/frontend/src/layout/panel-layout/navbar/NavBar.tsxindex 717c96c873dc..5a9dc8e77366 100644--- a/frontend/src/layout/panel-layout/navbar/NavBar.tsx+++ b/frontend/src/layout/panel-layout/navbar/NavBar.tsx@@ -35,6 +35,8 @@ import { NavSearchBar, NavSearchButton } from '../../../lib/components/NavSearchimport { navigation3000Logic } from '../../navigation-3000/navigationLogic'import { NavBarFooter } from './NavBarFooter'import { PanelLayoutPanels } from './PanelLayoutPanels'+import { PostHogTeamCohortBanner } from './PostHogTeamCohortBanner'+import { postHogTeamCohortBannerLogic } from './postHogTeamCohortBannerLogic'import { FlatNavBrowse } from './tabs/flat-nav/FlatNavBrowse'import { navProductsTabLogic } from './tabs/navProductsTabLogic'import { NavTabBrowse } from './tabs/NavTabBrowse'@@ -134,6 +136,7 @@ export function NavBar(): JSX.Element {const { toggleCommand } = useActions(commandLogic)const { sidebarDensity } = useValues(uiCustomizationLogic)const isSimpleSidepanelEnabled = useFeatureFlag('SIMPLE_SIDEPANEL')+ const { bannerVisible: isCohortBannerVisible } = useValues(postHogTeamCohortBannerLogic)const isOverlayOpen = isSimpleSidepanelEnabled && isNavCollapsed && isNavOverlayOpenconst isLayoutNavCollapsed = isNavCollapsed && !isOverlayOpenconst isFlatNavEnabled = useFeatureFlag('FLAT_NAV', 'test')@@ -421,6 +424,12 @@ export function NavBar(): JSX.Element {<div className={cn('p-1', !isSimpleSidepanelEnabled && isLayoutNavCollapsed && 'hidden')}><NavBarFooter isLayoutNavCollapsed={isLayoutNavCollapsed} /></div>+ {/* The collapsed nav hides the footer without the simple side panel, so the reminder renders here instead. */}+ {!isSimpleSidepanelEnabled && isLayoutNavCollapsed && isCohortBannerVisible && (+ <div className="flex justify-center p-1">+ <PostHogTeamCohortBanner isCollapsed />+ </div>+ )}</Tabs.Root>{!isMobileLayout && !isOverlayOpen && (<Resizerdiff --git a/frontend/src/layout/panel-layout/navbar/NavBarFooter.tsx b/frontend/src/layout/panel-layout/navbar/NavBarFooter.tsxindex 42d6c2f9a006..1fbf5e406f33 100644--- a/frontend/src/layout/panel-layout/navbar/NavBarFooter.tsx+++ b/frontend/src/layout/panel-layout/navbar/NavBarFooter.tsx@@ -15,6 +15,7 @@ import { urls } from 'scenes/urls'import { uiCustomizationLogic } from '~/layout/uiCustomizationLogic'import { InstallationStatusNavButton } from '../InstallationStatusNavButton'+import { PostHogTeamCohortBanner } from './PostHogTeamCohortBanner'export function NavBarFooter({ isLayoutNavCollapsed }: { isLayoutNavCollapsed: boolean }): JSX.Element {const isNotificationsEnabled = useFeatureFlag('REAL_TIME_NOTIFICATIONS')@@ -28,6 +29,7 @@ export function NavBarFooter({ isLayoutNavCollapsed }: { isLayoutNavCollapsed: b})}><DebugNotice isCollapsed={isLayoutNavCollapsed} />+ <PostHogTeamCohortBanner isCollapsed={isLayoutNavCollapsed} /></div><NavPanelAdvertisement />diff --git a/frontend/src/layout/panel-layout/navbar/PostHogTeamCohortBanner.stories.tsx b/frontend/src/layout/panel-layout/navbar/PostHogTeamCohortBanner.stories.tsxnew file mode 100644index 000000000000..670d7693828b--- /dev/null+++ b/frontend/src/layout/panel-layout/navbar/PostHogTeamCohortBanner.stories.tsx@@ -0,0 +1,39 @@+import type { Meta, StoryObj } from '@storybook/react'+import { useEffect } from 'react'++import { PostHogTeamCohortBanner } from './PostHogTeamCohortBanner'++const EXCLUDED_STORAGE_KEY = 'lib.components.Superpowers.superpowersLogic.excludedFromPostHogTeamCohort'++// Seeds the persisted opt-out instead of dispatching the toggle, whose listener writes person properties.+// The cleanup removes the seed, so later stories start with the default.+function withOptedOutOfCohort(Story: () => JSX.Element): JSX.Element {+ localStorage.setItem(EXCLUDED_STORAGE_KEY, JSON.stringify(true))+ useEffect(() => () => localStorage.removeItem(EXCLUDED_STORAGE_KEY), [])+ return <Story />+}++function OptedOutBanner({ isCollapsed }: { isCollapsed: boolean }): JSX.Element {+ return (+ <div className={isCollapsed ? 'w-fit' : 'w-[var(--project-navbar-width)]'}>+ <PostHogTeamCohortBanner isCollapsed={isCollapsed} />+ </div>+ )+}++const meta: Meta<typeof OptedOutBanner> = {+ title: 'Layout/Navigation sidebar/PostHog Team cohort banner',+ component: OptedOutBanner,+ decorators: [withOptedOutOfCohort],+ parameters: {+ layout: 'padded',+ viewMode: 'story',+ },+}+export default meta++type Story = StoryObj<typeof OptedOutBanner>++export const Expanded: Story = { args: { isCollapsed: false } }++export const Collapsed: Story = { args: { isCollapsed: true } }diff --git a/frontend/src/layout/panel-layout/navbar/PostHogTeamCohortBanner.tsx b/frontend/src/layout/panel-layout/navbar/PostHogTeamCohortBanner.tsxnew file mode 100644index 000000000000..70c32aea4453--- /dev/null+++ b/frontend/src/layout/panel-layout/navbar/PostHogTeamCohortBanner.tsx@@ -0,0 +1,62 @@+import { useActions, useValues } from 'kea'++import { IconX } from '@posthog/icons'++import { IconCohort } from 'lib/lemon-ui/icons'+import { LemonButton } from 'lib/lemon-ui/LemonButton'+import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'++import { postHogTeamCohortBannerLogic } from './postHogTeamCohortBannerLogic'++export function PostHogTeamCohortBanner({ isCollapsed }: { isCollapsed: boolean }): JSX.Element | null {+ const { bannerVisible } = useValues(postHogTeamCohortBannerLogic)+ const { dismissBanner, rejoinPostHogTeamCohort } = useActions(postHogTeamCohortBannerLogic)++ if (!bannerVisible) {+ return null+ }++ if (isCollapsed) {+ return (+ <ButtonPrimitive+ iconOnly+ aria-label="Rejoin the PostHog Team cohort"+ tooltip="You're out of the PostHog Team cohort. Click to rejoin."+ tooltipPlacement="right"+ onClick={() => rejoinPostHogTeamCohort(true)}+ data-attr="nav-posthog-team-cohort-rejoin"+ >+ <IconCohort className="text-warning" />+ </ButtonPrimitive>+ )+ }++ return (+ <div className="mb-2 flex w-full flex-col gap-1 rounded border border-l-4 border-l-warning bg-primary py-1 pl-2 pr-0.5 text-xs">+ <div className="flex items-start justify-between gap-1">+ <div className="flex min-w-0 items-start gap-1 pt-0.5">+ <IconCohort className="mt-px shrink-0 text-sm text-warning" />+ <span className="min-w-0 font-semibold">You're out of the PostHog Team cohort</span>+ </div>+ <LemonButton+ icon={<IconX />}+ tooltip="Dismiss"+ tooltipPlacement="right"+ size="xsmall"+ onClick={dismissBanner}+ data-attr="nav-posthog-team-cohort-banner-dismiss"+ />+ </div>+ <p className="mb-0 pr-1.5 text-secondary">Flags that target it are off for you.</p>+ <LemonButton+ type="secondary"+ size="xsmall"+ className="mb-1 mr-1.5"+ onClick={() => rejoinPostHogTeamCohort(false)}+ data-attr="nav-posthog-team-cohort-rejoin"+ >+ Rejoin cohort+ </LemonButton>+ </div>+ )+}diff --git a/frontend/src/layout/panel-layout/navbar/postHogTeamCohortBannerLogic.test.ts b/frontend/src/layout/panel-layout/navbar/postHogTeamCohortBannerLogic.test.tsnew file mode 100644index 000000000000..0d3cd6126482--- /dev/null+++ b/frontend/src/layout/panel-layout/navbar/postHogTeamCohortBannerLogic.test.ts@@ -0,0 +1,52 @@+import { MOCK_DEFAULT_USER } from 'lib/api.mock'++import posthog from 'posthog-js'++import { superpowersLogic } from 'lib/components/Superpowers/superpowersLogic'+import { userLogic } from 'scenes/userLogic'++import { initKeaTests } from '~/test/init'++import { postHogTeamCohortBannerLogic } from './postHogTeamCohortBannerLogic'++describe('postHogTeamCohortBannerLogic', () => {+ let logic: ReturnType<typeof postHogTeamCohortBannerLogic.build>++ beforeEach(() => {+ initKeaTests()+ userLogic.mount()+ userLogic.actions.loadUserSuccess({ ...MOCK_DEFAULT_USER, is_staff: true })+ superpowersLogic.mount()+ logic = postHogTeamCohortBannerLogic()+ logic.mount()+ superpowersLogic.actions.setExcludedFromPostHogTeamCohort(true)+ })++ afterEach(() => {+ logic.unmount()+ })++ it('shows the banner again after a remount, and after leaving the cohort again', () => {+ logic.actions.dismissBanner()+ expect(logic.values.bannerVisible).toBe(false)++ logic.unmount()+ logic = postHogTeamCohortBannerLogic()+ logic.mount()+ expect(logic.values.bannerVisible).toBe(true)++ logic.actions.dismissBanner()+ superpowersLogic.actions.setExcludedFromPostHogTeamCohort(true)+ expect(logic.values.bannerVisible).toBe(true)+ })++ it('rejoining clears the opt-out and hides the banner', () => {+ logic.actions.rejoinPostHogTeamCohort(false)++ expect(superpowersLogic.values.excludedFromPostHogTeamCohort).toBe(false)+ expect(logic.values.bannerVisible).toBe(false)+ expect(posthog.capture).toHaveBeenCalledWith('nav posthog team cohort banner rejoin clicked', {+ nav_collapsed: false,+ })+ })+})diff --git a/frontend/src/layout/panel-layout/navbar/postHogTeamCohortBannerLogic.ts b/frontend/src/layout/panel-layout/navbar/postHogTeamCohortBannerLogic.tsnew file mode 100644index 000000000000..6b1159768db8--- /dev/null+++ b/frontend/src/layout/panel-layout/navbar/postHogTeamCohortBannerLogic.ts@@ -0,0 +1,82 @@+import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'+import posthog from 'posthog-js'++import { superpowersLogic } from 'lib/components/Superpowers/superpowersLogic'++import type { UserType } from '~/types'++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface postHogTeamCohortBannerLogicValues {+ excludedFromPostHogTeamCohort: boolean // superpowersLogic+ user: UserType | null // superpowersLogic+ bannerVisible: boolean+ dismissed: boolean+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface postHogTeamCohortBannerLogicActions {+ setExcludedFromPostHogTeamCohort: (excluded: boolean) => {+ excluded: boolean+ } // superpowersLogic+ dismissBanner: () => {+ value: true+ }+ rejoinPostHogTeamCohort: (navCollapsed: boolean) => {+ navCollapsed: boolean+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface postHogTeamCohortBannerLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ bannerVisible: (user: UserType | null, excludedFromPostHogTeamCohort: boolean, dismissed: boolean) => boolean+ }+}++export type postHogTeamCohortBannerLogicType = MakeLogicType<+ postHogTeamCohortBannerLogicValues,+ postHogTeamCohortBannerLogicActions,+ Record<string, any>,+ postHogTeamCohortBannerLogicMeta+>++export const postHogTeamCohortBannerLogic = kea<postHogTeamCohortBannerLogicType>([+ path(['layout', 'panel-layout', 'navbar', 'postHogTeamCohortBannerLogic']),+ connect(() => ({+ values: [superpowersLogic, ['excludedFromPostHogTeamCohort', 'user']],+ actions: [superpowersLogic, ['setExcludedFromPostHogTeamCohort']],+ })),+ actions({+ dismissBanner: true,+ rejoinPostHogTeamCohort: (navCollapsed: boolean) => ({ navCollapsed }),+ }),+ reducers({+ // Not persisted, so a page refresh shows the banner again while the opt-out is still on.+ // Any change to the opt-out clears the dismissal, so leaving the cohort again shows the banner.+ dismissed: [+ false,+ {+ dismissBanner: () => true,+ setExcludedFromPostHogTeamCohort: () => false,+ },+ ],+ }),+ selectors({+ bannerVisible: [+ (s) => [s.user, s.excludedFromPostHogTeamCohort, s.dismissed],+ (user: UserType | null, excludedFromPostHogTeamCohort: boolean, dismissed: boolean): boolean =>+ !!user?.is_staff && excludedFromPostHogTeamCohort && !dismissed,+ ],+ }),+ listeners(({ actions }) => ({+ dismissBanner: () => {+ // pinned: analytics event name, renaming breaks dashboards+ posthog.capture('nav posthog team cohort banner dismissed')+ },+ rejoinPostHogTeamCohort: ({ navCollapsed }) => {+ // pinned: analytics event name, renaming breaks dashboards+ posthog.capture('nav posthog team cohort banner rejoin clicked', { nav_collapsed: navCollapsed })+ actions.setExcludedFromPostHogTeamCohort(false)+ },+ })),+])