: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): add hover refresh to dashboard widget tiles (#65507)
Matt Pua58340ad489bb
diff --git a/frontend/src/lib/components/Cards/CardMetaRefreshButton.tsx b/frontend/src/lib/components/Cards/CardMetaRefreshButton.tsxnew file mode 100644index 000000000000..9889bdc1ae5f--- /dev/null+++ b/frontend/src/lib/components/Cards/CardMetaRefreshButton.tsx@@ -0,0 +1,37 @@+import { IconRefresh } from '@posthog/icons'++import { dayjs, type Dayjs } from 'lib/dayjs'+import { LemonButton } from 'lib/lemon-ui/LemonButton'++/** Hover-revealed refresh icon for a card header. Pass to `CardMeta`'s `refreshControl`; the+ * `.CardMeta__refresh` class is the hook `CardMeta.scss` uses to hide it until the tile is hovered.+ * Callers decide whether to render it at all (gating differs per card type). */+export function CardMetaRefreshButton({+ onRefresh,+ lastRefresh,+ disabledReason,+ dataAttr,+}: {+ onRefresh: () => void+ lastRefresh?: string | number | Dayjs | null+ disabledReason?: string+ dataAttr: string+}): JSX.Element {+ return (+ <LemonButton+ className="CardMeta__refresh"+ icon={<IconRefresh />}+ size="small"+ onClick={onRefresh}+ disabledReason={disabledReason}+ tooltip={+ disabledReason+ ? undefined+ : lastRefresh+ ? `Refresh data (last computed ${dayjs(lastRefresh).fromNow()})`+ : 'Refresh data'+ }+ data-attr={dataAttr}+ />+ )+}diff --git a/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx b/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsxindex 7efc9ea1e17c..38f8125afbfc 100644--- a/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx+++ b/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx@@ -2,12 +2,13 @@ import clsx from 'clsx'import { useActions, useValues } from 'kea'import React, { useCallback, useEffect, useRef, useState } from 'react'-import { IconInfo, IconRefresh, IconThumbsDown, IconThumbsUp } from '@posthog/icons'+import { IconInfo, IconThumbsDown, IconThumbsUp } from '@posthog/icons'import { lemonToast } from '@posthog/lemon-ui'import { areAlertsSupportedForInsight, insightAlertsLogic } from 'lib/components/Alerts/insightAlertsLogic'import { ManageAlertsModal } from 'lib/components/Alerts/views/ManageAlertsModal'import { CardMeta } from 'lib/components/Cards/CardMeta'+import { CardMetaRefreshButton } from 'lib/components/Cards/CardMetaRefreshButton'import { DashboardTileRefreshDataButton } from 'lib/components/Cards/InsightCard/DashboardTileRefreshDataButton'import { TopHeading } from 'lib/components/Cards/InsightCard/TopHeading'import { EditableField } from 'lib/components/EditableField/EditableField'@@ -298,20 +299,11 @@ export function InsightMeta({// dashboards, matching the "⋯" menu (which is already gated there).const refreshControl =refresh && showEditingControls && !tileRefreshing ? (- <LemonButton- className="CardMeta__refresh"- icon={<IconRefresh />}- size="small"- onClick={() => refresh()}+ <CardMetaRefreshButton+ onRefresh={() => refresh()}+ lastRefresh={insight.last_refresh}disabledReason={refreshDisabledReason}- tooltip={- refreshDisabledReason- ? undefined- : insight.last_refresh- ? `Refresh data (last computed ${dayjs(insight.last_refresh).fromNow()})`- : 'Refresh data'- }- data-attr="insight-card-refresh"+ dataAttr="insight-card-refresh"/>) : nulldiff --git a/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.test.tsx b/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.test.tsxindex 8bc77c293581..9ec60faf5338 100644--- a/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.test.tsx+++ b/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.test.tsx@@ -199,7 +199,7 @@ describe('DashboardWidgetItem', () => {expect(screen.getByText('Dashboard')).toBeInTheDocument()expect(screen.getByRole('button', { name: 'Hide description' })).toBeInTheDocument()expect(screen.getByRole('button', { name: 'Remove from dashboard' })).toBeInTheDocument()- const refreshTrigger = screen.getByRole('button', { name: /Refresh data/i })+ const refreshTrigger = document.querySelector('[data-attr="dashboard-tile-refresh-data"]') as HTMLElementexpect(refreshTrigger).toBeInTheDocument()expect(screen.getByText(/Last computed/i)).toBeInTheDocument()diff --git a/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.tsx b/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.tsxindex 2eb74ec68bfa..c14f58484371 100644--- a/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.tsx+++ b/products/dashboards/frontend/components/DashboardWidgetItem/DashboardWidgetItem.tsx@@ -3,6 +3,7 @@ import { useValues } from 'kea'import React, { useState } from 'react'import { createPortal } from 'react-dom'+import { CardMetaRefreshButton } from 'lib/components/Cards/CardMetaRefreshButton'import { DashboardTileRefreshDataButton } from 'lib/components/Cards/InsightCard/DashboardTileRefreshDataButton'import { dashboardWidgetMenusLogic } from 'lib/components/Cards/InsightCard/dashboardWidgetMenusLogic'import { DashboardWidgetPlacementMenus } from 'lib/components/Cards/InsightCard/DashboardWidgetPlacementMenus'@@ -203,6 +204,15 @@ function DashboardWidgetItemContent({const refreshDisabledReason = loading ? 'Refreshing...' : undefined+ // Refresh icon revealed on tile hover, mirroring insight tiles. Gated on editing controls so it+ // stays off public/export dashboards, and hidden while the tile is loading (refresh stays reachable+ // via the always-present "⋯" menu for touch/keyboard). CardMeta's CSS handles the hover reveal.+ const showHoverRefresh =+ !!showEditingControls && !isUnknownWidgetType && headerLayout === 'dashboard_tile' && !loading+ const refreshControl = showHoverRefresh ? (+ <CardMetaRefreshButton onRefresh={onRefresh} lastRefresh={lastFetchedAt} dataAttr="dashboard-widget-refresh" />+ ) : null+return (<><WidgetCardHeader@@ -220,6 +230,7 @@ function DashboardWidgetItemContent({showEditingControls={showEditingControls}isDashboardEditMode={isDashboardEditMode}shouldHideMoreButton={widgetCardShouldHideMoreButton(placement, showEditingControls)}+ refreshControl={refreshControl}moreButtonOverlay={<>{titleHref && (diff --git a/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.test.tsx b/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.test.tsxindex b814a5c994c4..e6dd70e76d5c 100644--- a/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.test.tsx+++ b/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.test.tsx@@ -127,6 +127,21 @@ describe('WidgetCardHeader', () => {expect(screen.getByRole('link', { name: /Top issues/i })).toHaveAttribute('href', '/error_tracking')})+ it('forwards the hover refresh control into the dashboard_tile header', () => {+ const { container } = render(+ <WidgetCardHeader+ layout="dashboard_tile"+ title="Top issues"+ topHeading={<span>Error tracking • Last 7 days</span>}+ moreButtonOverlay={<div>Menu</div>}+ refreshControl={<button className="CardMeta__refresh" data-attr="dashboard-widget-refresh" />}+ />+ )++ expect(container.querySelector('[data-attr="dashboard-widget-refresh"]')).toBeTruthy()+ expect(container.querySelector('.CardMeta__controls .CardMeta__refresh')).toBeTruthy()+ })+it('renders simple layout without inline refresh', () => {const { container } = render(<WidgetCardHeader layout="simple" title="My widget" showEditingControls={false} />)diff --git a/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.tsx b/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.tsxindex d3f7b6a24642..48b37abce704 100644--- a/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.tsx+++ b/products/dashboards/frontend/components/WidgetCard/WidgetCardHeader.tsx@@ -42,6 +42,8 @@ export type WidgetCardHeaderProps = {isDashboardEditMode?: booleanshouldHideMoreButton?: booleanmoreButtonOverlay?: MoreProps['overlay']+ /** Refresh control revealed on tile hover (dashboard_tile layout only); forwarded to CardMeta. */+ refreshControl?: JSX.Element | nullonDragHandleMouseDown?: React.MouseEventHandler<HTMLDivElement>}@@ -173,6 +175,7 @@ export function WidgetCardHeader({isDashboardEditMode,shouldHideMoreButton,moreButtonOverlay,+ refreshControl,onDragHandleMouseDown,}: WidgetCardHeaderProps): JSX.Element {const showWidgetType = headerMeta?.showWidgetType ?? true@@ -236,6 +239,7 @@ export function WidgetCardHeader({topHeading={(resolvedTopHeading as JSX.Element | null) ?? null}onMouseDown={showEditingControls ? onDragHandleMouseDown : undefined}moreButtons={moreButtonOverlay as JSX.Element | undefined}+ refreshControl={refreshControl}content={<>{titleEl}