Skip to content

Commit b1147ac

Browse files
authored
fix(ourlogs): Avoid errors if you remove a column being sorted on (#90298)
For example, if you deleted a column after sorting on it, we used to error. Now, we always find a valid sort and valid columns, regardless of what you have done. Fixes LOGS-74
1 parent ce83eb7 commit b1147ac

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

static/app/views/explore/contexts/logs/fields.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ export function defaultLogFields(): OurLogKnownFieldKey[] {
1212
}
1313

1414
export function getLogFieldsFromLocation(location: Location): OurLogFieldKey[] {
15-
return decodeList(location.query[LOGS_FIELDS_KEY]);
15+
const fields = decodeList(location.query[LOGS_FIELDS_KEY]);
16+
if (fields.length) {
17+
return fields;
18+
}
19+
return defaultLogFields();
1620
}

static/app/views/explore/contexts/logs/logsPageParams.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function LogsPageParamsProvider({
8989
: getLogFieldsFromLocation(location);
9090
const sortBys = isTableEditingFrozen
9191
? [logsTimestampDescendingSortBy]
92-
: getLogSortBysFromLocation(location);
92+
: getLogSortBysFromLocation(location, fields);
9393
const projectIds = isOnEmbeddedView
9494
? (limitToProjectIds ?? [-1])
9595
: decodeProjects(location);

static/app/views/explore/contexts/logs/sortBys.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,31 @@ export const logsTimestampDescendingSortBy: Sort = {
1212
kind: 'desc' as const,
1313
};
1414

15-
function defaultLogSortBys(): Sort[] {
16-
return [logsTimestampDescendingSortBy];
17-
}
18-
19-
export function getLogSortBysFromLocation(location: Location): Sort[] {
15+
export function getLogSortBysFromLocation(location: Location, fields: string[]): Sort[] {
2016
const sortBys = decodeSorts(location.query[LOGS_SORT_BYS_KEY]);
2117

2218
if (sortBys.length > 0) {
23-
return sortBys;
19+
if (sortBys.every(sortBy => fields.includes(sortBy.field))) {
20+
return sortBys;
21+
}
22+
}
23+
24+
if (fields.includes(OurLogKnownFieldKey.TIMESTAMP)) {
25+
return [logsTimestampDescendingSortBy];
26+
}
27+
28+
if (!fields[0]) {
29+
throw new Error(
30+
'fields should not be empty - did you somehow delete all of the fields?'
31+
);
2432
}
2533

26-
return defaultLogSortBys();
34+
return [
35+
{
36+
field: fields[0],
37+
kind: 'desc' as const,
38+
},
39+
];
2740
}
2841

2942
export function updateLocationWithLogSortBys(

0 commit comments

Comments
 (0)