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 1 commit
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
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', () => {
mofojed marked this conversation as resolved.
Show resolved Hide resolved
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: 13 additions & 3 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,9 +240,10 @@ class IrisGridTreeTableModel extends IrisGridTableModelTemplate<
}

get layoutHints(): DhType.LayoutHints | null | undefined {
// TODO: Update this when JS API types are updated with this.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (this.table as any).layoutHints;
if (isLayoutTreeTable(this.table)) {
return this.table.layoutHints;
}
return undefined;
mofojed marked this conversation as resolved.
Show resolved Hide resolved
}

get hasExpandableRows(): boolean {
Expand Down
Loading