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

Add SearchDisplayMode layout hints #3512

Merged
merged 6 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ public class LayoutHintBuilder {

private Map<String, ColumnGroup> columnGroups;

/**
* The display mode for the search bar.
*/
public enum SearchDisplayModes {
/**
* Use the system default
*/
Default,
/**
* Permit the search bar to be displayed, regardless of system settings
*/
Show,
/**
* Hide the search bar, regardless of system settings.
*/
Hide
}

private SearchDisplayModes searchDisplayMode = SearchDisplayModes.Default;


/**
* Helper class to maintain sub-properties for auto filter columns
*/
Expand Down Expand Up @@ -231,6 +252,11 @@ public static LayoutHintBuilder fromString(String attrs) {
lhb.groupableColumns(groupableColumns);
}

final String searchableStr = options.get("searchable");
if (searchableStr != null && !searchableStr.isEmpty()) {
lhb.setSearchBarAccess(SearchDisplayModes.valueOf(searchableStr));
}

final String columnGroupsStr = options.get("columnGroups");
if (columnGroupsStr != null && !columnGroupsStr.isEmpty()) {
Arrays.stream(columnGroupsStr.split("\\|"))
Expand Down Expand Up @@ -555,6 +581,30 @@ public LayoutHintBuilder groupableColumns(Collection<String> columns) {
return this;
}

/**
* Set the search bar to explicitly be accessible or inaccessible, or use system default.
*
* @param searchable The display mode to use
* @return This LayoutHintBuilder
*/
@ScriptApi
public LayoutHintBuilder setSearchBarAccess(final SearchDisplayModes searchable) {
searchDisplayMode = searchable;
return this;
}

/**
* Set the search bar to explicitly be accessible or inaccessible, or use system default.
*
* @param searchable The display mode to use
* @return This LayoutHintBuilder
*/
@ScriptApi
public LayoutHintBuilder setSearchBarAccess(final String searchable) {
searchDisplayMode = SearchDisplayModes.valueOf(searchable);
return this;
}

// endregion

/**
Expand Down Expand Up @@ -601,6 +651,10 @@ public String build() {
sb.append("groupable=").append(String.join(",", groupableColumns)).append(';');
}

if (searchDisplayMode != SearchDisplayModes.Default) {
sb.append("searchable=").append(searchDisplayMode.toString()).append(';');
}

if (columnGroups != null && !columnGroups.isEmpty()) {
sb.append("columnGroups=");
String groupStrings =
Expand Down Expand Up @@ -712,6 +766,13 @@ public int getAutoFilterFetchSize(String column) {
return groupableColumns == null ? Collections.emptySet() : Collections.unmodifiableSet(groupableColumns);
}

public @NotNull SearchDisplayModes getSearchDisplayMode() {
if (searchDisplayMode == null) {
searchDisplayMode = SearchDisplayModes.Default;
}
return searchDisplayMode;
}

/**
* Get the map of column groups for the UI.
*
Expand Down
18 changes: 17 additions & 1 deletion py/server/deephaven/table.py
mofojed marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
_JPair = jpy.get_type("io.deephaven.api.agg.Pair")
_JMatchPair = jpy.get_type("io.deephaven.engine.table.MatchPair")
_JLayoutHintBuilder = jpy.get_type("io.deephaven.engine.util.LayoutHintBuilder")
_JSearchDisplayMode = jpy.get_type("io.deephaven.engine.util.LayoutHintBuilder$SearchDisplayModes")
_JSnapshotWhenOptions = jpy.get_type("io.deephaven.api.snapshot.SnapshotWhenOptions")

# PartitionedTable
Expand Down Expand Up @@ -88,6 +89,14 @@ class NodeType(Enum):
include_constituent=True. The constituent level is the lowest in a rollup table. These nodes have column names
and types from the source table of the RollupTable. """

class SearchDisplayMode(Enum):
"""An enum of search display modes for layout hints"""
DEFAULT = _JSearchDisplayMode.Default
"""Use the system default. This may depend on your user and/or system settings."""
SHOW = _JSearchDisplayMode.Show
"""Permit the search bar to be displayed, regardless of user or system settings."""
HIDE = _JSearchDisplayMode.Hide
"""Hide the search bar, regardless of user or system settings."""

class _FormatOperationsRecorder(Protocol):
"""A mixin for creating format operations to be applied to individual nodes of either RollupTable or TreeTable."""
Expand Down Expand Up @@ -1852,7 +1861,7 @@ def format_row_where(self, cond: str, formula: str) -> Table:

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) -> Table:
column_groups: List[dict] = None, search_display_mode: SearchDisplayMode = None) -> Table:
""" Sets layout hints on the Table

Args:
Expand All @@ -1867,6 +1876,9 @@ def layout_hints(self, front: Union[str, List[str]] = None, back: Union[str, Lis
name (str): The group name
children (List[str]): The
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
Expand All @@ -1893,6 +1905,10 @@ def layout_hints(self, front: Union[str, List[str]] = None, back: Union[str, Lis
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

Expand Down
27 changes: 21 additions & 6 deletions py/server/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from deephaven.html import to_html
from deephaven.jcompat import j_hashmap
from deephaven.pandas import to_pandas
from deephaven.table import Table
from deephaven.table import Table, SearchDisplayMode
from tests.testbase import BaseTestCase


Expand Down Expand Up @@ -608,6 +608,12 @@ def test_format_row_where(self):
self.assertIsNotNone(t)

def test_layout_hints(self):
def verify_layout_hint(t: Table, layout_hint_str: str):
attrs = self.test_table.attributes()
attrs["LayoutHints"] = layout_hint_str
self.assertIsNotNone(t)
self.assertEquals(attrs, t.attributes())

t = self.test_table.layout_hints(front="d", back="b", freeze="c", hide="d", column_groups=[
{
"name": "Group1",
Expand All @@ -624,19 +630,28 @@ def test_layout_hints(self):
"color": "RED"
}
])
self.assertIsNotNone(t)
verify_layout_hint(t, "front=d;back=b;hide=d;freeze=c;columnGroups=name:Group1::children:a,b|name:Group2::children:c,d::color:#123456|name:Group3::children:e,f::color:#ff0000;")

t = self.test_table.layout_hints(front=["d", "e"], back=["a", "b"], freeze=["c"], hide=["d"])
self.assertIsNotNone(t)
verify_layout_hint(t, "front=d,e;back=a,b;hide=d;freeze=c;")

t = self.test_table.layout_hints(front="e")
self.assertIsNotNone(t)
verify_layout_hint(t, "front=e;")

t = self.test_table.layout_hints(front=["e"])
self.assertIsNotNone(t)
verify_layout_hint(t, "front=e;")

t = self.test_table.layout_hints(search_display_mode=SearchDisplayMode.SHOW)
verify_layout_hint(t, "searchable=Show;")

t = self.test_table.layout_hints(search_display_mode=SearchDisplayMode.HIDE)
verify_layout_hint(t, "searchable=Hide;")

t = self.test_table.layout_hints(search_display_mode=SearchDisplayMode.DEFAULT)
verify_layout_hint(t, "")

t = self.test_table.layout_hints()
self.assertIsNotNone(t)
verify_layout_hint(t, "")

with self.assertRaises(DHError) as cm:
t = self.test_table.layout_hints(front=["e"], back=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public ColumnGroup(String groupStr) {
}

private boolean savedLayoutsAllowed = true;

private String searchDisplayMode = JsLayoutHints.SEARCH_DISPLAY_DEFAULT;
private String[] frontColumns;
private String[] backColumns;
private String[] hiddenColumns;
Expand Down Expand Up @@ -88,6 +90,11 @@ public JsLayoutHints parse(String hints) {
frozenColumns = JsObject.freeze(freezeStr.split(","));
}

final String searchableStr = options.get("searchable");
if (searchableStr != null && !searchableStr.isEmpty()) {
searchDisplayMode = searchableStr;
}

final String groupsStr = options.get("columnGroups");
if (groupsStr != null && !groupsStr.isEmpty()) {
ColumnGroup[] groups =
Expand All @@ -100,11 +107,21 @@ public JsLayoutHints parse(String hints) {
return this;
}

@JsProperty(namespace = "dh.SearchDisplayMode")
public static final String SEARCH_DISPLAY_DEFAULT = "Default",
SEARCH_DISPLAY_HIDE = "Hide",
SEARCH_DISPLAY_SHOW = "Show";

@JsProperty
public boolean getAreSavedLayoutsAllowed() {
return savedLayoutsAllowed;
}

@JsProperty
public String getSearchDisplayMode() {
return searchDisplayMode;
}

@JsProperty
public String[] getFrontColumns() {
return frontColumns;
Expand Down