-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into 1949-errors-not-visible
- Loading branch information
Showing
14 changed files
with
4,101 additions
and
13,507 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,40 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { isElementOfType } from '@deephaven/react-hooks'; | ||
import { getSettings, RootState } from '@deephaven/redux'; | ||
import { ListView as DHListView } from '@deephaven/components'; | ||
import { ListView as DHListViewJSApi } from '@deephaven/jsapi-components'; | ||
import { SerializedListViewProps, useListViewProps } from './useListViewProps'; | ||
import ObjectView from './ObjectView'; | ||
import useReExportedTable from './useReExportedTable'; | ||
|
||
function ListView(props: SerializedListViewProps): JSX.Element | null { | ||
const settings = useSelector(getSettings<RootState>); | ||
const { children, ...listViewProps } = useListViewProps(props); | ||
|
||
const isObjectView = isElementOfType(children, ObjectView); | ||
const table = useReExportedTable(children); | ||
|
||
if (isObjectView) { | ||
return ( | ||
table && ( | ||
<DHListViewJSApi | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...listViewProps} | ||
table={table} | ||
settings={settings} | ||
/> | ||
) | ||
); | ||
} | ||
|
||
return ( | ||
<DHListView | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...listViewProps} | ||
> | ||
{children} | ||
</DHListView> | ||
); | ||
} | ||
|
||
export default ListView; |
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
42 changes: 42 additions & 0 deletions
42
plugins/ui/src/js/src/elements/spectrum/useSelectionEventCallback.ts
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,42 @@ | ||
import type { ItemKey, ItemSelection } from '@deephaven/components'; | ||
import { useCallback } from 'react'; | ||
|
||
export type SerializedSelection = 'all' | ItemKey[]; | ||
|
||
export type SerializedSelectionEventCallback = ( | ||
event: SerializedSelection | ||
) => void; | ||
|
||
/** | ||
* Selection can be 'all' or a Set of keys. If it is a Set, serialize it as an | ||
* array. | ||
* @param selection Selection to serialize | ||
* @returns Serialized selection | ||
*/ | ||
export function serializeSelectionEvent( | ||
selection: ItemSelection | ||
): SerializedSelection { | ||
if (selection instanceof Set) { | ||
return [...selection]; | ||
} | ||
|
||
return selection; | ||
} | ||
|
||
/** | ||
* Get a callback function that can be passed to selection change event handler | ||
* props of Spectrum components. | ||
* @param callback Callback to be called with the serialized selection | ||
* @returns A callback to be passed into the Spectrum component that transforms | ||
* the selection and calls the provided callback | ||
*/ | ||
export function useSelectionEventCallback( | ||
callback?: SerializedSelectionEventCallback | ||
): (selection: ItemSelection) => void { | ||
return useCallback( | ||
(selection: ItemSelection) => { | ||
callback?.(serializeSelectionEvent(selection)); | ||
}, | ||
[callback] | ||
); | ||
} |
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,76 @@ | ||
import { ReactElement } from 'react'; | ||
import type { SelectionMode } from '@react-types/shared'; | ||
import { ListViewProps as DHListViewProps } from '@deephaven/components'; | ||
import { ListViewProps as DHListViewJSApiProps } from '@deephaven/jsapi-components'; | ||
import { ObjectViewProps } from './ObjectView'; | ||
import { | ||
SerializedSelectionEventCallback, | ||
useSelectionEventCallback, | ||
} from './spectrum/useSelectionEventCallback'; | ||
|
||
type Density = Required<DHListViewProps>['density']; | ||
|
||
type WrappedDHListViewJSApiProps = Omit<DHListViewJSApiProps, 'table'> & { | ||
children: ReactElement<ObjectViewProps>; | ||
}; | ||
|
||
type WrappedDHListViewProps = Omit< | ||
DHListViewProps, | ||
'density' | 'selectionMode' | ||
> & { | ||
// The dh UI spec specifies that density and selectionMode should be uppercase, | ||
// but the Spectrum props are lowercase. We'll accept either to keep things | ||
// more flexible. | ||
density?: Density | Uppercase<Density>; | ||
selectionMode?: SelectionMode | Uppercase<SelectionMode>; | ||
}; | ||
|
||
export interface SerializedListViewEventProps { | ||
/** Handler that is called when selection changes */ | ||
onChange?: SerializedSelectionEventCallback; | ||
|
||
/** | ||
* Handler that is called when the selection changes. | ||
* @deprecated Use `onChange` instead | ||
*/ | ||
onSelectionChange?: SerializedSelectionEventCallback; | ||
} | ||
|
||
export type SerializedListViewProps = ( | ||
| WrappedDHListViewProps | ||
| WrappedDHListViewJSApiProps | ||
) & | ||
SerializedListViewEventProps; | ||
|
||
/** | ||
* Wrap ListView props with the appropriate serialized event callbacks. | ||
* @param props Props to wrap | ||
* @returns Wrapped props | ||
*/ | ||
export function useListViewProps({ | ||
density, | ||
selectionMode, | ||
onChange, | ||
onSelectionChange, | ||
...otherProps | ||
}: SerializedListViewProps): DHListViewProps | WrappedDHListViewJSApiProps { | ||
const densityLc = density?.toLowerCase() as Density; | ||
const selectionModeLc = selectionMode?.toLowerCase() as SelectionMode; | ||
|
||
const serializedOnChange = useSelectionEventCallback(onChange); | ||
const serializedOnSelectionChange = | ||
useSelectionEventCallback(onSelectionChange); | ||
|
||
return { | ||
density: densityLc, | ||
selectionMode: selectionModeLc, | ||
onChange: onChange == null ? undefined : serializedOnChange, | ||
onSelectionChange: | ||
onSelectionChange == null ? undefined : serializedOnSelectionChange, | ||
// The @deephaven/components `ListView` has its own normalization logic that | ||
// handles primitive children types (string, number, boolean). It also | ||
// handles nested children inside of `Item` and `Section` components, so | ||
// we are intentionally not wrapping `otherProps` in `mapSpectrumProps` | ||
...otherProps, | ||
}; | ||
} |
Oops, something went wrong.