|
1 | | -import { useCallback } from 'react'; |
2 | | -import { |
3 | | - assertIsDashboardPluginProps, |
4 | | - DashboardPluginComponentProps, |
5 | | - DehydratedDashboardPanelProps, |
6 | | - useDashboardPanel, |
7 | | -} from '@deephaven/dashboard'; |
| 1 | +import { forwardRef, useMemo } from 'react'; |
8 | 2 | import { useApi } from '@deephaven/jsapi-bootstrap'; |
9 | 3 | import { useConnection } from '@deephaven/jsapi-components'; |
10 | 4 | import { ChartModel, ChartModelFactory } from '@deephaven/chart'; |
11 | 5 | import type { dh as DhType, IdeConnection } from '@deephaven/jsapi-types'; |
12 | 6 | import { IrisGridUtils } from '@deephaven/iris-grid'; |
13 | 7 | import { getTimeZone, store } from '@deephaven/redux'; |
| 8 | +import { type WidgetComponentProps } from '@deephaven/plugin'; |
14 | 9 | import { |
15 | | - ChartPanel, |
16 | 10 | ChartPanelMetadata, |
17 | 11 | GLChartPanelState, |
18 | 12 | isChartPanelDehydratedProps, |
19 | 13 | isChartPanelTableMetadata, |
20 | 14 | } from './panels'; |
| 15 | +import ConnectedChartPanel, { |
| 16 | + type ChartPanel, |
| 17 | + type ChartPanelProps, |
| 18 | +} from './panels/ChartPanel'; |
21 | 19 |
|
22 | 20 | async function createChartModel( |
23 | 21 | dh: DhType, |
@@ -86,41 +84,41 @@ async function createChartModel( |
86 | 84 | return ChartModelFactory.makeModelFromSettings(dh, settings as any, table); |
87 | 85 | } |
88 | 86 |
|
89 | | -export function ChartPlugin( |
90 | | - props: DashboardPluginComponentProps |
91 | | -): JSX.Element | null { |
92 | | - assertIsDashboardPluginProps(props); |
93 | | - const dh = useApi(); |
94 | | - const connection = useConnection(); |
| 87 | +export const ChartPlugin = forwardRef( |
| 88 | + (props: WidgetComponentProps, ref: React.Ref<ChartPanel>) => { |
| 89 | + const dh = useApi(); |
| 90 | + const connection = useConnection(); |
95 | 91 |
|
96 | | - const hydrate = useCallback( |
97 | | - (hydrateProps: DehydratedDashboardPanelProps, id: string) => ({ |
98 | | - ...hydrateProps, |
99 | | - localDashboardId: id, |
100 | | - makeModel: () => { |
101 | | - const { metadata } = hydrateProps; |
102 | | - const panelState = isChartPanelDehydratedProps(hydrateProps) |
103 | | - ? hydrateProps.panelState |
104 | | - : undefined; |
105 | | - if (metadata == null) { |
106 | | - throw new Error('Metadata is required for chart panel'); |
107 | | - } |
| 92 | + const hydratedProps = useMemo( |
| 93 | + () => ({ |
| 94 | + ...(props as unknown as ChartPanelProps), |
| 95 | + metadata: props.metadata as ChartPanelMetadata, |
| 96 | + localDashboardId: props.localDashboardId, |
| 97 | + makeModel: () => { |
| 98 | + const { metadata } = props; |
| 99 | + const panelState = isChartPanelDehydratedProps(props) |
| 100 | + ? (props as unknown as ChartPanelProps).panelState |
| 101 | + : undefined; |
| 102 | + if (metadata == null) { |
| 103 | + throw new Error('Metadata is required for chart panel'); |
| 104 | + } |
108 | 105 |
|
109 | | - return createChartModel(dh, connection, metadata, panelState); |
110 | | - }, |
111 | | - }), |
112 | | - [dh, connection] |
113 | | - ); |
| 106 | + return createChartModel( |
| 107 | + dh, |
| 108 | + connection, |
| 109 | + metadata as ChartPanelMetadata, |
| 110 | + panelState |
| 111 | + ); |
| 112 | + }, |
| 113 | + }), |
| 114 | + [dh, connection, props] |
| 115 | + ); |
114 | 116 |
|
115 | | - useDashboardPanel({ |
116 | | - dashboardProps: props, |
117 | | - componentName: ChartPanel.COMPONENT, |
118 | | - component: ChartPanel, |
119 | | - supportedTypes: dh.VariableType.FIGURE, |
120 | | - hydrate, |
121 | | - }); |
| 117 | + // eslint-disable-next-line react/jsx-props-no-spreading |
| 118 | + return <ConnectedChartPanel ref={ref} {...hydratedProps} />; |
| 119 | + } |
| 120 | +); |
122 | 121 |
|
123 | | - return null; |
124 | | -} |
| 122 | +ChartPlugin.displayName = 'ChartPlugin'; |
125 | 123 |
|
126 | 124 | export default ChartPlugin; |
0 commit comments