Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DH-17076 LayoutHints on TreeTables were not being applied #2041

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
Comment on lines +65 to +73
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is identical to the test above it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. undefined vs. property not existing, it is technically different. e.g.

var o = { foo: 'bar', fiz: undefined }
var o2 = { ...o }
delete o2.fiz

console.log(o.hasOwnProperty('fiz')) // true
console.log(o2.hasOwnProperty('fiz')) //false

});
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 @@ -230,6 +239,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;
mofojed marked this conversation as resolved.
Show resolved Hide resolved
}

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