Skip to content

Commit 357d489

Browse files
authored
feat: allow extra buttons in insight card more menu (PostHog#12133)
1 parent 4b01c34 commit 357d489

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

frontend/src/lib/components/InsightCard/InsightCard.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export interface InsightCardProps extends React.HTMLAttributes<HTMLDivElement> {
154154
rename?: () => void
155155
duplicate?: () => void
156156
moveToDashboard?: (dashboard: DashboardType) => void
157+
/** buttons to add to the "more" menu on the card**/
158+
moreButtons?: JSX.Element | null
157159
}
158160

159161
interface InsightMetaProps
@@ -170,6 +172,7 @@ interface InsightMetaProps
170172
| 'moveToDashboard'
171173
| 'showEditingControls'
172174
| 'showDetailsControls'
175+
| 'moreButtons'
173176
> {
174177
/**
175178
* Optional callback to update height of the primary InsightMeta div. Allow for coordinating InsightViz height
@@ -195,6 +198,7 @@ function InsightMeta({
195198
setAreDetailsShown,
196199
showEditingControls = true,
197200
showDetailsControls = true,
201+
moreButtons,
198202
}: InsightMetaProps): JSX.Element {
199203
const { short_id, name, description, tags, color, filters, dashboards } = insight
200204
const { exporterResourceParams, insightProps } = useValues(insightLogic)
@@ -406,6 +410,12 @@ function InsightMeta({
406410
]}
407411
/>
408412
) : null}
413+
{moreButtons && (
414+
<>
415+
<LemonDivider />
416+
{moreButtons}
417+
</>
418+
)}
409419
{editable && (
410420
<>
411421
<LemonDivider />
@@ -553,6 +563,7 @@ function InsightCardInternal(
553563
moveToDashboard,
554564
className,
555565
children,
566+
moreButtons,
556567
...divProps
557568
}: InsightCardProps,
558569
ref: React.Ref<HTMLDivElement>
@@ -616,6 +627,7 @@ function InsightCardInternal(
616627
setAreDetailsShown={setAreDetailsShown}
617628
showEditingControls={showEditingControls}
618629
showDetailsControls={showDetailsControls}
630+
moreButtons={moreButtons}
619631
/>
620632
<InsightViz
621633
insight={insight}

frontend/src/scenes/dashboard/DashboardItems.tsx

+34-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,29 @@ import { dashboardLogic, BREAKPOINT_COLUMN_COUNTS, BREAKPOINTS } from 'scenes/da
1010
import clsx from 'clsx'
1111
import { InsightCard } from 'lib/components/InsightCard'
1212
import { useResizeObserver } from 'lib/hooks/useResizeObserver'
13+
import { LemonButton } from 'lib/components/LemonButton'
14+
import { DashboardEventSource } from 'lib/utils/eventUsageLogic'
1315

1416
export function DashboardItems(): JSX.Element {
15-
const { dashboard, items, layouts, dashboardMode, placement, isRefreshing, highlightedInsightId, refreshStatus } =
16-
useValues(dashboardLogic)
17-
const { updateLayouts, updateContainerWidth, updateItemColor, removeItem, refreshAllDashboardItems } =
18-
useActions(dashboardLogic)
17+
const {
18+
dashboard,
19+
items,
20+
layouts,
21+
dashboardMode,
22+
placement,
23+
isRefreshing,
24+
highlightedInsightId,
25+
refreshStatus,
26+
canEditDashboard,
27+
} = useValues(dashboardLogic)
28+
const {
29+
updateLayouts,
30+
updateContainerWidth,
31+
updateItemColor,
32+
removeItem,
33+
refreshAllDashboardItems,
34+
setDashboardMode,
35+
} = useActions(dashboardLogic)
1936
const { duplicateInsight, renameInsight, moveToDashboard } = useActions(insightsModel)
2037

2138
const [resizingItem, setResizingItem] = useState<any>(null)
@@ -103,6 +120,19 @@ export function DashboardItems(): JSX.Element {
103120
DashboardPlacement.ProjectHomepage,
104121
].includes(placement)}
105122
showDetailsControls={placement != DashboardPlacement.Export}
123+
moreButtons={
124+
canEditDashboard ? (
125+
<LemonButton
126+
onClick={() =>
127+
setDashboardMode(DashboardMode.Edit, DashboardEventSource.MoreDropdown)
128+
}
129+
status="stealth"
130+
fullWidth
131+
>
132+
Edit layout (E)
133+
</LemonButton>
134+
) : null
135+
}
106136
/>
107137
))}
108138
</ReactGridLayout>

0 commit comments

Comments
 (0)