: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(dashboards): responsive add-widget modal with product intros (#64390)
Matt Pua2bc9b86df35a
diff --git a/.agents/skills/manage-dashboard-widgets/references/checklist-new-widget-type.md b/.agents/skills/manage-dashboard-widgets/references/checklist-new-widget-type.mdindex 61c1c5363392..cc38ec838553 100644--- a/.agents/skills/manage-dashboard-widgets/references/checklist-new-widget-type.md+++ b/.agents/skills/manage-dashboard-widgets/references/checklist-new-widget-type.md@@ -86,6 +86,7 @@ Use when the product area already has a widget and you need another visualizatioUse when introducing a new **`groupId`**, not just another variant in an existing group.- [ ] Add **`groupId`** to `DASHBOARD_WIDGET_GROUP_LABELS` in `catalog.ts`; matching `group_id`/`group_label` on BE **`WidgetSpec`**+- [ ] Add the product's icon to **`DASHBOARD_WIDGET_GROUP_ICONS`** in `catalog.ts` (use the canonical product icon from `defaultTree.tsx` `iconTypes`) — shown next to the group heading in the Add widget picker- [ ] Storybook title path: `'Dashboards/Dashboard Widgets/Widget types/<groupLabel>/<label>'`- [ ] **UI + query reuse** — pick one pattern (do not fork query paths):@@ -98,6 +99,7 @@ Use when introducing a new **`groupId`**, not just another variant in an existin- [ ] RBAC: extend `DashboardWidgetProductAccess`, `WIDGET_PRODUCT_ACCESS_CHECKS`, BE `WidgetSpec.required_product_access` (+ optional `product_access_denied_message`)- [ ] Availability: new `WidgetAvailabilityRequirementId` in `widgetAvailability.ts` + BE `WidgetSpec.availability_requirements` when catalog uses `availability`; optional branch in `WidgetAvailabilitySetupPrompt`- [ ] Optional **`titleHref`** on catalog — product scene route for header "View" link (`urls.*` or scene path)+- [ ] Optional **`DASHBOARD_WIDGET_GROUP_PRODUCT_INTRO`** entry in `catalog.ts` (`{ productKey, requirement, valueProp, ctaLabel, docsHref }`) — surfaces a group-level nudge in the Add widget picker (value-prop one-liner + explore CTA). The `requirement` (a `WidgetAvailabilityRequirementId`) gates it directly: shown only while that requirement is unmet, so it's only meaningful for products that gate on a project setting (skip for areas with no requirement, e.g. `experiments`, `activity`)- [ ] Net-new product: see [`products/README.md`](../../../products/README.md) for product bootstrap before wiring the widget## 5. Frontend widget componentdiff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex c8515c0da5cc..9bdfbf38bb33 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -293,6 +293,7 @@ export const dashboardLogic = kea<dashboardLogicType>([setAddWidgetModalOpen: (open: boolean) => ({ open }),toggleAddWidgetSelectedType: (widgetType: string) => ({ widgetType }),clearAddWidgetSelectedTypes: true,+ toggleAddWidgetCollapsedGroup: (groupId: string) => ({ groupId }),addWidgetTileFinished: true,/** One-shot signal asking the view to scroll the dashboard to the bottom (e.g. after adding tiles). */requestScrollToBottom: true,@@ -1352,6 +1353,21 @@ export const dashboardLogic = kea<dashboardLogicType>([clearAddWidgetSelectedTypes: () => [],},],+ addWidgetCollapsedGroups: [+ [] as string[],+ {+ setAddWidgetModalOpen: (state, { open }) => (open ? [] : state),+ toggleAddWidgetCollapsedGroup: (state, { groupId }) => {+ const collapsed = new Set(state)+ if (collapsed.has(groupId)) {+ collapsed.delete(groupId)+ } else {+ collapsed.add(groupId)+ }+ return Array.from(collapsed)+ },+ },+ ],})),selectors(() => ({shouldUseStreaming: [diff --git a/products/dashboards/frontend/widget_types/catalog.ts b/products/dashboards/frontend/widget_types/catalog.tsindex baee36ddddd2..6984170c6c03 100644--- a/products/dashboards/frontend/widget_types/catalog.ts+++ b/products/dashboards/frontend/widget_types/catalog.ts@@ -1,6 +1,10 @@+import type { ComponentType } from 'react'++import { IconFlask, IconLive, IconRewindPlay, IconWarning } from '@posthog/icons'+import { urls } from 'scenes/urls'-import { QuickFilterContext } from '~/queries/schema/schema-general'+import { ProductKey, QuickFilterContext } from '~/queries/schema/schema-general'import { ActivityTab } from '~/types'import {@@ -18,7 +22,7 @@ import {ExperimentsListWidgetPreview,} from '../widgets/previews/ExperimentsWidgetPreviews'import { SessionReplayWidgetPreview } from '../widgets/previews/SessionReplayWidgetPreview'-import type { WidgetAvailabilityConfig } from './widgetAvailability'+import type { WidgetAvailabilityConfig, WidgetAvailabilityRequirementId } from './widgetAvailability'export const DASHBOARD_WIDGET_HEADER_LAYOUTS = ['simple', 'dashboard_tile'] as const@@ -81,6 +85,58 @@ export function getDashboardWidgetGroupLabel(groupId: string): string {return DASHBOARD_WIDGET_GROUP_LABELS[groupId as keyof typeof DASHBOARD_WIDGET_GROUP_LABELS] ?? groupId}+/** Product icons shown next to group headings in the Add widget picker, keyed by `groupId`. */+export const DASHBOARD_WIDGET_GROUP_ICONS = {+ activity: IconLive,+ error_tracking: IconWarning,+ session_replay: IconRewindPlay,+ experiments: IconFlask,+} as const satisfies Record<keyof typeof DASHBOARD_WIDGET_GROUP_LABELS, ComponentType<{ className?: string }>>++export function getDashboardWidgetGroupIcon(groupId: string): ComponentType<{ className?: string }> | undefined {+ return DASHBOARD_WIDGET_GROUP_ICONS[groupId as keyof typeof DASHBOARD_WIDGET_GROUP_ICONS]+}++type DashboardWidgetGroupProductIntroConfig = {+ productKey: ProductKey+ /** Setup requirement that gates the nudge — shown only while this requirement is unmet. */+ requirement: WidgetAvailabilityRequirementId+ /** One-liner pitching why the product is worth a look — shown up front in the picker nudge. */+ valueProp: string+ /** Label for the CTA link (e.g. "Explore error tracking"). */+ ctaLabel: string+ docsHref: string+}++/**+ * Pitch shown next to a group heading when the product's setup requirement (see `availability`) is unmet.+ * Keyed by catalog `groupId`; only products that gate on a project setting belong here — areas with no+ * setup requirement (e.g. `experiments`, `activity`) are intentionally omitted.+ */+export const DASHBOARD_WIDGET_GROUP_PRODUCT_INTRO = {+ error_tracking: {+ productKey: ProductKey.ERROR_TRACKING,+ requirement: 'exception_autocapture',+ valueProp: 'Catch and resolve the errors hurting your users.',+ ctaLabel: 'Explore error tracking',+ docsHref: 'https://posthog.com/docs/error-tracking',+ },+ session_replay: {+ productKey: ProductKey.SESSION_REPLAY,+ requirement: 'session_replay_enabled',+ valueProp: 'Watch real sessions to see exactly where users get stuck.',+ ctaLabel: 'Explore session replay',+ docsHref: 'https://posthog.com/docs/session-replay',+ },+} as const satisfies Partial<Record<keyof typeof DASHBOARD_WIDGET_GROUP_LABELS, DashboardWidgetGroupProductIntroConfig>>++export type DashboardWidgetGroupProductIntro =+ (typeof DASHBOARD_WIDGET_GROUP_PRODUCT_INTRO)[keyof typeof DASHBOARD_WIDGET_GROUP_PRODUCT_INTRO]++export function getDashboardWidgetGroupProductIntro(groupId: string): DashboardWidgetGroupProductIntro | undefined {+ return DASHBOARD_WIDGET_GROUP_PRODUCT_INTRO[groupId as keyof typeof DASHBOARD_WIDGET_GROUP_PRODUCT_INTRO]+}+export type DashboardWidgetCatalogEntry = {/** Stable key for grouping widgets from the same product area. */groupId: keyof typeof DASHBOARD_WIDGET_GROUP_LABELS | (string & {})diff --git a/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx b/products/dashboards/frontend/widgets/AddWidgetModal.test.tsxindex 89e579dad9e9..84b886631527 100644--- a/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx+++ b/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx@@ -113,4 +113,48 @@ describe('AddWidgetModal', () => {expect(screen.getByTestId('error-tracking-preview')).toBeInTheDocument()expect(screen.queryByText("You haven't captured any exceptions")).not.toBeInTheDocument()})++ it('shows a group-level product nudge when the setup requirement is unmet', () => {+ renderAddWidgetModal()++ expect(screen.getByRole('link', { name: /Explore error tracking/i })).toHaveAttribute(+ 'href',+ 'https://posthog.com/docs/error-tracking'+ )+ })++ it('does not show the nudge once the setup requirement is met', () => {+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM, autocapture_exceptions_opt_in: true })+ renderAddWidgetModal()++ expect(screen.queryByRole('link', { name: /Explore error tracking/i })).not.toBeInTheDocument()+ })++ it('does not nudge for product areas without a setup requirement', () => {+ renderAddWidgetModal()++ expect(screen.queryByRole('link', { name: /Explore experiments/i })).not.toBeInTheDocument()+ })++ it('collapses and expands a section when its header is clicked', async () => {+ renderAddWidgetModal()++ expect(screen.getByRole('checkbox', { name: 'Top issues' })).toBeInTheDocument()++ await userEvent.click(screen.getByRole('button', { name: /Error tracking/i }))+ expect(screen.queryByRole('checkbox', { name: 'Top issues' })).not.toBeInTheDocument()++ await userEvent.click(screen.getByRole('button', { name: /Error tracking/i }))+ expect(screen.getByRole('checkbox', { name: 'Top issues' })).toBeInTheDocument()+ })++ it('resets collapsed sections when the modal is reopened', async () => {+ const logic = renderAddWidgetModal()++ await userEvent.click(screen.getByRole('button', { name: /Error tracking/i }))+ expect(logic.values.addWidgetCollapsedGroups).toContain('error_tracking')++ logic.actions.setAddWidgetModalOpen(true)+ expect(logic.values.addWidgetCollapsedGroups).toEqual([])+ })})diff --git a/products/dashboards/frontend/widgets/AddWidgetModal.tsx b/products/dashboards/frontend/widgets/AddWidgetModal.tsxindex 4c48848f1f4a..643c2e4ac8fb 100644--- a/products/dashboards/frontend/widgets/AddWidgetModal.tsx+++ b/products/dashboards/frontend/widgets/AddWidgetModal.tsx@@ -1,18 +1,28 @@+import clsx from 'clsx'import { useActions, useValues } from 'kea'import posthog from 'posthog-js'import { Fragment } from 'react'+import { IconChevronDown, IconChevronRight, IconLightBulb } from '@posthog/icons'+import { LemonButton } from 'lib/lemon-ui/LemonButton'import { LemonDivider } from 'lib/lemon-ui/LemonDivider'import { LemonModal } from 'lib/lemon-ui/LemonModal'+import { Link } from 'lib/lemon-ui/Link'import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'+import { teamLogic } from 'scenes/teamLogic'++import { ProductKey } from '~/queries/schema/schema-general'import {DASHBOARD_WIDGET_CATALOG_GROUPS,DASHBOARD_WIDGET_PREVIEWS,type DashboardWidgetCatalogEntry,type DashboardWidgetCatalogKey,+ getDashboardWidgetGroupIcon,+ getDashboardWidgetGroupProductIntro,} from '../widget_types/catalog'+import { isWidgetAvailabilityRequirementMet } from '../widget_types/widgetAvailability'import {type AddWidgetPayload,getAddButtonLabel,@@ -61,9 +71,11 @@ function AddWidgetCatalogPicker({}export function AddWidgetModal({ isOpen, onClose, loading, onAdd }: AddWidgetModalProps): JSX.Element {- const { addWidgetSelectedTypes } = useValues(dashboardLogic)- const { toggleAddWidgetSelectedType } = useActions(dashboardLogic)+ const { addWidgetSelectedTypes, addWidgetCollapsedGroups } = useValues(dashboardLogic)+ const { toggleAddWidgetSelectedType, toggleAddWidgetCollapsedGroup } = useActions(dashboardLogic)+ const { currentTeam } = useValues(teamLogic)const selectedTypes = new Set(addWidgetSelectedTypes)+ const collapsedGroups = new Set(addWidgetCollapsedGroups)const selectedCount = selectedTypes.size@@ -80,13 +92,17 @@ export function AddWidgetModal({ isOpen, onClose, loading, onAdd }: AddWidgetModonClose()}+ function handleProductIntroClicked(productType: ProductKey): void {+ posthog.capture('dashboard add widget modal - product intro clicked', { product_type: productType })+ }+return (<LemonModalisOpen={isOpen}onClose={onClose}title="Add widget"description="Bring context from your different PostHog products into one dashboard."- width={960}+ width={1200}footer={<><LemonButton@@ -114,24 +130,78 @@ export function AddWidgetModal({ isOpen, onClose, loading, onAdd }: AddWidgetMod><div className="@container/add-widget-modal"><div- className="grid grid-cols-1 @min-[48rem]/add-widget-modal:grid-cols-2 gap-x-3 gap-y-4"+ className="grid grid-cols-1 @min-[56rem]/add-widget-modal:grid-cols-2 gap-x-3 gap-y-4"aria-label="Widget types">- {DASHBOARD_WIDGET_CATALOG_GROUPS.map((group, groupIndex) => (- <Fragment key={group.groupId}>- {groupIndex > 0 ? <LemonDivider className="col-span-full my-0" /> : null}- <h5 className="col-span-full mx-0 my-0">{group.groupLabel}</h5>- {group.widgets.map(({ widgetType, entry }) => (- <AddWidgetCatalogPicker- key={widgetType}- widgetType={widgetType}- entry={entry}- selected={selectedTypes.has(widgetType)}- onToggleWidgetType={handleToggleWidgetType}- />- ))}- </Fragment>- ))}+ {DASHBOARD_WIDGET_CATALOG_GROUPS.map((group, groupIndex) => {+ const productIntro = getDashboardWidgetGroupProductIntro(group.groupId)+ // Nudge only when the product's setup requirement (a project setting) is unmet.+ const showProductIntro =+ !!productIntro && !isWidgetAvailabilityRequirementMet(productIntro.requirement, currentTeam)+ const GroupIcon = getDashboardWidgetGroupIcon(group.groupId)+ const isCollapsed = collapsedGroups.has(group.groupId)++ return (+ <Fragment key={group.groupId}>+ {groupIndex > 0 ? <LemonDivider className="col-span-full my-0" /> : null}+ <div+ role="button"+ tabIndex={0}+ aria-expanded={!isCollapsed}+ onClick={() => toggleAddWidgetCollapsedGroup(group.groupId)}+ onKeyDown={(e) => {+ if (e.key === 'Enter' || e.key === ' ') {+ e.preventDefault()+ toggleAddWidgetCollapsedGroup(group.groupId)+ }+ }}+ className={clsx(+ 'col-span-full flex flex-wrap items-center gap-x-3 gap-y-1 rounded px-3 py-2 cursor-pointer',+ 'focus:outline-none focus-visible:ring-2 focus-visible:ring-accent',+ showProductIntro ? 'bg-accent-highlight-secondary' : 'bg-surface-secondary'+ )}+ >+ <h5 className="m-0 flex shrink-0 items-center gap-1.5">+ {isCollapsed ? (+ <IconChevronRight className="shrink-0 text-base text-secondary" />+ ) : (+ <IconChevronDown className="shrink-0 text-base text-secondary" />+ )}+ {GroupIcon ? <GroupIcon className="text-base text-secondary" /> : null}+ {group.groupLabel}+ </h5>+ {showProductIntro && productIntro ? (+ <span className="flex items-start gap-1.5 text-xs text-secondary">+ <IconLightBulb className="mt-0.5 shrink-0 text-sm text-accent" />+ <span>+ {productIntro.valueProp}{' '}+ <Link+ to={productIntro.docsHref}+ target="_blank"+ onClick={(e) => {+ e.stopPropagation()+ handleProductIntroClicked(productIntro.productKey)+ }}+ >+ {productIntro.ctaLabel}+ </Link>+ </span>+ </span>+ ) : null}+ </div>+ {!isCollapsed &&+ group.widgets.map(({ widgetType, entry }) => (+ <AddWidgetCatalogPicker+ key={widgetType}+ widgetType={widgetType}+ entry={entry}+ selected={selectedTypes.has(widgetType)}+ onToggleWidgetType={handleToggleWidgetType}+ />+ ))}+ </Fragment>+ )+ })}</div></div></LemonModal>diff --git a/products/dashboards/frontend/widgets/WidgetTypePickerCard.tsx b/products/dashboards/frontend/widgets/WidgetTypePickerCard.tsxindex e8fe5f0071c1..166c67d04e13 100644--- a/products/dashboards/frontend/widgets/WidgetTypePickerCard.tsx+++ b/products/dashboards/frontend/widgets/WidgetTypePickerCard.tsx@@ -55,7 +55,7 @@ export function WidgetTypePickerCard({<WidgetTypePickerSelectionIndicator selected={selected} /></div><p className="text-xs text-muted m-0 mt-0.5 mb-2">{description}</p>- <div className="pointer-events-none select-none" aria-hidden="true">+ <div className="pointer-events-none select-none overflow-hidden rounded" aria-hidden="true">{preview}</div></div>