Skip to content

Commit 88c9d06

Browse files
authored
fix(spans-migration): changed type and wording of dropped fields warnings (#101479)
changed the changed reason types on the frontend to reflect the changes i've made to the backend. I've also changed up the wording for the frontend errors as suggested. Widgets have been simplified to one sentence and queries have slightly changed wording to not use "dropped"
1 parent 1ecae19 commit 88c9d06

File tree

4 files changed

+58
-44
lines changed

4 files changed

+58
-44
lines changed

static/app/views/dashboards/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type WidgetChangedReason = {
101101
}> | null;
102102
orderby: Array<{
103103
orderby: string;
104-
reason: string;
104+
reason: string | string[];
105105
}> | null;
106106
selected_columns: string[];
107107
};

static/app/views/dashboards/widgetCard/widgetCardContextMenu.tsx

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {t, tct} from 'sentry/locale';
1515
import type {PageFilters} from 'sentry/types/core';
1616
import type {Organization} from 'sentry/types/organization';
1717
import {trackAnalytics} from 'sentry/utils/analytics';
18+
import {isEquation, stripEquationPrefix} from 'sentry/utils/discover/fields';
1819
import {
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
}

static/app/views/explore/hooks/useSaveQuery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type ExploreQueryChangedReason = {
3030
}> | null;
3131
orderby: Array<{
3232
orderby: string;
33-
reason: string;
33+
reason: string | string[];
3434
}> | null;
3535
};
3636

static/app/views/explore/spans/droppedFieldsAlert.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Text} from 'sentry/components/core/text';
55
import List from 'sentry/components/list';
66
import ListItem from 'sentry/components/list/listItem';
77
import {t, tct} from 'sentry/locale';
8+
import {stripEquationPrefix} from 'sentry/utils/discover/fields';
89
import {useExploreId} from 'sentry/views/explore/contexts/pageParamsContext';
910
import {useGetSavedQuery} from 'sentry/views/explore/hooks/useGetSavedQueries';
1011

@@ -30,16 +31,16 @@ export function DroppedFieldsAlert(): React.JSX.Element | null {
3031
const changedReason = savedQuery.changedReason;
3132
if (changedReason.columns.length > 0) {
3233
columnsWarning.push(
33-
tct(`The following fields were dropped: [columns]`, {
34+
tct(`[columns] is no longer supported`, {
3435
columns: changedReason.columns.join(', '),
3536
})
3637
);
3738
}
3839
if (changedReason.equations) {
3940
equationsWarning.push(
4041
...changedReason.equations.map(equation =>
41-
tct(`[equation] was dropped because [reason] is unsupported`, {
42-
equation: equation.equation,
42+
tct(`[equation] is no longer supported because [reason] is unsupported`, {
43+
equation: stripEquationPrefix(equation.equation),
4344
reason:
4445
typeof equation.reason === 'string'
4546
? equation.reason
@@ -50,12 +51,23 @@ export function DroppedFieldsAlert(): React.JSX.Element | null {
5051
}
5152
if (changedReason.orderby) {
5253
orderbyWarning.push(
53-
...changedReason.orderby.map(equation =>
54-
tct(`[orderby] was dropped because [reason]`, {
55-
orderby: equation.orderby,
56-
reason: equation.reason,
57-
})
58-
)
54+
...changedReason.orderby.map(orderby => {
55+
const orderbyWithoutPrefix = orderby.orderby.startsWith('-')
56+
? orderby.orderby.replace('-', '')
57+
: orderby.orderby;
58+
const reasonText =
59+
typeof orderby.reason === 'string' ? orderby.reason : orderby.reason.join(', ');
60+
61+
// make sure that the reason and the orderby aren't the same and word it correctly
62+
return typeof orderby.reason === 'string' || orderbyWithoutPrefix === reasonText
63+
? tct(`sorting by [orderby] is no longer supported`, {
64+
orderby: orderbyWithoutPrefix,
65+
})
66+
: tct(`sorting by [orderby] is not supported because [reason] is unsupported`, {
67+
orderby: orderby.orderby,
68+
reason: reasonText,
69+
});
70+
})
5971
);
6072
}
6173

0 commit comments

Comments
 (0)