Skip to content

Commit 1442ace

Browse files
authored
refactor: Convert core DashboardPlugins to new config type (#1519)
Fixes #1507 Didn't convert `ConsolePlugin` yet. The `notebooksUrl` prop was added for markdown notebooks, but uses a Vite env variable to set it
1 parent 3e834de commit 1442ace

30 files changed

Lines changed: 418 additions & 285 deletions

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app-utils/src/components/AppBootstrap.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
RefreshTokenBootstrap,
66
useBroadcastLoginListener,
77
} from '@deephaven/jsapi-components';
8+
import { type DashboardPlugin } from '@deephaven/plugin';
89
import FontBootstrap from './FontBootstrap';
910
import PluginsBootstrap from './PluginsBootstrap';
1011
import AuthBootstrap from './AuthBootstrap';
@@ -21,6 +22,9 @@ export type AppBootstrapProps = {
2122
/** URL of the plugins to load. */
2223
pluginsUrl: string;
2324

25+
/** The core plugins to load. */
26+
getCorePlugins?: () => Promise<DashboardPlugin[]>;
27+
2428
/** Font class names to load. */
2529
fontClassNames?: string[];
2630

@@ -37,6 +41,7 @@ export type AppBootstrapProps = {
3741
export function AppBootstrap({
3842
fontClassNames,
3943
pluginsUrl,
44+
getCorePlugins,
4045
serverUrl,
4146
children,
4247
}: AppBootstrapProps): JSX.Element {
@@ -51,7 +56,7 @@ export function AppBootstrap({
5156
useBroadcastLoginListener(onLogin, onLogout);
5257
return (
5358
<FontBootstrap fontClassNames={fontClassNames}>
54-
<PluginsBootstrap pluginsUrl={pluginsUrl}>
59+
<PluginsBootstrap getCorePlugins={getCorePlugins} pluginsUrl={pluginsUrl}>
5560
<ClientBootstrap
5661
serverUrl={serverUrl}
5762
options={clientOptions}

packages/app-utils/src/components/PluginsBootstrap.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type DashboardPlugin } from '@deephaven/plugin';
12
import React, { createContext, useEffect, useState } from 'react';
23
import { PluginModuleMap, loadModulePlugins } from '../plugins';
34

@@ -9,6 +10,9 @@ export type PluginsBootstrapProps = {
910
*/
1011
pluginsUrl: string;
1112

13+
/** The core plugins to load. */
14+
getCorePlugins?: () => Promise<DashboardPlugin[]>;
15+
1216
/**
1317
* The children to render wrapped with the PluginsContext.
1418
* Note that it renders the children even if the plugins aren't loaded yet.
@@ -21,24 +25,29 @@ export type PluginsBootstrapProps = {
2125
*/
2226
export function PluginsBootstrap({
2327
pluginsUrl,
28+
getCorePlugins,
2429
children,
2530
}: PluginsBootstrapProps): JSX.Element {
2631
const [plugins, setPlugins] = useState<PluginModuleMap | null>(null);
2732
useEffect(
2833
function initPlugins() {
2934
let isCanceled = false;
3035
async function loadPlugins(): Promise<void> {
36+
const corePlugins = (await getCorePlugins?.()) ?? [];
3137
const pluginModules = await loadModulePlugins(pluginsUrl);
3238
if (!isCanceled) {
33-
setPlugins(pluginModules);
39+
const corePluginPairs = corePlugins.map(
40+
plugin => [plugin.name, plugin] as const
41+
);
42+
setPlugins(new Map([...corePluginPairs, ...pluginModules]));
3443
}
3544
}
3645
loadPlugins();
3746
return () => {
3847
isCanceled = true;
3948
};
4049
},
41-
[pluginsUrl]
50+
[pluginsUrl, getCorePlugins]
4251
);
4352

4453
return (

packages/app-utils/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './usePlugins';
88
export * from './useConnection';
99
export * from './useServerConfig';
1010
export * from './useUser';
11+
export * from './useLoadTablePlugin';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useCallback } from 'react';
2+
import {
3+
type TablePluginComponent,
4+
isTablePlugin,
5+
isLegacyTablePlugin,
6+
} from '@deephaven/plugin';
7+
import Log from '@deephaven/log';
8+
import usePlugins from './usePlugins';
9+
10+
const log = Log.module('@deephaven/app-utils/useTablePlugin');
11+
12+
/**
13+
* Creates a table plugin loader function.
14+
* @returns A function to load a Table plugin element by name
15+
*/
16+
export function useLoadTablePlugin(): (name: string) => TablePluginComponent {
17+
const plugins = usePlugins();
18+
19+
const plugin = useCallback(
20+
(name: string) => {
21+
// First check if we have any plugin modules loaded that match the TablePlugin.
22+
const pluginModule = plugins.get(name);
23+
if (pluginModule != null) {
24+
if (isTablePlugin(pluginModule)) {
25+
return pluginModule.component;
26+
}
27+
if (isLegacyTablePlugin(pluginModule)) {
28+
return pluginModule.TablePlugin;
29+
}
30+
}
31+
32+
const errorMessage = `Unable to find table plugin ${name}.`;
33+
log.error(errorMessage);
34+
throw new Error(errorMessage);
35+
},
36+
[plugins]
37+
);
38+
39+
return plugin;
40+
}
41+
42+
export default useLoadTablePlugin;

packages/code-studio/src/AppRoot.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ import React from 'react';
22
import { Provider } from 'react-redux';
33
import { MonacoUtils } from '@deephaven/console';
44
import { store } from '@deephaven/redux';
5+
import { DownloadServiceWorkerUtils } from '@deephaven/iris-grid';
56
import MonacoWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
67
import AppRouter from './main/AppRouter';
7-
import DownloadServiceWorkerUtils from './DownloadServiceWorkerUtils';
88

99
export function AppRoot(): JSX.Element {
10-
DownloadServiceWorkerUtils.registerOnLoaded();
10+
DownloadServiceWorkerUtils.register(
11+
new URL(
12+
`${import.meta.env.BASE_URL ?? ''}download/serviceWorker.js`,
13+
window.location.href
14+
)
15+
);
1116
MonacoUtils.init({ getWorker: () => new MonacoWorker() });
1217

1318
// disable annoying dnd-react warnings

packages/code-studio/src/index.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,39 @@ const pluginsURL = new URL(
2727
document.baseURI
2828
);
2929

30+
// Lazy load the configs because it breaks initial page loads otherwise
31+
async function getCorePlugins() {
32+
const dashboardCorePlugins = await import(
33+
'@deephaven/dashboard-core-plugins'
34+
);
35+
const {
36+
GridPluginConfig,
37+
PandasPluginConfig,
38+
ChartPluginConfig,
39+
ChartBuilderPluginConfig,
40+
FilterPluginConfig,
41+
MarkdownPluginConfig,
42+
LinkerPluginConfig,
43+
} = dashboardCorePlugins;
44+
return [
45+
GridPluginConfig,
46+
PandasPluginConfig,
47+
ChartPluginConfig,
48+
ChartBuilderPluginConfig,
49+
FilterPluginConfig,
50+
MarkdownPluginConfig,
51+
LinkerPluginConfig,
52+
];
53+
}
54+
3055
ReactDOM.render(
3156
<ApiBootstrap apiUrl={apiURL.href} setGlobally>
3257
<Suspense fallback={<LoadingOverlay />}>
33-
<AppBootstrap serverUrl={apiURL.origin} pluginsUrl={pluginsURL.href}>
58+
<AppBootstrap
59+
getCorePlugins={getCorePlugins}
60+
serverUrl={apiURL.origin}
61+
pluginsUrl={pluginsURL.href}
62+
>
3463
<AppRoot />
3564
</AppBootstrap>
3665
</Suspense>

0 commit comments

Comments
 (0)