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(dashboards): show add tile button in edit mode (#60711)

Matt Puaaf28739d3daf
diff --git a/frontend/src/scenes/dashboard/DashboardHeader.test.tsx b/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
index 86ec11a70f49..cb94522dbcdc 100644
--- a/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeader.test.tsx
@@ -113,7 +113,7 @@ describe('DashboardHeader', () => {
scenario: 'Edit mode',
dashboardMode: DashboardMode.Edit,
canEdit: true,
- visible: ['dashboard-edit-mode-discard', 'dashboard-edit-mode-save'],
+ visible: ['dashboard-edit-mode-discard', 'dashboard-edit-mode-save', 'dashboard-add-tile'],
notVisible: ['dashboard-share-button', 'add-text-tile-to-dashboard', 'dashboard-add-graph-header'],
},
{
diff --git a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
index 9daf4a405c63..62d58d6ff9ba 100644
--- a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
@@ -19,6 +19,69 @@ import { AccessControlLevel, AccessControlResourceType, DashboardMode } from '~/
import { addInsightToDashboardLogic } from './addInsightToDashboardModalLogic'
import { DashboardLoadAction, dashboardLogic } from './dashboardLogic'
+export function DashboardAddTileButton(): JSX.Element | null {
+ const { dashboard } = useValues(dashboardLogic)
+ const { loadDashboard } = useActions(dashboardLogic)
+ const { showAddInsightToDashboardModal } = useActions(addInsightToDashboardLogic)
+ const { push } = useActions(router)
+
+ if (!dashboard) {
+ return null
+ }
+
+ return (
+ <MaxTool
+ className="shrink-0"
+ identifier="upsert_dashboard"
+ context={{
+ current_dashboard: {
+ id: dashboard.id,
+ name: dashboard.name,
+ description: dashboard.description,
+ tags: dashboard.tags,
+ },
+ }}
+ contextDescription={{
+ text: dashboard.name,
+ icon: iconForType('dashboard'),
+ }}
+ active={false}
+ callback={() => loadDashboard({ action: DashboardLoadAction.Update })}
+ position="top-right"
+ >
+ <AccessControlAction
+ resourceType={AccessControlResourceType.Dashboard}
+ minAccessLevel={AccessControlLevel.Editor}
+ userAccessLevel={dashboard.user_access_level}
+ >
+ <LemonMenu
+ items={[
+ {
+ label: 'Insight',
+ onClick: showAddInsightToDashboardModal,
+ 'data-attr': 'dashboard-add-insight',
+ },
+ {
+ label: 'Text card',
+ onClick: () => push(urls.dashboardTextTile(dashboard.id, 'new')),
+ 'data-attr': 'dashboard-add-text-tile',
+ },
+ {
+ label: 'Button',
+ onClick: () => push(urls.dashboardButtonTile(dashboard.id, 'new')),
+ 'data-attr': 'dashboard-add-button-tile',
+ },
+ ]}
+ >
+ <LemonButton type="primary" data-attr="dashboard-add-tile" size="small" icon={<IconPlusSmall />}>
+ Add
+ </LemonButton>
+ </LemonMenu>
+ </AccessControlAction>
+ </MaxTool>
+ )
+}
+
export function EditModeActions(): JSX.Element {
const { dashboardLoading, canEditDashboard } = useValues(dashboardLogic)
const { setDashboardMode, cancelEditMode } = useActions(dashboardLogic)
@@ -68,6 +131,7 @@ export function EditModeActions(): JSX.Element {
Save
</LemonButton>
</AppShortcut>
+ <DashboardAddTileButton />
</>
)
}
@@ -91,8 +155,7 @@ export function FullscreenModeActions(): JSX.Element {
export function ViewModeActions(): JSX.Element {
const { dashboard, canEditDashboard, tiles } = useValues(dashboardLogic)
- const { setDashboardMode, loadDashboard } = useActions(dashboardLogic)
- const { showAddInsightToDashboardModal } = useActions(addInsightToDashboardLogic)
+ const { setDashboardMode } = useActions(dashboardLogic)
const { push } = useActions(router)
if (!dashboard) {
return <></>
@@ -133,59 +196,7 @@ export function ViewModeActions(): JSX.Element {
</LemonButton>
</AppShortcut>
)}
- <MaxTool
- identifier="upsert_dashboard"
- context={{
- current_dashboard: {
- id: dashboard.id,
- name: dashboard.name,
- description: dashboard.description,
- tags: dashboard.tags,
- },
- }}
- contextDescription={{
- text: dashboard.name,
- icon: iconForType('dashboard'),
- }}
- active={false}
- callback={() => loadDashboard({ action: DashboardLoadAction.Update })}
- position="top-right"
- >
- <AccessControlAction
- resourceType={AccessControlResourceType.Dashboard}
- minAccessLevel={AccessControlLevel.Editor}
- userAccessLevel={dashboard.user_access_level}
- >
- <LemonMenu
- items={[
- {
- label: 'Insight',
- onClick: showAddInsightToDashboardModal,
- 'data-attr': 'dashboard-add-insight',
- },
- {
- label: 'Text card',
- onClick: () => push(urls.dashboardTextTile(dashboard.id, 'new')),
- 'data-attr': 'dashboard-add-text-tile',
- },
- {
- label: 'Button',
- onClick: () => push(urls.dashboardButtonTile(dashboard.id, 'new')),
- 'data-attr': 'dashboard-add-button-tile',
- },
- ]}
- >
- <LemonButton
- type="primary"
- data-attr="dashboard-add-tile"
- size="small"
- icon={<IconPlusSmall />}
- >
- Add
- </LemonButton>
- </LemonMenu>
- </AccessControlAction>
- </MaxTool>
+ <DashboardAddTileButton />
</>
)
}