-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #442 The layout hints will only be used as the initial state. Not sure how we'd want to try to combine a change in `ui.table` from the server w/ other changes the user may have made already. At least initially I think this is fine to give the same functionality as current `table.layout_hints` ```py from deephaven import ui from deephaven.plot import express as dx _stocks = dx.data.stocks() stocks_with_hints = ui.table( _stocks, front_columns=["exchange"], frozen_columns=["sym"], back_columns=['side'], hidden_columns=['dollars', 'SPet500'], column_groups=[{"name": "test_group", "children": ["size", "random"], "color": "lemonchiffon"}] ) ```
- Loading branch information
1 parent
0564299
commit 5e3c5e2
Showing
11 changed files
with
302 additions
and
58 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import type { dh } from '@deephaven/jsapi-types'; | ||
|
||
export interface UITableLayoutHints { | ||
frontColumns?: string[]; | ||
frozenColumns?: string[]; | ||
backColumns?: string[]; | ||
hiddenColumns?: string[]; | ||
columnGroups?: dh.ColumnGroup[]; | ||
} | ||
|
||
// This tricks TS into believing the class extends dh.Table | ||
// Even though it is through a proxy | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
interface JsTableProxy extends dh.Table {} | ||
|
||
/** | ||
* Class to proxy JsTable. | ||
* Any methods implemented in this class will be utilized over the underlying JsTable methods. | ||
* Any methods not implemented in this class will be proxied to the table. | ||
*/ | ||
class JsTableProxy { | ||
private table: dh.Table; | ||
|
||
layoutHints: dh.LayoutHints | null = null; | ||
|
||
constructor({ | ||
table, | ||
layoutHints, | ||
}: { | ||
table: dh.Table; | ||
layoutHints: UITableLayoutHints; | ||
}) { | ||
this.table = table; | ||
|
||
const { | ||
frontColumns = null, | ||
frozenColumns = null, | ||
backColumns = null, | ||
hiddenColumns = null, | ||
columnGroups = null, | ||
} = layoutHints; | ||
|
||
this.layoutHints = { | ||
frontColumns, | ||
frozenColumns, | ||
backColumns, | ||
hiddenColumns, | ||
columnGroups, | ||
areSavedLayoutsAllowed: false, | ||
}; | ||
|
||
// eslint-disable-next-line no-constructor-return | ||
return new Proxy(this, { | ||
// We want to use any properties on the proxy model if defined | ||
// If not, then proxy to the underlying model | ||
get(target, prop, receiver) { | ||
// Does this class have a getter for the prop | ||
// Getter functions are on the prototype | ||
const proxyHasGetter = | ||
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(target), prop) | ||
?.get != null; | ||
|
||
if (proxyHasGetter) { | ||
return Reflect.get(target, prop, receiver); | ||
} | ||
|
||
// Does this class implement the property | ||
const proxyHasProp = Object.prototype.hasOwnProperty.call(target, prop); | ||
|
||
// Does the class implement a function for the property | ||
const proxyHasFn = Object.prototype.hasOwnProperty.call( | ||
Object.getPrototypeOf(target), | ||
prop | ||
); | ||
|
||
const trueTarget = proxyHasProp || proxyHasFn ? target : target.table; | ||
const value = Reflect.get(trueTarget, prop, receiver); | ||
|
||
if (typeof value === 'function') { | ||
return value.bind(trueTarget); | ||
} | ||
|
||
return value; | ||
}, | ||
set(target, prop, value) { | ||
const proxyHasSetter = | ||
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(target), prop) | ||
?.set != null; | ||
|
||
if (proxyHasSetter) { | ||
return Reflect.set(target, prop, value, target); | ||
} | ||
|
||
return Reflect.set(target.table, prop, value, target.table); | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export default JsTableProxy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters