Skip to content

Commit

Permalink
useReExportedTable (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Apr 8, 2024
1 parent e73556c commit 696506e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
19 changes: 4 additions & 15 deletions plugins/ui/src/js/src/elements/ListView.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import React, { ReactElement } from 'react';
import { useSelector } from 'react-redux';
import { isElementOfType } from '@deephaven/react-hooks';
import { getSettings, RootState } from '@deephaven/redux';
import {
ListView as DHListView,
ListViewProps as DHListViewProps,
} from '@deephaven/components';
import {
ListView as DHListViewJSApi,
ListViewProps as DHListViewJSApiProps,
useTableClose,
} from '@deephaven/jsapi-components';
import { isElementOfType, usePromiseFactory } from '@deephaven/react-hooks';
import { getSettings, RootState } from '@deephaven/redux';
import {
SerializedListViewEventProps,
useListViewProps,
} from './useListViewProps';
import ObjectView, { ObjectViewProps } from './ObjectView';
import { fetchReexportedTable } from './ElementUtils';
import useReExportedTable from './useReExportedTable';

type WrappedDHListViewJSApiProps = Omit<DHListViewJSApiProps, 'table'> & {
children: ReactElement<ObjectViewProps>;
Expand All @@ -30,17 +29,7 @@ function ListView({ children, ...props }: ListViewProps) {
const listViewProps = useListViewProps(props);

const isObjectView = isElementOfType(children, ObjectView);

const maybeExportedTable =
isObjectView && children.props.object.type === 'Table'
? children.props.object
: null;

const { data: table } = usePromiseFactory(fetchReexportedTable, [
maybeExportedTable,
]);

useTableClose(table);
const table = useReExportedTable(children);

if (isObjectView) {
return (
Expand Down
17 changes: 3 additions & 14 deletions plugins/ui/src/js/src/elements/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import {
import {
Picker as DHPickerJSApi,
PickerProps as DHPickerJSApiProps,
useTableClose,
} from '@deephaven/jsapi-components';
import { isElementOfType, usePromiseFactory } from '@deephaven/react-hooks';
import { isElementOfType } from '@deephaven/react-hooks';
import { getSettings, RootState } from '@deephaven/redux';
import { SerializedPickerEventProps, usePickerProps } from './usePickerProps';
import ObjectView, { ObjectViewProps } from './ObjectView';
import { fetchReexportedTable } from './ElementUtils';
import useReExportedTable from './useReExportedTable';

type WrappedDHPickerJSApiProps = Omit<DHPickerJSApiProps, 'table'> & {
children: ReactElement<ObjectViewProps>;
Expand All @@ -27,17 +26,7 @@ function Picker({ children, ...props }: PickerProps) {
const pickerProps = usePickerProps(props);

const isObjectView = isElementOfType(children, ObjectView);

const maybeExportedTable =
isObjectView && children.props.object.type === 'Table'
? children.props.object
: null;

const { data: table } = usePromiseFactory(fetchReexportedTable, [
maybeExportedTable,
]);

useTableClose(table);
const table = useReExportedTable(children);

if (isObjectView) {
return (
Expand Down
25 changes: 25 additions & 0 deletions plugins/ui/src/js/src/elements/useReExportedTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ReactNode } from 'react';
import { useTableClose } from '@deephaven/jsapi-components';
import type { dh } from '@deephaven/jsapi-types';
import { isElementOfType, usePromiseFactory } from '@deephaven/react-hooks';
import ObjectView from './ObjectView';
import { fetchReexportedTable } from './ElementUtils';

export function useReExportedTable(node: ReactNode): dh.Table | null {
const isObjectView = isElementOfType(node, ObjectView);

const maybeExportedTable =
isObjectView && node.props.object.type === 'Table'
? node.props.object
: null;

const { data: table } = usePromiseFactory(fetchReexportedTable, [
maybeExportedTable,
]);

useTableClose(table);

return table;
}

export default useReExportedTable;

0 comments on commit 696506e

Please sign in to comment.