Skip to content

Commit 6ed5e6f

Browse files
committed
Cleanup
1 parent a172040 commit 6ed5e6f

2 files changed

Lines changed: 47 additions & 46 deletions

File tree

packages/dashboard-core-plugins/src/WidgetLoaderPlugin.tsx

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ import {
1616
isWidgetPlugin,
1717
isWidgetMiddlewarePlugin,
1818
createChainedComponent,
19+
createChainedPanelComponent,
1920
usePlugins,
2021
type WidgetPlugin,
2122
type WidgetMiddlewarePlugin,
22-
type WidgetPanelProps,
23-
type WidgetMiddlewarePanelProps,
2423
} from '@deephaven/plugin';
2524
import { WidgetPanel } from './panels';
2625
import { type WidgetPanelDescriptor } from './panels/WidgetPanelTypes';
@@ -37,50 +36,6 @@ interface WidgetTypeInfo {
3736
middleware: WidgetMiddlewarePlugin[];
3837
}
3938

40-
/**
41-
* Creates a panel component that chains middleware around a base panel component.
42-
* Each middleware panel wraps the next, with the base panel at the innermost layer.
43-
*/
44-
function createChainedPanelComponent<T>(
45-
basePanelComponent: React.ComponentType<WidgetPanelProps<T>>,
46-
middleware: WidgetMiddlewarePlugin<T>[]
47-
): React.ComponentType<WidgetPanelProps<T>> {
48-
// Filter to middleware that has a panelComponent and extract just the panel components
49-
type MiddlewareWithPanel = WidgetMiddlewarePlugin<T> & {
50-
panelComponent: React.ComponentType<WidgetMiddlewarePanelProps<T>>;
51-
};
52-
const panelMiddleware = middleware.filter(
53-
(m): m is MiddlewareWithPanel => m.panelComponent != null
54-
);
55-
56-
if (panelMiddleware.length === 0) {
57-
return basePanelComponent;
58-
}
59-
60-
// Build the chain from inside out (base panel is innermost)
61-
return [...panelMiddleware]
62-
.reverse()
63-
.reduce<React.ComponentType<WidgetPanelProps<T>>>(
64-
(WrappedPanel, middlewarePlugin) => {
65-
const { panelComponent: MiddlewarePanelComponent } = middlewarePlugin;
66-
67-
function ChainedPanel(props: WidgetPanelProps<T>) {
68-
return (
69-
// eslint-disable-next-line react/jsx-props-no-spreading
70-
<MiddlewarePanelComponent {...props} Component={WrappedPanel} />
71-
);
72-
}
73-
ChainedPanel.displayName = `${middlewarePlugin.name}Panel(${
74-
(WrappedPanel as React.ComponentType).displayName ??
75-
(WrappedPanel as React.ComponentType).name ??
76-
'Panel'
77-
})`;
78-
return ChainedPanel;
79-
},
80-
basePanelComponent
81-
);
82-
}
83-
8439
export function WrapWidgetPlugin(
8540
plugin: WidgetPlugin
8641
): React.ForwardRefExoticComponent<PanelProps & React.RefAttributes<unknown>> {

packages/plugin/src/PluginUtils.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
type ElementMap,
1515
type WidgetMiddlewarePlugin,
1616
type WidgetComponentProps,
17+
type WidgetPanelProps,
18+
type WidgetMiddlewarePanelProps,
1719
} from './PluginTypes';
1820

1921
const log = Log.module('@deephaven/plugin.PluginUtils');
@@ -136,3 +138,47 @@ export function createChainedComponent<T>(
136138
baseComponent
137139
);
138140
}
141+
142+
/**
143+
* Creates a panel component that chains middleware around a base panel component.
144+
* Each middleware panel wraps the next, with the base panel at the innermost layer.
145+
*/
146+
export function createChainedPanelComponent<T>(
147+
basePanelComponent: React.ComponentType<WidgetPanelProps<T>>,
148+
middleware: WidgetMiddlewarePlugin<T>[]
149+
): React.ComponentType<WidgetPanelProps<T>> {
150+
// Filter to middleware that has a panelComponent and extract just the panel components
151+
type MiddlewareWithPanel = WidgetMiddlewarePlugin<T> & {
152+
panelComponent: React.ComponentType<WidgetMiddlewarePanelProps<T>>;
153+
};
154+
const panelMiddleware = middleware.filter(
155+
(m): m is MiddlewareWithPanel => m.panelComponent != null
156+
);
157+
158+
if (panelMiddleware.length === 0) {
159+
return basePanelComponent;
160+
}
161+
162+
// Build the chain from inside out (base panel is innermost)
163+
return [...panelMiddleware]
164+
.reverse()
165+
.reduce<React.ComponentType<WidgetPanelProps<T>>>(
166+
(WrappedPanel, middlewarePlugin) => {
167+
const { panelComponent: MiddlewarePanelComponent } = middlewarePlugin;
168+
169+
function ChainedPanel(props: WidgetPanelProps<T>) {
170+
return (
171+
// eslint-disable-next-line react/jsx-props-no-spreading
172+
<MiddlewarePanelComponent {...props} Component={WrappedPanel} />
173+
);
174+
}
175+
ChainedPanel.displayName = `${middlewarePlugin.name}Panel(${
176+
(WrappedPanel as React.ComponentType).displayName ??
177+
(WrappedPanel as React.ComponentType).name ??
178+
'Panel'
179+
})`;
180+
return ChainedPanel;
181+
},
182+
basePanelComponent
183+
);
184+
}

0 commit comments

Comments
 (0)