Skip to content

Commit

Permalink
Picker table support (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Mar 22, 2024
1 parent 09c8eec commit 3c86c7d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
51 changes: 45 additions & 6 deletions plugins/ui/src/js/src/elements/Picker.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Picker as DHPicker } from '@deephaven/components';
import {
Picker as DHPicker,
PickerProps as DHPickerProps,
} from '@deephaven/components';
Picker as DHPickerJSApi,
PickerProps as DHPickerJSApiProps,
} from '@deephaven/jsapi-components';
import type { Table } from '@deephaven/jsapi-types';
import { SerializedPickerEventProps, usePickerProps } from './usePickerProps';

function Picker(props: DHPickerProps & SerializedPickerEventProps) {
function Picker({
children,
...props
}: DHPickerJSApiProps & SerializedPickerEventProps) {
const pickerProps = usePickerProps(props);
const [table, setTable] = React.useState<Table | null>(null);

const maybeExportedObject = children?.props?.object;

useEffect(() => {
if (maybeExportedObject == null) {
return;
}

let isMounted = true;
async function load() {
console.log('[TESTING] exportedTable:', maybeExportedObject);

Check warning on line 26 in plugins/ui/src/js/src/elements/Picker.tsx

View workflow job for this annotation

GitHub Actions / test-js / unit

Unexpected console statement

Check warning on line 26 in plugins/ui/src/js/src/elements/Picker.tsx

View workflow job for this annotation

GitHub Actions / test-js / unit

Unexpected console statement
const reexportedTable = await maybeExportedObject.reexport();
const newTable = await reexportedTable.fetch<Table>();

if (!isMounted) {
return;
}

setTable(newTable);
}

load();

return () => {
isMounted = false;
};
}, [maybeExportedObject]);

if (maybeExportedObject == null) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <DHPicker {...pickerProps}>{children}</DHPicker>;
}

const { children: _throwAway, ...restProps } = pickerProps;
// eslint-disable-next-line react/jsx-props-no-spreading
return <DHPicker {...pickerProps} />;
return table && <DHPickerJSApi {...restProps} table={table} />;
}

export default Picker;
3 changes: 3 additions & 0 deletions plugins/ui/src/js/src/elements/usePickerProps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ObjectView from './ObjectView';
import {
SerializedFocusEventCallback,
useFocusEventCallback,
Expand All @@ -8,6 +9,8 @@ import {
} from './spectrum/useKeyboardEventCallback';

export interface SerializedPickerEventProps {
children: typeof ObjectView;

/** Handler that is called when the element receives focus. */
onFocus?: SerializedFocusEventCallback;

Expand Down

0 comments on commit 3c86c7d

Please sign in to comment.