-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ComboBox - @deephaven/jsapi-components (#2077)
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
- Loading branch information
Showing
10 changed files
with
285 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
export { | ||
ActionBar, | ||
type SpectrumActionBarProps as ActionBarProps, | ||
// ComboBox is exported from ComboBox.tsx as a custom DH component. Re-exporting | ||
// the Spectrum props type for upstream consumers that need to compose prop types. | ||
type SpectrumComboBoxProps, | ||
// ListBox - we aren't planning to support this component | ||
MenuTrigger, | ||
type SpectrumMenuTriggerProps as MenuTriggerProps, | ||
// TableView - we aren't planning to support this component | ||
// Picker is exported from Picker.tsx as a custom DH component. Re-exporting | ||
// the Spectrum props type for upstream consumers that need to compose prop types. | ||
type SpectrumPickerProps, | ||
TagGroup, | ||
type SpectrumTagGroupProps as TagGroupProps, | ||
} from '@adobe/react-spectrum'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
ComboBoxNormalized, | ||
NormalizedItem, | ||
SpectrumComboBoxProps, | ||
} from '@deephaven/components'; | ||
import { useCallback } from 'react'; | ||
import { PickerWithTableProps } from './PickerProps'; | ||
import { usePickerProps } from './utils'; | ||
|
||
export type ComboBoxProps = PickerWithTableProps< | ||
SpectrumComboBoxProps<NormalizedItem> | ||
>; | ||
|
||
export function ComboBox(props: ComboBoxProps): JSX.Element { | ||
const { | ||
onInputChange: onInputChangeInternal, | ||
onSearchTextChange, | ||
...pickerProps | ||
} = usePickerProps<ComboBoxProps>(props); | ||
|
||
const onInputChange = useCallback( | ||
(value: string) => { | ||
onInputChangeInternal?.(value); | ||
onSearchTextChange(value); | ||
}, | ||
[onInputChangeInternal, onSearchTextChange] | ||
); | ||
|
||
return ( | ||
<ComboBoxNormalized | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...pickerProps} | ||
onInputChange={onInputChange} | ||
/> | ||
); | ||
} | ||
|
||
export default ComboBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
NormalizedItem, | ||
PickerPropsT, | ||
SpectrumPickerProps, | ||
} from '@deephaven/components'; | ||
import { dh as DhType } from '@deephaven/jsapi-types'; | ||
import { Settings } from '@deephaven/jsapi-utils'; | ||
|
||
export type PickerWithTableProps<TProps> = Omit< | ||
PickerPropsT<TProps>, | ||
'children' | ||
> & { | ||
table: DhType.Table; | ||
/* The column of values to use as item keys. Defaults to the first column. */ | ||
keyColumn?: string; | ||
/* The column of values to display as primary text. Defaults to the `keyColumn` value. */ | ||
labelColumn?: string; | ||
|
||
/* The column of values to map to icons. */ | ||
iconColumn?: string; | ||
|
||
settings?: Settings; | ||
}; | ||
|
||
export type PickerProps = PickerWithTableProps< | ||
SpectrumPickerProps<NormalizedItem> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './ComboBox'; | ||
export * from './ListView'; | ||
export * from './Picker'; | ||
export * from './PickerProps'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './itemUtils'; | ||
export * from './useItemRowDeserializer'; | ||
export * from './usePickerProps'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.