: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
fix(alerts): keep the alert deletion banner off for metrics insights (#114267)
Jimmy Zhue75e69a339f8
diff --git a/products/alerts/frontend/logic/insightAlertsLogic.test.ts b/products/alerts/frontend/logic/insightAlertsLogic.test.tsindex 084905c9ef94..5accda41fec9 100644--- a/products/alerts/frontend/logic/insightAlertsLogic.test.ts+++ b/products/alerts/frontend/logic/insightAlertsLogic.test.ts@@ -1,6 +1,8 @@import { expectLogic } from 'kea-test-utils'import api from 'lib/api'+import { FEATURE_FLAGS } from 'lib/constants'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { insightDataLogic } from 'scenes/insights/insightDataLogic'import { createEmptyInsight, insightLogic } from 'scenes/insights/insightLogic'import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'@@ -273,6 +275,34 @@ describe('insightAlertsLogic', () => {expect(hogFunctionsListSpy).toHaveBeenCalledTimes(1)})+ it.each([+ { metricsEnabled: true, expectedWarning: false },+ { metricsEnabled: false, expectedWarning: true },+ ])(+ 'with metrics flag $metricsEnabled, a metrics query on an insight with alerts sets the deletion warning to $expectedWarning',+ async ({ metricsEnabled, expectedWarning }) => {+ featureFlagLogic.mount()+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.METRICS]: metricsEnabled })+ const insightLogicProps: InsightLogicProps = {+ dashboardItemId: Insight42,+ cachedInsight: {+ ...createEmptyInsight(Insight42),+ id: 42,+ query: METRICS_QUERY,+ alerts: [{ id: 'alert-a' }] as AlertType[],+ },+ }+ mountInsightStack(insightLogicProps)+ const alertsLogic = insightAlertsLogic({ insightId: 42, insightLogicProps, deferInitialAlertsLoad: true })+ alertsLogic.mount()++ await expectLogic(alertsLogic, () => {+ insightVizDataLogic(insightLogicProps).actions.setQuery(METRICS_QUERY)+ }).toDispatchActions(['setShouldShowAlertDeletionWarning'])+ expect(alertsLogic.values.shouldShowAlertDeletionWarning).toBe(expectedWarning)+ }+ )+it('refreshes destination counts after an alert is saved', async () => {const insightLogicProps: InsightLogicProps = {dashboardItemId: Insight42,diff --git a/products/alerts/frontend/logic/insightAlertsLogic.ts b/products/alerts/frontend/logic/insightAlertsLogic.tsindex f6b9b5d32bc7..d895d19b936b 100644--- a/products/alerts/frontend/logic/insightAlertsLogic.ts+++ b/products/alerts/frontend/logic/insightAlertsLogic.ts@@ -2,7 +2,8 @@ import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path,import { loaders } from 'kea-loaders'import api from 'lib/api'-import { NON_TIME_SERIES_DISPLAY_TYPES } from 'lib/constants'+import { FEATURE_FLAGS, NON_TIME_SERIES_DISPLAY_TYPES } from 'lib/constants'+import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'import { insightLogic } from 'scenes/insights/insightLogic'import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'@@ -130,6 +131,7 @@ export function alertsToThresholdGoalLines(alerts: AlertType[]): GoalLine[] {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface insightAlertsLogicValues {+ featureFlags: FeatureFlagsSet // featureFlagLogicinsight: Partial<InsightModel<Node<Record<string, any>>>> // insightLogicbreakdownFilter: BreakdownFilter | null | undefined // insightVizDataLogicshowAlertThresholdLines: boolean | null | undefined // insightVizDataLogic@@ -250,6 +252,8 @@ export const insightAlertsLogic = kea<insightAlertsLogicType>([['showAlertThresholdLines', 'breakdownFilter'],insightLogic(props.insightLogicProps),['insight'],+ featureFlagLogic,+ ['featureFlags'],],})),@@ -411,11 +415,10 @@ export const insightAlertsLogic = kea<insightAlertsLogicType>([actions.loadAlertDestinationCounts(values.alerts)},setQuery: ({ query }) => {- if (values.alerts.length === 0 || areAlertsSupportedForInsight(query)) {- actions.setShouldShowAlertDeletionWarning(false)- } else {- actions.setShouldShowAlertDeletionWarning(true)- }+ const metricsAlertsEnabled = !!values.featureFlags[FEATURE_FLAGS.METRICS]+ actions.setShouldShowAlertDeletionWarning(+ values.alerts.length > 0 && !areAlertsSupportedForInsight(query, { metricsAlertsEnabled })+ )},setShowAlertAnomalyPoints: ({ show }) => {// When toggling on, reload alerts from the API to get latest check data