@@ -15,6 +15,7 @@ import {t, tct} from 'sentry/locale';
1515import type { PageFilters } from 'sentry/types/core' ;
1616import type { Organization } from 'sentry/types/organization' ;
1717import { trackAnalytics } from 'sentry/utils/analytics' ;
18+ import { isEquation , stripEquationPrefix } from 'sentry/utils/discover/fields' ;
1819import {
1920 MEPState ,
2021 useMEPSettingContext ,
@@ -113,54 +114,55 @@ export const useDroppedColumnsWarning = (widget: Widget): React.JSX.Element | nu
113114 return null ;
114115 }
115116
116- const baseWarning = t (
117- "This widget may look different from its original query. Here's why:"
118- ) ;
119- const columnsWarning = [ ] ;
120- const equationsWarning = [ ] ;
121- const orderbyWarning = [ ] ;
117+ const columnsDropped = [ ] ;
118+ const equationsDropped = [ ] ;
119+ const orderbyDropped = [ ] ;
122120 for ( const changedReason of widget . changedReason ) {
123121 if ( changedReason . selected_columns . length > 0 ) {
124- columnsWarning . push (
125- tct ( `The following fields were dropped: [columns].` , {
126- columns : changedReason . selected_columns . join ( ', ' ) ,
127- } )
128- ) ;
122+ columnsDropped . push ( ...changedReason . selected_columns ) ;
129123 }
130124 if ( changedReason . equations ) {
131- equationsWarning . push (
132- ...changedReason . equations . map ( equation =>
133- tct ( `[equation] was dropped because [reason] is unsupported.` , {
134- equation : equation . equation ,
135- reason :
136- typeof equation . reason === 'string'
137- ? equation . reason
138- : equation . reason . join ( ', ' ) ,
139- } )
140- )
125+ equationsDropped . push (
126+ ...changedReason . equations . map ( equation => equation . equation )
141127 ) ;
142128 }
143129 if ( changedReason . orderby ) {
144- orderbyWarning . push (
145- ...changedReason . orderby . map ( equation =>
146- tct ( `[orderby] was dropped because [reason].` , {
147- orderby : equation . orderby ,
148- reason : equation . reason ,
149- } )
130+ orderbyDropped . push (
131+ ...changedReason . orderby . flatMap ( orderby =>
132+ typeof orderby . reason === 'string' ? orderby . orderby : orderby . reason
150133 )
151134 ) ;
152135 }
153136 }
154137
155- const allWarnings = [ ...columnsWarning , ...equationsWarning , ...orderbyWarning ] ;
138+ const orderbyDroppedWithoutNegation = orderbyDropped . map ( orderby =>
139+ orderby . startsWith ( '-' ) ? orderby . replace ( '-' , '' ) : orderby
140+ ) ;
141+ const equationsDroppedParsed = equationsDropped . map ( equation => {
142+ if ( isEquation ( equation ) ) {
143+ return stripEquationPrefix ( equation ) ;
144+ }
145+ return equation ;
146+ } ) ;
147+ const combinedWarnings = [
148+ ...columnsDropped ,
149+ ...equationsDroppedParsed ,
150+ ...orderbyDroppedWithoutNegation ,
151+ ] ;
152+ const allWarningsSet = new Set ( combinedWarnings ) ;
153+ const allWarnings = [ ...allWarningsSet ] ;
156154
157155 if ( allWarnings . length > 0 ) {
158156 return (
159- < div style = { { alignContent : 'flex-start' } } >
160- < StyledText as = "p" > { baseWarning } </ StyledText >
161- { allWarnings . map ( ( warning , index ) => (
162- < StyledText key = { index } > { warning } </ StyledText >
163- ) ) }
157+ < div >
158+ < StyledText as = "p" >
159+ { tct (
160+ 'This widget looks different because it was migrated to the spans dataset and [columns] is not supported.' ,
161+ {
162+ columns : allWarnings . join ( ', ' ) ,
163+ }
164+ ) }
165+ </ StyledText >
164166 </ div >
165167 ) ;
166168 }
0 commit comments