Skip to content

Commit

Permalink
initial impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jnumainville committed Mar 14, 2024
1 parent bca3880 commit 3910e5b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
2 changes: 2 additions & 0 deletions plugins/ui/src/deephaven/ui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .picker import picker
from .section import section
from .item import item
from .list_view import list_view

from . import html

Expand All @@ -34,6 +35,7 @@
"icon_wrapper",
"item",
"illustrated_message",
"list_view",
"html",
"number_field",
"panel",
Expand Down
83 changes: 83 additions & 0 deletions plugins/ui/src/deephaven/ui/components/list_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from __future__ import annotations

from typing import Callable, Any, Union

from deephaven.table import Table

from .item import ItemElement
from .. import Element
from ..elements import BaseElement
from .._internal.utils import create_props
from ..types import ColumnName, Stringable, Selection
from .spectrum import ActionButtonElement

ListViewItem = Union[Stringable, ItemElement]

ListViewElement = Element

# TODO: ActionGroupElement and ActionMenuElement are not created yet
ActionGroupElement = Element
ActionMenuElement = Element


def list_view(
*children: ListViewItem | Table,
key_column: ColumnName | None = None,
label_column: ColumnName | None = None,
description_column: ColumnName | None = None,
icon_column: ColumnName | None = None,
action_buttons: ActionButtonElement
| ActionGroupElement
| ActionMenuElement
| None = None,
default_selected_keys: Selection | None = None,
selected_keys: Selection | None = None,
render_empty_state: Element | None = None,
on_selection_change: Callable[[Selection], None] | None = None,
on_change: Callable[[Selection], None] | None = None,
**props: Any,
) -> ListViewElement:
"""
A list view that can be used to create a list of items. Children should be one of two types:
1. If children are of type `ListViewItem`, they are the list items.
2. If children are of type `Table`, the values in the table are the list items.
There can only be one child, the `Table`.
Args:
*children: The options to render within the list_view.
key_column:
Only valid if children are of type Table.
The column of values to use as item keys. Defaults to the first column.
label_column:
Only valid if children are of type Table.
The column of values to display as primary text. Defaults to the key_column value.
description_column:
Only valid if children are of type Table.
The column of values to display as descriptions.
icon_column: Only valid if children are of type Table.
The column of values to map to icons.
action_buttons:
Only valid if any `ListViewItem` children do not already have embedded buttons.
The action buttons to render for all elements within the list view.
The `on_*` event handlers within the passed object will be modified
so that the second argument is the key for the `list_view` item that the buttons are embedded in.
default_selected_keys:
The initial selected key in the collection (uncontrolled).
selected_keys:
The currently selected key in the collection (controlled).
render_empty_state:
Sets what the `list_view` should render when there is no content to display.
on_selection_change:
Handler that is called when the selection changes.
on_change:
Alias of `on_selection_change`. Handler that is called when the selection changes.
**props:
Any other ListView prop, except items, dragAndDropHooks, and onLoadMore.
Returns:
The rendered ListView.
"""
children, props = create_props(locals())

return BaseElement("deephaven.ui.components.ListView", *children, **props)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from .basic import spectrum_element
from ...elements import Element

ActionButtonElement = Element


def action_button(
*children: Any,
Expand Down Expand Up @@ -86,7 +88,7 @@ def action_button(
aria_details: str | None = None,
UNSAFE_class_name: str | None = None,
UNSAFE_style: CSSProperties | None = None,
) -> Element:
) -> ActionButtonElement:
"""
ActionButtons allow users to perform an action. They're used for similar, task-based options within a workflow, and are ideal for interfaces where buttons aren't meant to draw a lot of attention.
Python implementation for the Adobe React Spectrum ActionButton component: https://react-spectrum.adobe.com/react-spectrum/ActionButton.html
Expand Down
3 changes: 2 additions & 1 deletion plugins/ui/src/deephaven/ui/types/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Literal, Union, List, Tuple, Callable, TypedDict
from typing import Any, Dict, Literal, Union, List, Tuple, Callable, TypedDict, Sequence
from deephaven import SortDirection


Expand Down Expand Up @@ -106,3 +106,4 @@ class RowDataValue(CellData):
Stringable = Union[str, int, float, bool]
Key = Stringable
Dependencies = Union[Tuple[Any], List[Any]]
Selection = Sequence[Key]

0 comments on commit 3910e5b

Please sign in to comment.