feat: DH-22891: Example middleware plugin#1372
Conversation
## feat: DH-22891: Example middleware plugin
Adds `table-middleware-example`, a minimal `WidgetMiddlewarePlugin`
demonstrating how a middleware plugin is inserted into a widget's render
chain and how it can **wrap** the next component and **inject** custom
props — with no coupling to IrisGrid or any other specific widget.
### What it does
- A single shared body hook (`exampleMiddlewareBody`) returning `{
inject, wrap }`: injects a custom `exampleInjectedProp` and wraps the
wrapped component in an `ExampleMiddlewareContext.Provider` plus a small
"Wrapped by example middleware" banner.
- The one body hook drives both middleware paths via the
`@deephaven/plugin` factories: `createWidgetMiddleware` (non-panel /
dashboard) and `createPanelMiddleware` (panel path, which preserves
golden-layout's panel ref so `componentState` persistence stays intact).
- Wired up as a `PluginType.MIDDLEWARE_PLUGIN` with `supportedTypes:
['Table', 'TreeTable', 'HierarchicalTable', 'PartitionedTable']`,
registered in `plugins/manifest.json`.
…-options-middleware-example
…-options-middleware-example
…-options-middleware-example
There was a problem hiding this comment.
Pull request overview
This PR adds a new example plugin, table-middleware-example, under plugins/table-middleware-example/src/js. It demonstrates the WidgetMiddlewarePlugin mechanism: a middleware component is inserted into a widget's render chain (for Table, TreeTable, HierarchicalTable, and PartitionedTable) and can inject custom props onto the next component and wrap it (here, with a context provider and a small banner). A single shared body hook (exampleMiddlewareBody) drives both the non-panel widget path (createWidgetMiddleware) and the ref-preserving panel path (createPanelMiddleware). The plugin is intentionally minimal and decoupled from IrisGrid, serving as documentation-by-example for the new middleware API in @deephaven/plugin.
Changes:
- Adds a shared
exampleMiddlewareBodyreturning{ inject, wrap }, plusExampleWidgetMiddleware/ExamplePanelMiddlewarebuilt from it via the@deephaven/pluginfactories. - Registers everything as a
PluginType.MIDDLEWARE_PLUGIN(ExampleMiddlewarePlugin) with a small context (ExampleMiddlewareContext) and barrel exports. - Adds standard plugin scaffolding (package.json, vite.config.ts, README, LICENSE, .gitignore) and a
package-lock.jsonworkspace link entry.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
plugins/table-middleware-example/src/js/src/exampleMiddlewareBody.tsx |
Shared body hook implementing inject and wrap behavior. |
plugins/table-middleware-example/src/js/src/ExampleWidgetMiddleware.tsx |
Non-panel widget middleware built via createWidgetMiddleware. |
plugins/table-middleware-example/src/js/src/ExamplePanelMiddleware.tsx |
Panel-path middleware built via createPanelMiddleware (ref-forwarding). |
plugins/table-middleware-example/src/js/src/ExampleMiddlewarePlugin.ts |
WidgetMiddlewarePlugin definition wiring both paths and supportedTypes. |
plugins/table-middleware-example/src/js/src/ExampleMiddlewareContext.ts |
Context type/provider read by descendants of the wrapped widget. |
plugins/table-middleware-example/src/js/src/index.ts |
Barrel exports and default export of the plugin. |
plugins/table-middleware-example/src/js/package.json |
Package metadata, deps, and build scripts. |
plugins/table-middleware-example/src/js/vite.config.ts |
Vite library build config (cjs, externalized deps). |
plugins/table-middleware-example/src/js/README.md |
Documentation of the example; overstates manifest registration (flagged). |
plugins/table-middleware-example/src/js/LICENSE |
Apache-2.0 license text. |
plugins/table-middleware-example/src/js/.gitignore |
Ignores node_modules and dist. |
package-lock.json |
Adds workspace link entry for the new plugin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Adds
table-middleware-example, a minimalWidgetMiddlewarePlugindemonstrating how a middleware plugin is inserted into a widget's render chain and how it can wrap the next component and inject custom props - with no coupling to IrisGrid or any other specific widget.What it does
exampleMiddlewareBody) returning{ inject, wrap }: injects a customexampleInjectedPropand wraps thewrapped component in an
ExampleMiddlewareContext.Providerplus a small"Wrapped by example middleware" banner.
@deephaven/pluginfactories:createWidgetMiddleware(non-panel /dashboard) and
createPanelMiddleware(panel path, which preservesgolden-layout's panel ref so
componentStatepersistence stays intact).PluginType.MIDDLEWARE_PLUGINwithsupportedTypes: ['Table', 'TreeTable', 'HierarchicalTable', 'PartitionedTable'].The middleware example needs to be registered in
plugins/manifest.jsonto be loaded in dev mode.