@@ -8,7 +8,37 @@ import type {Group} from 'sentry/types/group';
88import { useApiQuery } from 'sentry/utils/queryClient' ;
99import useOrganization from 'sentry/utils/useOrganization' ;
1010
11- type EventGroupingInfoResponse = Record < string , EventGroupVariant > ;
11+ type EventGroupingInfoResponseOld = Record < string , EventGroupVariant > ;
12+ type EventGroupingInfoResponse = {
13+ grouping_config : string | null ;
14+ variants : Record < string , EventGroupVariant > ;
15+ } ;
16+
17+ // temporary function to convert the old response structure to the new one
18+ function eventGroupingInfoResponseOldToNew (
19+ old : EventGroupingInfoResponseOld | null
20+ ) : EventGroupingInfoResponse | null {
21+ const grouping_config = old
22+ ? (
23+ Object . values ( old ) . find (
24+ variant => 'config' in variant && variant . config ?. id
25+ ) as any
26+ ) ?. config ?. id
27+ : null ;
28+ return old
29+ ? {
30+ grouping_config,
31+ variants : old ,
32+ }
33+ : null ;
34+ }
35+
36+ // temporary function to check if the respinse is old type
37+ function isOld (
38+ data : EventGroupingInfoResponseOld | EventGroupingInfoResponse | null
39+ ) : data is EventGroupingInfoResponseOld {
40+ return data ? ! ( 'grouping_config' in data ) : false ;
41+ }
1242
1343function generatePerformanceGroupInfo ( {
1444 event,
@@ -27,21 +57,24 @@ function generatePerformanceGroupInfo({
2757
2858 return group
2959 ? {
30- [ group . issueType ] : {
31- contributes : true ,
32- description : t ( 'performance problem' ) ,
33- hash : event . occurrence ?. fingerprint [ 0 ] || '' ,
34- hashMismatch : false ,
35- hint : null ,
36- key : group . issueType ,
37- type : EventGroupVariantType . PERFORMANCE_PROBLEM ,
38- evidence : {
39- op : evidenceData ?. op ,
40- parent_span_ids : evidenceData ?. parentSpanIds ,
41- cause_span_ids : evidenceData ?. causeSpanIds ,
42- offender_span_ids : evidenceData ?. offenderSpanIds ,
43- desc : t ( 'performance problem' ) ,
44- fingerprint : hash ,
60+ grouping_config : null ,
61+ variants : {
62+ [ group . issueType ] : {
63+ contributes : true ,
64+ description : t ( 'performance problem' ) ,
65+ hash : event . occurrence ?. fingerprint [ 0 ] || '' ,
66+ hashMismatch : false ,
67+ hint : null ,
68+ key : group . issueType ,
69+ type : EventGroupVariantType . PERFORMANCE_PROBLEM ,
70+ evidence : {
71+ op : evidenceData ?. op ,
72+ parent_span_ids : evidenceData ?. parentSpanIds ,
73+ cause_span_ids : evidenceData ?. causeSpanIds ,
74+ offender_span_ids : evidenceData ?. offenderSpanIds ,
75+ desc : t ( 'performance problem' ) ,
76+ fingerprint : hash ,
77+ } ,
4578 } ,
4679 } ,
4780 }
@@ -61,14 +94,26 @@ export function useEventGroupingInfo({
6194
6295 const hasPerformanceGrouping = event . occurrence && event . type === 'transaction' ;
6396
64- const { data, isPending, isError, isSuccess} = useApiQuery < EventGroupingInfoResponse > (
65- [ `/projects/${ organization . slug } /${ projectSlug } /events/${ event . id } /grouping-info/` ] ,
66- { enabled : ! hasPerformanceGrouping , staleTime : Infinity }
67- ) ;
97+ const { data, isPending, isError, isSuccess} = useApiQuery <
98+ EventGroupingInfoResponseOld | EventGroupingInfoResponse
99+ > ( [ `/projects/${ organization . slug } /${ projectSlug } /events/${ event . id } /grouping-info/` ] , {
100+ enabled : ! hasPerformanceGrouping ,
101+ staleTime : Infinity ,
102+ } ) ;
68103
69- const groupInfo = hasPerformanceGrouping
104+ const groupInfoRaw = hasPerformanceGrouping
70105 ? generatePerformanceGroupInfo ( { group, event} )
71106 : ( data ?? null ) ;
72107
73- return { groupInfo, isPending, isError, isSuccess, hasPerformanceGrouping} ;
108+ const groupInfo = isOld ( groupInfoRaw )
109+ ? eventGroupingInfoResponseOldToNew ( groupInfoRaw )
110+ : groupInfoRaw ;
111+
112+ return {
113+ groupInfo,
114+ isPending,
115+ isError,
116+ isSuccess,
117+ hasPerformanceGrouping,
118+ } ;
74119}
0 commit comments