: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(heatmaps): combine page history days (#117201)
Jordan Mryyand041712a823a
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 4c7b631f29f4..19c37b87b325 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -8034,6 +8034,26 @@ snapshots:hash: v1.k794b7964.fc4421d5eb2f507adff62378c528a85f0d2afda601f5c64c427c01f8be0017e6.CwCi0RyySiohuekOKlnZxKFInJdQLJTSVx3upnSWs_gproducts-web-analytics-content-autopilot-workspace--site-settings--light:hash: v1.k794b7964.db7571e09c46c966f50fb87b8b34511803d4aef56c41faa405c2db039f17fa43.PUpkT3j7DpGmhBztUzWMk0vKk_5cA4nMK6WztMyXBRE+ products-web-analytics-heatmaps-page-history-tile--captured--dark:+ hash: v1.k794b7964.3881025c6495a4df5758fddd204376e5f589273afb0736c2467005013fb7db1e.JnN8qnMYkIRJDCnuutYXiHORM5IeymnAyeHzgOhTq6w+ products-web-analytics-heatmaps-page-history-tile--captured--light:+ hash: v1.k794b7964.1f051deb08f0684793ab4c368f61f0d2954482e907e4bf36f96cf46188de3e5e.5Mfyo0QNQtrQXn0FQLJWL4sG619U6KrmSTz-eJkTtdQ+ products-web-analytics-heatmaps-page-history-tile--failed-replacement--dark:+ hash: v1.k794b7964.41cc67fd2ca7954749a809171bfe4408246645265186cb30e7bed83237d85b8f.OnixNd4o0S1uBf8tibvjo9aR1LmLAcS4iEapEKHTETs+ products-web-analytics-heatmaps-page-history-tile--failed-replacement--light:+ hash: v1.k794b7964.22a4954721b94af4e0a5c30f68649a2d7b2124dcb1c60130cb653415df96a50d.KvqRcS4kG5VzsPlLglhBPS_SdbXGx0dbh_9571yzb_U+ products-web-analytics-heatmaps-page-history-tile--first-capture-in-progress--dark:+ hash: v1.k794b7964.fbc7ea2a46697130dbe9382c230189afda07dfaaa8a75fba1b0cffba1bf826c1.w5ppzkqjBeijdddhNYyone3GeKl8IWypGmYEMSkqsCA+ products-web-analytics-heatmaps-page-history-tile--first-capture-in-progress--light:+ hash: v1.k794b7964.43d9fc75e730eaa1625d7fd950d33052dee9d2124362de6365eeaf802968d0c0.E_I3dZnHJgMAB9dWW_GfR-0t7A8QKzVazpxJll60mAw+ products-web-analytics-heatmaps-page-history-tile--missing-thumbnail--dark:+ hash: v1.k794b7964.d2c2d8b7ff56af22ad0e660a0c0e980eaa1507e028a5672c0ea11deb6ddae0a5.Xmj4QT0V1HKVw5uHABS-adxui7U8vaj7lRrN-LQmVSc+ products-web-analytics-heatmaps-page-history-tile--missing-thumbnail--light:+ hash: v1.k794b7964.8e1f91f8d155b7a66ea393cf1895dd025176eea1635934f2be63cfaa4ad3b01c.6OBO6UhXyUZzrVyL0sGkvKLoVwdfEI3X_kGadCOGkCI+ products-web-analytics-heatmaps-page-history-tile--selected-background--dark:+ hash: v1.k794b7964.8d3d7f4ba2a97212a0d1c68b16982ba71a902cf6d8889d48022f2cfe59ce9209.2MwScNH2wVIx6uK_QijfCBCFnw4z-KRihTOEpsITQgI+ products-web-analytics-heatmaps-page-history-tile--selected-background--light:+ hash: v1.k794b7964.3435d41444afd76282bbfd17dd3bc2d9d037846aa9270252a2b591b6a8ed1b10.u6-DZZ7Y9yreXXUYUtH-Cue2cQmxLhVfiN9Ipu7WUUAproducts-wizard-wizard-run-diff-viewer--default--dark:hash: v1.k794b7964.17c89495f75eed7f73f303b37e9871070e332d1f2b82ff0817f9d1ddd27828c0.bQzhC4f7HDdgFTn6hyiTj0toFWvU9TaivKJpUyOHcBIproducts-wizard-wizard-run-diff-viewer--default--light:@@ -10967,13 +10987,13 @@ snapshots:scenes-app-heatmap--generating--light:hash: v1.k794b7964.3bb8caf591d48254690d88d7fd91f56d37f174fd436856e05068fc48b6447c8c.sj0fwc61KHPb3o_hlXH-J5n47Aa8TVTmCRmQvWWcaDMscenes-app-heatmap--historical-day--dark:- hash: v1.k794b7964.2e4ffd7d5626936008038af691026115e73084a3b60fc1566b7b3b853c951c22.J5o3V5sje7hrWnHfIxFv8CZ-js6Gmm59OjPIGRDvdDQ+ hash: v1.k794b7964.460c7aa2326c13351e8d42b737e8529f0d3557ba311bb097cd6a34c2d8ed38a8.brpuqdCaYi2TStnZvORDKkY6fx__AcDcPp9ai5NzZS8scenes-app-heatmap--historical-day--light:- hash: v1.k794b7964.50014e66961df3b9b4ff6ae15fb699dce99914b489144448ecce5c20c2cad474.imke0qNh5hu3gsKYEfmjLnOHqnzP5FJ_8mF1eFBPYq8+ hash: v1.k794b7964.0a91a0dd93dd04277099c7b9fc39abedfcec062e5988f9692641c3d8ea61aff9.fibuxYBkpOd-KpkP-OugBCbxwbcxgaEUAUCeNBGFrLEscenes-app-heatmap--historical-day-narrow--dark:- hash: v1.k794b7964.975049d7b4e3f60a43f8bf05ff6156372e84bc02ed4220d435aeddd6bd9710ea.OJF7JsONehAysRwV14mVAZjQmVP2Fu3V5DZ6GDtM2pI+ hash: v1.k794b7964.d6e870a63d60094651d8aea51f67d8cc9f19aabdb308e932784079979c0d9ee3.y9kS46cisT8MHXTqwYa8CNXh5H9rbcJPEAwnsXD62bQscenes-app-heatmap--historical-day-narrow--light:- hash: v1.k794b7964.6b2487ec31c787c26982f8860229a20d407d5b4313aa8f11da9a7afdca7bf9e8.g-rTb-3eQKxQayKSRoAgci6m9YYHwPCNT_Tz_whTHi0+ hash: v1.k794b7964.df72a86e80079b5e0a0fd639a4c0645c70ab3f7f72bf7b016ecc72cce4c3c1a8.MihSk2xNk3DZNKYIW6D10yRFKTqlHFcPg3DaqYgOLtoscenes-app-heatmap--iframe-example--dark:hash: v1.k794b7964.edc8641f41da1365aaa55e532b36b6fe272234b86f6ce1ef317d0d3d586eac79.kgs_gmdNN7IN2c8RZPsQrShFeZ8ChwmTy0atI73o1wsscenes-app-heatmap--iframe-example--light:diff --git a/products/web_analytics/frontend/heatmaps/history/PageHistoryDateControls.tsx b/products/web_analytics/frontend/heatmaps/history/PageHistoryDateControls.tsxindex d2cbfc4e474b..ca8c31caa08b 100644--- a/products/web_analytics/frontend/heatmaps/history/PageHistoryDateControls.tsx+++ b/products/web_analytics/frontend/heatmaps/history/PageHistoryDateControls.tsx@@ -4,59 +4,92 @@ import { IconChevronLeft, IconChevronRight } from '@posthog/icons'import { LemonButton, LemonSelect } from '@posthog/lemon-ui'import { isUsableCapture, pageHistoryLogic } from './pageHistoryLogic'-import { formatCaptureDay } from './pageHistoryUtils'+import { formatCaptureDay, formatHistoryDateRange } from './pageHistoryUtils'export function PageHistoryDateControls({ id }: { id: string }): JSX.Element {const logic = pageHistoryLogic({ id })- const { captures, selectedBackground, previousCapture, nextCapture, historyBrowseDisabledReason } = useValues(logic)- const { browseCapture, navigateCapture } = useActions(logic)+ const {+ captures,+ selectedBackground,+ selectedDateRange,+ isCombinedRange,+ previousCapture,+ nextCapture,+ historyBrowseDisabledReason,+ } = useValues(logic)+ const { browseCapture, navigateCapture, openRangeEditor } = useActions(logic)return (<div className="flex flex-wrap items-center gap-1" aria-label="Historical interaction dates">- <LemonButton- size="small"- icon={<IconChevronLeft />}- onClick={() => navigateCapture('previous')}- aria-label={- previousCapture- ? `Previous available capture: ${formatCaptureDay(previousCapture.captured_on, 'long')}`- : 'Previous available capture'- }- disabledReason={- historyBrowseDisabledReason ||- (!previousCapture ? 'This is the oldest available screenshot.' : undefined)- }- tooltip={previousCapture ? `Inspect ${formatCaptureDay(previousCapture.captured_on)}` : undefined}- data-attr="heatmap-page-history-previous-day"- />- <LemonSelect- size="small"- value={selectedBackground?.id}- onSelect={browseCapture}- aria-label="Historical interaction day"- disabledReason={historyBrowseDisabledReason}- options={[...captures].reverse().map((capture) => ({- value: capture.id,- label: `${formatCaptureDay(capture.captured_on)}${isUsableCapture(capture) ? '' : ' (no screenshot)'}`,- }))}- data-attr="heatmap-page-history-dates"- />- <LemonButton- size="small"- icon={<IconChevronRight />}- onClick={() => navigateCapture('next')}- aria-label={- nextCapture- ? `Next available capture: ${formatCaptureDay(nextCapture.captured_on, 'long')}`- : 'Next available capture'- }- disabledReason={- historyBrowseDisabledReason ||- (!nextCapture ? 'This is the newest available screenshot.' : undefined)- }- tooltip={nextCapture ? `Inspect ${formatCaptureDay(nextCapture.captured_on)}` : undefined}- data-attr="heatmap-page-history-next-day"- />+ {isCombinedRange && selectedDateRange ? (+ <LemonButton+ size="small"+ type="secondary"+ onClick={openRangeEditor}+ disabledReason={historyBrowseDisabledReason}+ data-attr="heatmap-page-history-range"+ >+ {formatHistoryDateRange(selectedDateRange)}+ </LemonButton>+ ) : (+ <>+ <LemonButton+ size="small"+ icon={<IconChevronLeft />}+ onClick={() => navigateCapture('previous')}+ aria-label={+ previousCapture+ ? `Previous available capture: ${formatCaptureDay(previousCapture.captured_on, 'long')}`+ : 'Previous available capture'+ }+ disabledReason={+ historyBrowseDisabledReason ||+ (!previousCapture ? 'This is the oldest available screenshot.' : undefined)+ }+ tooltip={+ previousCapture ? `Inspect ${formatCaptureDay(previousCapture.captured_on)}` : undefined+ }+ data-attr="heatmap-page-history-previous-day"+ />+ <LemonSelect+ size="small"+ value={selectedBackground?.id}+ onSelect={browseCapture}+ aria-label="Historical interaction day"+ disabledReason={historyBrowseDisabledReason}+ options={[...captures].reverse().map((capture) => ({+ value: capture.id,+ label: `${formatCaptureDay(capture.captured_on)}${isUsableCapture(capture) ? '' : ' (no screenshot)'}`,+ }))}+ data-attr="heatmap-page-history-dates"+ />+ <LemonButton+ size="small"+ icon={<IconChevronRight />}+ onClick={() => navigateCapture('next')}+ aria-label={+ nextCapture+ ? `Next available capture: ${formatCaptureDay(nextCapture.captured_on, 'long')}`+ : 'Next available capture'+ }+ disabledReason={+ historyBrowseDisabledReason ||+ (!nextCapture ? 'This is the newest available screenshot.' : undefined)+ }+ tooltip={nextCapture ? `Inspect ${formatCaptureDay(nextCapture.captured_on)}` : undefined}+ data-attr="heatmap-page-history-next-day"+ />+ <LemonButton+ size="small"+ type="tertiary"+ onClick={openRangeEditor}+ disabledReason={historyBrowseDisabledReason}+ data-attr="heatmap-page-history-combine"+ >+ Combine days+ </LemonButton>+ </>+ )}</div>)}diff --git a/products/web_analytics/frontend/heatmaps/history/PageHistoryRangeEditor.tsx b/products/web_analytics/frontend/heatmaps/history/PageHistoryRangeEditor.tsxnew file mode 100644index 000000000000..76ce67ee4c21--- /dev/null+++ b/products/web_analytics/frontend/heatmaps/history/PageHistoryRangeEditor.tsx@@ -0,0 +1,114 @@+import { useActions, useValues } from 'kea'++import { IconCamera } from '@posthog/icons'+import { LemonBanner, LemonButton, LemonLabel, LemonModal, LemonSelect } from '@posthog/lemon-ui'++import { isUsableCapture, pageHistoryLogic } from './pageHistoryLogic'+import { formatCaptureDay, formatCaptureTimestamp, formatHistoryDateRange } from './pageHistoryUtils'++export function PageHistoryRangeEditor({ id }: { id: string }): JSX.Element | null {+ const logic = pageHistoryLogic({ id })+ const { rangeEditorOpen, rangeDraft, rangeDraftBackground, rangeDraftCaptures, rangeDraftError, captures } =+ useValues(logic)+ const { setRangeEditorOpen, setRangeDraft, applyRangeDraft } = useActions(logic)+ if (!rangeEditorOpen) {+ return null+ }+ const options = captures.map((capture) => ({+ value: capture.id,+ label: formatCaptureDay(capture.captured_on),+ disabledReason: !isUsableCapture(capture) ? 'No screenshot is available for this date.' : undefined,+ }))++ return (+ <LemonModal+ isOpen={rangeEditorOpen}+ onClose={() => setRangeEditorOpen(false)}+ title="Combine interaction days"+ width={480}+ footer={+ <div className="flex justify-end gap-2">+ <LemonButton type="secondary" onClick={() => setRangeEditorOpen(false)}>+ Cancel+ </LemonButton>+ <LemonButton+ type="primary"+ onClick={applyRangeDraft}+ disabledReason={rangeDraftError}+ data-attr="heatmap-page-history-apply-range"+ >+ Apply+ </LemonButton>+ </div>+ }+ data-attr="heatmap-page-history-range-editor"+ >+ <p>View several days of interactions on one saved screenshot.</p>+ <div className="flex flex-wrap gap-3 mb-3">+ <div>+ <LemonLabel htmlFor="heatmap-history-from">From</LemonLabel>+ <LemonSelect+ id="heatmap-history-from"+ aria-label="History range start"+ options={options}+ value={rangeDraft?.fromId}+ onChange={(value) => setRangeDraft(value, rangeDraft?.toId ?? value)}+ />+ </div>+ <div>+ <LemonLabel htmlFor="heatmap-history-to">To</LemonLabel>+ <LemonSelect+ id="heatmap-history-to"+ aria-label="History range end"+ options={options}+ value={rangeDraft?.toId}+ onChange={(value) => setRangeDraft(rangeDraft?.fromId ?? value, value)}+ />+ </div>+ </div>+ {rangeDraftBackground ? (+ <div+ className="rounded border bg-surface-secondary p-3 mb-3"+ data-attr="heatmap-page-history-range-preview"+ >+ <strong>+ <span>{`Interactions: ${formatHistoryDateRange({ date_from: rangeDraftCaptures[0].captured_on, date_to: rangeDraftBackground.captured_on })}`}</span>+ </strong>+ <div className="flex items-center gap-3 mt-2">+ <div className="relative w-24 h-16 shrink-0 rounded bg-surface-primary flex items-center justify-center overflow-hidden">+ <IconCamera className="text-muted text-xl" />+ {rangeDraftBackground.thumbnail_url ? (+ <img+ key={rangeDraftBackground.thumbnail_url}+ src={rangeDraftBackground.thumbnail_url}+ alt={`Screenshot preview for ${formatCaptureDay(rangeDraftBackground.captured_on, 'long')}`}+ className="absolute inset-0 w-full h-full object-cover object-top"+ onError={(event) => {+ event.currentTarget.hidden = true+ }}+ />+ ) : null}+ </div>+ <div className="min-w-0 text-sm">+ <span>{`Screenshot used: ${formatCaptureTimestamp(rangeDraftBackground)}`}</span>+ <p className="text-xs text-muted mb-0 mt-1">+ <span>{`Newest available screenshot in this period · ${rangeDraftBackground.width}px`}</span>+ </p>+ </div>+ </div>+ </div>+ ) : (+ <LemonBanner type="warning" className="mb-3">+ {rangeDraftError}+ </LemonBanner>+ )}+ <LemonBanner type="warning">+ All interactions will be positioned on this screenshot. Page changes can move older clicks onto+ different elements. Inspect individual days if the layout changed.+ </LemonBanner>+ <p className="text-xs text-muted mt-2 mb-0">+ Range endpoints need an available screenshot with the same screen width and timezone.+ </p>+ </LemonModal>+ )+}diff --git a/products/web_analytics/frontend/heatmaps/history/PageHistoryStrip.tsx b/products/web_analytics/frontend/heatmaps/history/PageHistoryStrip.tsxindex b834c4209ad7..159a3733792e 100644--- a/products/web_analytics/frontend/heatmaps/history/PageHistoryStrip.tsx+++ b/products/web_analytics/frontend/heatmaps/history/PageHistoryStrip.tsx@@ -11,6 +11,7 @@ import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'import { dateFilterToText } from 'lib/utils/dateFilters'import { pageHistoryLogic } from './pageHistoryLogic'+import { PageHistoryRangeEditor } from './PageHistoryRangeEditor'import { PageHistoryTile } from './PageHistoryTile'import { formatCaptureDay, formatCaptureTimestamp, formatHistoryDateRange } from './pageHistoryUtils'@@ -27,14 +28,22 @@ export function PageHistoryStrip({ id }: { id: string }): JSX.Element {historyPageCount,historyExpanded,selectedDateRange,+ isCombinedRange,selectedBackground,historyBrowseDisabledReason,missingCaptureDate,missingDateAlternatives,navigationNotice,} = useValues(logic)- const { browseCapture, clearSelection, loadHistory, setHistoryPage, setHistoryExpanded, setMissingCaptureDate } =- useActions(logic)+ const {+ browseCapture,+ selectCapture,+ clearSelection,+ loadHistory,+ setHistoryPage,+ setHistoryExpanded,+ setMissingCaptureDate,+ } = useActions(logic)const { effectiveCommonFilters } = useValues(heatmapDataLogic({ context: 'in-app' }))const contextRef = useRef<HTMLElement | null>(null)const [browserMaxHeight, setBrowserMaxHeight] = useState(640)@@ -167,6 +176,23 @@ export function PageHistoryStrip({ id }: { id: string }): JSX.Element {) : null}</div></div>+ {isCombinedRange && selectedDateRange ? (+ <LemonBanner+ type="warning"+ className="mt-2"+ action={{+ children: 'Review days individually',+ onClick: () => {+ if (selectedBackground) {+ selectCapture(selectedBackground.id)+ }+ },+ }}+ >+ All interactions are positioned on this screenshot. Page changes during this period can move clicks+ onto different elements.+ </LemonBanner>+ ) : null}{historyLoadFailed ? (<LemonBannertype="error"@@ -189,7 +215,7 @@ export function PageHistoryStrip({ id }: { id: string }): JSX.Element {{missingCaptureDate ? (<LemonBanner type="info" className="mt-2" onClose={() => setMissingCaptureDate(null)}><p className="mb-1">- <span>{`No screenshot was saved for ${formatCaptureDay(missingCaptureDate)}. ${selectedBackground ? `Still viewing the ${dayjs(selectedBackground.captured_on).format('MMM D')} screenshot and its interaction day.` : 'Your current view is unchanged.'}`}</span>+ <span>{`No screenshot was saved for ${formatCaptureDay(missingCaptureDate)}. ${selectedBackground ? `Still viewing the ${dayjs(selectedBackground.captured_on).format('MMM D')} screenshot${isCombinedRange ? ' with your combined interaction dates' : ' and its interaction day'}.` : 'Your current view is unchanged.'}`}</span></p><p className="text-xs mb-2">A missing screenshot does not indicate whether interactions exist.</p><div className="flex flex-wrap gap-2">@@ -319,6 +345,7 @@ export function PageHistoryStrip({ id }: { id: string }): JSX.Element {</div></div>) : null}+ <PageHistoryRangeEditor id={id} /></section>)}diff --git a/products/web_analytics/frontend/heatmaps/history/PageHistoryTile.stories.tsx b/products/web_analytics/frontend/heatmaps/history/PageHistoryTile.stories.tsxnew file mode 100644index 000000000000..8b50735379da--- /dev/null+++ b/products/web_analytics/frontend/heatmaps/history/PageHistoryTile.stories.tsx@@ -0,0 +1,81 @@+import type { Meta, StoryObj } from '@storybook/react'++import type { HeatmapScreenshotHistoryItemApi } from 'products/web_analytics/frontend/generated/api.schemas'++import { PageHistoryTile } from './PageHistoryTile'++const capture: HeatmapScreenshotHistoryItemApi = {+ id: '00000000-0000-4000-8000-000000000001',+ captured_on: '2024-01-21',+ captured_at: '2024-01-21T02:40:00Z',+ width: 1024,+ timezone: 'UTC',+ day_start: '2024-01-21T00:00:00Z',+ day_end: '2024-01-22T00:00:00Z',+ expires_at: '2024-04-20T00:00:00Z',+ revision: '00000000-0000-4000-8000-000000000002',+ latest_request: null,+ thumbnail_url:+ 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="320" height="240"%3E%3Crect width="320" height="240" fill="%23e3e6dd"/%3E%3Crect x="24" y="24" width="272" height="60" fill="white"/%3E%3Crect x="24" y="100" width="80" height="80" fill="white"/%3E%3Crect x="120" y="100" width="80" height="80" fill="white"/%3E%3Crect x="216" y="100" width="80" height="80" fill="white"/%3E%3C/svg%3E',+ content_url: '/example-capture.jpg',+ trigger: 'scheduled',+ status: 'ok',+ failure_cause: null,+ page_status: 200,+}++const meta: Meta<typeof PageHistoryTile> = {+ title: 'Products/Web Analytics/Heatmaps/Page history tile',+ component: PageHistoryTile,+ parameters: { mockDate: '2024-01-21T12:00:00Z' },+ args: { capture, selected: false, onSelect: () => {} },+ decorators: [+ (Story) => (+ <div className="w-28">+ <Story />+ </div>+ ),+ ],+}+export default meta++type Story = StoryObj<typeof PageHistoryTile>++export const Captured: Story = {}+export const SelectedBackground: Story = { args: { selected: true } }+export const MissingThumbnail: Story = { args: { capture: { ...capture, thumbnail_url: null } } }+export const FailedReplacement: Story = {+ args: {+ capture: {+ ...capture,+ latest_request: {+ request_id: '00000000-0000-4000-8000-000000000003',+ state: 'failed',+ deadline: '2024-01-21T12:30:00Z',+ completed_at: '2024-01-21T12:02:00Z',+ failure_cause: 'browserless_timeout',+ page_status: null,+ },+ },+ },+}+export const FirstCaptureInProgress: Story = {+ args: {+ capture: {+ ...capture,+ status: 'pending',+ revision: null,+ content_url: null,+ thumbnail_url: null,+ captured_at: null,+ latest_request: {+ request_id: '00000000-0000-4000-8000-000000000003',+ state: 'running',+ deadline: '2024-01-21T12:30:00Z',+ completed_at: null,+ failure_cause: null,+ page_status: null,+ },+ },+ },+}diff --git a/products/web_analytics/frontend/heatmaps/history/pageHistoryLogic.test.ts b/products/web_analytics/frontend/heatmaps/history/pageHistoryLogic.test.tsindex 3e9923c0e267..36e6f45c03d3 100644--- a/products/web_analytics/frontend/heatmaps/history/pageHistoryLogic.test.ts+++ b/products/web_analytics/frontend/heatmaps/history/pageHistoryLogic.test.ts@@ -167,6 +167,48 @@ describe('pageHistoryLogic', () => {expect(scene.values.previewUnavailable).toBe(true)})+ it('previews a complete range without changing the applied view until Apply', async () => {+ await expectLogic(logic, () => logic.actions.selectCapture('cap-3')).toFinishAllListeners()+ logic.actions.openRangeEditor()+ logic.actions.setRangeDraft('cap-1', 'cap-3')+ expect(logic.values.rangeDraftBackground?.id).toBe('cap-3')+ expect(dataLogic.values.dateRangeOverride?.date_from).toBe('2024-05-03')+ logic.actions.setRangeEditorOpen(false)+ expect(dataLogic.values.dateRangeOverride?.date_from).toBe('2024-05-03')+ logic.actions.openRangeEditor()+ logic.actions.setRangeDraft('cap-1', 'cap-3')+ await expectLogic(logic, () => logic.actions.applyRangeDraft()).toFinishAllListeners()+ expect(logic.values.rangeEditorOpen).toBe(false)+ expect(dataLogic.values.dateRangeOverride).toMatchObject({+ date_from: '2024-05-01',+ date_to: '2024-05-03',+ timestamp_to: '2024-05-04T00:00:00Z',+ })+ await expectLogic(logic, () => logic.actions.browseCapture('cap-1')).toFinishAllListeners()+ expect(logic.values.selectedDateRange).toMatchObject({ date_from: '2024-05-01', date_to: '2024-05-01' })+ })++ it.each([{ width: 1440 }, { timezone: 'America/New_York' }])(+ 'keeps the applied view when an incompatible range is drafted: %s',+ async (difference) => {+ await expectLogic(logic, () => {+ logic.actions.loadHistorySuccess(+ historyResponse([...captures, capture('cap-4', '2024-05-04', difference)])+ )+ logic.actions.selectCapture('cap-1')+ }).toFinishAllListeners()+ logic.actions.openRangeEditor()+ logic.actions.setRangeDraft('cap-1', 'cap-4')+ expect(logic.values.rangeDraftError).toContain('same screen width and timezone')+ await expectLogic(logic, () => logic.actions.applyRangeDraft()).toFinishAllListeners()+ expect(dataLogic.values.dateRangeOverride).toMatchObject({+ date_from: '2024-05-01',+ date_to: '2024-05-01',+ })+ expect(logic.values.rangeEditorOpen).toBe(true)+ }+ )+it('preserves the shown day when a missing date is requested and explicitly identifies navigation gaps', async () => {await expectLogic(logic, () => logic.actions.selectCapture('cap-1')).toFinishAllListeners()await expectLogic(logic, () => logic.actions.browseCapture('cap-2')).toFinishAllListeners()@@ -316,20 +358,23 @@ describe('pageHistoryLogic', () => {expect(logic.values.history).toEqual(historyResponse(captures))})- it.each(['cap-1', 'cap-3'])('explains recovery when the selected day expires: %s', async (expiredId) => {- await expectLogic(logic, () => logic.actions.selectCapture(expiredId)).toFinishAllListeners()- dataLogic.actions.setCommonFilters({ date_from: '-30d', filter_test_accounts: true })- await expectLogic(logic, () =>- logic.actions.loadHistorySuccess(- historyResponse(captures.filter((capture) => capture.id !== expiredId))- )- ).toFinishAllListeners()- expect(logic.values.isSelectionActive).toBe(false)- expect(logic.values.navigationNotice).toContain('no longer available')- expect(logic.values.historyExpanded).toBe(true)- expect(dataLogic.values.dateRangeOverride).toBeNull()- expect(dataLogic.values.commonFilters).toEqual({ date_from: '-30d', filter_test_accounts: true })- })+ it.each(['cap-1', 'cap-3'])(+ 'explains recovery when a combined-range endpoint expires: %s',+ async (expiredId) => {+ await expectLogic(logic, () => logic.actions.setSelectionRange('cap-1', 'cap-3')).toFinishAllListeners()+ dataLogic.actions.setCommonFilters({ date_from: '-30d', filter_test_accounts: true })+ await expectLogic(logic, () =>+ logic.actions.loadHistorySuccess(+ historyResponse(captures.filter((capture) => capture.id !== expiredId))+ )+ ).toFinishAllListeners()+ expect(logic.values.isSelectionActive).toBe(false)+ expect(logic.values.navigationNotice).toContain('no longer available')+ expect(logic.values.historyExpanded).toBe(true)+ expect(dataLogic.values.dateRangeOverride).toBeNull()+ expect(dataLogic.values.commonFilters).toEqual({ date_from: '-30d', filter_test_accounts: true })+ }+ )it.each(['exit history', 'edit the page URL', 'switch to an iframe'])('restores current filters and width when users %s',diff --git a/products/web_analytics/frontend/heatmaps/history/pageHistoryLogic.ts b/products/web_analytics/frontend/heatmaps/history/pageHistoryLogic.tsindex ddc2c6c5c0a5..d5179a748816 100644--- a/products/web_analytics/frontend/heatmaps/history/pageHistoryLogic.ts+++ b/products/web_analytics/frontend/heatmaps/history/pageHistoryLogic.ts@@ -91,6 +91,7 @@ export interface pageHistoryLogicValues {historyLoading: booleanhistoryPage: numberhistoryPageCount: number+ isCombinedRange: booleanisSelectionActive: booleanmissingCaptureDate: string | nullmissingDateAlternatives: HeatmapScreenshotHistoryItemApi[]@@ -98,6 +99,14 @@ export interface pageHistoryLogicValues {nextCapture: HeatmapScreenshotHistoryItemApi | nullpageHistoryEnabled: booleanpreviousCapture: HeatmapScreenshotHistoryItemApi | null+ rangeDraft: {+ fromId: string+ toId: string+ } | null+ rangeDraftBackground: HeatmapScreenshotHistoryItemApi | null+ rangeDraftCaptures: HeatmapScreenshotHistoryItemApi[]+ rangeDraftError: string | null+ rangeEditorOpen: booleanselectedBackground: HeatmapScreenshotHistoryItemApi | nullselectedCaptures: HeatmapScreenshotHistoryItemApi[]selectedDateRange: HeatmapDateRangeOverride | null@@ -129,6 +138,9 @@ export interface pageHistoryLogicActions {setType: (type: HeatmapType) => {type: HeatmapType} // heatmapLogic+ applyRangeDraft: () => {+ value: true+ }applySelection: () => {value: true}@@ -156,6 +168,9 @@ export interface pageHistoryLogicActions {navigateCapture: (direction: 'next' | 'previous') => {direction: 'next' | 'previous'}+ openRangeEditor: () => {+ value: true+ }pageChanged: () => {value: true}@@ -174,6 +189,23 @@ export interface pageHistoryLogicActions {setNavigationNotice: (notice: string | null) => {notice: string | null}+ setRangeDraft: (+ fromId: string,+ toId: string+ ) => {+ fromId: string+ toId: string+ }+ setRangeEditorOpen: (open: boolean) => {+ open: boolean+ }+ setSelectionRange: (+ anchorId: string,+ extentId: string+ ) => {+ anchorId: string+ extentId: string+ }}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -201,6 +233,25 @@ export interface pageHistoryLogicMeta {usableCaptures: HeatmapScreenshotHistoryItemApi[],missingCaptureDate: string | null) => HeatmapScreenshotHistoryItemApi[]+ rangeDraftError: (+ captures: HeatmapScreenshotHistoryItemApi[],+ rangeDraft: {+ fromId: string+ toId: string+ } | null,+ historyBrowseDisabledReason: string | null+ ) => string | null+ rangeDraftCaptures: (+ captures: HeatmapScreenshotHistoryItemApi[],+ rangeDraft: {+ fromId: string+ toId: string+ } | null,+ rangeDraftError: string | null+ ) => HeatmapScreenshotHistoryItemApi[]+ rangeDraftBackground: (+ rangeDraftCaptures: HeatmapScreenshotHistoryItemApi[]+ ) => HeatmapScreenshotHistoryItemApi | nullhistoryBrowseDisabledReason: (hasUnsavedChanges: boolean) => string | nullselectedCaptures: (captures: HeatmapScreenshotHistoryItemApi[],@@ -212,6 +263,7 @@ export interface pageHistoryLogicMeta {selectedCaptures: HeatmapScreenshotHistoryItemApi[]) => HeatmapScreenshotHistoryItemApi | nullisSelectionActive: (selectedCaptures: HeatmapScreenshotHistoryItemApi[]) => boolean+ isCombinedRange: (selectedDateRange: HeatmapDateRangeOverride | null) => boolean}}@@ -249,6 +301,11 @@ export const pageHistoryLogic = kea<pageHistoryLogicType>([navigateCapture: (direction: 'previous' | 'next') => ({ direction }),setMissingCaptureDate: (date: string | null) => ({ date }),setNavigationNotice: (notice: string | null) => ({ notice }),+ openRangeEditor: true,+ setRangeEditorOpen: (open: boolean) => ({ open }),+ setRangeDraft: (fromId: string, toId: string) => ({ fromId, toId }),+ applyRangeDraft: true,+ setSelectionRange: (anchorId: string, extentId: string) => ({ anchorId, extentId }),setHistoryPage: (page: number) => ({ page }),setHistoryExpanded: (expanded: boolean) => ({ expanded }),clearSelection: true,@@ -271,6 +328,7 @@ export const pageHistoryLogic = kea<pageHistoryLogicType>([null as string | null,{selectCapture: (_, { id }) => id,+ setSelectionRange: (_, { anchorId }) => anchorId,clearSelection: () => null,},],@@ -278,6 +336,7 @@ export const pageHistoryLogic = kea<pageHistoryLogicType>([null as string | null,{selectCapture: (_, { id }) => id,+ setSelectionRange: (_, { extentId }) => extentId,clearSelection: () => null,},],@@ -286,8 +345,22 @@ export const pageHistoryLogic = kea<pageHistoryLogicType>([{setHistoryExpanded: (_, { expanded }) => expanded,clearSelection: () => false,+ openRangeEditor: () => false,+ },+ ],+ rangeEditorOpen: [+ false,+ {+ setRangeEditorOpen: (_, { open }) => open,+ openRangeEditor: () => true,+ clearSelection: () => false,+ selectCapture: () => false,},],+ rangeDraft: [+ null as { fromId: string; toId: string } | null,+ { setRangeDraft: (_, { fromId, toId }) => ({ fromId, toId }) },+ ],missingCaptureDate: [null as string | null,{ setMissingCaptureDate: (_, { date }) => date, selectCapture: () => null, clearSelection: () => null },@@ -363,6 +436,44 @@ export const pageHistoryLogic = kea<pageHistoryLogicType>([].filter((capture): capture is HeatmapScreenshotHistoryItemApi => !!capture)},],+ rangeDraftError: [+ (s) => [s.captures, s.rangeDraft, s.historyBrowseDisabledReason],+ (+ captures: HeatmapScreenshotHistoryItemApi[],+ draft: { fromId: string; toId: string } | null,+ disabledReason: string | null+ ): string | null => {+ if (disabledReason) {+ return disabledReason+ }+ const from = captures.find((capture) => capture.id === draft?.fromId)+ const to = captures.find((capture) => capture.id === draft?.toId)+ if (!from || !to || !isUsableCapture(from) || !isUsableCapture(to)) {+ return 'Choose available screenshots for both dates.'+ }+ if (from.captured_on > to.captured_on) {+ return 'Choose a start date on or before the end date.'+ }+ if (!selectCapturesBetween(captures, from.id, to.id).some((capture) => capture.id === to.id)) {+ return 'Combined days need screenshots with the same screen width and timezone.'+ }+ return null+ },+ ],+ rangeDraftCaptures: [+ (s) => [s.captures, s.rangeDraft, s.rangeDraftError],+ (+ captures: HeatmapScreenshotHistoryItemApi[],+ draft: { fromId: string; toId: string } | null,+ error: string | null+ ): HeatmapScreenshotHistoryItemApi[] =>+ draft && !error ? selectCapturesBetween(captures, draft.fromId, draft.toId) : [],+ ],+ rangeDraftBackground: [+ (s) => [s.rangeDraftCaptures],+ (captures: HeatmapScreenshotHistoryItemApi[]): HeatmapScreenshotHistoryItemApi | null =>+ captures.at(-1) ?? null,+ ],historyBrowseDisabledReason: [(s) => [s.hasUnsavedChanges],(hasUnsavedChanges: boolean): string | null =>@@ -397,6 +508,10 @@ export const pageHistoryLogic = kea<pageHistoryLogicType>([(s) => [s.selectedCaptures],(captures: HeatmapScreenshotHistoryItemApi[]): boolean => captures.length > 0,],+ isCombinedRange: [+ (s) => [s.selectedDateRange],+ (range: HeatmapDateRangeOverride | null): boolean => !!range && range.date_from !== range.date_to,+ ],}),listeners(({ actions, values, cache, key, props }) => {const clearSelectionOnUnsavedChange = (): void => {@@ -465,6 +580,25 @@ export const pageHistoryLogic = kea<pageHistoryLogicType>([)}},+ openRangeEditor: () => {+ const selected = values.selectedCaptures+ const latest = values.usableCaptures.at(-1)+ if (!latest) {+ actions.setRangeEditorOpen(false)+ return+ }+ actions.setRangeDraft(selected[0]?.id ?? latest.id, selected.at(-1)?.id ?? latest.id)+ },+ applyRangeDraft: () => {+ const draft = values.rangeDraft+ if (!draft || values.rangeDraftError) {+ return+ }+ actions.setSelectionRange(draft.fromId, draft.toId)+ actions.setRangeEditorOpen(false)+ actions.setMissingCaptureDate(null)+ actions.setNavigationNotice(null)+ },selectCapture: ({ id }) => {const index = values.captures.findIndex((capture) => capture.id === id)if (index >= 0) {@@ -472,6 +606,7 @@ export const pageHistoryLogic = kea<pageHistoryLogicType>([}actions.applySelection()},+ setSelectionRange: () => actions.applySelection(),applySelection: () => {const background = values.selectedBackgroundconst range = values.selectedDateRange