Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(replay-vision): show draft saved status in scanner editor (#116218)

Hayne Ryu016cd5871995
diff --git a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
index 6be0b304ca0d..fa7c2897b738 100644
--- a/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ScannerEditorScene.tsx
@@ -47,6 +47,7 @@ import { ReplayVisionFeedbackButton } from '../components/ReplayVisionFeedbackBu
import { getReplayVisionEditDisabledReason } from '../utils/accessControl'
import { ExampleObservations } from './components/ExampleObservations'
import { ScannerBudget } from './components/ScannerBudget'
+import { ScannerDraftStatus } from './components/ScannerDraftStatus'
import { ScannerGoalDraft } from './components/ScannerGoalDraft'
import { ScannerGoalFlow } from './components/ScannerGoalFlow'
import { ScannerGoalOverview } from './components/ScannerGoalOverview'
@@ -551,6 +552,7 @@ function EditorFooter({
{step === 'budget' && durationError ? <div className="text-danger text-sm">{durationError}</div> : null}
{fromOverview ? (
<div className="flex flex-wrap items-center justify-end gap-2">
+ <ScannerDraftStatus scannerId={scannerId} fromOverview />
<LemonButton
type="tertiary"
onClick={handleCancel}
@@ -580,6 +582,7 @@ function EditorFooter({
</LemonButton>
) : null}
<div className="flex flex-wrap items-center gap-2 ml-auto">
+ <ScannerDraftStatus scannerId={scannerId} fromOverview={false} />
<LemonButton
type="tertiary"
onClick={handleCancel}
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerDraftStatus.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerDraftStatus.tsx
new file mode 100644
index 000000000000..237629f48420
--- /dev/null
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerDraftStatus.tsx
@@ -0,0 +1,71 @@
+import { useValues } from 'kea'
+import { useEffect, useRef, useState } from 'react'
+
+import { IconCheckCircle, IconWarning } from '@posthog/icons'
+import { Tooltip } from '@posthog/lemon-ui'
+
+import { dayjs } from 'lib/dayjs'
+
+import { replayScannerLogic } from '../replayScannerLogic'
+
+const FLASH_MS = 2000
+
+export function ScannerDraftStatus({
+ scannerId,
+ fromOverview,
+}: {
+ scannerId: string
+ fromOverview: boolean
+}): JSX.Element | null {
+ const { isNew, hasUnsavedChanges, scannerDraftSavedAt } = useValues(replayScannerLogic({ id: scannerId }))
+ const [justSaved, setJustSaved] = useState(false)
+ const mountedWith = useRef(scannerDraftSavedAt)
+
+ useEffect(() => {
+ if (scannerDraftSavedAt === null || scannerDraftSavedAt === mountedWith.current) {
+ return
+ }
+ setJustSaved(true)
+ const timer = window.setTimeout(() => setJustSaved(false), FLASH_MS)
+ return () => window.clearTimeout(timer)
+ }, [scannerDraftSavedAt])
+
+ if (!isNew || !hasUnsavedChanges) {
+ return null
+ }
+
+ const createHint = fromOverview
+ ? 'The scanner is created from the overview.'
+ : 'The scanner is created on the last step.'
+
+ // Dirty form without a timestamp: the browser refused the draft write.
+ if (scannerDraftSavedAt === null) {
+ return (
+ <Tooltip
+ title={`Your browser couldn't store the draft, so leaving the editor loses the edits. ${createHint}`}
+ >
+ <span
+ className="flex items-center gap-1 text-xs text-warning cursor-default"
+ data-attr="vision-editor-draft-status"
+ >
+ <IconWarning className="text-base shrink-0" />
+ Draft not saved
+ </span>
+ </Tooltip>
+ )
+ }
+
+ return (
+ <Tooltip
+ title={`Saved at ${dayjs(scannerDraftSavedAt).format('LTS')}. Every edit is kept in this draft. ${createHint}`}
+ >
+ <span
+ className="flex items-center gap-1 text-xs text-secondary cursor-default"
+ data-attr="vision-editor-draft-status"
+ >
+ <IconCheckCircle className="text-base text-success shrink-0" />
+ {justSaved ? 'Saved just now' : 'Draft saved'}
+ </span>
+ </Tooltip>
+ )
+}