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(replay-vision): snappier scanner toggle and color-coded type column (#61271)

Kim Svatos Dugana79ca9ad3f1a
diff --git a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx
index fb72ae2c50e9..b2d555c25956 100644
--- a/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx
+++ b/products/replay_vision/frontend/replay_scanners/ReplayScannersScene.tsx
@@ -2,7 +2,7 @@ import { useActions, useValues } from 'kea'
import { router } from 'kea-router'
import { IconCopy, IconPencil, IconPlus, IconSearch, IconTrash } from '@posthog/icons'
-import { LemonButton, LemonInput, LemonSwitch, LemonTable, LemonTag, Link } from '@posthog/lemon-ui'
+import { LemonButton, LemonInput, LemonSwitch, LemonTable, LemonTag, LemonTagType, Link } from '@posthog/lemon-ui'
import { AccessControlAction } from 'lib/components/AccessControlAction'
import { XRayHog } from 'lib/components/hedgehogs'
@@ -21,13 +21,27 @@ import { AccessControlLevel, AccessControlResourceType } from '~/types'
import { FilterPill } from '../components/FilterPill'
import { VisionQuotaMeter } from './components/VisionQuotaMeter'
import { replayScannersLogic } from './replayScannersLogic'
-import { ENABLED_OPTIONS, EnabledFilter, SCANNER_TYPE_OPTIONS, ScannerType, ReplayScanner } from './types'
+import {
+ ENABLED_OPTIONS,
+ EnabledFilter,
+ SCANNER_TYPE_OPTIONS,
+ ScannerType,
+ ReplayScanner,
+ scannerTypeLabel,
+} from './types'
const TYPE_OPTIONS: { value: ScannerType; label: string }[] = SCANNER_TYPE_OPTIONS.map(({ value, label }) => ({
value,
label,
}))
+const SCANNER_TYPE_TAG_TYPE: Record<ScannerType, LemonTagType> = {
+ monitor: 'primary',
+ classifier: 'completion',
+ scorer: 'warning',
+ summarizer: 'success',
+}
+
export const scene: SceneExport = {
component: ReplayScannersScene,
logic: replayScannersLogic,
@@ -35,8 +49,16 @@ export const scene: SceneExport = {
}
export function ReplayScannersScene(): JSX.Element {
- const { filteredScanners, scanners, scannersLoading, search, enabledFilter, scannerTypeFilter, hasActiveFilters } =
- useValues(replayScannersLogic)
+ const {
+ filteredScanners,
+ scanners,
+ scannersLoading,
+ togglingIds,
+ search,
+ enabledFilter,
+ scannerTypeFilter,
+ hasActiveFilters,
+ } = useValues(replayScannersLogic)
const {
loadScanners,
deleteScanner,
@@ -75,10 +97,11 @@ export function ReplayScannersScene(): JSX.Element {
<LemonSwitch
checked={scanner.enabled}
onChange={() => toggleScannerEnabled(scanner.id)}
+ disabled={togglingIds.includes(scanner.id)}
size="small"
/>
</AccessControlAction>
- <span className={scanner.enabled ? 'text-success' : 'text-muted'}>
+ <span className={`inline-block min-w-[4.5rem] ${scanner.enabled ? 'text-success' : 'text-muted'}`}>
{scanner.enabled ? 'Enabled' : 'Disabled'}
</span>
</div>
@@ -88,7 +111,11 @@ export function ReplayScannersScene(): JSX.Element {
{
title: 'Type',
key: 'scanner_type',
- render: (_, scanner) => <LemonTag type="option">{scanner.scanner_type}</LemonTag>,
+ render: (_, scanner) => (
+ <LemonTag type={SCANNER_TYPE_TAG_TYPE[scanner.scanner_type]}>
+ {scannerTypeLabel(scanner.scanner_type)}
+ </LemonTag>
+ ),
sorter: (a, b) => a.scanner_type.localeCompare(b.scanner_type),
},
{
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannersLogic.test.ts b/products/replay_vision/frontend/replay_scanners/replayScannersLogic.test.ts
index 48e07f714ee1..1fc283656fc3 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannersLogic.test.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannersLogic.test.ts
@@ -50,6 +50,9 @@ describe('replayScannersLogic', () => {
get: {
'/api/projects/:team/vision/scanners/': { results: [] },
},
+ patch: {
+ '/api/projects/:team/vision/scanners/:id/': () => [200, {}],
+ },
})
initKeaTests()
logic = replayScannersLogic({ tabId: 'test' })
@@ -122,12 +125,24 @@ describe('replayScannersLogic', () => {
})
})
- it('toggleScannerEnabledSuccess flips the scanner row', async () => {
+ it('toggleScannerEnabled optimistically flips the row and marks it in-flight', async () => {
await expectLogic(logic, () => {
logic.actions.loadScannersSuccess(scanners)
- logic.actions.toggleScannerEnabledSuccess('a')
+ logic.actions.toggleScannerEnabled('a')
}).toMatchValues({
scanners: expect.arrayContaining([expect.objectContaining({ id: 'a', enabled: false })]),
+ togglingIds: ['a'],
+ })
+ })
+
+ it('revertScannerEnabled flips the row back and clears the in-flight id', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.loadScannersSuccess(scanners)
+ logic.actions.toggleScannerEnabled('a')
+ logic.actions.revertScannerEnabled('a')
+ }).toMatchValues({
+ scanners: expect.arrayContaining([expect.objectContaining({ id: 'a', enabled: true })]),
+ togglingIds: [],
})
})
})
diff --git a/products/replay_vision/frontend/replay_scanners/replayScannersLogic.ts b/products/replay_vision/frontend/replay_scanners/replayScannersLogic.ts
index 9892d1bdba2d..7445dbb5adde 100644
--- a/products/replay_vision/frontend/replay_scanners/replayScannersLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/replayScannersLogic.ts
@@ -58,7 +58,8 @@ export const replayScannersLogic = kea<replayScannersLogicType>([
duplicateScanner: (id: string) => ({ id }),
duplicateScannerSuccess: (scanner: ReplayScanner) => ({ scanner }),
toggleScannerEnabled: (id: string) => ({ id }),
- toggleScannerEnabledSuccess: (id: string) => ({ id }),
+ toggleScannerEnabledDone: (id: string) => ({ id }),
+ revertScannerEnabled: (id: string) => ({ id }),
setSearch: (search: string) => ({ search }),
setEnabledFilter: (values: EnabledFilter[]) => ({ values }),
setScannerTypeFilter: (scannerTypes: ScannerType[]) => ({ scannerTypes }),
@@ -72,8 +73,18 @@ export const replayScannersLogic = kea<replayScannersLogicType>([
loadScannersSuccess: (_, { scanners }) => scanners,
deleteScannerSuccess: (state, { id }) => state.filter((l) => l.id !== id),
duplicateScannerSuccess: (state, { scanner }) => [...state, scanner],
- toggleScannerEnabledSuccess: (state, { id }) =>
+ toggleScannerEnabled: (state, { id }) =>
state.map((l) => (l.id === id ? { ...l, enabled: !l.enabled } : l)),
+ revertScannerEnabled: (state, { id }) =>
+ state.map((l) => (l.id === id ? { ...l, enabled: !l.enabled } : l)),
+ },
+ ],
+ togglingIds: [
+ [] as string[],
+ {
+ toggleScannerEnabled: (state, { id }) => [...state, id],
+ toggleScannerEnabledDone: (state, { id }) => state.filter((i) => i !== id),
+ revertScannerEnabled: (state, { id }) => state.filter((i) => i !== id),
},
],
scannersLoading: [
@@ -168,19 +179,22 @@ export const replayScannersLogic = kea<replayScannersLogicType>([
},
toggleScannerEnabled: async ({ id }) => {
+ // The reducer has already flipped `enabled` optimistically, so this reflects the new target state.
const scanner = values.scanners.find((l) => l.id === id)
if (!scanner) {
return
}
const teamId = teamLogic.values.currentTeamId
if (!teamId) {
+ actions.revertScannerEnabled(id)
return
}
try {
- await visionScannersPartialUpdate(String(teamId), id, { enabled: !scanner.enabled })
- actions.toggleScannerEnabledSuccess(id)
+ await visionScannersPartialUpdate(String(teamId), id, { enabled: scanner.enabled })
+ actions.toggleScannerEnabledDone(id)
} catch (error) {
- lemonToast.error(`Failed to ${scanner.enabled ? 'disable' : 'enable'} scanner: ${String(error)}`)
+ lemonToast.error(`Failed to ${scanner.enabled ? 'enable' : 'disable'} scanner: ${String(error)}`)
+ actions.revertScannerEnabled(id)
}
},
})),