Skip to content

Commit 0c71663

Browse files
committed
updated support for plugin configuration, added warnings for disallowed plugins
1 parent 43ee4ce commit 0c71663

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

config.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,36 @@
306306
realtimeProductAPIDs: [],
307307

308308
/**
309-
* Plugin Support: true enables a plugin without options.
310-
*
311-
* TODO: Add support for plugins with options
309+
* Plugin Support
310+
* Example configuration:
311+
* plugins: {
312+
// Simple enable
313+
anotherPlugin: {
314+
enabled: true
315+
},
316+
// Enable with options
317+
configuredPlugin: {
318+
enabled: true,
319+
// these are passed as arguments to the plugin constructor
320+
configuration: [
321+
{
322+
setting1: 'value1',
323+
setting2: 'value2'
324+
}
325+
]
326+
}
327+
}
312328
*/
313329
plugins: {
314330
/**
315331
* Enable/disable summary widgets. Added in R3.4.0.
316332
*/
317-
summaryWidgets: true,
318-
BarChart: true
333+
summaryWidgets: {
334+
enabled: true
335+
},
336+
BarChart: {
337+
enabled: true
338+
}
319339
},
320340

321341
/**

loader.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,37 @@ define([
117117

118118
// install optional plugins, summary widget is handled separately as it was added long ago
119119
if (config.plugins) {
120-
if (config.plugins.summaryWidgets) {
120+
if (
121+
config.plugins.summaryWidgets === true ||
122+
config.plugins.summaryWidgets?.enabled === true
123+
) {
121124
openmct.install(openmct.plugins.SummaryWidget());
122125
}
123126

124-
const pluginsToInstall = Object.keys(config.plugins).filter(
125-
(plugin) => plugin !== 'summaryWidgets' && optionalPlugins.includes(plugin)
126-
);
127+
const pluginErrors = [];
128+
const pluginsToInstall = Object.keys(config.plugins).filter((plugin) => {
129+
const isSummaryWidget = plugin === 'summaryWidgets';
130+
const allowedPlugin = optionalPlugins.includes(plugin);
131+
const pluginEnabled = config.plugins[plugin]?.enabled;
132+
133+
if (!allowedPlugin && !isSummaryWidget) {
134+
pluginErrors.push(plugin);
135+
}
136+
137+
return allowedPlugin && pluginEnabled && !isSummaryWidget;
138+
});
139+
140+
// Warn if any plugins are not supported
141+
if (pluginErrors.length > 0) {
142+
console.warn(
143+
`Unable to install plugins: ${pluginErrors.join(', ')}. Please verify the plugin name is correct and is included in the supported plugins list. Available plugins: ${optionalPlugins.join(', ')}`
144+
);
145+
}
127146

128147
pluginsToInstall.forEach((plugin) => {
129-
const { options = [] } = config.plugins[plugin];
148+
const { configuration = [] } = config.plugins[plugin];
130149

131-
openmct.install(openmct.plugins[plugin](...options));
150+
openmct.install(openmct.plugins[plugin](...configuration));
132151
});
133152
}
134153

0 commit comments

Comments
 (0)