Skip to content

Commit 4cce1a2

Browse files
authored
[Bar Charts] Enable (#278)
1 parent eb701bc commit 4cce1a2

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

config.js

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

308308
/**
309-
* Plugin Support: true enables a plugin.
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+
}
310328
*/
311329
plugins: {
312330
/**
313331
* Enable/disable summary widgets. Added in R3.4.0.
314332
*/
315-
summaryWidgets: true
333+
summaryWidgets: {
334+
enabled: true
335+
},
336+
BarChart: {
337+
enabled: false
338+
}
316339
},
317340

318341
/**

loader.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ define([
2929
IdentityProvider,
3030
MCWSPersistenceProviderPlugin
3131
) {
32+
const ALLOWED_OPTIONAL_PLUGINS = ['BarChart'];
33+
3234
function loader(config) {
3335
let persistenceLoaded;
3436
const persistenceLoadedPromise = new Promise((resolve) => {
@@ -113,10 +115,40 @@ define([
113115
});
114116
}
115117

118+
// install optional plugins, summary widget is handled separately as it was added long ago
116119
if (config.plugins) {
117-
if (config.plugins.summaryWidgets) {
120+
if (
121+
config.plugins.summaryWidgets === true ||
122+
config.plugins.summaryWidgets?.enabled === true
123+
) {
118124
openmct.install(openmct.plugins.SummaryWidget());
119125
}
126+
127+
const pluginErrors = [];
128+
const pluginsToInstall = Object.entries(config.plugins).filter(([plugin, pluginConfig]) => {
129+
const isSummaryWidget = plugin === 'summaryWidgets';
130+
const allowedPlugin = ALLOWED_OPTIONAL_PLUGINS.includes(plugin);
131+
const pluginEnabled = pluginConfig?.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: ${ALLOWED_OPTIONAL_PLUGINS.join(', ')}`
144+
);
145+
}
146+
147+
pluginsToInstall.forEach(([plugin, pluginConfig]) => {
148+
const { configuration = [] } = pluginConfig;
149+
150+
openmct.install(openmct.plugins[plugin](...configuration));
151+
});
120152
}
121153

122154
openmct.branding({

0 commit comments

Comments
 (0)