Skip to content

Commit 5a93960

Browse files
authored
fix(explore): Preserve sort when adding group by (#81258)
We use the first available option to sort when there's no sort specified. In aggregate mode, when adding a group by, the first option changes from the aggregate function to the group by field thus implicitly changing the sort. This ensures that the aggregate functions are higher in the list so the default sort doesnt change when the group by changes.
1 parent 0dfc654 commit 5a93960

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

static/app/views/explore/tables/spansTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export function SpansTable({setError}: SpansTableProps) {
179179
<IconWarning data-test-id="error-indicator" color="gray300" size="lg" />
180180
</TableStatus>
181181
) : result.isFetched && result.data?.length ? (
182-
result.data?.slice(0, 50)?.map((row, i) => (
182+
result.data?.map((row, i) => (
183183
<TableRow key={i}>
184184
{visibleFields.map((field, j) => {
185185
return (

static/app/views/explore/toolbar/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function ExploreToolbar({extras}: ExploreToolbarProps) {
3232
return sampleFields;
3333
}
3434

35-
const allFields = [...groupBys];
35+
const allFields: string[] = [];
3636

3737
for (const visualize of visualizes) {
3838
for (const yAxis of visualize.yAxes) {
@@ -43,6 +43,13 @@ export function ExploreToolbar({extras}: ExploreToolbarProps) {
4343
}
4444
}
4545

46+
for (const groupBy of groupBys) {
47+
if (allFields.includes(groupBy)) {
48+
continue;
49+
}
50+
allFields.push(groupBy);
51+
}
52+
4653
return allFields.filter(Boolean);
4754
}, [resultMode, sampleFields, groupBys, visualizes]);
4855

0 commit comments

Comments
 (0)