Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(insights): move secondary title actions into a more menu on narrow scenes (#121513)

ruby childs8e8d058f12ae
diff --git a/frontend/src/layout/scenes/components/QuillSceneTitleSection.tsx b/frontend/src/layout/scenes/components/QuillSceneTitleSection.tsx
index 7c58ee1c495f..4e42cca2df07 100644
--- a/frontend/src/layout/scenes/components/QuillSceneTitleSection.tsx
+++ b/frontend/src/layout/scenes/components/QuillSceneTitleSection.tsx
@@ -146,7 +146,7 @@ export function QuillSceneTitleSection({
the menus onto their own line, where the divider would lead the line, so it hides there. */}
<div
ref={setMenuBarSlot}
- className="flex min-w-0 items-center empty:hidden before:mx-1 before:h-4 before:w-px before:shrink-0 before:bg-[var(--border)] before:content-[''] @max-xl/main-content:before:hidden"
+ className="flex shrink-0 items-center empty:hidden before:mx-1 before:h-4 before:w-px before:shrink-0 before:bg-[var(--border)] before:content-[''] @max-xl/main-content:before:hidden"
/>
</>
}
diff --git a/frontend/src/layout/scenes/components/SceneMenuBar.tsx b/frontend/src/layout/scenes/components/SceneMenuBar.tsx
index 5f629127fd19..61920ba548a2 100644
--- a/frontend/src/layout/scenes/components/SceneMenuBar.tsx
+++ b/frontend/src/layout/scenes/components/SceneMenuBar.tsx
@@ -288,7 +288,7 @@ function hasNoRenderableChildren(children: ReactNode): boolean {
}
const MENU_TRIGGER_CLASSES =
- 'flex items-center outline-hidden select-none px-2 h-7 rounded-sm text-xs font-medium hover:bg-fill-hover data-[popup-open]:bg-fill-selected disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent'
+ 'flex items-center whitespace-nowrap outline-hidden select-none px-2 h-7 rounded-sm text-xs font-medium hover:bg-fill-hover data-[popup-open]:bg-fill-selected disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent'
export function SceneMenuBarMenu({
label,
diff --git a/frontend/src/layout/scenes/components/SceneTitleSecondaryActions.tsx b/frontend/src/layout/scenes/components/SceneTitleSecondaryActions.tsx
new file mode 100644
index 000000000000..8b6f70046220
--- /dev/null
+++ b/frontend/src/layout/scenes/components/SceneTitleSecondaryActions.tsx
@@ -0,0 +1,39 @@
+import type { ReactNode } from 'react'
+
+import { IconEllipsis } from '@posthog/icons'
+import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@posthog/quill'
+
+interface SceneTitleSecondaryActionsProps {
+ /** The secondary actions as buttons, for a wide scene */
+ children: ReactNode
+ /** The same actions as menu items, for a narrow scene */
+ menu: ReactNode
+}
+
+/**
+ * The secondary title actions under the Today layout. A narrow scene keeps only the primary action in view and moves
+ * these into a "More actions" menu, so the title actions do not run into the scene menu bar.
+ */
+export function SceneTitleSecondaryActions({ children, menu }: SceneTitleSecondaryActionsProps): JSX.Element {
+ return (
+ <>
+ <div className="flex items-center gap-1 @max-5xl/main-content:hidden">{children}</div>
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ render={
+ <Button
+ variant="outline"
+ size="icon"
+ aria-label="More actions"
+ className="hidden @max-5xl/main-content:inline-flex"
+ data-attr="scene-title-more-actions"
+ />
+ }
+ >
+ <IconEllipsis className="rotate-90" />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">{menu}</DropdownMenuContent>
+ </DropdownMenu>
+ </>
+ )
+}
diff --git a/products/product_analytics/frontend/insights/insightScene/InsightPageHeader.tsx b/products/product_analytics/frontend/insights/insightScene/InsightPageHeader.tsx
index e8a173992334..ecd474620f58 100644
--- a/products/product_analytics/frontend/insights/insightScene/InsightPageHeader.tsx
+++ b/products/product_analytics/frontend/insights/insightScene/InsightPageHeader.tsx
@@ -150,17 +150,12 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
maxToolProps={readDataMaxToolProps}
actions={
todayRailNav ? (
- <>
- {insightMode !== ItemMode.Edit && isPersistedInsight && (
- <InsightShareMenu insight={insight} />
- )}
- <QuillInsightPageHeaderActions
- insightLogicProps={insightLogicProps}
- isPersistedInsight={isPersistedInsight}
- canCreateAlertForInsight={canCreateAlertForInsight}
- saveInsightToFolder={saveInsightToFolder}
- />
- </>
+ <QuillInsightPageHeaderActions
+ insightLogicProps={insightLogicProps}
+ isPersistedInsight={isPersistedInsight}
+ canCreateAlertForInsight={canCreateAlertForInsight}
+ saveInsightToFolder={saveInsightToFolder}
+ />
) : (
<>
{insightMode === ItemMode.Edit && isSavedInsight && (
diff --git a/products/product_analytics/frontend/insights/insightScene/InsightShareMenu.tsx b/products/product_analytics/frontend/insights/insightScene/InsightShareMenu.tsx
index acaf88bb523a..93768687aa98 100644
--- a/products/product_analytics/frontend/insights/insightScene/InsightShareMenu.tsx
+++ b/products/product_analytics/frontend/insights/insightScene/InsightShareMenu.tsx
@@ -16,14 +16,47 @@ interface InsightShareMenuProps {
insight: { short_id?: string | null; name?: string | null; derived_name?: string | null }
}
+export interface InsightShareItem {
+ label: string
+ icon?: JSX.Element
+ onClick: () => void
+ dataAttr: string
+}
+
+/** The share options of a saved insight, or null when it has no short id yet. */
+export function useInsightShareItems(insight: InsightShareMenuProps['insight']): InsightShareItem[] | null {
+ const { push } = useActions(router)
+ const { openShareToSpace } = useActions(analyticsShareLogic)
+ const { itemSpaces } = useValues(analyticsShareLogic)
+ const shortId = insight.short_id
+ if (!shortId) {
+ return null
+ }
+ const insightName = insight.name || insight.derived_name || 'Untitled insight'
+ const insightSpace = itemSpaces[shareTargetKey({ type: 'insight', ref: shortId })]
+ return [
+ {
+ label: insightSpace ? `Move from ${insightSpace}` : 'Add to a collection',
+ icon: <IconShare />,
+ onClick: () => openShareToSpace({ type: 'insight', ref: shortId, name: insightName }),
+ dataAttr: 'insight-share-into-space',
+ },
+ {
+ label: 'Share publicly or embed',
+ onClick: () => push(urls.insightSharing(shortId as InsightShortId)),
+ dataAttr: 'insight-share-publicly',
+ },
+ ]
+}
+
/**
* The Share menu of a saved insight under the Today navigation. It lives apart from the header so the
* spaces logics, and the project tree they load, mount only for people with the flag.
*/
export function InsightShareMenu({ insight }: InsightShareMenuProps): JSX.Element | null {
- const { push } = useActions(router)
- const { openShareToSpace, loadItemSpace } = useActions(analyticsShareLogic)
+ const { loadItemSpace } = useActions(analyticsShareLogic)
const { itemSpaces } = useValues(analyticsShareLogic)
+ const shareItems = useInsightShareItems(insight)
const shortId = insight.short_id
const insightName = insight.name || insight.derived_name || 'Untitled insight'
const insightSpace = shortId ? itemSpaces[shareTargetKey({ type: 'insight', ref: shortId })] : undefined
@@ -34,25 +67,18 @@ export function InsightShareMenu({ insight }: InsightShareMenuProps): JSX.Elemen
}
}, [shortId, insightSpace, insightName, loadItemSpace])
- if (!shortId) {
+ if (!shareItems) {
return null
}
return (
<>
<LemonMenu
- items={[
- {
- label: insightSpace ? `Move from ${insightSpace}` : 'Add to a collection',
- icon: <IconShare />,
- onClick: () => openShareToSpace({ type: 'insight', ref: shortId, name: insightName }),
- 'data-attr': 'insight-share-into-space',
- },
- {
- label: 'Share publicly or embed',
- onClick: () => push(urls.insightSharing(shortId as InsightShortId)),
- 'data-attr': 'insight-share-publicly',
- },
- ]}
+ items={shareItems.map(({ label, icon, onClick, dataAttr }) => ({
+ label,
+ icon,
+ onClick,
+ 'data-attr': dataAttr,
+ }))}
>
<LemonButton type="secondary" size="small" icon={<IconShare />} data-attr="insight-share-menu">
Share
diff --git a/products/product_analytics/frontend/insights/insightScene/QuillInsightPageHeaderActions.tsx b/products/product_analytics/frontend/insights/insightScene/QuillInsightPageHeaderActions.tsx
index f63fdf38e28d..9d4b9c94cf37 100644
--- a/products/product_analytics/frontend/insights/insightScene/QuillInsightPageHeaderActions.tsx
+++ b/products/product_analytics/frontend/insights/insightScene/QuillInsightPageHeaderActions.tsx
@@ -1,7 +1,14 @@
import { useActions, useValues } from 'kea'
+import { router } from 'kea-router'
-import { IconPlus } from '@posthog/icons'
-import { Button } from '@posthog/quill'
+import { IconBell, IconPlus, IconShare, IconWarning } from '@posthog/icons'
+import {
+ Button,
+ DropdownMenuItem,
+ DropdownMenuSub,
+ DropdownMenuSubContent,
+ DropdownMenuSubTrigger,
+} from '@posthog/quill'
import { AccessControlAction } from 'lib/components/AccessControlAction'
import { InsightSubscribeProminentButton } from 'lib/components/Scenes/InsightSubscribeProminentButton'
@@ -10,12 +17,16 @@ import { insightDataLogic } from 'scenes/insights/insightDataLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightSceneLogic } from 'scenes/insights/insightSceneLogic'
import { getOverrideWarningPropsForButton } from 'scenes/insights/utils'
+import { urls } from 'scenes/urls'
+import { SceneTitleSecondaryActions } from '~/layout/scenes/components/SceneTitleSecondaryActions'
import { isBIVisualizationNode } from '~/queries/utils'
import { AccessControlLevel, AccessControlResourceType, InsightLogicProps, ItemMode } from '~/types'
import { insightModalsLogic } from 'products/product_analytics/frontend/insights/insightScene/insightModalsLogic'
+import { urlForSubscriptions } from 'products/subscriptions/frontend/components/Subscriptions/utils'
+import { InsightShareMenu, useInsightShareItems } from './InsightShareMenu'
import { openInsightEditor } from './openInsightEditor'
import { QuillInsightSaveButton } from './QuillInsightSaveButton'
@@ -45,6 +56,8 @@ export function QuillInsightPageHeaderActions({
const { query, queryChanged } = useValues(insightDataLogic(insightProps))
const { cancelChanges } = useActions(insightDataLogic(insightProps))
const biEnabled = useFeatureFlag('SQL_EDITOR_BI_MODE')
+ const shareItems = useInsightShareItems(insight)
+ const { push } = useActions(router)
const overrideWarning = getOverrideWarningPropsForButton(query, filtersOverride, variablesOverride)
@@ -73,21 +86,65 @@ export function QuillInsightPageHeaderActions({
)}
{insightMode !== ItemMode.Edit && isPersistedInsight && (
- <Button
- variant="outline"
- data-attr="insight-add-to-dashboard-prominent-button"
- onClick={() => openAddToDashboardModal()}
+ <SceneTitleSecondaryActions
+ menu={
+ <>
+ {shareItems && (
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger data-attr="insight-more-menu-share">
+ <IconShare />
+ Share
+ </DropdownMenuSubTrigger>
+ <DropdownMenuSubContent>
+ {shareItems.map(({ label, icon, onClick, dataAttr }) => (
+ <DropdownMenuItem key={dataAttr} onClick={onClick} data-attr={dataAttr}>
+ {icon}
+ {label}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ )}
+ <DropdownMenuItem
+ data-attr="insight-more-menu-add-to-dashboard"
+ onClick={() => openAddToDashboardModal()}
+ >
+ <IconPlus />
+ Add to dashboard
+ </DropdownMenuItem>
+ {canCreateAlertForInsight && (
+ <DropdownMenuItem
+ data-attr="insight-more-menu-alerts"
+ onClick={() => push(urls.insightAlerts(insight.short_id!))}
+ >
+ <IconWarning />
+ Alerts
+ </DropdownMenuItem>
+ )}
+ <DropdownMenuItem
+ data-attr="insight-more-menu-subscriptions"
+ onClick={() => push(urlForSubscriptions({ insightShortId: insight.short_id! }))}
+ >
+ <IconBell />
+ Subscriptions
+ </DropdownMenuItem>
+ </>
+ }
>
- <IconPlus />
- Add to dashboard
- </Button>
- )}
-
- {insightMode !== ItemMode.Edit && isPersistedInsight && (
- <InsightSubscribeProminentButton
- insightShortId={insight.short_id!}
- canCreateAlert={canCreateAlertForInsight}
- />
+ <InsightShareMenu insight={insight} />
+ <Button
+ variant="outline"
+ data-attr="insight-add-to-dashboard-prominent-button"
+ onClick={() => openAddToDashboardModal()}
+ >
+ <IconPlus />
+ Add to dashboard
+ </Button>
+ <InsightSubscribeProminentButton
+ insightShortId={insight.short_id!}
+ canCreateAlert={canCreateAlertForInsight}
+ />
+ </SceneTitleSecondaryActions>
)}
{insightMode !== ItemMode.Edit ? (