Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into widget-hydration-py
Browse files Browse the repository at this point in the history
  • Loading branch information
mofojed committed Mar 13, 2024
2 parents 980ca7b + 7e7302e commit 2dcbae2
Show file tree
Hide file tree
Showing 19 changed files with 938 additions and 447 deletions.
8 changes: 4 additions & 4 deletions docker/data/storage/notebooks/DEMO.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def picker():
)


p = picker()
result = picker()
```

## Using Tables
Expand Down Expand Up @@ -197,7 +197,7 @@ def stock_table_input(source, default_sym="", default_exchange=""):
return [
ui.panel(
# Add a callback for when user double clicks a row in the table
ui.table(t1).on_row_double_press(handle_row_double_press),
ui.table(t1, on_row_double_press=handle_row_double_press),
title="Stock Row Press",
),
ui.panel(t2, title="Stock Filtered Table"),
Expand Down Expand Up @@ -226,7 +226,7 @@ def hist_demo(source, column):
x=column,
nbins=bin_count,
),
{bin_count, hist_range, source, column},
[bin_count, hist_range, source, column],
)

return [
Expand Down Expand Up @@ -322,7 +322,7 @@ def table_tabs(source):
return ui.tabs(
ui.tab_list(
ui.item("Unfiltered", key="Unfiltered"),
ui.item(ui.icon("vsGithubAlt"), "CAT", key="CAT"),
ui.item(ui.icon("vsGithubAlt"), ui.text("CAT"), key="CAT"),
ui.item("DOG", key="DOG"),
),
ui.tab_panels(
Expand Down
826 changes: 468 additions & 358 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:ci:unit": "jest --config jest.config.unit.cjs --ci --cacheDirectory $PWD/.jest-cache",
"test:ci:lint": "jest --config jest.config.lint.cjs --ci --cacheDirectory $PWD/.jest-cache",
"e2e": "playwright run",
"e2e:docker": "./tools/run_docker.sh e2e-tests",
"e2e:docker": "DEEPHAVEN_PORT=10001 ./tools/run_docker.sh e2e-tests",
"e2e:update-snapshots": "./tools/run_docker.sh update-snapshots",
"update-dh-packages": "lerna run update-dh-packages"
},
Expand Down
3 changes: 2 additions & 1 deletion plugins/example-theme/src/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"@deephaven/plugin": "^0.58.0",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
},
"private": true
}
14 changes: 14 additions & 0 deletions plugins/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.

- - -
## ui-v0.9.0 - 2024-03-09
#### Bug Fixes
- Tab Panels contents should take up the full height (#340) - (6028195) - mofojed
- Remove tooltip prop (#334) - (cbe2140) - Joe
- add missing dependencies params for liveness scope and table listener hooks (#291) - (9d6b7de) - niloc132
- added missing picker imports (#332) - (272cdf9) - Joe
#### Build system
- Update dh ui packages to ^0.66.1 (#330) - (9433a98) - bmingles
#### Features
- Add ui.table press event listener support (#346) - (b805683) - mofojed
- UI Picker JS (#333) - (e3af9f5) - bmingles

- - -

## ui-v0.8.0 - 2024-02-28
#### Bug Fixes
- Use correct formatting settings for ui.table (#326) - (4762053) - mofojed
Expand Down
31 changes: 21 additions & 10 deletions plugins/ui/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,8 @@ ui_table(
column_display_names: dict[ColumnName, ColumnNameCombination] | None,
on_row_press: Callable[[RowIndex, RowData], None] | None,
on_row_double_press: Callable[[RowIndex, RowData], None] | None
on_cell_press: Callable[[CellIndex, Any], None] | None,
on_cell_double_press: Callable[[CellIndex, Any], None] | None
on_cell_press: Callable[[CellIndex, CellData], None] | None,
on_cell_double_press: Callable[[CellIndex, CellData], None] | None
on_column_press: Callable[[ColumnName], None] | None,
on_columns_double_press: Callable[[ColumnName], None] | None,
on_search: Callable[[str], None],
Expand Down Expand Up @@ -1275,8 +1275,8 @@ ui_table(
| `column_display_names` | `dict[ColumnName, ColumnNameCombination] \| None` | The display names. If a sequence of column names is provided for a column, the display name will be set to the longest column name that can be fully displayed. |
| `on_row_press` | `Callable[[RowIndex, RowData], None] \| None` | The callback function to run when a cell in a row is released (such as a click). The first parameter is the row index, and the second is the row data provided in a dictionary where the column names are the keys. |
| `on_row_double_press` | `Callable[[RowIndex, RowData], None] \| None` | The callback function to run when a cell in a row is double pressed. The first parameter is the row index, and the second is the row data provided in a dictionary where the column names are the keys. |
| `on_cell_press` | `Callable[[CellIndex, Any], None] \| None` | The callback function to run when a cell is released (such as a click). The first parameter is the cell index, and the second is the cell data. |
| `on_cell_double_press` | `Callable[[CellIndex, Any], None] \| None` | The callback function to run when a cell is double pressed. The first parameter is the cell index, and the second is the cell data. |
| `on_cell_press` | `Callable[[CellIndex, CellData], None] \| None` | The callback function to run when a cell is released (such as a click). The first parameter is the cell index, and the second is the cell data. |
| `on_cell_double_press` | `Callable[[CellIndex, CellData], None] \| None` | The callback function to run when a cell is double pressed. The first parameter is the cell index, and the second is the cell data. |
| `on_column_press` | `Callable[[ColumnName], None] \| None` | The callback function to run when a column is released (such as a click). The only parameter is the column name. |
| `on_column_double_press` | `Callable[[ColumnName], None] \| None` | The callback function to run when a cell in a column is double pressed. The only parameter is the column name. |
| `on_search` | `Callable[[str], None] \| None` | The callback function to run when the search bar is used. The only parameter is the search string. |
Expand Down Expand Up @@ -1669,10 +1669,11 @@ Below are some of the custom types that are used in the above API definitions:

```py
AggregationOperation = Literal["COUNT", "COUNT_DISTINCT", "DISTINCT", "MIN", "MAX", "SUM", "ABS_SUM", "VAR", "AVG", "STD", "FIRST", "LAST", "UNIQUE", "SKIP"]
CellIndex = [RowIndex, ColumnIndex]
# An index of None means a header was selected
GridIndex = [ColumnIndex | None, RowIndex | None]
CellIndex = [ColumnIndex, RowIndex]
Color = DeephavenColor | HexColor
# A ColumnIndex of None indicates a header row
ColumnIndex = int | None
ColumnIndex = int
ColumnName = str
ColumnData = list[Any]
# ID of a component. Used for linking.
Expand All @@ -1688,9 +1689,8 @@ DeephavenColor = Literal[...]
HexColor = str
LockType = Literal["shared", "exclusive"]
QuickFilterExpression = str
RowData = dict[ColumnName, Any]
# A RowIndex of None indicates a header column
RowIndex = int | None
RowData = dict[ColumnName, RowDataValue]
RowIndex = int
SelectionStyle = Literal["HIGHLIGHT", "CHECKBOX"]
SelectionArea = Literal["CELL", "ROW", "COLUMN"]
SelectionMode = Literal["SINGLE", "MULTIPLE"]
Expand All @@ -1714,6 +1714,17 @@ ColumnIndexCombination = Combination[ColumnIndex]
CellIndexCombination = Combination[CellIndex]
SelectionStyleCombination = Combination[SelectionStyle]

