Skip to content

feat: UI ComboBox component#588

Merged
bmingles merged 5 commits intodeephaven:mainfrom
bmingles:201-ui-combobox
Jul 9, 2024
Merged

feat: UI ComboBox component#588
bmingles merged 5 commits intodeephaven:mainfrom
bmingles:201-ui-combobox

Conversation

@bmingles
Copy link
Copy Markdown
Contributor

@bmingles bmingles commented Jun 27, 2024

ui.combo_box

Testing

from deephaven import ui


@ui.component
def ui_combo_box():
    value, set_value = ui.use_state("")

    combo = ui.combo_box(
        "Text 1",
        "Text 2",
        "Text 3",
        label="Text",
        on_selection_change=set_value,
        selected_key=value,
    )

    text = ui.text("Selection: " + str(value))

    return combo, text


my_combo_box = ui_combo_box()
import deephaven.ui as ui
from deephaven import time_table
import datetime

# Ticking table with initial row count of 200 that adds a row every second
initial_row_count = 200
_table = time_table(
    "PT1S",
    start_time=datetime.datetime.now() - datetime.timedelta(seconds=initial_row_count),
).update(
    [
        "Id=new Integer(i)",
        "Display=new String(`Display `+i)",
    ]
)


@ui.component
def ui_combo_box_item_table_source(table):
    value, set_value = ui.use_state("")

    combo = ui.combo_box(
        ui.item_table_source(table, key_column="Id", label_column="Display"),
        label="Text",
        on_change=set_value,
        selected_key=value,
    )

    text = ui.text(f"Selection: {value}")

    return combo, text


my_combo_box_item_table_source = ui_combo_box_item_table_source(_table)

resolves #201

Comment thread plugins/ui/src/deephaven/ui/components/combo_box.py Outdated
bmingles added a commit to deephaven/web-client-ui that referenced this pull request Jul 3, 2024
Jsapi support for ComboBox. Includes some splitting out of existing
Picker logic to make code re-usable.

Should be testable with plugins PR
deephaven/deephaven-plugins#588
I have also deployed an alpha
[0.83.1-alpha-combobox.8](https://www.npmjs.com/package/@deephaven/components/v/0.83.1-alpha-combobox.8)
if you need it, although should only matter for types I think.

```python
from deephaven import empty_table, ui, time_table
import datetime


# Change this to test different data types
key_column="Timestamp"


initial_row_count=5 * 8760 # 5 years in hours

# Tick every 6 hours (makes it easier to test Timestamp filters for a whole day like `2024-01-02`)
_items = time_table("PT6H", start_time=datetime.datetime.now() - datetime.timedelta(hours=initial_row_count)).update([
    # Timestamp column also implicitly included in `time_table`
    "Int=new Integer(i)",
    "Long=new Long(i)",
    "BigInt=new java.math.BigInteger(``+i)",
    "String=new String(`a`+i * 1000)",
])


@ui.component
def ui_combo_box(items):
    value, set_value = ui.use_state("")

    combo = ui.combo_box(
        ui.item_table_source(
            items,
            key_column=key_column,
            label_column=key_column,
        ),
        label=key_column,
        on_selection_change=set_value,
        menu_trigger="focus",
        selected_key=value,
    )

    # Show current selection in a ui.text component
    text = ui.text("Selection: " + str(value))

    return combo, text


my_combo_box = ui_combo_box(_items)
```

There is a known issue with inconsistent open as you type for table data
sources.
#2115

resolves #2074
@bmingles bmingles force-pushed the 201-ui-combobox branch 2 times, most recently from c95cea5 to 1e4140f Compare July 5, 2024 16:23
@bmingles bmingles marked this pull request as ready for review July 5, 2024 21:17
@bmingles bmingles requested a review from mofojed July 8, 2024 13:50
Copy link
Copy Markdown
Member

@mofojed mofojed left a comment

Choose a reason for hiding this comment

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

Minor change, looks good

Comment thread plugins/ui/docs/README.md Outdated
Co-authored-by: Mike Bender <mikebender@deephaven.io>
@bmingles bmingles requested a review from mofojed July 9, 2024 14:23
@bmingles bmingles merged commit 0564299 into deephaven:main Jul 9, 2024
@bmingles bmingles deleted the 201-ui-combobox branch July 9, 2024 19:23
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.

Combobox

2 participants