Skip to content

Commit

Permalink
Add no partition column case
Browse files Browse the repository at this point in the history
  • Loading branch information
georgecwan committed Nov 1, 2023
1 parent 4875616 commit a9b210f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
9 changes: 7 additions & 2 deletions packages/iris-grid/src/IrisGridTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
45 changes: 26 additions & 19 deletions packages/iris-grid/src/IrisGridUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@ describe('dehydration methods', () => {
});

describe('hydration methods', () => {
const model = irisGridTestUtils.makeModel(
irisGridTestUtils.makeTable({
columns: irisGridTestUtils.makeColumns(5, 'name_'),
})
);

it.each([
[
'hydrateIrisGridPanelStateV1',
Expand All @@ -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',
{
Expand All @@ -715,7 +723,7 @@ describe('hydration methods', () => {
'hydrateIrisGridPanelStateV1 unselected partition',
{
isSelectingPartition: false,
partition: '',
partition: 'a',
partitionColumn: 'name_0',
advancedSettings: [],
},
Expand All @@ -724,7 +732,7 @@ describe('hydration methods', () => {
'hydrateIrisGridPanelStateV1 one selected partition',
{
isSelectingPartition: true,
partition: '',
partition: 'a',
partitionColumn: 'name_0',
advancedSettings: [],
},
Expand Down Expand Up @@ -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) => {
Expand Down
11 changes: 8 additions & 3 deletions packages/iris-grid/src/IrisGridUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export interface DehydratedIrisGridState {
export interface DehydratedIrisGridPanelStateV1 {
isSelectingPartition: boolean;
partition: string | null;
partitionColumn: ColumnName;
partitionColumn: ColumnName | null;
advancedSettings: [AdvancedSettingsType, boolean][];
}

Expand All @@ -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(
Expand Down Expand Up @@ -350,7 +352,10 @@ class IrisGridUtils {
const { partitionColumns, partitions } = isPanelStateV2(irisGridPanelState)
? irisGridPanelState
: {
partitionColumns: [irisGridPanelState.partitionColumn],
partitionColumns:
irisGridPanelState.partitionColumn !== null
? [irisGridPanelState.partitionColumn]
: [],
partitions: [irisGridPanelState.partition],
};

Expand Down

0 comments on commit a9b210f

Please sign in to comment.