Skip to content

Commit

Permalink
fix: Allow LayoutHints to be accessible from Python, TreeTables
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mofojed committed May 29, 2024
1 parent dbf2b2d commit e4e1895
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
60 changes: 60 additions & 0 deletions py/server/deephaven/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ private enum RebuildStep {
private Column rowExpandedCol;
private final Column actionCol;
private final JsArray<Column> groupedColumns;
private JsLayoutHints layoutHints;

// The source JsTable behind the original HierarchicalTable, lazily built at this time
private final JsLazy<Promise<JsTable>> sourceTable;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e4e1895

Please sign in to comment.