: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): rename tile groups and tabs from the group menu (#128362)
Matt Pua1b811ea24c09
diff --git a/frontend/src/scenes/dashboard/DashboardItems.test.tsx b/frontend/src/scenes/dashboard/DashboardItems.test.tsxindex baad66f24966..e38bdd9a2bf6 100644--- a/frontend/src/scenes/dashboard/DashboardItems.test.tsx+++ b/frontend/src/scenes/dashboard/DashboardItems.test.tsx@@ -1,6 +1,6 @@import '@testing-library/jest-dom'-import { fireEvent, render, within } from '@testing-library/react'+import { fireEvent, render, waitFor, within } from '@testing-library/react'import { useActions, useAsyncActions, useValues } from 'kea'import { router } from 'kea-router'import type { PositionStrategy } from 'react-grid-layout/core'@@ -224,6 +224,7 @@ const mockInsightCard = jest.fn()const mockUpdateContainerWidth = jest.fn()const mockMoveTileToSection = jest.fn()const mockChangeTileGroupDisplay = jest.fn()+const mockRenameTileGroup = jest.fn()const mockPositionStrategies = new Map<Element, unknown>()let mockGridWidth = 1200let mockGridMounts = 0@@ -297,6 +298,7 @@ describe('DashboardItems', () => {setDashboardMode: jest.fn(),moveTileToSection: mockMoveTileToSection,changeTileGroupDisplay: mockChangeTileGroupDisplay,+ renameTileGroup: mockRenameTileGroup,}}@@ -817,6 +819,31 @@ describe('DashboardItems', () => {})+ it.each([+ { layout: 'bands', overrides: {}, item: 'Rename group' },+ { layout: 'tabs', overrides: { activeTileGroupTab: 'plans' }, item: 'Rename tab' },+ ])('renames a group from the group menu in $layout', async ({ overrides, item }) => {+ showBands(overrides)+ const bandValues = mockedUseValues.getMockImplementation()!+ mockedUseValues.mockImplementation((logic) =>+ logic === dashboardsModel ? { dashboardsLoading: false } : bandValues(logic)+ )+ const defaultActions = mockedUseActions.getMockImplementation()!+ mockedUseActions.mockImplementation((logic) =>+ logic === dashboardsModel ? { loadDashboardsIfNeeded: jest.fn() } : defaultActions(logic)+ )++ const { container, findByText, findByDisplayValue, unmount } = render(<DashboardItems />)+ fireEvent.click(container.querySelector('[data-attr="dashboard-tile-group-menu"]')!)+ fireEvent.click(await findByText(item))++ fireEvent.change(await findByDisplayValue('Plans'), { target: { value: 'Pricing plans' } })+ fireEvent.click(await findByText('Submit'))++ await waitFor(() => expect(mockRenameTileGroup).toHaveBeenCalledWith('plans', 'Pricing plans'))+ unmount()+ })+it('keeps a band grid mounted when a tile streams into the band', () => {const defaultValues = mockedUseValues.getMockImplementation()!showBands()diff --git a/frontend/src/scenes/dashboard/DashboardItems.tsx b/frontend/src/scenes/dashboard/DashboardItems.tsxindex becd61ec3647..fd5fd5a3c3c0 100644--- a/frontend/src/scenes/dashboard/DashboardItems.tsx+++ b/frontend/src/scenes/dashboard/DashboardItems.tsx@@ -154,6 +154,7 @@ export function DashboardItems({ showCreateAnomalyAlertButton }: DashboardItemsPcopyToDashboard,copyGroupToDashboard,changeTileGroupDisplay,+ renameTileGroup,setDashboardEditing,toggleTileGroup,selectTileGroupTab,@@ -278,6 +279,7 @@ export function DashboardItems({ showCreateAnomalyAlertButton }: DashboardItemsPconst onCopyGroupToDashboard = canEditDashboard && isEditablePlacement ? copyGroupToDashboard : undefinedconst onChangeGroupDisplay = canEditDashboard && isEditablePlacement ? changeTileGroupDisplay : undefined+ const onRenameTileGroup = canEditDashboard && isEditablePlacement ? renameTileGroup : undefinedconst isLayoutZoomToggled = layoutEditMode && layoutZoom !== 1@@ -844,6 +846,7 @@ export function DashboardItems({ showCreateAnomalyAlertButton }: DashboardItemsPisDropTarget={dropTargetKey === section.key}collapsedTileGroupKeys={collapsedTileGroupKeys}onToggleTileGroup={toggleTileGroup}+ onRenameTileGroup={onRenameTileGroup}copyToDestinations={copyToDestinations}onCopyGroupToDashboard={onCopyGroupToDashboard}copyLoading={copyGroupToDashboardLoading}@@ -867,6 +870,7 @@ export function DashboardItems({ showCreateAnomalyAlertButton }: DashboardItemsPsections={tileGroupSections}activeSectionKey={tileGroupSections[activeTabIndex].key}onSelect={selectTileGroupTab}+ onRenameGroup={onRenameTileGroup}copyToDestinations={copyToDestinations}onCopyGroupToDashboard={onCopyGroupToDashboard}copyLoading={copyGroupToDashboardLoading}diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex a6f9fd17160e..6baf485ec089 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -1191,6 +1191,13 @@ export interface dashboardLogicActions {tile: DashboardTile}}+ renameTileGroup: (+ groupKey: string,+ title: string+ ) => {+ groupKey: string+ title: string+ }reportDashboardFilterChange: (changeType: DashboardFilterChangeType,properties: Record<string, boolean | number | string | null | undefined>@@ -2031,6 +2038,7 @@ export const dashboardLogic = kea<dashboardLogicType>([selectTileGroupTab: (sectionKey: string) => ({ sectionKey }),refreshOpenTileGroupsWaiting: true,changeTileGroupDisplay: (groupDisplay: TileGroupDisplay) => ({ groupDisplay }),+ renameTileGroup: (groupKey: string, title: string) => ({ groupKey, title }),refreshTileGroup: (groupKey: string) => ({ groupKey }),setWaitingTileRefresh: (waiting: WaitingTileRefresh) => ({ waiting }),clearWaitingTileRefresh: (tileIds: number[]) => ({ tileIds }),@@ -5685,6 +5693,13 @@ export const dashboardLogic = kea<dashboardLogicType>([changeTileGroupDisplay: ({ groupDisplay }) => {actions.triggerDashboardUpdate({ group_display: groupDisplay })},+ renameTileGroup: ({ groupKey, title }) => {+ // The API replaces every group on write, so send the others back unchanged.+ const groups = values.dashboard?.customization?.groups ?? {}+ actions.triggerDashboardUpdate({+ groups: { ...groups, [groupKey]: { ...groups[groupKey], title: title.trim() } },+ })+ },refreshTileGroup: async ({ groupKey }) => {const { waitingTileRefresh: waiting, refreshStatus, widgetRefreshStatus } = values// A tile leaves the waiting list only once it loads, so one still loading must not load again.diff --git a/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroup.tsx b/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroup.tsxindex 049a7dd62c1a..e2e39f63df71 100644--- a/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroup.tsx+++ b/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroup.tsx@@ -17,6 +17,7 @@ interface DashboardTileGroupProps {tileCount: numbercollapsed: booleanonToggle: () => void+ onRename?: (title: string) => voidcopyToDestinations?: DashboardWidgetPlacementDestination[]onCopyToDashboard?: (dashboardId: number, dashboardName: string) => voidcopyLoading?: boolean@@ -29,6 +30,7 @@ export function DashboardTileGroup({tileCount,collapsed,onToggle,+ onRename,copyToDestinations,onCopyToDashboard,copyLoading,@@ -63,9 +65,11 @@ export function DashboardTileGroup({</LemonButton>{group.title && collapsed && <span className="shrink-0 text-secondary text-xs">{tileCountLabel}</span>}<div className="min-w-4 flex-1 border-t border-primary" />- {(onChangeGroupDisplay || onCopyToDashboard) && (+ {(onRename || onChangeGroupDisplay || onCopyToDashboard) && (<DashboardTileGroupMenugroupDisplay="sections"+ title={group.title}+ onRename={onRename}onChangeGroupDisplay={onChangeGroupDisplay}copyToDestinations={copyToDestinations}onCopyToDashboard={onCopyToDashboard}diff --git a/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroupMenu.tsx b/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroupMenu.tsxindex d61b7219a644..71efed05091f 100644--- a/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroupMenu.tsx+++ b/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroupMenu.tsx@@ -1,25 +1,30 @@-import { useActions } from 'kea'+import { useActions, useValues } from 'kea'import { DashboardWidgetPlacementMenu } from 'lib/components/Cards/InsightCard/DashboardWidgetPlacementMenu'import type { DashboardWidgetPlacementDestination } from 'lib/components/Cards/InsightCard/DashboardWidgetPlacementMenu'import { LemonButton } from 'lib/lemon-ui/LemonButton'import { More } from 'lib/lemon-ui/LemonButton/More'+import { LemonDialog } from 'lib/lemon-ui/LemonDialog'import { LemonDivider } from 'lib/lemon-ui/LemonDivider'+import { LemonField } from 'lib/lemon-ui/LemonField'+import { LemonInput } from 'lib/lemon-ui/LemonInput'import { dashboardsModel } from '~/models/dashboardsModel'import type { TileGroupDisplay } from '~/types'const MENU_ITEMS: Record<TileGroupDisplay,- { copyLabel: string; copyNoun: string; switchTo: TileGroupDisplay; switchLabel: string }+ { renameLabel: string; copyLabel: string; copyNoun: string; switchTo: TileGroupDisplay; switchLabel: string }> = {sections: {+ renameLabel: 'Rename group',copyLabel: 'Copy group to dashboard',copyNoun: 'group',switchTo: 'tabs',switchLabel: 'Show all groups as tabs',},tabs: {+ renameLabel: 'Rename tab',copyLabel: 'Copy tab to dashboard',copyNoun: 'tab',switchTo: 'sections',@@ -31,6 +36,8 @@ interface DashboardTileGroupMenuProps {// Set by the caller to match where this menu renders: "sections" in the group header,// "tabs" in the tab bar. Not read from the dashboard's actual display mode.groupDisplay: TileGroupDisplay+ title?: string+ onRename?: (title: string) => voidonChangeGroupDisplay?: (groupDisplay: TileGroupDisplay) => voidcopyToDestinations?: DashboardWidgetPlacementDestination[]onCopyToDashboard?: (dashboardId: number, dashboardName: string) => void@@ -39,13 +46,33 @@ interface DashboardTileGroupMenuProps {export function DashboardTileGroupMenu({groupDisplay,+ title,+ onRename,onChangeGroupDisplay,copyToDestinations,onCopyToDashboard,copyLoading,}: DashboardTileGroupMenuProps): JSX.Element {const { loadDashboardsIfNeeded } = useActions(dashboardsModel)- const { copyLabel, copyNoun, switchTo, switchLabel } = MENU_ITEMS[groupDisplay]+ // Each rename sends every group, so a second rename before the first saves would undo it.+ const { dashboardLoading: dashboardSaving } = useValues(dashboardsModel)+ const { renameLabel, copyLabel, copyNoun, switchTo, switchLabel } = MENU_ITEMS[groupDisplay]++ const openRenameDialog = (): void => {+ if (!onRename) {+ return+ }+ LemonDialog.openForm({+ title: renameLabel,+ initialValues: { title: title ?? '' },+ content: (+ <LemonField name="title">+ <LemonInput placeholder="Leave blank to show the tile count" maxLength={200} autoFocus />+ </LemonField>+ ),+ onSubmit: ({ title: newTitle }) => onRename(newTitle),+ })+ }return (<More@@ -56,6 +83,19 @@ export function DashboardTileGroupMenu({dropdown={{ onVisibilityChange: (visible) => visible && onCopyToDashboard && loadDashboardsIfNeeded() }}overlay={<div className="min-w-48 p-1">+ {onRename && (+ <>+ <LemonButton+ fullWidth+ onClick={openRenameDialog}+ disabledReason={dashboardSaving ? 'Saving dashboard changes' : undefined}+ data-attr="dashboard-tile-group-menu-rename"+ >+ {renameLabel}+ </LemonButton>+ {(onCopyToDashboard || onChangeGroupDisplay) && <LemonDivider />}+ </>+ )}{onCopyToDashboard && (<><DashboardWidgetPlacementMenudiff --git a/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroupTabs.tsx b/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroupTabs.tsxindex 97a1db099735..f3478318daf4 100644--- a/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroupTabs.tsx+++ b/products/dashboards/frontend/components/DashboardTileGroup/DashboardTileGroupTabs.tsx@@ -11,6 +11,7 @@ interface DashboardTileGroupTabsProps {sections: DashboardSection[]activeSectionKey: stringonSelect: (sectionKey: string) => void+ onRenameGroup?: (groupKey: string, title: string) => voidcopyToDestinations?: DashboardWidgetPlacementDestination[]onCopyGroupToDashboard?: (groupKey: string, dashboardId: number, dashboardName: string) => voidcopyLoading?: boolean@@ -22,6 +23,7 @@ export function DashboardTileGroupTabs({sections,activeSectionKey,onSelect,+ onRenameGroup,copyToDestinations,onCopyGroupToDashboard,copyLoading,@@ -49,9 +51,15 @@ export function DashboardTileGroupTabs({}))}rightSlotClassName="pr-0"rightSlot={- (onChangeGroupDisplay || onCopyGroupToDashboard) && (+ (onRenameGroup || onChangeGroupDisplay || onCopyGroupToDashboard) && (<DashboardTileGroupMenugroupDisplay="tabs"+ title={activeSection?.kind === 'group' ? activeSection.group.title : undefined}+ onRename={+ activeSection?.kind === 'group' && onRenameGroup+ ? (title) => onRenameGroup(activeSection.groupKey, title)+ : undefined+ }onChangeGroupDisplay={onChangeGroupDisplay}copyToDestinations={copyToDestinations}onCopyToDashboard={diff --git a/products/dashboards/frontend/components/DashboardTileSectionBand.tsx b/products/dashboards/frontend/components/DashboardTileSectionBand.tsxindex abcf881002f5..7ba101936300 100644--- a/products/dashboards/frontend/components/DashboardTileSectionBand.tsx+++ b/products/dashboards/frontend/components/DashboardTileSectionBand.tsx@@ -14,6 +14,7 @@ interface DashboardTileSectionBandProps {isDropTarget: booleancollapsedTileGroupKeys: string[]onToggleTileGroup: (groupKey: string) => void+ onRenameTileGroup?: (groupKey: string, title: string) => voidcopyToDestinations?: DashboardWidgetPlacementDestination[]onCopyGroupToDashboard?: (groupKey: string, dashboardId: number, dashboardName: string) => voidcopyLoading?: boolean@@ -27,6 +28,7 @@ export function DashboardTileSectionBand({isDropTarget,collapsedTileGroupKeys,onToggleTileGroup,+ onRenameTileGroup,copyToDestinations,onCopyGroupToDashboard,copyLoading,@@ -47,6 +49,7 @@ export function DashboardTileSectionBand({tileCount={section.tiles.length}collapsed={collapsedTileGroupKeys.includes(section.groupKey)}onToggle={() => onToggleTileGroup(section.groupKey)}+ onRename={onRenameTileGroup ? (title) => onRenameTileGroup(section.groupKey, title) : undefined}copyToDestinations={copyToDestinations}onCopyToDashboard={onCopyGroupToDashboard