: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(error-tracking): only offer creatable alert wizard combinations (#74206)
Aleksander Błaszkiewicz626fb70ea0cc
diff --git a/frontend/src/lib/components/Alerting/AlertWizard/alertWizardLogic.ts b/frontend/src/lib/components/Alerting/AlertWizard/alertWizardLogic.tsindex 66e62a8f0f31..97f2c3cf613b 100644--- a/frontend/src/lib/components/Alerting/AlertWizard/alertWizardLogic.ts+++ b/frontend/src/lib/components/Alerting/AlertWizard/alertWizardLogic.ts@@ -82,6 +82,43 @@ function hasSubTemplateForDestination(return subTemplates?.some((t) => t.template_id === destination.templateId) ?? false}+// Not every trigger has a sub-template for every destination (e.g. GitHub only+// covers "issue created", not "issue reopened"). Entry points that lock the+// trigger skip the trigger step, so the destination list is the only place left+// to keep uncreatable combinations out of the wizard.+function creatableDestinations(+ triggerKey: HogFunctionSubTemplateIdType | null | undefined,+ destinations: WizardDestination[]+): WizardDestination[] {+ if (!triggerKey) {+ return destinations+ }+ return destinations.filter((destination) => hasSubTemplateForDestination(triggerKey, destination))+}++interface WizardUrlState {+ step: WizardStep+ destinationKey: string | null+ triggerKey: HogFunctionSubTemplateIdType | null+}++// The wizard mirrors its position into the URL, so a link can point at a+// destination/trigger pair that has no sub-template (hand-edited, or a pair that+// used to exist). Rewind such a state to the last step that is still valid+// instead of restoring into a configure step that can never be submitted.+function sanitizeWizardState(state: WizardUrlState, allDestinations: WizardDestination[]): WizardUrlState {+ const destination = allDestinations.find((d) => d.key === state.destinationKey) ?? null+ if (!destination) {+ return { step: WizardStep.Destination, destinationKey: null, triggerKey: null }+ }+ const triggerKey =+ state.triggerKey && hasSubTemplateForDestination(state.triggerKey, destination) ? state.triggerKey : null+ if (!triggerKey && state.step === WizardStep.Configure) {+ return { step: WizardStep.Trigger, destinationKey: destination.key, triggerKey: null }+ }+ return { step: state.step, destinationKey: destination.key, triggerKey }+}+// Pre-applies `kind IN (selectedKinds)` as a top-level property filter on the// sub-template's filter group. A null or empty `selectedKinds` leaves filters// untouched (matches every kind). Used by the health-alerts family so a per-page@@ -146,6 +183,7 @@ export interface alertWizardLogicValues {alertCreated: booleanalertCreationView: AlertCreationViewallDestinations: WizardDestination[]+ availableDestinations: WizardDestination[]availableTriggers: WizardTrigger[]configuration: {inputs: Record<@@ -272,10 +310,11 @@ export interface alertWizardLogicActions {export interface alertWizardLogicMeta {key: string__keaTypeGenInternalSelectorTypes: {+ availableDestinations: (allDestinations: WizardDestination[]) => WizardDestination[]usedDestinationKeys: (existingAlerts: HogFunctionType[], allDestinations: WizardDestination[]) => Set<string>sortedDestinations: (usedDestinationKeys: Set<string>,- allDestinations: WizardDestination[]+ availableDestinations: WizardDestination[]) => WizardDestination[]primaryDestinations: (sortedDestinations: WizardDestination[]) => WizardDestination[]extraDestinations: (sortedDestinations: WizardDestination[]) => WizardDestination[]@@ -458,7 +497,13 @@ export const alertWizardLogic = kea<alertWizardLogicType>([],})),- selectors({+ selectors(({ props: logicProps }) => ({+ availableDestinations: [+ (s) => [s.allDestinations],+ (allDestinations: WizardDestination[]): WizardDestination[] =>+ creatableDestinations(logicProps.presetTriggerKey, allDestinations),+ ],+usedDestinationKeys: [(s) => [s.existingAlerts, s.allDestinations],(existingAlerts: HogFunctionType[], allDestinations: WizardDestination[]): Set<string> => {@@ -474,9 +519,9 @@ export const alertWizardLogic = kea<alertWizardLogicType>([],sortedDestinations: [- (s) => [s.usedDestinationKeys, s.allDestinations],- (usedDestinationKeys: Set<string>, allDestinations: WizardDestination[]): WizardDestination[] => {- return [...allDestinations].sort((a, b) => {+ (s) => [s.usedDestinationKeys, s.availableDestinations],+ (usedDestinationKeys: Set<string>, availableDestinations: WizardDestination[]): WizardDestination[] => {+ return [...availableDestinations].sort((a, b) => {const aUsed = usedDestinationKeys.has(a.key) ? 1 : 0const bUsed = usedDestinationKeys.has(b.key) ? 1 : 0return bUsed - aUsed@@ -559,7 +604,7 @@ export const alertWizardLogic = kea<alertWizardLogicType>([inputs: inputValues,}),],- }),+ })),listeners(({ values, actions, props: logicProps }) => ({createAlertSuccess: () => {@@ -798,11 +843,16 @@ export const alertWizardLogic = kea<alertWizardLogicType>([const wizardTrigger = searchParams.wizard_trigger as HogFunctionSubTemplateIdType | undefinedif (wizardStep && values.alertCreationView !== AlertCreationView.Wizard) {- actions.restoreWizardState({- step: wizardStep,- destinationKey: wizardDest ?? null,- triggerKey: wizardTrigger ?? null,- })+ actions.restoreWizardState(+ sanitizeWizardState(+ {+ step: wizardStep,+ destinationKey: wizardDest ?? null,+ triggerKey: wizardTrigger ?? null,+ },+ values.availableDestinations+ )+ )}},})),