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

feat: ListView actions #448

Merged
merged 16 commits into from
May 23, 2024
Merged

Conversation

bmingles
Copy link
Contributor

@bmingles bmingles commented Apr 29, 2024

  • ui.action_group
  • ui.action_menu
  • ui.list_action_group
  • ui.list_action_menu
  • Cleaned up some element name utils

Testing

  • I tested action_group and action_menu in isolation
  • I tested list_action_group and list_action_menu in list_view actions prop as well as in item_table_source

resolves #445

@bmingles bmingles force-pushed the 445-list-view-actions branch from 40018d0 to 5bc8d47 Compare May 1, 2024 21:24
@bmingles bmingles linked an issue May 3, 2024 that may be closed by this pull request
@bmingles bmingles force-pushed the 445-list-view-actions branch 2 times, most recently from 9c9e317 to 9acde26 Compare May 9, 2024 16:07
bmingles added a commit to deephaven/web-client-ui that referenced this pull request May 15, 2024
* Wrapper components for `ActionGroup` and `ActionMenu` to support
primitive items
* `ListActionGroup` and `ListActionMenu` components to support providing
actions prop to `ListView`
* `ListView` `actions` prop support

The branch in [this
PR](deephaven/deephaven-plugins#448) can be used
to see this in action. I also published an alpha this branch
([0.77.1-alpha-listview-actions.4](https://www.npmjs.com/package/@deephaven/components/v/0.77.1-alpha-listview-actions.4))
to make types work in plugins

### Example of standalone `ui.action_group` and `ui.action_menu`
```python
from deephaven import ui


@ui.component
def action_group():
    action, on_action = ui.use_state("")
    selected_keys, set_selected_keys = ui.use_state(['Aaa'])

    selection_text = ui.text("Selection: " + ", ".join(map(str, selected_keys)), grid_column="span 2")

    return 'Action Group', (" - " if action else "") + action, ui.action_group(
        ui.item(
            ui.icon('vsAccount'),
            'Aaa',
            text_value="Aaa"
        ),
        'Bbb',
        'Ccc',
        selection_mode="multiple",
        selected_keys=selected_keys,
        on_action=on_action,
        on_change=set_selected_keys,
    ), selection_text,
    

ag = action_group()


@ui.component
def action_menu():
    action, on_action = ui.use_state("")

    return 'Action Menu', (" - " if action else "") + action, ui.action_menu(
        ui.item(
            ui.icon('vsAccount'),
            'Aaa',
            text_value="Aaa"
        ),
        'Bbb',
        'Ccc',
        on_action=on_action,
        align_self="start"
    )
    

am = action_menu()
```

### Example showing actions in `ui.list_view` with different densities

```python
import deephaven.ui as ui
from deephaven import time_table
import datetime

initial_row_count=2000
icon_names = ['vsAccount']

columns = [
    "Id=new Integer(i)",
    "Display=new String(`Display `+i)",
    "Description=new String(`Description `+i)",
    "Icon=(String) icon_names[0]"
]
# Tables with initial row count of 200 that adds a row every second
column_types_ticking = time_table("PT1S", start_time=datetime.datetime.now() - datetime.timedelta(seconds=initial_row_count)).update([
    columns
])
column_types = empty_table(initial_row_count).update(columns)


#### Component definitions ####

@ui.component
def labeled_lv(label, *args, **kwargs):
    return ui.flex(
        ui.text(label),
        ui.list_view(
            *args,
            **kwargs
        ),
        direction="column",
        flex=1,
        min_width=0,
    )

@ui.component
def ui_list_view_table(data, density):
    value, set_value = ui.use_state([2, 4, 5])

    # Action Groups

    ag_action, set_ag_action = ui.use_state(['', ''])
    on_ag_action=ui.use_callback(lambda a,i : set_ag_action([a,str(i)]), [])

    lv_actions = labeled_lv(
        "Actions (text only)",
        data,
        density=density,
        max_height=5000,
        key_column="Id",
        label_column="Display",
        icon_column="Icon",
        aria_label="List View",
        on_change=set_value,
        selected_keys=value,
        actions=ui.list_action_group(
            'Edit',
            'Delete',
            on_action=on_ag_action,
        ),
    )

    lv_actions_icon = labeled_lv(
        "Actions (icon only)",
        data,
        density=density,
        max_height=5000,
        key_column="Id",
        label_column="Display",
        icon_column="Icon",
        aria_label="List View",
        on_change=set_value,
        selected_keys=value,
        actions=ui.list_action_group(
            ui.item(
                ui.icon('vsEdit'),
                ui.text('Edit'),
                key='Edit',
            ),
            ui.item(
                ui.icon('vsTrash'),
                ui.text('Delete'),
                key='Delete'
            ),
            max_width=80,
            button_label_behavior="collapse",
            overflow_mode="collapse",
            on_action=on_ag_action,
        ),
    )
    
    action_group_text = ui.text("Action: " + ag_action[0] + ", Item: " + ag_action[1])

    # Action Menus

    am_action, set_am_action = ui.use_state(['', ''])
    on_am_action=ui.use_callback(lambda a,i : set_am_action([a,str(i)]), [])

    lv_action_menu = labeled_lv(
        "Action Menu (text only)",
        data,
        density=density,
        max_height=5000,
        key_column="Id",
        label_column="Display",
        icon_column="Icon",
        aria_label="List View",
        selected_keys=value,
        on_change=set_value,
        actions=ui.list_action_menu(
            'Edit',
            'Delete',
            on_action=on_am_action,
        ),
    )

    lv_action_menu2 = labeled_lv(
        "Action Menu (icons)",
        data,
        density=density,
        max_height=5000,
        key_column="Id",
        label_column="Display",
        icon_column="Icon",
        aria_label="List View",
        selected_keys=value,
        on_change=set_value,
        actions=ui.list_action_menu(
             ui.item(
                ui.icon('vsEdit'),
                ui.text('Edit'),
                key='Edit',
                text_value="Edit"
            ),
            ui.item(
                ui.icon('vsTrash'),
                ui.text('Delete'),
                key='Delete',
                text_value="Delete"
            ),
            on_action=on_am_action,
        ),
    )

    action_menu_text = ui.text("Action: " + am_action[0] + ", Item: " + am_action[1])

    return ui.flex(
        ui.flex(
            lv_actions,
            lv_actions_icon,
            direction="row",
        ),
        action_group_text,
        ui.flex(
            lv_action_menu,
            lv_action_menu2,
            direction="row"
        ),
        action_menu_text,
        direction="column",
    )

@ui.component
def examples(data):
    density, set_density = ui.use_state(["COMPACT"])

    return 'Density', ui.action_group(
        'COMPACT', 
        'REGULAR', 
        'SPACIOUS',
        selected_keys=density,
        selection_mode="SINGLE",
        on_change=set_density
    ), ui_list_view_table(data, density[0])

lv_table = examples(column_types)
# lv_table = examples(column_types_ticking)
```
@bmingles bmingles force-pushed the 445-list-view-actions branch from 9acde26 to 39e0210 Compare May 17, 2024 16:15
@bmingles bmingles force-pushed the 445-list-view-actions branch from 39e0210 to c11bb1c Compare May 21, 2024 14:55
@bmingles bmingles marked this pull request as ready for review May 21, 2024 15:23
@bmingles bmingles changed the title feat: DRAFT ListView actions feat: ListView actions May 21, 2024
@bmingles bmingles requested a review from mofojed May 21, 2024 17:42
plugins/ui/docs/README.md Outdated Show resolved Hide resolved
plugins/ui/docs/README.md Outdated Show resolved Hide resolved
Comment on lines +4 to +12
def action_group(*children, **props):
"""
An ActionGroup is a grouping of ActionButtons that are related to one another.

Args:
children: A list of Item or primitive elements.
**props: Any other ActionGroup prop.
"""
return BaseElement(f"deephaven.ui.components.ActionGroup", *children, **props)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a follow-up TODO to explicitly add/document the props for this. @AkshatJawne could take that on, get him exposed to updating some Python code in a plugin.

@AkshatJawne as a precursor to what I mean, it would be similar to this change: https://github.com/deephaven/deephaven-plugins/pull/306/files
Right now this code accepts any keyword argument, but we want to explicitly add any prop that can be used and document it. They would generally map to the same props that are available on the UI component this maps to (in this case, the Spectrum ActionGroup).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will take a look and get started!

plugins/ui/src/js/src/elements/ElementConstants.ts Outdated Show resolved Hide resolved
@bmingles bmingles requested a review from mofojed May 21, 2024 21:24
@bmingles
Copy link
Contributor Author

@mofojed I made suggested changes and created follow up tickets for the pydocs.

@AkshatJawne AkshatJawne mentioned this pull request May 22, 2024
@bmingles bmingles merged commit ca65b69 into deephaven:main May 23, 2024
13 checks passed
@bmingles bmingles deleted the 445-list-view-actions branch May 23, 2024 16:46
@AkshatJawne AkshatJawne mentioned this pull request May 23, 2024
AkshatJawne added a commit that referenced this pull request May 24, 2024
Resolves #482

Changes Implemented:
- Added documentation for `action_menu` introduced in
#448
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui.list_view - action support
3 participants