Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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 @@ -27,48 +27,6 @@ describe('EventGroupingInfo', () => {

beforeEach(() => {
MockApiClient.clearMockResponses();
groupingInfoRequest = MockApiClient.addMockResponse({
url: `/projects/org-slug/project-slug/events/${event.id}/grouping-info/`,
body: {
app: {
contributes: true,
description: 'variant description',
hash: '123',
hashMismatch: false,
key: 'key',
type: EventGroupVariantType.CHECKSUM,
},
},
});
});

it('fetches and renders grouping info for errors', async () => {
render(<EventGroupingInfoSection {...defaultProps} />);
await userEvent.click(
screen.getByRole('button', {name: 'View Event Grouping Information Section'})
);
expect(await screen.findByText('variant description')).toBeInTheDocument();
expect(screen.getByText('123')).toBeInTheDocument();
});

it('gets performance grouping info from group/event data', async () => {
const perfEvent = EventFixture({
type: 'transaction',
occurrence: {fingerprint: ['123'], evidenceData: {op: 'bad-op'}},
});
const perfGroup = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});

render(
<EventGroupingInfoSection {...defaultProps} event={perfEvent} group={perfGroup} />
);

expect(await screen.findByText('performance problem')).toBeInTheDocument();
expect(screen.getByText('123')).toBeInTheDocument();
// Should not make grouping-info request
expect(groupingInfoRequest).not.toHaveBeenCalled();
});

it('works with new groupingInfo format', async () => {
groupingInfoRequest = MockApiClient.addMockResponse({
url: `/projects/org-slug/project-slug/events/${event.id}/grouping-info/`,
body: {
Expand All @@ -85,28 +43,18 @@ describe('EventGroupingInfo', () => {
},
},
});
render(<EventGroupingInfoSection {...defaultProps} />);
});

it('fetches and renders grouping info for errors', async () => {
render(<EventGroupingInfoSection {...defaultProps} />);
await userEvent.click(
screen.getByRole('button', {name: 'View Event Grouping Information Section'})
);
expect(await screen.findByText('variant description')).toBeInTheDocument();
expect(screen.getByText('123')).toBeInTheDocument();
});
it('gets performance new grouping info from group/event data', async () => {
groupingInfoRequest = MockApiClient.addMockResponse({
url: `/projects/org-slug/project-slug/events/${event.id}/grouping-info/`,
body: {
grouping_config: null,
variants: {
app: {
contributes: true,
description: 'variant description',
hash: '123',
hashMismatch: false,
key: 'key',
type: EventGroupVariantType.CHECKSUM,
},
},
},
});

it('gets performance grouping info from group/event data', async () => {
const perfEvent = EventFixture({
type: 'transaction',
occurrence: {fingerprint: ['123'], evidenceData: {op: 'bad-op'}},
Expand Down
46 changes: 8 additions & 38 deletions static/app/components/events/groupingInfo/useEventGroupingInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,11 @@ import type {Group} from 'sentry/types/group';
import {useApiQuery} from 'sentry/utils/queryClient';
import useOrganization from 'sentry/utils/useOrganization';

type EventGroupingInfoResponseOld = Record<string, EventGroupVariant>;
type EventGroupingInfoResponse = {
grouping_config: string | null;
variants: Record<string, EventGroupVariant>;
};

// temporary function to convert the old response structure to the new one
function eventGroupingInfoResponseOldToNew(
old: EventGroupingInfoResponseOld | null
): EventGroupingInfoResponse | null {
const grouping_config = old
? (
Object.values(old).find(
variant => 'config' in variant && variant.config?.id
) as any
)?.config?.id
: null;
return old
? {
grouping_config,
variants: old,
}
: null;
}

// temporary function to check if the respinse is old type
function isOld(
data: EventGroupingInfoResponseOld | EventGroupingInfoResponse | null
): data is EventGroupingInfoResponseOld {
return data ? !('grouping_config' in data) : false;
}

function generatePerformanceGroupInfo({
event,
group,
Expand Down Expand Up @@ -94,21 +67,18 @@ export function useEventGroupingInfo({

const hasPerformanceGrouping = event.occurrence && event.type === 'transaction';

const {data, isPending, isError, isSuccess} = useApiQuery<
EventGroupingInfoResponseOld | EventGroupingInfoResponse
>([`/projects/${organization.slug}/${projectSlug}/events/${event.id}/grouping-info/`], {
enabled: !hasPerformanceGrouping,
staleTime: Infinity,
});
const {data, isPending, isError, isSuccess} = useApiQuery<EventGroupingInfoResponse>(
[`/projects/${organization.slug}/${projectSlug}/events/${event.id}/grouping-info/`],
{
enabled: !hasPerformanceGrouping,
staleTime: Infinity,
}
);

const groupInfoRaw = hasPerformanceGrouping
const groupInfo = hasPerformanceGrouping
? generatePerformanceGroupInfo({group, event})
: (data ?? null);

const groupInfo = isOld(groupInfoRaw)
? eventGroupingInfoResponseOldToNew(groupInfoRaw)
: groupInfoRaw;

return {
groupInfo,
isPending,
Expand Down
Loading