|
@@ -1,4 +1,5 @@
|
|
|
-import {useCallback, useEffect, useState} from 'react';
|
|
|
+import {useEffect, useState} from 'react';
|
|
|
+import {InjectedRouter, PlainRoute} from 'react-router';
|
|
|
import styled from '@emotion/styled';
|
|
|
|
|
|
import {addErrorMessage} from 'sentry/actionCreators/indicator';
|
|
@@ -10,7 +11,6 @@ import space from 'sentry/styles/space';
|
|
|
import {EventIdResponse, Group, Organization, Project} from 'sentry/types';
|
|
|
import handleXhrErrorResponse from 'sentry/utils/handleXhrErrorResponse';
|
|
|
import useApi from 'sentry/utils/useApi';
|
|
|
-import {useRouteContext} from 'sentry/utils/useRouteContext';
|
|
|
import useSessionStorage from 'sentry/utils/useSessionStorage';
|
|
|
|
|
|
type StoredLinkedEvent = {
|
|
@@ -23,23 +23,37 @@ type StoredLinkedEvent = {
|
|
|
type Props = {
|
|
|
eventId: string;
|
|
|
orgSlug: Organization['slug'];
|
|
|
+ route: PlainRoute;
|
|
|
+ router: InjectedRouter;
|
|
|
};
|
|
|
|
|
|
const errorMessage = t(
|
|
|
'An error occurred while fetching the data of the breadcrumb event link'
|
|
|
);
|
|
|
|
|
|
-export function LinkedEvent({orgSlug, eventId}: Props) {
|
|
|
+export function LinkedEvent({orgSlug, eventId, route, router}: Props) {
|
|
|
const [storedLinkedEvent, setStoredLinkedEvent, removeStoredLinkedEvent] =
|
|
|
useSessionStorage<undefined | StoredLinkedEvent>(eventId);
|
|
|
|
|
|
const [eventIdLookup, setEventIdLookup] = useState<undefined | EventIdResponse>();
|
|
|
const [hasError, setHasError] = useState(false);
|
|
|
- const routeContext = useRouteContext();
|
|
|
|
|
|
const api = useApi();
|
|
|
|
|
|
- const fetchEventById = useCallback(async () => {
|
|
|
+ useEffect(() => {
|
|
|
+ fetchEventById();
|
|
|
+ router.setRouteLeaveHook(route, onRouteLeave);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ fetchIssueByGroupId();
|
|
|
+ }, [eventIdLookup]);
|
|
|
+
|
|
|
+ function onRouteLeave() {
|
|
|
+ removeStoredLinkedEvent();
|
|
|
+ }
|
|
|
+
|
|
|
+ async function fetchEventById() {
|
|
|
if (storedLinkedEvent) {
|
|
|
return;
|
|
|
}
|
|
@@ -57,22 +71,14 @@ export function LinkedEvent({orgSlug, eventId}: Props) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ addErrorMessage(errorMessage);
|
|
|
handleXhrErrorResponse(errorMessage)(error);
|
|
|
|
|
|
// do nothing. The link won't be displayed
|
|
|
}
|
|
|
- }, [storedLinkedEvent, api, eventId, orgSlug]);
|
|
|
-
|
|
|
- const onRouteLeave = useCallback(() => {
|
|
|
- removeStoredLinkedEvent();
|
|
|
- }, [removeStoredLinkedEvent]);
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- fetchEventById();
|
|
|
- routeContext.router.setRouteLeaveHook(routeContext, onRouteLeave);
|
|
|
- }, [fetchEventById, routeContext, onRouteLeave]);
|
|
|
+ }
|
|
|
|
|
|
- const fetchIssueByGroupId = useCallback(async () => {
|
|
|
+ async function fetchIssueByGroupId() {
|
|
|
if (!!storedLinkedEvent || !eventIdLookup) {
|
|
|
return;
|
|
|
}
|
|
@@ -97,11 +103,7 @@ export function LinkedEvent({orgSlug, eventId}: Props) {
|
|
|
|
|
|
// do nothing. The link won't be displayed
|
|
|
}
|
|
|
- }, [api, orgSlug, eventIdLookup, storedLinkedEvent, setStoredLinkedEvent]);
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- fetchIssueByGroupId();
|
|
|
- }, [fetchIssueByGroupId]);
|
|
|
+ }
|
|
|
|
|
|
if (hasError) {
|
|
|
return null;
|