Skip to content

Commit

Permalink
feat(issues): Preserve group when switching environment (#82907)
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper authored Jan 6, 2025
1 parent dc029c9 commit 108bb13
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions static/app/views/issueDetails/groupDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Fragment, useCallback, useEffect, useState} from 'react';
import styled from '@emotion/styled';
import * as Sentry from '@sentry/react';
import isEqual from 'lodash/isEqual';
import * as qs from 'query-string';

import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
Expand Down Expand Up @@ -263,7 +264,43 @@ function useFetchGroupDetails(): FetchGroupDetailsState {
[event]
);

const group = groupData ?? null;
// If the environment changes, we need to refetch the group, but we can
// still display the previous group while the new group is loading.
const previousGroupData = useMemoWithPrevious<{
cachedGroup: typeof groupData | null;
previousEnvironments: typeof environments | null;
previousGroupData: typeof groupData | null;
}>(
previousInstance => {
// Preserve the previous group if:
// - New group is not yet available
// - Previously we had group data
// - The previous group id is the same as the current group id
// - The previous environments are not the same as the current environments
if (
!groupData &&
previousInstance?.cachedGroup &&
previousInstance.cachedGroup.id === groupId &&
!isEqual(previousInstance.previousEnvironments, environments)
) {
return {
previousGroupData: previousInstance.previousGroupData,
previousEnvironments: previousInstance.previousEnvironments,
cachedGroup: previousInstance.cachedGroup,
};
}

// If group data is available, store in memo for comparison later
return {
cachedGroup: groupData,
previousEnvironments: environments,
previousGroupData: null,
};
},
[groupData, environments, groupId]
);

const group = groupData ?? previousGroupData.cachedGroup ?? null;

useEffect(() => {
if (defined(group)) {
Expand Down Expand Up @@ -750,13 +787,7 @@ function GroupDetails(props: GroupDetailsProps) {
shouldForceProject
>
{config?.showFeedbackWidget && <FloatingFeedbackWidget />}
<GroupDetailsPageContent
{...props}
{...{
group,
...fetchGroupDetailsProps,
}}
/>
<GroupDetailsPageContent {...props} {...fetchGroupDetailsProps} group={group} />
</PageFiltersContainer>
</SentryDocumentTitle>
</Fragment>
Expand Down

0 comments on commit 108bb13

Please sign in to comment.