diff --git a/packages/iris-grid/src/IrisGridTestUtils.ts b/packages/iris-grid/src/IrisGridTestUtils.ts index c716b0dffb..364b630503 100644 --- a/packages/iris-grid/src/IrisGridTestUtils.ts +++ b/packages/iris-grid/src/IrisGridTestUtils.ts @@ -92,8 +92,13 @@ class IrisGridTestUtils { makeTable({ columns = this.makeColumns(), size = 1000000000, - sort = [] as Sort[], - layoutHints = {} as LayoutHints, + sort = [], + layoutHints = {}, + }: { + columns?: Column[]; + size?: number; + sort?: readonly Sort[]; + layoutHints?: LayoutHints; } = {}): Table { // eslint-disable-next-line @typescript-eslint/no-explicit-any const table = new (this.dh as any).Table({ columns, size, sort }); diff --git a/packages/iris-grid/src/IrisGridUtils.test.ts b/packages/iris-grid/src/IrisGridUtils.test.ts index 839d25b69d..a9507c8952 100644 --- a/packages/iris-grid/src/IrisGridUtils.test.ts +++ b/packages/iris-grid/src/IrisGridUtils.test.ts @@ -669,6 +669,12 @@ describe('dehydration methods', () => { }); describe('hydration methods', () => { + const model = irisGridTestUtils.makeModel( + irisGridTestUtils.makeTable({ + columns: irisGridTestUtils.makeColumns(5, 'name_'), + }) + ); + it.each([ [ 'hydrateIrisGridPanelStateV1', @@ -690,18 +696,20 @@ describe('hydration methods', () => { ], ])('%s invalid column error', (_label, panelState) => { expect(() => - IrisGridUtils.hydrateIrisGridPanelState( - irisGridTestUtils.makeModel( - irisGridTestUtils.makeTable({ - columns: irisGridTestUtils.makeColumns(5, 'name_'), - }) - ), - panelState - ) + IrisGridUtils.hydrateIrisGridPanelState(model, panelState) ).toThrow('Invalid partition column INVALID'); }); it.each([ + [ + 'hydrateIrisGridPanelStateV1 null partition column', + { + isSelectingPartition: false, + partition: null, + partitionColumn: null, + advancedSettings: [], + }, + ], [ 'hydrateIrisGridPanelStateV1 null partition', { @@ -715,7 +723,7 @@ describe('hydration methods', () => { 'hydrateIrisGridPanelStateV1 unselected partition', { isSelectingPartition: false, - partition: '', + partition: 'a', partitionColumn: 'name_0', advancedSettings: [], }, @@ -724,7 +732,7 @@ describe('hydration methods', () => { 'hydrateIrisGridPanelStateV1 one selected partition', { isSelectingPartition: true, - partition: '', + partition: 'a', partitionColumn: 'name_0', advancedSettings: [], }, @@ -775,18 +783,17 @@ describe('hydration methods', () => { }, ], ])('%s partitions and columns match', (_label, panelState) => { - const result = IrisGridUtils.hydrateIrisGridPanelState( - irisGridTestUtils.makeModel( - irisGridTestUtils.makeTable({ - columns: irisGridTestUtils.makeColumns(5, 'name_'), - }) - ), - panelState - ); + const result = IrisGridUtils.hydrateIrisGridPanelState(model, panelState); expect(result.isSelectingPartition).toBe(panelState.isSelectingPartition); if (isPanelStateV1(panelState)) { expect(result.partitions).toEqual([panelState.partition]); - expect(result.partitionColumns[0].name).toBe(panelState.partitionColumn); + if (panelState.partitionColumn !== null) { + expect(result.partitionColumns[0].name).toBe( + panelState.partitionColumn + ); + } else { + expect(result.partitionColumns).toEqual([]); + } } else { expect(result.partitions).toEqual(panelState.partitions); panelState.partitionColumns.forEach((partition, index) => { diff --git a/packages/iris-grid/src/IrisGridUtils.ts b/packages/iris-grid/src/IrisGridUtils.ts index 39172fb60c..061851756f 100644 --- a/packages/iris-grid/src/IrisGridUtils.ts +++ b/packages/iris-grid/src/IrisGridUtils.ts @@ -146,7 +146,7 @@ export interface DehydratedIrisGridState { export interface DehydratedIrisGridPanelStateV1 { isSelectingPartition: boolean; partition: string | null; - partitionColumn: ColumnName; + partitionColumn: ColumnName | null; advancedSettings: [AdvancedSettingsType, boolean][]; } @@ -164,7 +164,9 @@ export type DehydratedIrisGridPanelState = export function isPanelStateV1( state: DehydratedIrisGridPanelState ): state is DehydratedIrisGridPanelStateV1 { - return (state as DehydratedIrisGridPanelStateV1).partitionColumn != null; + return ( + (state as DehydratedIrisGridPanelStateV1).partitionColumn !== undefined + ); } export function isPanelStateV2( @@ -350,7 +352,10 @@ class IrisGridUtils { const { partitionColumns, partitions } = isPanelStateV2(irisGridPanelState) ? irisGridPanelState : { - partitionColumns: [irisGridPanelState.partitionColumn], + partitionColumns: + irisGridPanelState.partitionColumn !== null + ? [irisGridPanelState.partitionColumn] + : [], partitions: [irisGridPanelState.partition], };