: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): filter add widget modal by product badges (#120185)
Frank Hamand3bc113275293
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex 2555fcd7a4e7..3e13f57b33f6 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -328,6 +328,7 @@ export interface dashboardLogicValues {variables: Variable[] // variableDataLogicaccessDeniedToDashboard: booleanaddWidgetCollapsedGroups: string[]+ addWidgetFilteredGroups: string[]addWidgetModalOpen: booleanaddWidgetSelectedTypes: string[]addWidgetTileLoading: boolean@@ -1089,6 +1090,9 @@ export interface dashboardLogicActions {toggleAddWidgetCollapsedGroup: (groupId: string) => {groupId: string}+ toggleAddWidgetFilteredGroup: (groupId: string) => {+ groupId: string+ }toggleAddWidgetSelectedType: (widgetType: string) => {widgetType: string}@@ -1540,6 +1544,7 @@ export const dashboardLogic = kea<dashboardLogicType>([toggleAddWidgetSelectedType: (widgetType: string) => ({ widgetType }),clearAddWidgetSelectedTypes: true,toggleAddWidgetCollapsedGroup: (groupId: string) => ({ groupId }),+ toggleAddWidgetFilteredGroup: (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,@@ -2877,6 +2882,21 @@ export const dashboardLogic = kea<dashboardLogicType>([},},],+ addWidgetFilteredGroups: [+ [] as string[],+ {+ setAddWidgetModalOpen: (state, { open }) => (open ? [] : state),+ toggleAddWidgetFilteredGroup: (state, { groupId }) => {+ const filtered = new Set(state)+ if (filtered.has(groupId)) {+ filtered.delete(groupId)+ } else {+ filtered.add(groupId)+ }+ return Array.from(filtered)+ },+ },+ ],})),selectors(() => ({filterEditModeActive: [diff --git a/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx b/products/dashboards/frontend/widgets/AddWidgetModal.test.tsxindex a42e9e7cab9c..1f90bb9b3106 100644--- a/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx+++ b/products/dashboards/frontend/widgets/AddWidgetModal.test.tsx@@ -2,7 +2,7 @@ import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'import '@testing-library/jest-dom'-import { cleanup, render, screen } from '@testing-library/react'+import { cleanup, render, screen, within } from '@testing-library/react'import userEvent from '@testing-library/user-event'import { BindLogic } from 'kea'@@ -95,6 +95,25 @@ describe('AddWidgetModal', () => {])})+ it('filters widget sections to the selected product badges', async () => {+ renderAddWidgetModal()++ const badges = screen.getByTestId('dashboard-widget-product-badges')+ const sectionHeadings = (): string[] =>+ screen.getAllByRole('heading', { level: 5 }).map((heading) => heading.textContent ?? '')++ await userEvent.click(within(badges).getByText('Logs'))+ expect(sectionHeadings()).toEqual(['Logs'])++ await userEvent.click(within(badges).getByText('Error tracking'))+ expect(sectionHeadings()).toEqual(expect.arrayContaining(['Error tracking', 'Logs']))+ expect(sectionHeadings()).toHaveLength(2)++ await userEvent.click(within(badges).getByText('Logs'))+ await userEvent.click(within(badges).getByText('Error tracking'))+ expect(sectionHeadings()).toHaveLength(7)+ })+it('allows multi-select checkbox behavior within grouped layout', async () => {renderAddWidgetModal()diff --git a/products/dashboards/frontend/widgets/AddWidgetModal.tsx b/products/dashboards/frontend/widgets/AddWidgetModal.tsxindex af5552b288d0..cbce9dd8a858 100644--- a/products/dashboards/frontend/widgets/AddWidgetModal.tsx+++ b/products/dashboards/frontend/widgets/AddWidgetModal.tsx@@ -74,11 +74,17 @@ function AddWidgetCatalogPicker({}export function AddWidgetModal({ isOpen, onClose, loading, onAdd }: AddWidgetModalProps): JSX.Element {- const { addWidgetSelectedTypes, addWidgetCollapsedGroups } = useValues(dashboardLogic)- const { toggleAddWidgetSelectedType, toggleAddWidgetCollapsedGroup } = useActions(dashboardLogic)+ const { addWidgetSelectedTypes, addWidgetCollapsedGroups, addWidgetFilteredGroups } = useValues(dashboardLogic)+ const { toggleAddWidgetSelectedType, toggleAddWidgetCollapsedGroup, toggleAddWidgetFilteredGroup } =+ useActions(dashboardLogic)const { currentTeam } = useValues(teamLogic)const selectedTypes = new Set(addWidgetSelectedTypes)const collapsedGroups = new Set(addWidgetCollapsedGroups)+ const filteredGroups = new Set(addWidgetFilteredGroups)+ const visibleGroups =+ filteredGroups.size > 0+ ? DASHBOARD_WIDGET_CATALOG_GROUPS.filter((group) => filteredGroups.has(group.groupId))+ : DASHBOARD_WIDGET_CATALOG_GROUPSconst selectedCount = selectedTypes.size@@ -112,9 +118,22 @@ export function AddWidgetModal({ isOpen, onClose, loading, onAdd }: AddWidgetMod.sort((a, b) => a.groupLabel.localeCompare(b.groupLabel)).map((group) => {const GroupIcon = getDashboardWidgetGroupIcon(group.groupId)+ const isFiltered = filteredGroups.has(group.groupId)return (- <LemonTag key={group.groupId} type="muted">+ <LemonTag+ key={group.groupId}+ type={isFiltered ? 'primary' : 'muted'}+ tabIndex={0}+ aria-pressed={isFiltered}+ onClick={() => toggleAddWidgetFilteredGroup(group.groupId)}+ onKeyDown={(e) => {+ if (e.key === 'Enter' || e.key === ' ') {+ e.preventDefault()+ toggleAddWidgetFilteredGroup(group.groupId)+ }+ }}+ ><span className="flex items-center gap-1.5">{GroupIcon ? <GroupIcon className="size-4" /> : null}{group.groupLabel}@@ -157,7 +176,7 @@ export function AddWidgetModal({ isOpen, onClose, loading, onAdd }: AddWidgetModclassName="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) => {+ {visibleGroups.map((group, groupIndex) => {const productIntro = getDashboardWidgetGroupProductIntro(group.groupId)// Nudge only when the product's setup requirement (a project setting) is unmet.const showProductIntro =