diff --git a/packages/iris-grid/src/IrisGrid.test.tsx b/packages/iris-grid/src/IrisGrid.test.tsx index 3606e4bfc..038920510 100644 --- a/packages/iris-grid/src/IrisGrid.test.tsx +++ b/packages/iris-grid/src/IrisGrid.test.tsx @@ -265,6 +265,53 @@ describe('handleResizeColumn', () => { }); }); +describe('handleRollupChange', () => { + it('un-hides group-by columns', () => { + const columns = irisGridTestUtils.makeColumns(3); + const irisGrid = makeComponent( + irisGridTestUtils.makeModel(irisGridTestUtils.makeTable({ columns })) + ); + const { metricCalculator } = irisGrid.state; + const resetColumnWidth = jest.spyOn(metricCalculator, 'resetColumnWidth'); + + const groupByNames = [columns[1].name, columns[2].name]; + + act(() => { + irisGrid.handleRollupChange({ + columns: groupByNames, + showConstituents: true, + showNonAggregatedColumns: true, + }); + }); + + expect(resetColumnWidth).toHaveBeenCalledWith(1); + expect(resetColumnWidth).toHaveBeenCalledWith(2); + expect(irisGrid.state.rollupConfig?.columns).toEqual(groupByNames); + }); + + it('does not call resetColumnWidth when there are no group-by columns', () => { + const irisGrid = makeComponent( + irisGridTestUtils.makeModel( + irisGridTestUtils.makeTable({ + columns: irisGridTestUtils.makeColumns(3), + }) + ) + ); + const { metricCalculator } = irisGrid.state; + const resetColumnWidth = jest.spyOn(metricCalculator, 'resetColumnWidth'); + + act(() => { + irisGrid.handleRollupChange({ + columns: [], + showConstituents: true, + showNonAggregatedColumns: true, + }); + }); + + expect(resetColumnWidth).not.toHaveBeenCalled(); + }); +}); + // auto resize -> reset user width and set calculated width to content width // manual resize -> set user width to content width describe('handleResizeAllColumns', () => { diff --git a/packages/iris-grid/src/IrisGrid.tsx b/packages/iris-grid/src/IrisGrid.tsx index 412c5d394..c8c12447a 100644 --- a/packages/iris-grid/src/IrisGrid.tsx +++ b/packages/iris-grid/src/IrisGrid.tsx @@ -3797,8 +3797,19 @@ class IrisGrid extends Component { handleRollupChange(rollupConfig: UIRollupConfig): void { log.info('Rollup change', rollupConfig); + // Un-hide group-by columns for the rollup + if (rollupConfig?.columns != null && rollupConfig.columns.length > 0) { + const { model } = this.props; + const { metricCalculator } = this.state; + rollupConfig.columns.forEach(name => { + const modelIndex = model.getColumnIndexByName(name); + if (modelIndex != null) { + metricCalculator.resetColumnWidth(modelIndex); + } + }); + } + this.resetGridViewState(); - this.showAllColumns(); this.clearAllFilters(); this.startLoading(