Skip to content

Commit 2977dd2

Browse files
authored
fix: DH-17076 LayoutHints on TreeTables were not being applied (#2041)
- Related to DH-17076 - Needed a Core patch: deephaven/deephaven-core#5555 - Tested using both the Groovy snippet from the ticket - Fixes #2035
1 parent 77bea7d commit 2977dd2

4 files changed

Lines changed: 79 additions & 7 deletions

File tree

packages/iris-grid/src/IrisGridTableModelTemplate.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ class IrisGridTableModelTemplate<
177177

178178
private _columnHeaderGroups: ColumnHeaderGroup[] = [];
179179

180+
private _isColumnHeaderGroupsInitialized = false;
181+
180182
private _movedColumns: MoveOperation[] | null = null;
181183

182184
/**
@@ -224,11 +226,6 @@ class IrisGridTableModelTemplate<
224226
// These rows can be sparse, so using a map instead of an array.
225227
this.pendingNewDataMap = new Map();
226228
this.pendingNewRowCount = 0;
227-
228-
this.columnHeaderGroups = IrisGridUtils.parseColumnHeaderGroups(
229-
this,
230-
this.layoutHints?.columnGroups ?? []
231-
).groups;
232229
}
233230

234231
close(): void {
@@ -926,10 +923,12 @@ class IrisGridTableModelTemplate<
926923
}
927924

928925
get columnHeaderGroupMap(): Map<string, ColumnHeaderGroup> {
926+
this.initializeColumnHeaderGroups();
929927
return this._columnHeaderGroupMap;
930928
}
931929

932930
get columnHeaderGroups(): ColumnHeaderGroup[] {
931+
this.initializeColumnHeaderGroups();
933932
return this._columnHeaderGroups;
934933
}
935934

@@ -952,6 +951,16 @@ class IrisGridTableModelTemplate<
952951
this.columnHeaderMaxDepth = maxDepth;
953952
this.columnHeaderParentMap = parentMap;
954953
this._columnHeaderGroupMap = groupMap;
954+
this._isColumnHeaderGroupsInitialized = true;
955+
}
956+
957+
private initializeColumnHeaderGroups(): void {
958+
if (!this._isColumnHeaderGroupsInitialized) {
959+
this.columnHeaderGroups = IrisGridUtils.parseColumnHeaderGroups(
960+
this,
961+
this.layoutHints?.columnGroups ?? []
962+
).groups;
963+
}
955964
}
956965

957966
row(y: ModelIndex): R | null {

packages/iris-grid/src/IrisGridTestUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,16 @@ class IrisGridTestUtils {
100100
columns = this.makeColumns(),
101101
groupedColumns: DhType.Column[] = [],
102102
size = 1000000000,
103-
sort = []
103+
sort = [],
104+
layoutHints?: Partial<DhType.LayoutHints>
104105
): DhType.TreeTable {
105106
// eslint-disable-next-line @typescript-eslint/no-explicit-any
106107
const table = new (this.dh as any).TreeTable({
107108
columns,
108109
groupedColumns,
109110
size,
110111
sort,
112+
layoutHints,
111113
});
112114
table.copy = jest.fn(() => Promise.resolve(table));
113115
return table;

packages/iris-grid/src/IrisGridTreeTableModel.test.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import IrisGridTreeTableModel from './IrisGridTreeTableModel';
44

55
const irisGridTestUtils = new IrisGridTestUtils(dh);
66

7-
describe('IrisGridTreeTableModel', () => {
7+
describe('IrisGridTreeTableModel virtual columns', () => {
88
const expectedVirtualColumn = expect.objectContaining({
99
name: '__DH_UI_GROUP__',
1010
displayName: 'Group',
@@ -27,3 +27,48 @@ describe('IrisGridTreeTableModel', () => {
2727
}
2828
);
2929
});
30+
31+
describe('IrisGridTreeTableModel layoutHints', () => {
32+
test('null layout hints by default', () => {
33+
const columns = irisGridTestUtils.makeColumns();
34+
const table = irisGridTestUtils.makeTreeTable(columns, columns);
35+
const model = new IrisGridTreeTableModel(dh, table);
36+
37+
expect(model.layoutHints).toEqual(null);
38+
});
39+
40+
test('layoutHints set on tree table', () => {
41+
const columns = irisGridTestUtils.makeColumns();
42+
const layoutHints = { hiddenColumns: ['X'], frozenColumns: ['Y'] };
43+
const table = irisGridTestUtils.makeTreeTable(
44+
columns,
45+
columns,
46+
100,
47+
[],
48+
layoutHints
49+
);
50+
const model = new IrisGridTreeTableModel(dh, table);
51+
52+
expect(model.layoutHints).toEqual(layoutHints);
53+
});
54+
55+
test('layoutHints undefined (e.g. not set on the table)', () => {
56+
const columns = irisGridTestUtils.makeColumns();
57+
const table = irisGridTestUtils.makeTreeTable(columns, columns, 100, []);
58+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59+
(table as any).layoutHints = undefined;
60+
const model = new IrisGridTreeTableModel(dh, table);
61+
62+
expect(model.layoutHints).toEqual(undefined);
63+
});
64+
65+
test('layoutHints property does not exist should not crash', () => {
66+
const columns = irisGridTestUtils.makeColumns();
67+
const table = irisGridTestUtils.makeTreeTable(columns, columns, 100, []);
68+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
69+
delete (table as any).layoutHints;
70+
const model = new IrisGridTreeTableModel(dh, table);
71+
72+
expect(model.layoutHints).toEqual(undefined);
73+
});
74+
});

packages/iris-grid/src/IrisGridTreeTableModel.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ export interface UITreeRow extends UIRow {
2121
hasChildren: boolean;
2222
depth: number;
2323
}
24+
25+
type LayoutTreeTable = DhType.TreeTable & {
26+
layoutHints?: null | DhType.LayoutHints;
27+
};
28+
29+
function isLayoutTreeTable(table: DhType.TreeTable): table is LayoutTreeTable {
30+
return (table as LayoutTreeTable).layoutHints !== undefined;
31+
}
32+
2433
class IrisGridTreeTableModel extends IrisGridTableModelTemplate<
2534
DhType.TreeTable,
2635
UITreeRow
@@ -231,6 +240,13 @@ class IrisGridTreeTableModel extends IrisGridTableModelTemplate<
231240
return [this.virtualColumns.length, this.groupedColumns.length];
232241
}
233242

243+
get layoutHints(): DhType.LayoutHints | null | undefined {
244+
if (isLayoutTreeTable(this.table)) {
245+
return this.table.layoutHints;
246+
}
247+
return undefined;
248+
}
249+
234250
get hasExpandableRows(): boolean {
235251
return true;
236252
}

0 commit comments

Comments
 (0)