From 92cdb36879b395002216d6321d104fe731afc28d Mon Sep 17 00:00:00 2001 From: Shaheer Kochai Date: Fri, 1 Nov 2024 16:03:59 +0430 Subject: [PATCH] fix: redirect to docs on clicking alert setup guide in create alert page (#6265) --- .../src/container/FormAlertRules/index.tsx | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/frontend/src/container/FormAlertRules/index.tsx b/frontend/src/container/FormAlertRules/index.tsx index 9b33198ff7..05c4149d73 100644 --- a/frontend/src/container/FormAlertRules/index.tsx +++ b/frontend/src/container/FormAlertRules/index.tsx @@ -73,6 +73,19 @@ export enum AlertDetectionTypes { ANOMALY_DETECTION_ALERT = 'anomaly_rule', } +const ALERT_SETUP_GUIDE_URLS: Record = { + [AlertTypes.METRICS_BASED_ALERT]: + 'https://signoz.io/docs/alerts-management/metrics-based-alerts/?utm_source=product&utm_medium=alert-creation-page', + [AlertTypes.LOGS_BASED_ALERT]: + 'https://signoz.io/docs/alerts-management/log-based-alerts/?utm_source=product&utm_medium=alert-creation-page', + [AlertTypes.TRACES_BASED_ALERT]: + 'https://signoz.io/docs/alerts-management/trace-based-alerts/?utm_source=product&utm_medium=alert-creation-page', + [AlertTypes.EXCEPTIONS_BASED_ALERT]: + 'https://signoz.io/docs/alerts-management/exceptions-based-alerts/?utm_source=product&utm_medium=alert-creation-page', + [AlertTypes.ANOMALY_BASED_ALERT]: + 'https://signoz.io/docs/alerts-management/anomaly-based-alerts/?utm_source=product&utm_medium=alert-creation-page', +}; + // eslint-disable-next-line sonarjs/cognitive-complexity function FormAlertRules({ alertType, @@ -702,6 +715,29 @@ function FormAlertRules({ const isRuleCreated = !ruleId || ruleId === 0; + function handleRedirection(option: AlertTypes): void { + let url; + if ( + option === AlertTypes.METRICS_BASED_ALERT && + alertTypeFromURL === AlertDetectionTypes.ANOMALY_DETECTION_ALERT + ) { + url = ALERT_SETUP_GUIDE_URLS[AlertTypes.ANOMALY_BASED_ALERT]; + } else { + url = ALERT_SETUP_GUIDE_URLS[option]; + } + + if (url) { + logEvent('Alert: Check example alert clicked', { + dataSource: ALERTS_DATA_SOURCE_MAP[alertDef?.alertType as AlertTypes], + isNewRule: !ruleId || ruleId === 0, + ruleId, + queryType: currentQuery.queryType, + link: url, + }); + window.open(url, '_blank'); + } + } + useEffect(() => { if (!isRuleCreated) { logEvent('Alert: Edit page visited', { @@ -752,7 +788,11 @@ function FormAlertRules({ )} -