Просмотр исходного кода

fix(ui): Add missing incident redirect useEffect dependencies (#34561)

Scott Cooper 2 лет назад
Родитель
Сommit
a825e34fb3
1 измененных файлов с 11 добавлено и 8 удалено
  1. 11 8
      static/app/views/alerts/incidentRedirect.tsx

+ 11 - 8
static/app/views/alerts/incidentRedirect.tsx

@@ -1,4 +1,4 @@
-import {useEffect, useState} from 'react';
+import {useCallback, useEffect, useState} from 'react';
 import {browserHistory, RouteComponentProps} from 'react-router';
 
 import {Client} from 'sentry/api';
@@ -15,18 +15,21 @@ type Props = {
   organization: Organization;
 } & RouteComponentProps<{alertId: string; orgId: string}, {}>;
 
-function IncidentDetails({organization, params}: Props) {
+/**
+ * Reirects from an incident to the incident's metric alert details page
+ */
+function IncidentRedirect({organization, params}: Props) {
   const api = useApi();
   const [hasError, setHasError] = useState(false);
 
-  const track = () => {
+  const track = useCallback(() => {
     trackAdvancedAnalyticsEvent('alert_details.viewed', {
       organization,
       alert_id: parseInt(params.alertId, 10),
     });
-  };
+  }, [organization, params.alertId]);
 
-  const fetchData = async () => {
+  const fetchData = useCallback(async () => {
     setHasError(false);
 
     try {
@@ -38,12 +41,12 @@ function IncidentDetails({organization, params}: Props) {
     } catch (err) {
       setHasError(true);
     }
-  };
+  }, [setHasError, api, params.orgId, params.alertId, organization]);
 
   useEffect(() => {
     fetchData();
     track();
-  }, []);
+  }, [fetchData, track]);
 
   if (hasError) {
     return <LoadingError onRetry={fetchData} />;
@@ -52,4 +55,4 @@ function IncidentDetails({organization, params}: Props) {
   return <LoadingIndicator />;
 }
 
-export default IncidentDetails;
+export default IncidentRedirect;