Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(issues/replay): if fetchError, don't render replayId in highlights #76619

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ describe('HighlightsDataSection', function () {
url: `/projects/${organization.slug}/${project.slug}/`,
body: {...project, highlightTags: [], highlightContext: {}},
});
const replayId = undefined;
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/replays/${replayId}/`,
body: {},
});
render(
<HighlightsDataSection
event={event}
Expand Down Expand Up @@ -76,6 +81,12 @@ describe('HighlightsDataSection', function () {
body: {...project, highlightTags, highlightContext},
});

const replayId = undefined;
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/replays/${replayId}/`,
body: {},
});

render(<HighlightsDataSection event={event} project={project} />, {
organization,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {space} from 'sentry/styles/space';
import type {Event} from 'sentry/types/event';
import type {Project} from 'sentry/types/project';
import {trackAnalytics} from 'sentry/utils/analytics';
import useReplayData from 'sentry/utils/replays/hooks/useReplayData';
import theme from 'sentry/utils/theme';
import {useDetailedProject} from 'sentry/utils/useDetailedProject';
import {useFeedbackForm} from 'sentry/utils/useFeedbackForm';
Expand Down Expand Up @@ -147,6 +148,39 @@ function HighlightsData({
highlightContext,
location,
});
const highlightTagItems = getHighlightTagData({event, highlightTags});

// find the replayId from either context or tags, if it exists
const contextReplayItem = highlightContextDataItems.find(
e => e.data[0].key === 'replay_id'
);
const contextReplayId = contextReplayItem?.value ?? EMPTY_HIGHLIGHT_DEFAULT;

const tagReplayItem = highlightTagItems.find(e => e.originalTag.key === 'replayId');
const tagReplayId = tagReplayItem?.value ?? EMPTY_HIGHLIGHT_DEFAULT;

// if the id doesn't exist for either tag or context, it's rendered as '--'
c298lee marked this conversation as resolved.
Show resolved Hide resolved
const replayId =
contextReplayId !== EMPTY_HIGHLIGHT_DEFAULT
? contextReplayId
: tagReplayId !== EMPTY_HIGHLIGHT_DEFAULT
? tagReplayId
: undefined;

const {fetchError: replayFetchError} = useReplayData({
orgSlug: organization.slug,
replayId,
});

// if fetchError, replace the replayId so we don't link to an invalid replay
if (contextReplayItem && replayFetchError) {
contextReplayItem.value = EMPTY_HIGHLIGHT_DEFAULT;
}
if (tagReplayItem && replayFetchError) {
tagReplayItem.value = EMPTY_HIGHLIGHT_DEFAULT;
tagReplayItem.originalTag.value = EMPTY_HIGHLIGHT_DEFAULT;
}

const highlightContextRows = highlightContextDataItems.reduce<React.ReactNode[]>(
(rowList, {alias, data}, i) => {
const meta = getContextMeta(event, alias);
Expand All @@ -165,7 +199,6 @@ function HighlightsData({
[]
);

const highlightTagItems = getHighlightTagData({event, highlightTags});
const highlightTagRows = highlightTagItems.map((content, i) => (
<EventTagsTreeRow
key={`highlight-tag-${i}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,19 @@ const mockGroupApis = (
project: Project,
group: Group,
event: Event,
replayId: string | undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could we make this optional instead of explicitly undefined? That way you don't have to add undefined to all the callers, only when you want to specify the trace I guess.

replayId?: string;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup updated!

trace?: QuickTraceEvent
) => {
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/issues/${group.id}/`,
body: group,
});

MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/replays/${replayId}/`,
body: {},
});

MockApiClient.addMockResponse({
url: `/projects/${organization.slug}/${project.slug}/issues/`,
method: 'PUT',
Expand Down Expand Up @@ -358,7 +364,7 @@ describe('groupEventDetails', () => {

it('redirects on switching to an invalid environment selection for event', async function () {
const props = makeDefaultMockData();
mockGroupApis(props.organization, props.project, props.group, props.event);
mockGroupApis(props.organization, props.project, props.group, props.event, undefined);

const {rerender} = render(<TestComponent {...props} />);
expect(browserHistory.replace).not.toHaveBeenCalled();
Expand All @@ -370,7 +376,7 @@ describe('groupEventDetails', () => {

it('does not redirect when switching to a valid environment selection for event', async function () {
const props = makeDefaultMockData();
mockGroupApis(props.organization, props.project, props.group, props.event);
mockGroupApis(props.organization, props.project, props.group, props.event, undefined);

const {rerender} = render(<TestComponent {...props} />);

Expand All @@ -397,7 +403,8 @@ describe('groupEventDetails', () => {
tags: [{key: 'environment', value: 'dev'}],
previousEventID: 'prev-event-id',
nextEventID: 'next-event-id',
})
}),
undefined
);

render(<TestComponent event={undefined} eventError />);
Expand Down Expand Up @@ -429,7 +436,8 @@ describe('groupEventDetails', () => {
tags: [{key: 'environment', value: 'dev'}],
previousEventID: 'prev-event-id',
nextEventID: 'next-event-id',
})
}),
undefined
);

render(<TestComponent group={group} event={transaction} />, {
Expand Down Expand Up @@ -477,7 +485,8 @@ describe('groupEventDetails', () => {
tags: [{key: 'environment', value: 'dev'}],
previousEventID: 'prev-event-id',
nextEventID: 'next-event-id',
})
}),
undefined
);

render(<TestComponent group={group} event={transaction} />, {});
Expand All @@ -496,7 +505,7 @@ describe('groupEventDetails', () => {

it('renders event tags ui', async () => {
const props = makeDefaultMockData();
mockGroupApis(props.organization, props.project, props.group, props.event);
mockGroupApis(props.organization, props.project, props.group, props.event, undefined);
render(<TestComponent group={props.group} event={props.event} />, {});

expect(await screen.findByText('Event ID:')).toBeInTheDocument();
Expand Down Expand Up @@ -543,7 +552,8 @@ describe('EventCause', () => {
tags: [{key: 'environment', value: 'dev'}],
previousEventID: 'prev-event-id',
nextEventID: 'next-event-id',
})
}),
undefined
);

MockApiClient.addMockResponse({
Expand Down Expand Up @@ -603,7 +613,8 @@ describe('Platform Integrations', () => {
tags: [{key: 'environment', value: 'dev'}],
previousEventID: 'prev-event-id',
nextEventID: 'next-event-id',
})
}),
undefined
);

const component = SentryAppComponentFixture({
Expand Down Expand Up @@ -642,6 +653,7 @@ describe('Platform Integrations', () => {
props.project,
props.group,
props.event,
undefined,
mockedTrace(props.project)
);

Expand All @@ -660,10 +672,17 @@ describe('Platform Integrations', () => {
it('does not render root issues section if related perf issues do not exist', async () => {
const props = makeDefaultMockData();
const trace = mockedTrace(props.project);
mockGroupApis(props.organization, props.project, props.group, props.event, {
...trace,
performance_issues: [],
});
mockGroupApis(
props.organization,
props.project,
props.group,
props.event,
undefined,
{
...trace,
performance_issues: [],
}
);

render(<TestComponent group={props.group} event={props.event} />, {
organization: props.organization,
Expand Down
Loading