From e4e1895b1965b6f6afcf40413cbab6d8aebad9bc Mon Sep 17 00:00:00 2001 From: mikebender Date: Wed, 29 May 2024 10:32:10 -0400 Subject: [PATCH] fix: Allow LayoutHints to be accessible from Python, TreeTables - Related to Enterprise ticket DH-17076, which has been identified as a Blocker by support - Groovy had setLayoutHints exposed on TreeTables, but was not exposed through JsTreeTable and was also not accessible through Python - Added layoutHints to JsTreeTable, and exposed layout_hints through Python - Will have a follow up UI change as well to read the layout hints correctly from a JsTreeTable --- py/server/deephaven/table.py | 60 +++++++++++++++++++ .../web/client/api/tree/JsTreeTable.java | 20 +++++++ 2 files changed, 80 insertions(+) diff --git a/py/server/deephaven/table.py b/py/server/deephaven/table.py index 2eca7ae3417..f1019e94832 100644 --- a/py/server/deephaven/table.py +++ b/py/server/deephaven/table.py @@ -251,6 +251,66 @@ def with_filters(self, filters: Union[str, Filter, Sequence[str], Sequence[Filte except Exception as e: raise DHError(e, "with_filters operation on RollupTable failed.") from e + def layout_hints(self, front: Union[str, List[str]] = None, back: Union[str, List[str]] = None, + freeze: Union[str, List[str]] = None, hide: Union[str, List[str]] = None, + column_groups: List[dict] = None, search_display_mode: SearchDisplayMode = None) -> Table: + """ Sets layout hints on the Table + + Args: + front (Union[str, List[str]]): the columns to show at the front. + back (Union[str, List[str]]): the columns to show at the back. + freeze (Union[str, List[str]]): the columns to freeze to the front. + These will not be affected by horizontal scrolling. + hide (Union[str, List[str]]): the columns to hide. + column_groups (List[Dict]): A list of dicts specifying which columns should be grouped in the UI. + The dicts can specify the following: + + * name (str): The group name + * children (List[str]): The column names in the group + * color (Optional[str]): The hex color string or Deephaven color name + search_display_mode (SearchDisplayMode): set the search bar to explicitly be accessible or inaccessible, + or use the system default. :attr:`SearchDisplayMode.SHOW` will show the search bar, + :attr:`SearchDisplayMode.HIDE` will hide the search bar, and :attr:`SearchDisplayMode.DEFAULT` will + use the default value configured by the user and system settings. + + Returns: + a new table with the layout hints set + + Raises: + DHError + """ + try: + _j_layout_hint_builder = _JLayoutHintBuilder.get() + + if front is not None: + _j_layout_hint_builder.atFront(to_sequence(front)) + + if back is not None: + _j_layout_hint_builder.atBack(to_sequence(back)) + + if freeze is not None: + _j_layout_hint_builder.freeze(to_sequence(freeze)) + + if hide is not None: + _j_layout_hint_builder.hide(to_sequence(hide)) + + if column_groups is not None: + for group in column_groups: + _j_layout_hint_builder.columnGroup(group.get("name"), j_array_list(group.get("children")), + group.get("color", "")) + + if search_display_mode is not None: + _j_layout_hint_builder.setSearchBarAccess(search_display_mode.value) + + except Exception as e: + raise DHError(e, "failed to create layout hints") from e + + try: + return RollupTable(j_rollup_table=self.j_rollup_table.setLayoutHints(_j_layout_hint_builder.build()), + include_constituents=self.include_constituents, aggs=self.aggs, by=self.by) + except Exception as e: + raise DHError(e, "failed to set layout hints on table") from e + class TreeNodeOperationsRecorder(JObjectWrapper, _FormatOperationsRecorder, _SortOperationsRecorder, _FilterOperationsRecorder): diff --git a/web/client-api/src/main/java/io/deephaven/web/client/api/tree/JsTreeTable.java b/web/client-api/src/main/java/io/deephaven/web/client/api/tree/JsTreeTable.java index 79a28fb2e0d..37d8fecd497 100644 --- a/web/client-api/src/main/java/io/deephaven/web/client/api/tree/JsTreeTable.java +++ b/web/client-api/src/main/java/io/deephaven/web/client/api/tree/JsTreeTable.java @@ -359,6 +359,7 @@ private enum RebuildStep { private Column rowExpandedCol; private final Column actionCol; private final JsArray groupedColumns; + private JsLayoutHints layoutHints; // The source JsTable behind the original HierarchicalTable, lazily built at this time private final JsLazy> sourceTable; @@ -1082,6 +1083,25 @@ public String getDescription() { return tableDefinition.getAttributes().getDescription(); } + @JsProperty + @JsNullable + public JsLayoutHints getLayoutHints() { + if (layoutHints == null) { + createLayoutHints(); + } + return layoutHints; + } + + private void createLayoutHints() { + String hintsString = tableDefinition.getAttributes().getLayoutHints(); + JsLayoutHints jsHints = new JsLayoutHints(); + if (hintsString == null) { + layoutHints = null; + } else { + layoutHints = jsHints.parse(hintsString); + } + } + /** * The current number of rows given the table's contents and the various expand/collapse states of each node. (No * totalSize is provided at this time; its definition becomes unclear between roll-up and tree tables, especially