Skip to content

Commit b100027

Browse files
authored
feat: add plugins SDK and improve plugins middleware (#724)
* feat: add plugins SDK and improve plugins middleware * docs: add an explanatory README on plugins SDK development
1 parent fd1ab69 commit b100027

File tree

20 files changed

+495
-87
lines changed

20 files changed

+495
-87
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
**/.*
22
build
3+
build-ui
34
node_modules
45
hot
56
/lib/static/*.min.js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
build
3+
build-ui
34
hot
45
sqlite.db
56
*.log

lib/gui/routes/plugins.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
logError
1010
} from '../../server-utils';
1111
import {ReporterConfig} from '../../types';
12+
import {getPluginMiddlewareRoute} from '../../static/modules/utils/pluginMiddlewareRoute';
1213

1314
export const initPluginsRoutes = (router: Router, pluginConfig: ReporterConfig): Router => {
1415
if (!pluginConfig.pluginsEnabled) {
@@ -40,7 +41,7 @@ export const initPluginsRoutes = (router: Router, pluginConfig: ReporterConfig):
4041
const pluginRouter = Router();
4142
initPluginMiddleware(pluginRouter);
4243

43-
router.use(`/plugin-routes/${pluginName}`, pluginRouter);
44+
router.use(getPluginMiddlewareRoute(pluginName), pluginRouter);
4445
} catch (err: unknown) {
4546
logError(err as Error);
4647
}

lib/static/components/extension-point.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function composeComponents(PluginComponent, pluginProps, currentComponent, posit
6060
}
6161
}
6262

63-
function getExtensionPointComponents(loadedPluginConfigs, pointName) {
63+
export function getExtensionPointComponents(loadedPluginConfigs, pointName) {
6464
return loadedPluginConfigs
6565
.map(config => {
6666
try {

lib/static/modules/load-plugin.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import * as JSXRuntime from 'react/jsx-runtime';
24
import * as Redux from 'redux';
35
import * as ReactRedux from 'react-redux';
46
import _ from 'lodash';
@@ -10,12 +12,17 @@ import reduceReducers from 'reduce-reducers';
1012
import immer from 'immer';
1113
import * as reselect from 'reselect';
1214
import axios from 'axios';
15+
import * as GravityUI from '@gravity-ui/uikit';
16+
import * as pluginsSDKUI from './plugins-sdk-ui';
1317
import * as selectors from './selectors';
1418
import actionNames from './action-names';
1519
import Details from '../components/details';
20+
import {getPluginMiddlewareRoute} from '@/static/modules/utils/pluginMiddlewareRoute';
1621

1722
const whitelistedDeps = {
1823
'react': React,
24+
'react/jsx-runtime': JSXRuntime,
25+
'react-dom': ReactDOM,
1926
'redux': Redux,
2027
'react-redux': ReactRedux,
2128
'lodash': _,
@@ -27,6 +34,8 @@ const whitelistedDeps = {
2734
'immer': immer,
2835
'reselect': reselect,
2936
'axios': axios,
37+
'@gravity-ui/uikit': GravityUI,
38+
'html-reporter/plugins-sdk/ui': pluginsSDKUI,
3039
'components': {
3140
Details
3241
}
@@ -91,8 +100,16 @@ async function initPlugin(plugin, pluginName, pluginConfig) {
91100
plugin = _.last(plugin);
92101
const depArgs = deps.map(dep => whitelistedDeps[dep]);
93102
// cyclic dep, resolve it dynamically
94-
const actions = await import('./actions');
95-
return plugin(...depArgs, {pluginName, pluginConfig, actions, actionNames, selectors});
103+
const actionsModule = await import('./actions');
104+
const actions = actionsModule.default || actionsModule;
105+
return plugin(...depArgs, {
106+
pluginName,
107+
pluginConfig,
108+
actions,
109+
actionNames,
110+
selectors,
111+
pluginServerEndpointPrefix: getPluginMiddlewareRoute(pluginName)
112+
});
96113
}
97114

98115
return plugin;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export {PanelSection} from '../new-ui/components/PanelSection';
2+
export {State} from '../new-ui/types/store';
3+
export * as Features from '../../constants/features';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const encodePackageNameRoute = (packageName: string): string => {
2+
return packageName.replace(/[/@.]/g, '__');
3+
};
4+
5+
export const getPluginMiddlewareRoute = (pluginName: string): string => {
6+
return `/plugin-routes/${encodePackageNameRoute(pluginName)}`;
7+
};

lib/static/new-ui.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,15 @@ body {
9999
color: var(--g-color-private-black-400);
100100
font-weight: 500;
101101
}
102+
103+
a, a:link, a:visited {
104+
color: var(--color-link);
105+
}
106+
107+
a:hover {
108+
color: var(--color-link-hover);
109+
}
110+
111+
b {
112+
font-weight: 500;
113+
}

lib/static/new-ui/components/InfoPanel/index.module.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
margin: 20px 0;
33
}
44

5-
.info-panel a:link, .info-panel a:visited {
6-
color: var(--color-link);
7-
}
8-
9-
.info-panel a:hover {
10-
color: var(--color-link-hover);
11-
}
12-
135
.extra-items-list {
146
padding-left: 24px;
157
list-style: none;

lib/static/new-ui/components/PanelSection/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, {ReactNode} from 'react';
33
import styles from './index.module.css';
44

55
interface PanelSectionProps {
6-
title: string;
6+
title: ReactNode;
77
description?: ReactNode;
88
children?: ReactNode;
99
}

0 commit comments

Comments
 (0)