# Data for one cell. Returned with click handlers.
class CellData(TypedDict):
type: str
text: str
value: Any

# Data for value of one column in a row. Returned with row press handlers.
class RowDataValue(CellData):
isExpandable: bool
isGrouped: bool

# Set a filter for a dashboard. Filter will apply to all items with a matching column/type, except for items specified in the `exclude_ids` parameter
class DashboardFilter(TypedDict):
# Name of column to filter on
Expand Down
25 changes: 24 additions & 1 deletion plugins/ui/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def stock_table_input(source, default_sym="", default_exchange=""):

return [
ui.panel(
ui.table(t1).on_row_double_press(handle_row_double_press),
ui.table(t1, on_row_double_press=handle_row_double_press),
title="Stock Table Input",
),
ui.panel(t2, title="Stock Filtered Table"),
Expand All @@ -769,6 +769,29 @@ def stock_table_input(source, default_sym="", default_exchange=""):
sti = stock_table_input(stocks, "CAT", "TPET")
```

### ui.table Events

The `ui.table` component has a few events that you can listen to. You can listen to different kinds of press events that include the data about the region pressed.

```py
import deephaven.ui as ui
import deephaven.plot.express as dx

te = ui.table(
dx.data.stocks(),
on_row_press=lambda row, data: print(f"Row Press: {row}, {data}"),
on_row_double_press=lambda row, data: print(f"Row Double Press: {row}, {data}"),
on_cell_press=lambda cell_index, data: print(f"Cell Press: {cell_index}, {data}"),
on_cell_double_press=lambda cell_index, data: print(
f"Cell Double Press: {cell_index}, {data}"
),
on_column_press=lambda column: print(f"Column Press: {column}"),
on_column_double_press=lambda column: print(f"Column Double Press: {column}"),
)
```

![Table events](table_events.png)

## Re-using components

In a previous example, we created a text_filter_table component. We can re-use that component, and display two tables with an input filter side-by-side:
Expand Down
Binary file added plugins/ui/examples/assets/table_events.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions plugins/ui/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ install_requires =
deephaven-core>=0.31.0
deephaven-plugin>=0.6.0
json-rpc
typing_extensions
include_package_data = True

[options.packages.find]
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/deephaven/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .hooks import *
from .object_types import *

__version__ = "0.8.0.dev0"
__version__ = "0.9.0.dev0"


class UIRegistration(Registration):
Expand Down
43 changes: 40 additions & 3 deletions plugins/ui/src/deephaven/ui/components/table.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
from __future__ import annotations

from deephaven.table import Table
from ..elements import UITable
from ..types import (
CellPressCallback,
ColumnPressCallback,
RowPressCallback,
)


def table(table: Table) -> UITable:
def table(
table: Table,
*,
on_row_press: RowPressCallback | None = None,
on_row_double_press: RowPressCallback | None = None,
on_cell_press: CellPressCallback | None = None,
on_cell_double_press: CellPressCallback | None = None,
on_column_press: ColumnPressCallback | None = None,
on_column_double_press: ColumnPressCallback | None = None,
) -> UITable:
"""
Add some extra methods to the Table class for giving hints to displaying a table
Customization to how a table is displayed, how it behaves, and listen to UI events.
Args:
table: The table to wrap
on_row_press: The callback function to run when a row is clicked.
The first parameter is the row index, and the second is the row data provided in a dictionary where the
column names are the keys.
on_row_double_press: The callback function to run when a row is double clicked.
The first parameter is the row index, and the second is the row data provided in a dictionary where the
column names are the keys.
on_cell_press: The callback function to run when a cell is clicked.
The first parameter is the cell index, and the second is the row data provided in a dictionary where the
column names are the keys.
on_cell_double_press: The callback function to run when a cell is double clicked.
The first parameter is the cell index, and the second is the row data provided in a dictionary where the
column names are the keys.
on_column_press: The callback function to run when a column is clicked.
The first parameter is the column name.
on_column_double_press: The callback function to run when a column is double clicked.
The first parameter is the column name.
"""
return UITable(table)
props = locals()
del props["table"]
return UITable(table, **props)
Loading

0 comments on commit 2dcbae2

Please sign in to comment.