Skip to content

Commit 024811d

Browse files
authored
feat: UI table respond to non-primitive prop changes (#1046)
Fixes #982 Also fixes a bug I found while implementing this where adding a custom column in the UI would cause formatting rule `if_` clauses to be removed.
1 parent 951a376 commit 024811d

20 files changed

+329
-140
lines changed

package-lock.json

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/ui/src/js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@fortawesome/react-fontawesome": "^0.2.0",
6363
"@internationalized/date": "^3.5.5",
6464
"classnames": "^2.5.1",
65+
"fast-deep-equal": "^3.1.3",
6566
"json-rpc-2.0": "^1.6.0",
6667
"nanoid": "^5.0.7",
6768
"react-markdown": "^8.0.7",

plugins/ui/src/js/src/elements/UITable/JsTableProxy.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface JsTableProxy extends dh.Table {}
1515

1616
/**
1717
* Class to proxy JsTable.
18+
* The JsTable passed to the constructor may be modified, so it is recommended to pass a copy.
1819
* Any methods implemented in this class will be utilized over the underlying JsTable methods.
1920
* Any methods not implemented in this class will be proxied to the table.
2021
*/
@@ -39,16 +40,24 @@ class JsTableProxy implements dh.Table {
3940
hiddenColumns: dh.Column[];
4041
};
4142

43+
private originalCustomColumns: dh.CustomColumn[];
44+
45+
private onClose: () => void;
46+
4247
layoutHints: dh.LayoutHints | null = null;
4348

4449
constructor({
4550
table,
4651
layoutHints,
52+
onClose,
4753
}: {
4854
table: dh.Table;
4955
layoutHints: UITableLayoutHints;
56+
onClose: () => void;
5057
}) {
5158
this.table = table;
59+
this.originalCustomColumns = table.customColumns;
60+
this.onClose = onClose;
5261

5362
this.stableColumns = {
5463
allColumns: [],
@@ -145,6 +154,23 @@ class JsTableProxy implements dh.Table {
145154
}
146155
}
147156

157+
close(): void {
158+
// Something causes close to get called twice which will throw some log spam if we try to close the table again
159+
if (!this.table.isClosed) {
160+
this.onClose();
161+
this.table.close();
162+
}
163+
}
164+
165+
applyCustomColumns(
166+
customColumns: Array<string | dh.CustomColumn>
167+
): Array<dh.CustomColumn> {
168+
return this.table.applyCustomColumns([
169+
...this.originalCustomColumns,
170+
...customColumns,
171+
]);
172+
}
173+
148174
get columns(): dh.Column[] {
149175
this.updateDisplayedColumns();
150176
return this.stableColumns.visibleColumns;

0 commit comments

Comments
 (0)