-
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.
- Loading branch information
Showing
2 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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 GitHub Actions / test-js / unit
|
||
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; |
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