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 that alert destination and status changes save automatically (#117883)

posthog[bot]33c2b8880778
diff --git a/products/alerts/frontend/components/AlertEditor.tsx b/products/alerts/frontend/components/AlertEditor.tsx
index aef62d5a5e60..bdbf78409a5b 100644
--- a/products/alerts/frontend/components/AlertEditor.tsx
+++ b/products/alerts/frontend/components/AlertEditor.tsx
@@ -74,6 +74,7 @@ export interface AlertEditorActionsProps {
trailingActions?: ReactNode
onSubmitAttempted?: () => void
showNoChangesLabel?: boolean
+ noChangesReason?: string
}
export function AlertEditorActions({
@@ -85,9 +86,10 @@ export function AlertEditorActions({
trailingActions,
onSubmitAttempted,
showNoChangesLabel = false,
+ noChangesReason = 'No changes to save',
}: AlertEditorActionsProps): JSX.Element {
const hasUnsavedChanges = hasChanges || hasPendingChanges
- const disabledReason = isEditing && !hasUnsavedChanges ? 'No changes to save' : undefined
+ const disabledReason = isEditing && !hasUnsavedChanges ? noChangesReason : undefined
let buttonLabel = 'Create alert'
if (isEditing) {
buttonLabel = showNoChangesLabel && !hasUnsavedChanges ? 'No changes' : 'Save'
diff --git a/products/alerts/frontend/components/AlertNotificationDestinationEditor.tsx b/products/alerts/frontend/components/AlertNotificationDestinationEditor.tsx
index d658b0210828..bb64d4718b55 100644
--- a/products/alerts/frontend/components/AlertNotificationDestinationEditor.tsx
+++ b/products/alerts/frontend/components/AlertNotificationDestinationEditor.tsx
@@ -87,6 +87,7 @@ interface AlertNotificationDestinationEditorProps<NotificationType extends strin
existingLoading: boolean
existing: AlertNotificationDestinationView[]
pending: PendingAlertNotificationDestinationView[]
+ pendingTooltip?: string
}
notificationType: {
options: LemonSelectOptions<NotificationType>
@@ -210,8 +211,10 @@ function ExistingDestinations({
function PendingDestinations({
destinations,
+ tooltip = 'Save this alert to add this destination.',
}: {
destinations: PendingAlertNotificationDestinationView[]
+ tooltip?: string
}): JSX.Element | null {
if (destinations.length === 0) {
return null
@@ -224,7 +227,7 @@ function PendingDestinations({
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 flex-wrap">
<span className="text-sm font-medium truncate">{destination.title}</span>
- <Tooltip title="Save this alert to add this destination.">
+ <Tooltip title={tooltip}>
<LemonTag type="warning" size="small">
Pending
</LemonTag>
@@ -353,7 +356,7 @@ export function AlertNotificationDestinationEditor<NotificationType extends stri
<ExistingDestinations loading={destinations.existingLoading} destinations={destinations.existing} />
) : null}
- <PendingDestinations destinations={destinations.pending} />
+ <PendingDestinations destinations={destinations.pending} tooltip={destinations.pendingTooltip} />
{hasDestinations ? <hr className="border-border m-0" /> : null}
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerAlertEditModal.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerAlertEditModal.tsx
index 2f6f6ebfbdd2..4ff25d1da157 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerAlertEditModal.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerAlertEditModal.tsx
@@ -70,7 +70,7 @@ function ScannerAlertEditModalContent({
scannerAlertFormLogic(formLogicProps)
)
const { touchAlertFormField } = useActions(scannerAlertFormLogic(formLogicProps))
- const { destinationGroups } = useValues(scannerAlertNotificationLogic(notificationLogicProps))
+ const { destinationGroups, pendingNotifications } = useValues(scannerAlertNotificationLogic(notificationLogicProps))
const { busyAlertIds } = useValues(scannerAlertsLogic({ scannerId }))
const { deleteAlert, snoozeAlertUntil, toggleAlertEnabled, unsnoozeAlert } = useActions(
scannerAlertsLogic({ scannerId })
@@ -205,12 +205,16 @@ function ScannerAlertEditModalContent({
isEditing
isSubmitting={isAlertFormSubmitting}
hasChanges={alertFormChanged}
+ hasPendingChanges={pendingNotifications.length > 0}
+ noChangesReason="No changes to save. Destination, snooze, and Enabled changes save automatically."
onSubmitAttempted={() => touchAlertFormField('name')}
leadingActions={leadingActions}
trailingActions={
<LemonSwitch
checked={alert.enabled ?? true}
label="Enabled"
+ tooltip="Saves automatically"
+ disabledReason={busyAlertIds.has(alert.id) ? 'Updating' : undefined}
onChange={() => toggleAlertEnabled(alert)}
/>
}
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerAlertNotifications.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerAlertNotifications.tsx
index ae88b74a15c6..cdf7102a7e91 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerAlertNotifications.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerAlertNotifications.tsx
@@ -24,6 +24,7 @@ function pendingDestinationView(notification: PendingVisionAlertNotification): {
export function ScannerAlertNotifications(): JSX.Element {
const {
+ autoSavesDestinations,
existingHogFunctionsLoading,
destinationGroups,
pendingNotifications,
@@ -72,12 +73,19 @@ export function ScannerAlertNotifications(): JSX.Element {
return (
<AlertNotificationDestinationEditor
- description="Each destination receives every notification this alert sends."
+ description={
+ autoSavesDestinations
+ ? 'Each destination receives every notification this alert sends. Added and removed destinations save automatically.'
+ : 'Each destination receives every notification this alert sends.'
+ }
destinations={{
showExisting: true,
existingLoading: existingHogFunctionsLoading,
existing: existingDestinations,
pending: pendingDestinations,
+ pendingTooltip: autoSavesDestinations
+ ? 'Not added yet. If it stays pending, save the alert to add it.'
+ : undefined,
}}
notificationType={{
options: VISION_ALERT_NOTIFICATION_TYPE_OPTIONS,
diff --git a/products/replay_vision/frontend/replay_scanners/scannerAlertNotificationLogic.test.ts b/products/replay_vision/frontend/replay_scanners/scannerAlertNotificationLogic.test.ts
new file mode 100644
index 000000000000..d921e7216409
--- /dev/null
+++ b/products/replay_vision/frontend/replay_scanners/scannerAlertNotificationLogic.test.ts
@@ -0,0 +1,66 @@
+import { expectLogic } from 'kea-test-utils'
+
+import api from 'lib/api'
+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+
+import { initKeaTests } from '~/test/init'
+
+import { visionAlertsDestinationsCreate } from 'products/replay_vision/frontend/generated/api'
+
+import { scannerAlertNotificationLogic } from './scannerAlertNotificationLogic'
+
+jest.mock('lib/api', () => {
+ const actual = jest.requireActual('lib/api')
+ return {
+ ...actual,
+ __esModule: true,
+ default: { ...actual.default, hogFunctions: { list: jest.fn() } },
+ }
+})
+
+jest.mock('products/replay_vision/frontend/generated/api', () => ({
+ __esModule: true,
+ visionAlertsDestinationsCreate: jest.fn(),
+ visionAlertsDestinationsDeleteCreate: jest.fn(),
+}))
+
+jest.mock('lib/lemon-ui/LemonToast/LemonToast', () => ({
+ lemonToast: {
+ success: jest.fn(),
+ error: jest.fn(),
+ },
+}))
+
+const mockApi = api as jest.Mocked<typeof api>
+const mockCreate = visionAlertsDestinationsCreate as jest.MockedFunction<typeof visionAlertsDestinationsCreate>
+
+describe('scannerAlertNotificationLogic', () => {
+ beforeEach(() => {
+ initKeaTests()
+ jest.clearAllMocks()
+ ;(mockApi.hogFunctions.list as jest.Mock).mockResolvedValue({ results: [] })
+ })
+
+ it.each([
+ ['an existing alert creates on add and points at Save to retry', 'alert-1', 'Save the alert to try again'],
+ ['a new alert creates on submit and points at reopening', undefined, 'Reopen the alert'],
+ ])('%s', async (_name, alertId, expectedToast) => {
+ mockCreate.mockRejectedValueOnce(new Error('API error'))
+
+ const logic = scannerAlertNotificationLogic({ alertId })
+ logic.mount()
+
+ await expectLogic(logic, () => {
+ logic.actions.addPendingNotification({ type: 'webhook', webhookUrl: 'https://example.com/hook' })
+ if (!alertId) {
+ logic.actions.createPendingHogFunctions('alert-1')
+ }
+ }).toFinishAllListeners()
+
+ expect(mockCreate).toHaveBeenCalledTimes(1)
+ expect(lemonToast.error).toHaveBeenCalledWith(expect.stringContaining(expectedToast))
+ expect(logic.values.pendingNotifications).toHaveLength(1)
+
+ logic.unmount()
+ })
+})
diff --git a/products/replay_vision/frontend/replay_scanners/scannerAlertNotificationLogic.ts b/products/replay_vision/frontend/replay_scanners/scannerAlertNotificationLogic.ts
index a02e9333317e..58bd4efc4cb2 100644
--- a/products/replay_vision/frontend/replay_scanners/scannerAlertNotificationLogic.ts
+++ b/products/replay_vision/frontend/replay_scanners/scannerAlertNotificationLogic.ts
@@ -36,6 +36,7 @@ export interface scannerAlertNotificationLogicValues {
slackIntegrations: IntegrationType[] | undefined // integrationsLogic
currentTeamId: number | null // teamLogic
addDisabledReason: string | undefined
+ autoSavesDestinations: boolean
destinationGroups: VisionAlertDestinationGroup[]
existingHogFunctions: HogFunctionType[]
existingHogFunctionsLoading: boolean
@@ -116,6 +117,7 @@ export interface scannerAlertNotificationLogicActions {
export interface scannerAlertNotificationLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
+ autoSavesDestinations: (arg: string | undefined) => boolean
firstSlackIntegration: (slackIntegrations: IntegrationType[] | undefined) => IntegrationType | undefined
urlInput: (selectedType: VisionAlertNotificationType) => AlertNotificationUrlInput | undefined
addDisabledReason: (
@@ -217,6 +219,10 @@ export const scannerAlertNotificationLogic = kea<scannerAlertNotificationLogicTy
})),
selectors({
+ autoSavesDestinations: [
+ () => [(_, props: ScannerAlertNotificationLogicProps) => props.alertId],
+ (alertId: string | undefined): boolean => !!alertId,
+ ],
firstSlackIntegration: [
(s) => [s.slackIntegrations],
(slackIntegrations: IntegrationType[] | undefined): IntegrationType | undefined => slackIntegrations?.[0],
@@ -331,7 +337,9 @@ export const scannerAlertNotificationLogic = kea<scannerAlertNotificationLogicTy
if (failedNotifications.length > 0) {
lemonToast.error(
- `Alert saved, but ${failedNotifications.length} notification destination(s) could not be created. Reopen the alert to add them again.`
+ values.autoSavesDestinations
+ ? `Could not add ${failedNotifications.length} notification destination(s). Save the alert to try again.`
+ : `Alert saved, but ${failedNotifications.length} notification destination(s) could not be created. Reopen the alert to add them again.`
)
actions.setPendingNotifications(failedNotifications)
} else {