Skip to content

Commit

Permalink
Improved selectionmode handling (deephaven#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Apr 17, 2024
1 parent e8caad1 commit 09b50b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion plugins/ui/src/deephaven/ui/components/list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .list_action_menu import ListActionMenuElement
from ..elements import BaseElement, Element
from .._internal.utils import create_props
from ..types import ColumnName, Stringable, Selection
from ..types import ColumnName, Stringable, Selection, SelectionMode

ListViewItem = Union[Stringable, ItemElement]
ListViewElement = Element
Expand All @@ -24,6 +24,7 @@ def list_view(
actions: ListActionGroupElement | ListActionMenuElement | None = None,
default_selected_keys: Selection | None = None,
selected_keys: Selection | None = None,
selection_mode: SelectionMode | None = "MULTIPLE",
render_empty_state: Element | None = None,
on_selection_change: Callable[[Selection], None] | None = None,
on_change: Callable[[Selection], None] | None = None,
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
Expand Up @@ -97,7 +97,8 @@ class RowDataValue(CellData):
ColumnData = List[Any]
TableData = Dict[ColumnName, ColumnData]
SearchMode = Literal["SHOW", "HIDE", "DEFAULT"]
SelectionMode = Literal["CELL", "ROW", "COLUMN"]
SelectionArea = Literal["CELL", "ROW", "COLUMN"]
SelectionMode = Literal["SINGLE", "MULTIPLE"]
Sentinel = Any
TransformedData = Any
StringSortDirection = Literal["ASC", "DESC"]
Expand Down
37 changes: 31 additions & 6 deletions plugins/ui/src/js/src/elements/ListView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactElement } from 'react';
import { useSelector } from 'react-redux';
import type { SelectionMode } from '@react-types/shared';
import { isElementOfType } from '@deephaven/react-hooks';
import { getSettings, RootState } from '@deephaven/redux';
import {
Expand All @@ -21,27 +22,51 @@ type WrappedDHListViewJSApiProps = Omit<DHListViewJSApiProps, 'table'> & {
children: ReactElement<ObjectViewProps>;
};

export type ListViewProps = (DHListViewProps | WrappedDHListViewJSApiProps) &
type WrappedDHListViewProps = Omit<DHListViewProps, 'selectionMode'> & {
// The spec specifies that selectionMode should be uppercase, but the Spectrum
// prop is lowercase. We'll accept either to keep things more flexible.s
selectionMode?: SelectionMode | Uppercase<SelectionMode>;
};

export type ListViewProps = (
| WrappedDHListViewProps
| WrappedDHListViewJSApiProps
) &
SerializedListViewEventProps;

function ListView({ children, ...props }: ListViewProps) {
function ListView({ children, selectionMode, ...props }: ListViewProps) {
const settings = useSelector(getSettings<RootState>);
const listViewProps = useListViewProps(props);

const isObjectView = isElementOfType(children, ObjectView);
const table = useReExportedTable(children);

const selectionModeLc = (selectionMode?.toLowerCase() ??
'none') as SelectionMode;

if (isObjectView) {
return (
table && (
// eslint-disable-next-line react/jsx-props-no-spreading
<DHListViewJSApi {...listViewProps} table={table} settings={settings} />
<DHListViewJSApi
// eslint-disable-next-line react/jsx-props-no-spreading
{...listViewProps}
selectionMode={selectionModeLc}
table={table}
settings={settings}
/>
)
);
}

// eslint-disable-next-line react/jsx-props-no-spreading
return <DHListView {...listViewProps}>{children}</DHListView>;
return (
<DHListView
// eslint-disable-next-line react/jsx-props-no-spreading
{...listViewProps}
selectionMode={selectionModeLc}
>
{children}
</DHListView>
);
}

export default ListView;

0 comments on commit 09b50b0

Please sign in to comment.