-
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.
ui.list_view - basic items + table support resolves #366
- Loading branch information
Showing
15 changed files
with
913 additions
and
591 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
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] | ||
); | ||
} |
Oops, something went wrong.