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.

feat(product-analytics): home tile details and new nav home switcher (#123895)

Daniel Parker5e6eb835f241
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 4919fd1c992f..08b6d260c5b7 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -14665,21 +14665,21 @@ snapshots:
scenes-app-product-analytics-home-dashboard-starter--with-custom-dashboard--light:
hash: v1.k794b7964.d046e7c378631fbc809bf0516603a283be253fbfe9ee3c8670ef9f048240f8a5.Eup-VPPpS0s9a1iCk1V6W9Qo2fJ_05f1XcZfa5Alfw8
scenes-app-product-analytics-home-overview--before-ingestion--dark:
- hash: v1.k794b7964.bff29edb6945a3e9b7b63468b02799247577a7732611ab762a8c4a357ccb44db.lE3XTYAk0219w1cEv9T2N4FFAcUwAEwRMuBoejf6XA0
+ hash: v1.k794b7964.89bcb90542c502956ba1914557af99c94d21c6e61797281c18e3e3020f9f1924.vjvWdPsD5gGrEzHNJ4aPzUHeNBJ1NX6YXraCn5LR1qY
scenes-app-product-analytics-home-overview--before-ingestion--light:
- hash: v1.k794b7964.3b226554d4329b049ef5851857667071eead3e8de9479a614215676c8f4f684e.kmG9sj_rm7-nQjDbwKKBXQQFEDwWRPnTQPuaGzOhmbY
+ hash: v1.k794b7964.917f5a58ac42a8dc7a286723cc1a45a2f26cdd1d15bd60d8974e688f7c2b344f.ih0PgcoqFvcu_u2WfaQG4ZtuLLk4Ta1U2Q1Xj0lenrk
scenes-app-product-analytics-home-overview--empty--dark:
- hash: v1.k794b7964.803d51407dca494e41d04f4cb5fb324abd193b22d9cad2b60b92087ec1bf76b5.nESq7Ay6ngu1UriAYHASMUKdnt6lU8FQZwgXkFcizKw
+ hash: v1.k794b7964.5f617b3e32787bc21998c3fc27c321d9f4c6be497ce812b4b0502f6361fb78e1.crR1u135qlBMMpqrGD4kO-tJH4xcIFxs3Y3s9t-usYM
scenes-app-product-analytics-home-overview--empty--light:
- hash: v1.k794b7964.bbc8f2807fbdbb994335bd45527ec76fae3715471ee2e97663b08bcc9fd6f622.UW0QtE1YywbSW_gQEL4Gq1k7rRkBXYQQtsxiE3GNf4I
+ hash: v1.k794b7964.063020d964ae9ba0fc5b83a1a1e26fa203dc3b77874136658d97ba98c74369bb.AGcHuFEO2HipWAP3sltBnYUNDVzj9eIThZvgfhf9tJs
scenes-app-product-analytics-home-overview--narrow--dark:
- hash: v1.k794b7964.10fdc8234bd0905062402d37caa4ce2a8841b9577e54d6f946585e6e194b7480.KN7FFNufCXONd_uyT1GaNv8JCcYJ05Ag5O947lb8HlU
+ hash: v1.k794b7964.8f659471d49943c09e372b4c053125dcba2423577219dbebaf0856132b878e7e.Pbyi6ueHc8IWZ4feYmyPcsp8O_QcomFcEtx59uRxcb4
scenes-app-product-analytics-home-overview--narrow--light:
- hash: v1.k794b7964.9d3c1454ad3f10dddcd9defa0e240d6d6a9b8b0ba1b3317178216b1659786105.7FSaWiLmk4cSkxrW6L5TBcb_SPcUpgkjvZizLmNQTA4
+ hash: v1.k794b7964.3a970df8da728bce6f18a2adba0cc66c846e02f3090cc11925a1477ef7084c66.b-huYobkC5OCeKeaNsLqDWA-sc8uic32bNbtKKtYmvA
scenes-app-product-analytics-home-overview--populated--dark:
- hash: v1.k794b7964.45cdcbe0f6092982422bc27d86136b4caa6dac940d0e066ed8e85afc8b4dbf4b.pnVy48OtiJfwaoROH5nC86yftcc4snM385QrZFBULDI
+ hash: v1.k794b7964.8f1ad5e647a300eb7de0954c7c652a9ef4f701b19957468ed40056f7290f0f55.BoH5mh6lfXNiWN7xKevBwvOCsxLqfdajuE6U30zpInA
scenes-app-product-analytics-home-overview--populated--light:
- hash: v1.k794b7964.8f7a61df2076dfa314f9cd59de52419f8668edfe59de7e9cb40b6e1addc72672.FLoplLDuZ4bUY_wnMH_1mp7Se0orpcdvbY-KnEZQobU
+ hash: v1.k794b7964.0cc8b9e2521b08b78d3fa9ae39827779e85415deb04142351ebedc9bded95510.-5O20ZJYCRyKV9SrYpVWYlC08Rl1fewTi8tNVSoWNL8
scenes-app-project-homepage--no-primary-dashboard--dark:
hash: v1.k794b7964.bdd0395e3875cbfe2b0853312e66ac8eeab17807acae8c5d6ae251bb06df61cd.BuB-luHXv5Ydt_CFRSDkaweFlYmEsz9z8SawKT-cAkY
scenes-app-project-homepage--no-primary-dashboard--light:
@@ -15085,21 +15085,21 @@ snapshots:
scenes-app-saved-insights--error-state--light:
hash: v1.k794b7964.0565c027e3f4486ba3d028e53f9afc6bfb3e63f0512a7ee3234604215de3b1f3.EzVsQ9cjARMpfneTgba7uAi47mATO2MWtPn4g5BfW6E
scenes-app-saved-insights--home--dark:
- hash: v1.k794b7964.4f6cb09aac8b830ed0aa50bfa1b140bde7615871026a5ca1d4f3211e2aa40f3a.XTeHYdm_qcSPcX50vAgwIJnQcor1Rs6mhTsjyhdoLAE
+ hash: v1.k794b7964.c4f279213da3c6451b95c3698401737043435c809e3cc7794206346d9ad57391.p7AR1HzQK-KS0fW1nzoU6iiDQBVT9kyKrefdA8aTmUM
scenes-app-saved-insights--home--light:
- hash: v1.k794b7964.a95724c4cf917467e053fcd850bcc9dc63f7e603e8c2607863a3e1031bfb448b.VkwBMS5QvfMZtQkklJsVaCxsMCH2FtXhBz-ts7EUEWI
+ hash: v1.k794b7964.59680d238240b93031d357d963c42e5f88d4653e3683e99f1e902f935aeeebba.lXZs0mA6DwIpC4RPWHDFji-1XssbzcjyM4G5GmFQYpk
scenes-app-saved-insights--home-narrow--dark:
- hash: v1.k794b7964.1ecb489740ff292c1609afeaee4c92a9b85eb2fa69a6d4319bf261c200ae1b43.lfjeIlUR65cvXSHJZKcaVHNJyPAHlkUMGq5onJOtLTo
+ hash: v1.k794b7964.c08e0fa20bf164abb181a57890049b3fb4141c3a032cf02ca379b94f86a4f33b.yRHSWPZOVt4TyWLliUlGTq__LEx_H-aYT5sx5XIGc4k
scenes-app-saved-insights--home-narrow--light:
- hash: v1.k794b7964.cd6dcf1039471f5017fadadd210d87997a3ee6d1daaf28409de92f88efb7cde5.yLtzV2OVUQtJJG-0gqF238QFCwLHRgxgloCBo0HdBHc
+ hash: v1.k794b7964.49ace0ddb84e6409292566518b1ff687c39fe7380a09bc6d24b793ddc6d514b4.yTR909xH6MUiiaHG3H5Zl6xdhUEBahU8EWpzGu775KM
scenes-app-saved-insights--home-phone--dark:
- hash: v1.k794b7964.9317f4e7470bca6402a4baf9b59d7538de03a56afa8f7b09adcab0d350f1ed8b.VQKSURoFdAhZ31HYipB6yFX3Q3DqVzqHXyzVXnImQqA
+ hash: v1.k794b7964.4376ad8dd995a3ee3e164bfb2636a45bb1bf38a138372ef49b6937ef98da8312.wY5s-Lv7zStXR7rF8ovHpknGjxhTLe8sNVoHQSAbKww
scenes-app-saved-insights--home-phone--light:
- hash: v1.k794b7964.a1a5cb33b508b105084b5f630cd861a36599093b9f2455af5c4f844167e74e47.tyv_ay9jqi__Y598pn77AJgC22NmnxIUQNS6aJozAgk
+ hash: v1.k794b7964.3043ae1c4d7f2742c5c0fcfc4b0f22554308092aa8ad36f5176be41393d8ac8f.gtJ3fDy9_Hmx0-3zFheKDm1SM5ppmqAL3-HxURSk26o
scenes-app-saved-insights--home-with-boolean-flag--dark:
- hash: v1.k794b7964.4f6cb09aac8b830ed0aa50bfa1b140bde7615871026a5ca1d4f3211e2aa40f3a.DGlI8zbpdZ8wOsFzUJK2IR5u8cJP9CeyKlGQagVqBRQ
+ hash: v1.k794b7964.c4f279213da3c6451b95c3698401737043435c809e3cc7794206346d9ad57391.f_3jH40hbfPe7_5SjcwmAXGGLioTUdJng8dC9HJtKKg
scenes-app-saved-insights--home-with-boolean-flag--light:
- hash: v1.k794b7964.a95724c4cf917467e053fcd850bcc9dc63f7e603e8c2607863a3e1031bfb448b.jlj0ZBOaomnmubjHsNSO9vMRJxk3JTH43pM6zu_YIdI
+ hash: v1.k794b7964.59680d238240b93031d357d963c42e5f88d4653e3683e99f1e902f935aeeebba.tdPfGroA-KYEtlIlqpfWEojtgd5XDMQZVri7H-JpquQ
scenes-app-saved-insights--list-view--dark:
hash: v1.k794b7964.87a635b42d5362c5eb23a783ae97c79125b56ad291a95fe160c7b075de5c4055.mjVdmGX-V-BQKFTIPoJ_KlSxTMUJ7CJb8Up3iVOKV8Q
scenes-app-saved-insights--list-view--light:
diff --git a/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.tsx b/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.tsx
index 73d59a49f37f..fa7b28e74454 100644
--- a/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.tsx
+++ b/frontend/src/lib/components/AnalyticsMetricCard/AnalyticsMetricCard.tsx
@@ -12,6 +12,8 @@ export interface AnalyticsMetricCardProps extends MetricCardProps {
onClick?: () => void
selected?: boolean
ariaLabel?: string
+ /** Rendered above the clickable area, so it can hold its own buttons. */
+ header?: ReactNode
adornment?: ReactNode
}
@@ -23,6 +25,7 @@ export function AnalyticsMetricCard({
onClick,
selected,
ariaLabel,
+ header,
adornment,
className,
dataAttr,
@@ -31,7 +34,10 @@ export function AnalyticsMetricCard({
}: AnalyticsMetricCardProps): JSX.Element {
const Content = onClick ? 'button' : 'div'
const hasValue = metricProps.value != null || metricProps.data?.some(Number.isFinite)
- const label = <span className={clsx('inline-flex items-center gap-1', selected && 'text-accent')}>{title}</span>
+ const label =
+ title != null ? (
+ <span className={clsx('inline-flex items-center gap-1', selected && 'text-accent')}>{title}</span>
+ ) : null
return (
<div
@@ -42,6 +48,7 @@ export function AnalyticsMetricCard({
className
)}
>
+ {header}
<Content
type={onClick ? 'button' : undefined}
onClick={
@@ -70,13 +77,23 @@ export function AnalyticsMetricCard({
</span>
) : error || !hasValue ? (
<>
- <span className="mb-2 text-sm font-medium">{label}</span>
+ {label && <span className="mb-2 text-sm font-medium">{label}</span>}
<span className={clsx('text-sm', error ? 'text-danger' : 'text-secondary')}>
{error || emptyMessage}
</span>
</>
) : (
- <MetricCard {...metricProps} title={label} className="h-full [&>div:first-child]:flex-1" />
+ <MetricCard
+ {...metricProps}
+ title={label}
+ className={clsx(
+ 'h-full',
+ // The subtitle takes the spare height, so a wrapped inline pill does not move the headline.
+ metricProps.changeInline
+ ? '[&>[data-attr=metric-card-subtitle]]:flex-1'
+ : '[&>div:first-child]:flex-1'
+ )}
+ />
)}
{onClick && selected === undefined && (
<IconChevronRight className="absolute bottom-3 right-3 size-3 text-secondary" aria-hidden />
diff --git a/frontend/src/lib/components/Cards/InsightCard/CompactInfoPopover.tsx b/frontend/src/lib/components/Cards/InsightCard/CompactInfoPopover.tsx
new file mode 100644
index 000000000000..5c41316f8aa8
--- /dev/null
+++ b/frontend/src/lib/components/Cards/InsightCard/CompactInfoPopover.tsx
@@ -0,0 +1,142 @@
+import React, { useCallback, useEffect, useRef, useState } from 'react'
+
+import { IconInfo } from '@posthog/icons'
+
+import { EditableField } from 'lib/components/EditableField/EditableField'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { Popover } from 'lib/lemon-ui/Popover'
+
+export function CompactInfoPopover({
+ onVisibilityChange,
+ popoverTopHeading,
+ metaTitle,
+ metaDescription,
+ metaDescriptionText,
+ onMetaSave,
+ metaDetails,
+}: {
+ onVisibilityChange?: (visible: boolean) => void
+ popoverTopHeading?: JSX.Element | null
+ metaTitle: string
+ metaDescription?: JSX.Element | null
+ metaDescriptionText: string
+ onMetaSave?: (updates: { name?: string; description?: string }) => void
+ metaDetails?: JSX.Element | null
+}): JSX.Element {
+ const [popoverVisible, setPopoverVisible] = useState(false)
+ useEffect(() => {
+ onVisibilityChange?.(popoverVisible)
+ }, [popoverVisible, onVisibilityChange])
+ useEffect(() => () => onVisibilityChange?.(false), [onVisibilityChange])
+ const [pinned, setPinned] = useState(false)
+ const hoverTimerRef = useRef<ReturnType<typeof setTimeout>>()
+
+ useEffect(() => () => clearTimeout(hoverTimerRef.current), [])
+
+ const clearHoverTimer = (): void => clearTimeout(hoverTimerRef.current)
+
+ const showDetails = useCallback(() => {
+ clearHoverTimer()
+ hoverTimerRef.current = setTimeout(() => setPopoverVisible(true), 300)
+ }, [])
+
+ const hideDetails = useCallback(() => {
+ clearHoverTimer()
+ hoverTimerRef.current = setTimeout(() => setPopoverVisible(false), 800)
+ }, [])
+
+ const handleClickInfo = useCallback(
+ (e: React.MouseEvent) => {
+ e.preventDefault()
+ e.stopPropagation()
+ clearHoverTimer()
+ const newPinned = !pinned
+ setPinned(newPinned)
+ setPopoverVisible(newPinned)
+ },
+ [pinned]
+ )
+
+ const handleClickOutside = useCallback(() => {
+ clearHoverTimer()
+ setPinned(false)
+ setPopoverVisible(false)
+ }, [])
+
+ return (
+ <Popover
+ visible={popoverVisible}
+ placement="bottom"
+ showArrow
+ onClickOutside={handleClickOutside}
+ onMouseEnterInside={showDetails}
+ onMouseLeaveInside={pinned ? undefined : hideDetails}
+ overlay={
+ <div
+ className="p-4 max-w-md space-y-3"
+ onMouseDown={(e) => e.stopPropagation()}
+ onClick={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+ }}
+ >
+ {popoverTopHeading && (
+ <h5 className="uppercase text-xs font-bold text-muted tracking-wide m-0">
+ {popoverTopHeading}
+ </h5>
+ )}
+ {onMetaSave ? (
+ <>
+ <EditableField
+ name="title"
+ value={metaTitle || ''}
+ onSave={(value) => onMetaSave({ name: value })}
+ placeholder="Untitled"
+ saveOnBlur
+ clickToEdit
+ compactButtons
+ compactIcon
+ className="font-semibold text-sm mt-1"
+ data-attr="insight-card-title"
+ />
+ <EditableField
+ name="description"
+ value={metaDescriptionText || ''}
+ onSave={(value) => onMetaSave({ description: value })}
+ placeholder="Enter description (optional)"
+ saveOnBlur
+ clickToEdit
+ multiline
+ markdown
+ compactButtons
+ compactIcon
+ className="text-xs w-full"
+ data-attr="insight-card-description"
+ />
+ </>
+ ) : (
+ <>
+ {metaTitle && <p className="font-semibold m-0">{metaTitle}</p>}
+ {metaDescription}
+ </>
+ )}
+ {metaDetails}
+ </div>
+ }
+ >
+ <span
+ className="ml-1 flex-shrink-0"
+ onMouseEnter={showDetails}
+ onMouseLeave={pinned ? undefined : hideDetails}
+ >
+ <LemonButton
+ icon={<IconInfo />}
+ size="small"
+ noPadding
+ data-attr="card-meta-info"
+ onClick={handleClickInfo}
+ />
+ </span>
+ </Popover>
+ )
+}
diff --git a/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx b/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx
index 197e6eeaac18..6327a771dbc0 100644
--- a/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx
+++ b/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx
@@ -1,23 +1,15 @@
import clsx from 'clsx'
import { useActions, useValues } from 'kea'
-import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
+import React, { useMemo, useState } from 'react'
-import {
- IconChevronRight,
- IconClock,
- IconInfo,
- IconPulse,
- IconThumbsDown,
- IconThumbsUp,
- IconWarning,
-} from '@posthog/icons'
+import { IconChevronRight, IconClock, IconPulse, IconThumbsDown, IconThumbsUp, IconWarning } from '@posthog/icons'
import { lemonToast } from '@posthog/lemon-ui'
import { CardMeta } from 'lib/components/Cards/CardMeta'
import { CardMetaRefreshButton } from 'lib/components/Cards/CardMetaRefreshButton'
+import { CompactInfoPopover } from 'lib/components/Cards/InsightCard/CompactInfoPopover'
import { DashboardTileRefreshDataButton } from 'lib/components/Cards/InsightCard/DashboardTileRefreshDataButton'
import { TopHeading } from 'lib/components/Cards/InsightCard/TopHeading'
-import { EditableField } from 'lib/components/EditableField/EditableField'
import { ExportButton } from 'lib/components/ExportButton/ExportButton'
import { ObjectTags } from 'lib/components/ObjectTags/ObjectTags'
import { captureImageLogic } from 'lib/components/Scenes/InsightOrDashboard/captureImageLogic'
@@ -31,7 +23,6 @@ import { LemonMenu } from 'lib/lemon-ui/LemonMenu'
import { LemonTableLoader } from 'lib/lemon-ui/LemonTable/LemonTableLoader'
import { LemonTag } from 'lib/lemon-ui/LemonTag'
import { Link } from 'lib/lemon-ui/Link'
-import { Popover } from 'lib/lemon-ui/Popover'
import { Spinner } from 'lib/lemon-ui/Spinner'
import { Splotch, SplotchColor } from 'lib/lemon-ui/Splotch'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
@@ -989,138 +980,3 @@ export function InsightMetaContent({
</>
)
}
-
-function CompactInfoPopover({
- onVisibilityChange,
- popoverTopHeading,
- metaTitle,
- metaDescription,
- metaDescriptionText,
- onMetaSave,
- metaDetails,
-}: {
- onVisibilityChange?: (visible: boolean) => void
- popoverTopHeading?: JSX.Element | null
- metaTitle: string
- metaDescription?: JSX.Element | null
- metaDescriptionText: string
- onMetaSave?: (updates: { name?: string; description?: string }) => void
- metaDetails?: JSX.Element | null
-}): JSX.Element {
- const [popoverVisible, setPopoverVisible] = useState(false)
- useEffect(() => {
- onVisibilityChange?.(popoverVisible)
- }, [popoverVisible, onVisibilityChange])
- useEffect(() => () => onVisibilityChange?.(false), [onVisibilityChange])
- const [pinned, setPinned] = useState(false)
- const hoverTimerRef = useRef<ReturnType<typeof setTimeout>>()
-
- useEffect(() => () => clearTimeout(hoverTimerRef.current), [])
-
- const clearHoverTimer = (): void => clearTimeout(hoverTimerRef.current)
-
- const showDetails = useCallback(() => {
- clearHoverTimer()
- hoverTimerRef.current = setTimeout(() => setPopoverVisible(true), 300)
- }, [])
-
- const hideDetails = useCallback(() => {
- clearHoverTimer()
- hoverTimerRef.current = setTimeout(() => setPopoverVisible(false), 800)
- }, [])
-
- const handleClickInfo = useCallback(
- (e: React.MouseEvent) => {
- e.preventDefault()
- e.stopPropagation()
- clearHoverTimer()
- const newPinned = !pinned
- setPinned(newPinned)
- setPopoverVisible(newPinned)
- },
- [pinned]
- )
-
- const handleClickOutside = useCallback(() => {
- clearHoverTimer()
- setPinned(false)
- setPopoverVisible(false)
- }, [])
-
- return (
- <Popover
- visible={popoverVisible}
- placement="bottom"
- showArrow
- onClickOutside={handleClickOutside}
- onMouseEnterInside={showDetails}
- onMouseLeaveInside={pinned ? undefined : hideDetails}
- overlay={
- <div
- className="p-4 max-w-md space-y-3"
- onMouseDown={(e) => e.stopPropagation()}
- onClick={(e) => {
- e.preventDefault()
- e.stopPropagation()
- }}
- >
- {popoverTopHeading && (
- <h5 className="uppercase text-xs font-bold text-muted tracking-wide m-0">
- {popoverTopHeading}
- </h5>
- )}
- {onMetaSave ? (
- <>
- <EditableField
- name="title"
- value={metaTitle || ''}
- onSave={(value) => onMetaSave({ name: value })}
- placeholder="Untitled"
- saveOnBlur
- clickToEdit
- compactButtons
- compactIcon
- className="font-semibold text-sm mt-1"
- data-attr="insight-card-title"
- />
- <EditableField
- name="description"
- value={metaDescriptionText || ''}
- onSave={(value) => onMetaSave({ description: value })}
- placeholder="Enter description (optional)"
- saveOnBlur
- clickToEdit
- multiline
- markdown
- compactButtons
- compactIcon
- className="text-xs w-full"
- data-attr="insight-card-description"
- />
- </>
- ) : (
- <>
- {metaTitle && <p className="font-semibold m-0">{metaTitle}</p>}
- {metaDescription}
- </>
- )}
- {metaDetails}
- </div>
- }
- >
- <span
- className="ml-1 flex-shrink-0"
- onMouseEnter={showDetails}
- onMouseLeave={pinned ? undefined : hideDetails}
- >
- <LemonButton
- icon={<IconInfo />}
- size="small"
- noPadding
- data-attr="card-meta-info"
- onClick={handleClickInfo}
- />
- </span>
- </Popover>
- )
-}
diff --git a/frontend/src/scenes/analytics/AnalyticsCreateModals.tsx b/frontend/src/scenes/analytics/AnalyticsCreateModals.tsx
index a7f4387ed72c..9145c83c915f 100644
--- a/frontend/src/scenes/analytics/AnalyticsCreateModals.tsx
+++ b/frontend/src/scenes/analytics/AnalyticsCreateModals.tsx
@@ -1,3 +1,6 @@
+import { useValues } from 'kea'
+
+import { newDashboardLogic } from 'scenes/dashboard/newDashboardLogic'
import { NewDashboardModal } from 'scenes/dashboard/NewDashboardModal'
import { NewInsightDialog } from './NewInsightDialog'
@@ -7,9 +10,12 @@ import { NewInsightDialog } from './NewInsightDialog'
* `newAnalyticsLogic` falls back to the products' own pages when no host is mounted.
*/
export function AnalyticsCreateModals(): JSX.Element {
+ const { setAsHomeTabDashboardAfterCreation } = useValues(newDashboardLogic)
+
return (
<>
- <NewDashboardModal />
+ {/* A dashboard made for product analytics Home shows on Home, so the user stays on that page. */}
+ <NewDashboardModal redirectAfterCreation={!setAsHomeTabDashboardAfterCreation} />
<NewInsightDialog />
</>
)
diff --git a/frontend/src/scenes/analytics/AnalyticsProductHome.test.tsx b/frontend/src/scenes/analytics/AnalyticsProductHome.test.tsx
index 0bbbcaee93bd..26f1a2908748 100644
--- a/frontend/src/scenes/analytics/AnalyticsProductHome.test.tsx
+++ b/frontend/src/scenes/analytics/AnalyticsProductHome.test.tsx
@@ -1,7 +1,10 @@
+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
+
import { cleanup, render, screen } from '@testing-library/react'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { teamLogic } from 'scenes/teamLogic'
import { initKeaTests } from '~/test/init'
@@ -11,12 +14,16 @@ jest.mock('products/product_analytics/frontend/insights/home/HomeTab', () => ({
HomeTab: () => <div>Product analytics dashboard</div>,
}))
+jest.mock('products/product_analytics/frontend/insights/home/HomeDashboardModals', () => ({
+ HomeDashboardModals: () => null,
+}))
+
jest.mock('./AnalyticsCreateModals', () => ({
AnalyticsCreateModals: () => null,
}))
jest.mock('~/layout/scenes/components/SceneTitleSection', () => ({
- SceneTitleSection: () => null,
+ SceneTitleSection: ({ actions }: { actions?: JSX.Element }) => <div>{actions}</div>,
}))
describe('AnalyticsProductHome', () => {
@@ -47,4 +54,17 @@ describe('AnalyticsProductHome', () => {
expect(screen.queryByText('Product analytics dashboard') !== null).toBe(railEnabled)
})
+
+ test.each([
+ ['the default dashboard', null, 'Make my own dashboard'],
+ ['a custom Home dashboard', 42, 'Home dashboard options'],
+ ])('lets the user change Home from %s', (_scenario, homeDashboardId, expectedControl) => {
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.TODAY_RAIL_NAV]: true })
+ teamLogic.mount()
+ teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, home_tab_dashboard: homeDashboardId })
+
+ render(<AnalyticsProductHome />)
+
+ expect(screen.queryByText(expectedControl) ?? screen.queryByLabelText(expectedControl)).not.toBeNull()
+ })
})
diff --git a/frontend/src/scenes/analytics/AnalyticsProductHome.tsx b/frontend/src/scenes/analytics/AnalyticsProductHome.tsx
index 604167148e90..861be9c21c2c 100644
--- a/frontend/src/scenes/analytics/AnalyticsProductHome.tsx
+++ b/frontend/src/scenes/analytics/AnalyticsProductHome.tsx
@@ -5,6 +5,8 @@ import { SceneExport } from 'scenes/sceneTypes'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
+import { HomeDashboardMenu } from 'products/product_analytics/frontend/insights/home/HomeDashboardMenu'
+import { HomeDashboardModals } from 'products/product_analytics/frontend/insights/home/HomeDashboardModals'
import { HomeTab } from 'products/product_analytics/frontend/insights/home/HomeTab'
import { AnalyticsCreateModals } from './AnalyticsCreateModals'
@@ -26,8 +28,10 @@ export function AnalyticsProductHome(): JSX.Element {
name="Product analytics"
description="How people use your product, ready-made by PostHog."
resourceType={{ type: 'analytics', forceIcon: <AnalyticsTypeIcon type="insight" /> }}
+ actions={<HomeDashboardMenu />}
/>
<HomeTab />
+ <HomeDashboardModals />
<AnalyticsCreateModals />
</SceneContent>
)
diff --git a/products/product_analytics/frontend/insights/home/HomeDashboardMenu.tsx b/products/product_analytics/frontend/insights/home/HomeDashboardMenu.tsx
new file mode 100644
index 000000000000..3fdd6fc772ca
--- /dev/null
+++ b/products/product_analytics/frontend/insights/home/HomeDashboardMenu.tsx
@@ -0,0 +1,57 @@
+import { useActions, useValues } from 'kea'
+import { router } from 'kea-router'
+
+import { IconEllipsis } from '@posthog/icons'
+import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@posthog/quill'
+
+import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
+
+import { homeDashboardChoiceLogic } from './homeDashboardChoiceLogic'
+
+/** Opens, changes, or removes the dashboard that replaces the default product analytics Home. */
+export function HomeDashboardMenu(): JSX.Element {
+ const { currentTeam } = useValues(teamLogic)
+ const { push } = useActions(router)
+ const { openHomeDashboardStarter, restorePostHogHome } = useActions(homeDashboardChoiceLogic)
+ const homeDashboardId = currentTeam?.home_tab_dashboard
+
+ if (!homeDashboardId) {
+ return (
+ <Button variant="outline" onClick={openHomeDashboardStarter} data-attr="home-tab-choose-dashboard">
+ Make my own dashboard
+ </Button>
+ )
+ }
+
+ return (
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ render={
+ <Button
+ size="icon"
+ aria-label="Home dashboard options"
+ tooltip="Home dashboard options"
+ data-attr="home-tab-dashboard-options"
+ />
+ }
+ >
+ <IconEllipsis />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="min-w-48">
+ <DropdownMenuItem
+ onClick={() => push(urls.dashboard(homeDashboardId))}
+ data-attr="home-tab-open-dashboard"
+ >
+ Open dashboard
+ </DropdownMenuItem>
+ <DropdownMenuItem onClick={openHomeDashboardStarter} data-attr="home-tab-choose-dashboard">
+ Change Home dashboard
+ </DropdownMenuItem>
+ <DropdownMenuItem onClick={restorePostHogHome} data-attr="home-tab-restore-posthog-home">
+ Use default dashboard
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )
+}
diff --git a/products/product_analytics/frontend/insights/home/HomeDashboardModals.tsx b/products/product_analytics/frontend/insights/home/HomeDashboardModals.tsx
new file mode 100644
index 000000000000..681c20fe5d5a
--- /dev/null
+++ b/products/product_analytics/frontend/insights/home/HomeDashboardModals.tsx
@@ -0,0 +1,50 @@
+import { useActions, useValues } from 'kea'
+
+import { SceneDashboardChoiceModal } from 'lib/components/SceneDashboardChoice/SceneDashboardChoiceModal'
+import { sceneDashboardChoiceModalLogic } from 'lib/components/SceneDashboardChoice/sceneDashboardChoiceModalLogic'
+import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
+import { Scene } from 'scenes/sceneTypes'
+import { teamLogic } from 'scenes/teamLogic'
+
+import { homeDashboardChoiceLogic } from './homeDashboardChoiceLogic'
+import { HomeDashboardStarterModal } from './HomeDashboardStarterModal'
+
+/** The dialogs that change which dashboard the product analytics Home shows. */
+export function HomeDashboardModals(): JSX.Element {
+ const { currentTeam, currentTeamLoading } = useValues(teamLogic)
+ const { dataProcessingAccepted, dataProcessingApprovalDisabledReason } = useValues(maxGlobalLogic)
+ const { isOpen, dashboardChoiceView } = useValues(
+ sceneDashboardChoiceModalLogic({ scene: Scene.ProductAnalyticsHomeTab })
+ )
+ const { dashboardCreationLoading } = useValues(homeDashboardChoiceLogic)
+ const {
+ closeSceneDashboardChoiceModal,
+ showDashboardPicker,
+ copyPostHogHome,
+ createHomeDashboardWithAI,
+ openHomeDashboardTemplates,
+ restorePostHogHome,
+ } = useActions(homeDashboardChoiceLogic)
+
+ return (
+ <>
+ <HomeDashboardStarterModal
+ isOpen={isOpen && dashboardChoiceView === 'starter'}
+ onClose={closeSceneDashboardChoiceModal}
+ onCopyPostHogHome={copyPostHogHome}
+ onTalkToAI={createHomeDashboardWithAI}
+ onStartFromTemplate={openHomeDashboardTemplates}
+ onChooseExisting={showDashboardPicker}
+ hasCustomDashboard={!!currentTeam?.home_tab_dashboard}
+ onRestorePostHogHome={restorePostHogHome}
+ restoringPostHogHome={currentTeamLoading}
+ creatingWithAI={dashboardCreationLoading}
+ aiDisabledReason={
+ !dataProcessingAccepted &&
+ (dataProcessingApprovalDisabledReason ?? 'Approve AI data processing to use PostHog AI')
+ }
+ />
+ <SceneDashboardChoiceModal scene={Scene.ProductAnalyticsHomeTab} />
+ </>
+ )
+}
diff --git a/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx b/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
index d055c4b4f3c9..af6ca5da7406 100644
--- a/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
+++ b/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx
@@ -167,6 +167,42 @@ describe('HomeTabDefault query reuse', () => {
await waitFor(() => expect(container.querySelector('[data-attr="metric-card-sparkline"]')).not.toBeNull())
})
+ it('shows the metric details and opens the same total in the insight editor, outside the tile button', async () => {
+ mockedQuery.mockImplementation(async () => ({
+ results: [{ ...trendsNumber.result[0], aggregated_value: 10 }],
+ last_refresh: new Date().toISOString(),
+ }))
+ render(
+ <HomeTabStatTile
+ stat={getHomeTabStatQueries({ date_from: '-7d' }, true).find(({ key }) => key === 'sessions')!}
+ compare
+ selected={false}
+ onSelect={() => {}}
+ />
+ )
+ const tileButton = screen.getByLabelText('Sessions', { selector: 'button' })
+ await waitFor(() => expect(within(tileButton).getByText('10')).toBeInTheDocument())
+
+ const info = document.querySelector('[data-attr="card-meta-info"]') as HTMLElement
+ const more = screen.getByLabelText('more')
+ expect(tileButton.contains(info) || tileButton.contains(more)).toBe(false)
+
+ await act(async () => info.click())
+ expect(await screen.findByText('Last 7 days')).toBeInTheDocument()
+ expect(screen.getByLabelText('Last computed time')).toBeInTheDocument()
+
+ await act(async () => more.click())
+ const explore = (await screen.findByText('Explore')).closest('a')!
+ const exploreQuery = JSON.parse(new URLSearchParams(new URL(explore.href).hash.slice(1)).get('q')!)
+ expect(exploreQuery).toMatchObject({
+ source: {
+ dateRange: { date_from: '-7d' },
+ compareFilter: { compare: true },
+ trendsFilter: { display: ChartDisplayType.BoldNumber },
+ },
+ })
+ })
+
it('replaces sample metrics and charts with live queries when the project starts receiving events', async () => {
ensureJsdom()
teamLogic.actions.loadCurrentTeamSuccess({ ...MOCK_DEFAULT_TEAM, ingested_event: false, is_demo: false })
diff --git a/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx b/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
index efdaf213da19..30c14540bea6 100644
--- a/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
+++ b/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx
@@ -3,7 +3,13 @@ import { useMemo } from 'react'
import { useChartTheme } from 'lib/charts/hooks'
import { AnalyticsMetricCard } from 'lib/components/AnalyticsMetricCard/AnalyticsMetricCard'
-import { Tooltip } from 'lib/lemon-ui/Tooltip'
+import { CardMeta } from 'lib/components/Cards/CardMeta'
+import { CompactInfoPopover } from 'lib/components/Cards/InsightCard/CompactInfoPopover'
+import { InsightDetails } from 'lib/components/Cards/InsightCard/InsightDetails'
+import { InsightMetaContent } from 'lib/components/Cards/InsightCard/InsightMeta'
+import { TopHeading } from 'lib/components/Cards/InsightCard/TopHeading'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'
import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'
import { formatBucketLabel } from 'lib/utils/timeBuckets'
import { sampleDataStateLogic } from 'scenes/insights/EmptyStates/sampleDataStateLogic'
@@ -16,10 +22,18 @@ import type { TrendsQueryResponse } from '~/queries/schema/schema-general'
import type { TrendResult } from '~/types'
import { homeTabDefaultLogic } from './homeTabDefaultLogic'
-import { getHomeTabStatValue, isHomeTabStatBucketInProgress, type HomeTabStatQuery } from './homeTabDefaultTiles'
+import {
+ getHomeTabExploreUrl,
+ getHomeTabStatInsightQuery,
+ getHomeTabStatValue,
+ isHomeTabStatBucketInProgress,
+ type HomeTabStatQuery,
+} from './homeTabDefaultTiles'
import { homeTabDataCollectionId, homeTabStatKey, homeTabStatTrendKey } from './homeTabQueryKeys'
import { getHomeTabSampleStatData } from './homeTabSampleData'
+const SESSION_DURATION_DESCRIPTION = 'Average duration of sessions with a page or screen view.'
+
interface HomeTabStatTileProps {
stat: HomeTabStatQuery
compare: boolean
@@ -73,7 +87,7 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt
currentTeam?.timezone ?? 'UTC',
currentTeam?.week_start_day
)
- const { response, responseError, responseLoading } = useValues(logic)
+ const { response, responseError, responseLoading, lastRefresh } = useValues(logic)
const loading = responseLoading || (!response && !responseError)
const results = (response as TrendsQueryResponse | undefined)?.results ?? (response as { result?: unknown })?.result
@@ -86,14 +100,51 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt
? ((value - previousValue) / Math.abs(previousValue)) * 100
: undefined
- const label =
- stat.description || stat.key === 'session_duration' ? (
- <Tooltip title={stat.description ?? 'Average duration of sessions with a page or screen view.'}>
- {stat.title}
- </Tooltip>
- ) : (
- stat.title
- )
+ const insightQuery = getHomeTabStatInsightQuery(stat)
+ const description = stat.description ?? (stat.key === 'session_duration' ? SESSION_DURATION_DESCRIPTION : null)
+ const header = (
+ <CardMeta
+ compact
+ showEditingControls
+ moreButtons={
+ <LemonButton
+ to={getHomeTabExploreUrl(insightQuery)}
+ fullWidth
+ data-attr={`home-tab-stat-explore-${stat.key}`}
+ >
+ Explore
+ </LemonButton>
+ }
+ content={
+ <InsightMetaContent
+ title={stat.title}
+ compact
+ showDescription={false}
+ infoPopover={
+ <CompactInfoPopover
+ popoverTopHeading={
+ <TopHeading
+ query={insightQuery}
+ lastRefresh={shouldShowSampleData ? null : lastRefresh}
+ resolvedDateRange={(response as TrendsQueryResponse | null)?.resolved_date_range}
+ />
+ }
+ metaTitle={stat.title}
+ metaDescription={
+ description ? (
+ <LemonMarkdown className="text-xs" lowKeyHeadings>
+ {description}
+ </LemonMarkdown>
+ ) : null
+ }
+ metaDescriptionText={description ?? ''}
+ metaDetails={<InsightDetails query={insightQuery} />}
+ />
+ }
+ />
+ }
+ />
+ )
const subtitle = !compare
? 'For selected period'
@@ -104,6 +155,7 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt
return (
<AnalyticsMetricCard
className="h-full w-full"
+ header={header}
adornment={
shouldShowSampleData ? (
<div className="flex justify-end px-3 pb-3">
@@ -111,7 +163,7 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt
</div>
) : undefined
}
- title={label}
+ title={null}
ariaLabel={stat.title}
onClick={onSelect}
selected={selected}
@@ -121,6 +173,7 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt
value={value ?? undefined}
showChange={compare}
change={changeFromPreviousPct != null ? { value: changeFromPreviousPct } : null}
+ changeInline
hoverChangeFromPreviousPoint
data={trend?.data}
labels={trend?.days}
diff --git a/products/product_analytics/frontend/insights/home/homeDashboardChoiceLogic.ts b/products/product_analytics/frontend/insights/home/homeDashboardChoiceLogic.ts
new file mode 100644
index 000000000000..55298f56b713
--- /dev/null
+++ b/products/product_analytics/frontend/insights/home/homeDashboardChoiceLogic.ts
@@ -0,0 +1,136 @@
+import { MakeLogicType, actions, connect, kea, listeners, path } from 'kea'
+
+import { sceneDashboardChoiceModalLogic } from 'lib/components/SceneDashboardChoice/sceneDashboardChoiceModalLogic'
+import { UNFILED_DASHBOARDS_FOLDER } from 'scenes/dashboard/dashboardConstants'
+import { newDashboardLogic } from 'scenes/dashboard/newDashboardLogic'
+import { Scene } from 'scenes/sceneTypes'
+
+import { getHomeTabDashboardTemplate } from './homeTabDefaultTiles'
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface homeDashboardChoiceLogicValues {
+ dashboardCreationLoading: boolean // newDashboardLogic
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface homeDashboardChoiceLogicActions {
+ addDashboard: (form: Partial<import('scenes/dashboard/newDashboardLogic').NewDashboardForm>) => {
+ form: Partial<import('scenes/dashboard/newDashboardLogic').NewDashboardForm>
+ } // newDashboardLogic
+ createDashboardFromTemplate: (
+ template: import('~/types').DashboardTemplateType,
+ variables: import('~/types').DashboardTemplateVariableType[],
+ redirectAfterCreation?: boolean | undefined,
+ creationContext?: string | null | undefined
+ ) => {
+ creationContext: string | null
+ redirectAfterCreation: boolean | undefined
+ template: import('~/types').DashboardTemplateType
+ variables: import('~/types').DashboardTemplateVariableType[]
+ } // newDashboardLogic
+ setAsHomeTabDashboardAfterCreation: (
+ setAsHomeTabDashboard: boolean,
+ openAI?: boolean | undefined
+ ) => {
+ openAI: boolean
+ setAsHomeTabDashboard: boolean
+ } // newDashboardLogic
+ showNewDashboardModal: () => {
+ value: true
+ } // newDashboardLogic
+ closeSceneDashboardChoiceModal: () => boolean // sceneDashboardChoiceModalLogic
+ setSceneDashboardChoice: (dashboardId: number | null) => {
+ dashboardId: number | null
+ } // sceneDashboardChoiceModalLogic
+ showDashboardPicker: () => boolean // sceneDashboardChoiceModalLogic
+ showSceneDashboardChoiceModal: () => boolean // sceneDashboardChoiceModalLogic
+ showStarterOptions: () => boolean // sceneDashboardChoiceModalLogic
+ copyPostHogHome: () => {
+ value: true
+ }
+ createHomeDashboardWithAI: () => {
+ value: true
+ }
+ openHomeDashboardStarter: () => {
+ value: true
+ }
+ openHomeDashboardTemplates: () => {
+ value: true
+ }
+ restorePostHogHome: () => {
+ value: true
+ }
+}
+
+export type homeDashboardChoiceLogicType = MakeLogicType<
+ homeDashboardChoiceLogicValues,
+ homeDashboardChoiceLogicActions
+>
+
+export const homeDashboardChoiceLogic = kea<homeDashboardChoiceLogicType>([
+ path(['products', 'product_analytics', 'home', 'homeDashboardChoiceLogic']),
+ connect(() => ({
+ values: [newDashboardLogic, ['isLoading as dashboardCreationLoading']],
+ actions: [
+ sceneDashboardChoiceModalLogic({ scene: Scene.ProductAnalyticsHomeTab }),
+ [
+ 'closeSceneDashboardChoiceModal',
+ 'setSceneDashboardChoice',
+ 'showDashboardPicker',
+ 'showSceneDashboardChoiceModal',
+ 'showStarterOptions',
+ ],
+ newDashboardLogic,
+ [
+ 'addDashboard',
+ 'createDashboardFromTemplate',
+ 'setAsHomeTabDashboardAfterCreation',
+ 'showNewDashboardModal',
+ ],
+ ],
+ })),
+ actions({
+ openHomeDashboardStarter: true,
+ copyPostHogHome: true,
+ createHomeDashboardWithAI: true,
+ openHomeDashboardTemplates: true,
+ restorePostHogHome: true,
+ }),
+ listeners(({ actions, values }) => ({
+ openHomeDashboardStarter: () => {
+ actions.showStarterOptions()
+ actions.showSceneDashboardChoiceModal()
+ },
+ copyPostHogHome: () => {
+ if (values.dashboardCreationLoading) {
+ return
+ }
+ actions.closeSceneDashboardChoiceModal()
+ actions.setAsHomeTabDashboardAfterCreation(true)
+ actions.createDashboardFromTemplate(getHomeTabDashboardTemplate(), [], false, 'product_analytics_home_copy')
+ },
+ createHomeDashboardWithAI: () => {
+ if (values.dashboardCreationLoading) {
+ return
+ }
+ actions.closeSceneDashboardChoiceModal()
+ actions.setAsHomeTabDashboardAfterCreation(true, true)
+ actions.addDashboard({
+ name: 'My product analytics dashboard',
+ description: '',
+ show: false,
+ useTemplate: '',
+ _create_in_folder: UNFILED_DASHBOARDS_FOLDER,
+ })
+ },
+ openHomeDashboardTemplates: () => {
+ actions.closeSceneDashboardChoiceModal()
+ actions.setAsHomeTabDashboardAfterCreation(true)
+ actions.showNewDashboardModal()
+ },
+ restorePostHogHome: () => {
+ actions.setSceneDashboardChoice(null)
+ actions.closeSceneDashboardChoiceModal()
+ },
+ })),
+])
diff --git a/products/product_analytics/frontend/insights/home/homeTabDefaultTiles.test.ts b/products/product_analytics/frontend/insights/home/homeTabDefaultTiles.test.ts
index 6da86fd5acfc..83b9b8894b26 100644
--- a/products/product_analytics/frontend/insights/home/homeTabDefaultTiles.test.ts
+++ b/products/product_analytics/frontend/insights/home/homeTabDefaultTiles.test.ts
@@ -21,6 +21,7 @@ import {
getHomeTabDashboardTemplate,
getHomeTabExploreUrl,
getHomeTabInterval,
+ getHomeTabStatInsightQuery,
getHomeTabStatQueries,
getHomeTabStatValue,
isHomeTabStatBucketInProgress,
@@ -288,6 +289,18 @@ describe('homeTabDefaultTiles', () => {
expect(editorQuery.source.dateRange).toEqual(dateRange)
})
+ it.each([
+ ['sessions', { display: ChartDisplayType.BoldNumber }],
+ ['daily_active_users', { display: ChartDisplayType.Metric, metricSummary: 'average' }],
+ ])('opens the %s tile as an insight that shows the same number', (key, trendsFilter) => {
+ const stat = getHomeTabStatQueries(dateRange, true).find((stat) => stat.key === key)!
+
+ expect(getHomeTabStatInsightQuery(stat)).toMatchObject({
+ kind: NodeKind.InsightVizNode,
+ source: { dateRange, compareFilter: { compare: true }, trendsFilter },
+ })
+ })
+
it('copies Home into a dashboard template with saved queries and a non-overlapping layout', () => {
const { tiles } = getHomeTabDashboardTemplate()
@@ -296,7 +309,6 @@ describe('homeTabDefaultTiles', () => {
'Sessions',
'First-time users',
'Avg. session duration',
- 'Avg. DAU',
'Daily active users',
'Top pages',
'Top screens',
@@ -318,7 +330,13 @@ describe('homeTabDefaultTiles', () => {
}
}
}
- expect(tiles.slice(0, 5).map((tile) => tile.type === 'INSIGHT' && tile.query)).toMatchObject([
+ expect(tiles.slice(0, 4).map((tile) => tile.layouts!.sm)).toMatchObject([
+ { x: 0, y: 0, w: 3 },
+ { x: 3, y: 0, w: 3 },
+ { x: 6, y: 0, w: 3 },
+ { x: 9, y: 0, w: 3 },
+ ])
+ expect(tiles.slice(0, 4).map((tile) => tile.type === 'INSIGHT' && tile.query)).toMatchObject([
{
source: {
series: [{ math: BaseMathType.WeeklyActiveUsers }],
@@ -337,12 +355,6 @@ describe('homeTabDefaultTiles', () => {
},
},
},
- {
- source: {
- interval: 'day',
- trendsFilter: { display: ChartDisplayType.Metric, metricSummary: 'average' },
- },
- },
])
})
})
diff --git a/products/product_analytics/frontend/insights/home/homeTabDefaultTiles.ts b/products/product_analytics/frontend/insights/home/homeTabDefaultTiles.ts
index 3a2d40ea69d9..8f9b05208a46 100644
--- a/products/product_analytics/frontend/insights/home/homeTabDefaultTiles.ts
+++ b/products/product_analytics/frontend/insights/home/homeTabDefaultTiles.ts
@@ -470,6 +470,24 @@ export function getHomeTabBreakdownOptions(dateRange: DateRange): HomeTabChartOp
]
}
+/** A metric tile as an insight. The tile averages daily points in React, so that summary moves into the query. */
+export function getHomeTabStatInsightQuery(stat: HomeTabStatQuery): InsightVizNode<TrendsQuery> {
+ return {
+ kind: NodeKind.InsightVizNode,
+ source:
+ stat.summary === 'daily_average'
+ ? {
+ ...stat.query,
+ trendsFilter: {
+ ...stat.query.trendsFilter,
+ display: ChartDisplayType.Metric,
+ metricSummary: 'average',
+ },
+ }
+ : stat.query,
+ }
+}
+
export function getHomeTabExploreUrl(query: HomeTabChartOption['query']): string {
const insightQuery: HomeTabChartOption['query'] = { ...query, embedded: undefined }
return urls.insightNew({ query: insightQuery })
@@ -516,7 +534,9 @@ export function getHomeTabDashboardTemplate(): DashboardTemplateType {
}
return { name: chart.title, description: chart.description, source: chart.query.source, w, h }
}
- const statTiles = getHomeTabStatQueries(dateRange, compare).map((stat): HomeTabDashboardTile => {
+ // A 12-column row holds four equal metric tiles, and the full-width Daily active users chart already shows Avg. DAU.
+ const statQueries = getHomeTabStatQueries(dateRange, compare).filter(({ key }) => key !== 'daily_active_users')
+ const statTiles = statQueries.map((stat): HomeTabDashboardTile => {
const weeklyActiveUsers = stat.key === 'active_users'
return {
name: HOME_TAB_STAT_DASHBOARD_NAMES[stat.key] ?? stat.title,
@@ -537,7 +557,7 @@ export function getHomeTabDashboardTemplate(): DashboardTemplateType {
...(stat.kind === 'duration_s' ? { aggregationAxisFormat: 'duration' } : {}),
},
},
- w: weeklyActiveUsers || stat.key === 'daily_active_users' ? 3 : 2,
+ w: 3,
h: 3,
}
})
diff --git a/products/product_analytics/frontend/insights/savedInsights/SavedInsights.tsx b/products/product_analytics/frontend/insights/savedInsights/SavedInsights.tsx
index b3acc6756cb6..afc2459d4f33 100644
--- a/products/product_analytics/frontend/insights/savedInsights/SavedInsights.tsx
+++ b/products/product_analytics/frontend/insights/savedInsights/SavedInsights.tsx
@@ -2,24 +2,12 @@ import { useActions, useValues } from 'kea'
import { router } from 'kea-router'
import { IconEllipsis, IconHeart, IconHeartFilled, IconTrash } from '@posthog/icons'
-import {
- Button,
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
- Tooltip as QuillTooltip,
- TooltipContent,
- TooltipTrigger,
-} from '@posthog/quill'
import 'scenes/saved-insights/SavedInsights.scss'
import { AccessControlAction } from 'lib/components/AccessControlAction'
import { ActivityLog } from 'lib/components/ActivityLog/ActivityLog'
import { BulkUpdateTagsButton } from 'lib/components/BulkActions/BulkUpdateTagsButton'
import { ObjectTags } from 'lib/components/ObjectTags/ObjectTags'
-import { SceneDashboardChoiceModal } from 'lib/components/SceneDashboardChoice/SceneDashboardChoiceModal'
-import { sceneDashboardChoiceModalLogic } from 'lib/components/SceneDashboardChoice/sceneDashboardChoiceModalLogic'
import { TZLabel } from 'lib/components/TZLabel'
import { dayjs } from 'lib/dayjs'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
@@ -37,12 +25,9 @@ import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { accessLevelSatisfied } from 'lib/utils/accessControlUtils'
import { cn } from 'lib/utils/css-classes'
import { deleteInsightWithUndo } from 'lib/utils/deleteWithUndo'
-import { UNFILED_DASHBOARDS_FOLDER } from 'scenes/dashboard/dashboardConstants'
-import { newDashboardLogic } from 'scenes/dashboard/newDashboardLogic'
import { NewDashboardModal } from 'scenes/dashboard/NewDashboardModal'
import { SavedInsightsEmptyState, SavedInsightsErrorState } from 'scenes/insights/EmptyStates'
import { useSummarizeInsight } from 'scenes/insights/summarizeInsight'
-import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
import { projectLogic } from 'scenes/projectLogic'
import { isDraftInsightRow } from 'scenes/saved-insights/draftInsight'
import { InsightIcon } from 'scenes/saved-insights/InsightIcon'
@@ -59,9 +44,10 @@ import { ProductKey } from '~/queries/schema/schema-general'
import { AccessControlLevel, AccessControlResourceType, ActivityScope, SavedInsightsTabs } from '~/types'
import { productAnalyticsEmptyState } from 'products/product_analytics/frontend/emptyState/productAnalyticsEmptyState'
-import { HomeDashboardStarterModal } from 'products/product_analytics/frontend/insights/home/HomeDashboardStarterModal'
+import { homeDashboardChoiceLogic } from 'products/product_analytics/frontend/insights/home/homeDashboardChoiceLogic'
+import { HomeDashboardMenu } from 'products/product_analytics/frontend/insights/home/HomeDashboardMenu'
+import { HomeDashboardModals } from 'products/product_analytics/frontend/insights/home/HomeDashboardModals'
import { HomeTab } from 'products/product_analytics/frontend/insights/home/HomeTab'
-import { getHomeTabDashboardTemplate } from 'products/product_analytics/frontend/insights/home/homeTabDefaultTiles'
import { NewInsightButton } from 'products/product_analytics/frontend/insights/newInsightMenu/NewInsightMenu'
import { NewInsightShortcuts } from 'products/product_analytics/frontend/insights/newInsightMenu/newInsightsMenu'
import { ProductAnalyticsNotifications } from 'products/product_analytics/frontend/notifications/ProductAnalyticsNotifications'
@@ -101,21 +87,9 @@ export function SavedInsights(): JSX.Element {
const { currentProjectId } = useValues(projectLogic)
const { notificationCount } = useValues(productAnalyticsNotificationsLogic)
- const { currentTeam, currentTeamLoading } = useValues(teamLogic)
- const { dataProcessingAccepted, dataProcessingApprovalDisabledReason } = useValues(maxGlobalLogic)
+ const { currentTeam } = useValues(teamLogic)
const summarizeInsight = useSummarizeInsight()
- const dashboardChoiceLogic = sceneDashboardChoiceModalLogic({ scene: Scene.ProductAnalyticsHomeTab })
- const { isOpen: homeDashboardModalOpen, dashboardChoiceView } = useValues(dashboardChoiceLogic)
- const {
- closeSceneDashboardChoiceModal,
- setSceneDashboardChoice,
- showDashboardPicker,
- showSceneDashboardChoiceModal,
- showStarterOptions,
- } = useActions(dashboardChoiceLogic)
- const { isLoading: dashboardCreationLoading } = useValues(newDashboardLogic)
- const { addDashboard, createDashboardFromTemplate, setAsHomeTabDashboardAfterCreation, showNewDashboardModal } =
- useActions(newDashboardLogic)
+ const { openHomeDashboardStarter, restorePostHogHome } = useActions(homeDashboardChoiceLogic)
const todayRailNav = useFeatureFlag('TODAY_RAIL_NAV')
const { tab } = filters
@@ -330,46 +304,6 @@ export function SavedInsights(): JSX.Element {
},
]
- const openHomeDashboardStarter = (): void => {
- showStarterOptions()
- showSceneDashboardChoiceModal()
- }
-
- const createHomeDashboardWithAI = (): void => {
- if (dashboardCreationLoading) {
- return
- }
- closeSceneDashboardChoiceModal()
- setAsHomeTabDashboardAfterCreation(true, true)
- addDashboard({
- name: 'My product analytics dashboard',
- description: '',
- show: false,
- useTemplate: '',
- _create_in_folder: UNFILED_DASHBOARDS_FOLDER,
- })
- }
-
- const copyPostHogHome = (): void => {
- if (dashboardCreationLoading) {
- return
- }
- closeSceneDashboardChoiceModal()
- setAsHomeTabDashboardAfterCreation(true)
- createDashboardFromTemplate(getHomeTabDashboardTemplate(), [], false, 'product_analytics_home_copy')
- }
-
- const openHomeDashboardTemplates = (): void => {
- closeSceneDashboardChoiceModal()
- setAsHomeTabDashboardAfterCreation(true)
- showNewDashboardModal()
- }
-
- const restorePostHogHome = (): void => {
- setSceneDashboardChoice(null)
- closeSceneDashboardChoiceModal()
- }
-
const homeDashboardActions =
tab === SavedInsightsTabs.Home && showHomeTab ? (
currentTeam?.home_tab_dashboard ? (
@@ -433,47 +367,7 @@ export function SavedInsights(): JSX.Element {
<NewInsightButton compact={tab === SavedInsightsTabs.Home && showHomeTab} />
{currentTeam?.home_tab_dashboard && tab === SavedInsightsTabs.Home && showHomeTab && (
<div className="@min-[48rem]/saved-insights:hidden">
- <DropdownMenu>
- <QuillTooltip>
- <TooltipTrigger
- delay={0}
- render={
- <DropdownMenuTrigger
- render={
- <Button
- size="icon"
- aria-label="Home dashboard options"
- data-attr="home-tab-dashboard-options"
- />
- }
- />
- }
- >
- <IconEllipsis />
- </TooltipTrigger>
- <TooltipContent>Home dashboard options</TooltipContent>
- </QuillTooltip>
- <DropdownMenuContent align="end" className="min-w-48">
- <DropdownMenuItem
- onClick={() => push(urls.dashboard(currentTeam.home_tab_dashboard!))}
- data-attr="home-tab-open-dashboard"
- >
- Open dashboard
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={openHomeDashboardStarter}
- data-attr="home-tab-choose-dashboard"
- >
- Change Home dashboard
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={restorePostHogHome}
- data-attr="home-tab-restore-posthog-home"
- >
- Use default dashboard
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ <HomeDashboardMenu />
</div>
)}
</>
@@ -524,23 +418,7 @@ export function SavedInsights(): JSX.Element {
{tab === SavedInsightsTabs.Home && showHomeTab ? (
<>
<HomeTab dashboardActions={homeDashboardActions} />
- <HomeDashboardStarterModal
- isOpen={homeDashboardModalOpen && dashboardChoiceView === 'starter'}
- onClose={closeSceneDashboardChoiceModal}
- onCopyPostHogHome={copyPostHogHome}
- onTalkToAI={createHomeDashboardWithAI}
- onStartFromTemplate={openHomeDashboardTemplates}
- onChooseExisting={showDashboardPicker}
- hasCustomDashboard={!!currentTeam?.home_tab_dashboard}
- onRestorePostHogHome={restorePostHogHome}
- restoringPostHogHome={currentTeamLoading}
- creatingWithAI={dashboardCreationLoading}
- aiDisabledReason={
- !dataProcessingAccepted &&
- (dataProcessingApprovalDisabledReason ?? 'Approve AI data processing to use PostHog AI')
- }
- />
- <SceneDashboardChoiceModal scene={Scene.ProductAnalyticsHomeTab} />
+ <HomeDashboardModals />
<NewDashboardModal redirectAfterCreation={false} />
</>
) : tab === SavedInsightsTabs.Notifications ? (