Skip to content

Commit

Permalink
fix: DH-17076 LayoutHints on TreeTables were not being applied (#2041)
Browse files Browse the repository at this point in the history
- Related to DH-17076
- Needed a Core patch:
deephaven/deephaven-core#5555
- Tested using both the Groovy snippet from the ticket
- Fixes #2035
  • Loading branch information
mofojed committed Jun 3, 2024
1 parent 77bea7d commit 2977dd2
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
19 changes: 14 additions & 5 deletions packages/iris-grid/src/IrisGridTableModelTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class IrisGridTableModelTemplate<

private _columnHeaderGroups: ColumnHeaderGroup[] = [];

private _isColumnHeaderGroupsInitialized = false;

private _movedColumns: MoveOperation[] | null = null;

/**
Expand Down Expand Up @@ -224,11 +226,6 @@ class IrisGridTableModelTemplate<
// These rows can be sparse, so using a map instead of an array.
this.pendingNewDataMap = new Map();
this.pendingNewRowCount = 0;

this.columnHeaderGroups = IrisGridUtils.parseColumnHeaderGroups(
this,
this.layoutHints?.columnGroups ?? []
).groups;
}

close(): void {
Expand Down Expand Up @@ -926,10 +923,12 @@ class IrisGridTableModelTemplate<
}

get columnHeaderGroupMap(): Map<string, ColumnHeaderGroup> {
this.initializeColumnHeaderGroups();
return this._columnHeaderGroupMap;
}

get columnHeaderGroups(): ColumnHeaderGroup[] {
this.initializeColumnHeaderGroups();
return this._columnHeaderGroups;
}

Expand All @@ -952,6 +951,16 @@ class IrisGridTableModelTemplate<
this.columnHeaderMaxDepth = maxDepth;
this.columnHeaderParentMap = parentMap;
this._columnHeaderGroupMap = groupMap;
this._isColumnHeaderGroupsInitialized = true;
}

private initializeColumnHeaderGroups(): void {
if (!this._isColumnHeaderGroupsInitialized) {
this.columnHeaderGroups = IrisGridUtils.parseColumnHeaderGroups(
this,
this.layoutHints?.columnGroups ?? []
).groups;
}
}

row(y: ModelIndex): R | null {
Expand Down
4 changes: 3 additions & 1 deletion packages/iris-grid/src/IrisGridTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ class IrisGridTestUtils {
columns = this.makeColumns(),
groupedColumns: DhType.Column[] = [],
size = 1000000000,
sort = []
sort = [],
layoutHints?: Partial<DhType.LayoutHints>
): DhType.TreeTable {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const table = new (this.dh as any).TreeTable({
columns,
groupedColumns,
size,
sort,
layoutHints,
});
table.copy = jest.fn(() => Promise.resolve(table));
return table;
Expand Down
47 changes: 46 additions & 1 deletion packages/iris-grid/src/IrisGridTreeTableModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import IrisGridTreeTableModel from './IrisGridTreeTableModel';

const irisGridTestUtils = new IrisGridTestUtils(dh);

describe('IrisGridTreeTableModel', () => {
describe('IrisGridTreeTableModel virtual columns', () => {
const expectedVirtualColumn = expect.objectContaining({
name: '__DH_UI_GROUP__',
displayName: 'Group',
Expand All @@ -27,3 +27,48 @@ describe('IrisGridTreeTableModel', () => {
}
);
});

describe('IrisGridTreeTableModel layoutHints', () => {
test('null layout hints by default', () => {
const columns = irisGridTestUtils.makeColumns();
const table = irisGridTestUtils.makeTreeTable(columns, columns);
const model = new IrisGridTreeTableModel(dh, table);

expect(model.layoutHints).toEqual(null);
});

test('layoutHints set on tree table', () => {
const columns = irisGridTestUtils.makeColumns();
const layoutHints = { hiddenColumns: ['X'], frozenColumns: ['Y'] };
const table = irisGridTestUtils.makeTreeTable(
columns,
columns,
100,
[],
layoutHints
);
const model = new IrisGridTreeTableModel(dh, table);

expect(model.layoutHints).toEqual(layoutHints);
});

test('layoutHints undefined (e.g. not set on the table)', () => {
const columns = irisGridTestUtils.makeColumns();
const table = irisGridTestUtils.makeTreeTable(columns, columns, 100, []);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(table as any).layoutHints = undefined;
const model = new IrisGridTreeTableModel(dh, table);

expect(model.layoutHints).toEqual(undefined);
});

test('layoutHints property does not exist should not crash', () => {
const columns = irisGridTestUtils.makeColumns();
const table = irisGridTestUtils.makeTreeTable(columns, columns, 100, []);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (table as any).layoutHints;
const model = new IrisGridTreeTableModel(dh, table);

expect(model.layoutHints).toEqual(undefined);
});
});
16 changes: 16 additions & 0 deletions packages/iris-grid/src/IrisGridTreeTableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export interface UITreeRow extends UIRow {
hasChildren: boolean;
depth: number;
}

type LayoutTreeTable = DhType.TreeTable & {
layoutHints?: null | DhType.LayoutHints;
};

function isLayoutTreeTable(table: DhType.TreeTable): table is LayoutTreeTable {
return (table as LayoutTreeTable).layoutHints !== undefined;
}

class IrisGridTreeTableModel extends IrisGridTableModelTemplate<
DhType.TreeTable,
UITreeRow
Expand Down Expand Up @@ -231,6 +240,13 @@ class IrisGridTreeTableModel extends IrisGridTableModelTemplate<
return [this.virtualColumns.length, this.groupedColumns.length];
}

get layoutHints(): DhType.LayoutHints | null | undefined {
if (isLayoutTreeTable(this.table)) {
return this.table.layoutHints;
}
return undefined;
}

get hasExpandableRows(): boolean {
return true;
}
Expand Down

0 comments on commit 2977dd2

Please sign in to comment.