Skip to content

Commit

Permalink
fix(app): Sorted aggregated columns no longer crash tables during ung…
Browse files Browse the repository at this point in the history
…rouping
  • Loading branch information
nicholaspun-wandb committed Nov 4, 2024
1 parent fc26837 commit b240cbc
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions weave-js/src/components/Panel2/PanelTable/tableState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
allObjPaths,
canSortType,
constFunction,
ConstNode,
constNodeUnsafe,
Expand Down Expand Up @@ -687,6 +688,16 @@ export async function disableGroupByCol(
) {
const colIds = _.isArray(colId) ? colId : [colId];
const groupBy = ts.groupBy;

// (WB-16067)
// We may try to sort on aggregated columns after ungrouping
// To prevent this, disable sorting on all the columns and re-enable
// after the ungroup
const initiallySortedCols = _.clone(ts.sort)
ts.sort.forEach(sortObj => {
ts = disableSortByCol(ts, sortObj.columnId)
})

ts = produce(ts, draft => {
draft.autoColumns = false;
for (const cid of colIds) {
Expand All @@ -701,9 +712,12 @@ export async function disableGroupByCol(
}
});
ts = await refreshSelectFunctions(ts, inputArrayNode, weave, stack);
if (ts.sort.find(s => s.columnId === colId) !== undefined) {
ts = disableSortByCol(ts, colId);
}

initiallySortedCols.forEach(sortObj => {
if (sortObj.columnId !== colId && canSortType(ts.columnSelectFunctions[sortObj.columnId].type)) {
ts = enableSortByCol(ts, sortObj.columnId, sortObj.dir === 'asc')
}
})
return ts;
}

Expand Down

0 comments on commit b240cbc

Please sign in to comment.