Skip to content

Commit

Permalink
#8523 Add alwaysRender property (#8754)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Nov 4, 2022
1 parent e116232 commit bd02390
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/developer-guide/plugins-howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ There is also a set of options to (dynamically) add/exclude containers:
- **showIn**: can be used to add a plugin to a container or more than one, in addition to the default one (it is an array of container plugin names)
- **hideFrom**: can be used to exclude a plugin from a given container or more than one (it is an array of container plugin names)
- **doNotHide**: can be used to show a plugin in the root container, in addition to the default one
- **alwaysRender**: can be used to always renders the component in the given container, regardless the priority
Note that also these properties accept dynamic expressions.
Expand Down
9 changes: 6 additions & 3 deletions web/client/plugins/Measure.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ export default createPlugin('Measure', {
text: <Message msgId="measureComponent.Measure"/>,
icon: <Glyphicon glyph="1-ruler"/>,
action: () => setControlProperty("measure", "enabled", true),
doNotHide: true
doNotHide: true,
priority: 2
},
SidebarMenu: {
name: 'measurement',
Expand All @@ -192,12 +193,14 @@ export default createPlugin('Measure', {
toggle: true,
toggleControl: 'measure',
toggleProperty: 'enabled',
doNotHide: true
doNotHide: true,
priority: 1
},
Map: {
name: 'Measure',
Tool: MeasureSupport,
doNotHide: true
doNotHide: true,
alwaysRender: true
}
},
reducers: {
Expand Down
19 changes: 16 additions & 3 deletions web/client/utils/PluginsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ const executeDeferredProp = (pluginImpl, pluginConfig, name) => pluginImpl && is
({...pluginImpl, [name]: pluginImpl[name](pluginConfig)}) :
pluginImpl;

const alwaysRender = (plugin, override = {}, container) => {
const pluginImpl = executeDeferredProp(plugin.impl, plugin.config, container);
return (
get(override, container + ".alwaysRender") ||
get(pluginImpl, container + ".alwaysRender") ||
false
);
};

const getPriority = (plugin, override = {}, container) => {
const pluginImpl = executeDeferredProp(plugin.impl, plugin.config, container);
return (
Expand Down Expand Up @@ -333,9 +342,13 @@ export const getPluginItems = (state, plugins = {}, pluginsConfig = {}, containe
}
return [...acc, curr];
}, [])
// include only plugins for which container is the preferred container
.filter((plugin) => isMorePrioritizedContainer(plugin, plugin.config.override, pluginsConfig,
getPriority(plugin, plugin.config.override, containerName)))
// include only plugins for which container is the preferred container
.filter((plugin) =>
alwaysRender(plugin, plugin.config.override, containerName)
|| isMorePrioritizedContainer(plugin, plugin.config.override, pluginsConfig,
getPriority(plugin, plugin.config.override, containerName)
)
)
.map((plugin) => {
const pluginName = getPluginSimpleName(plugin.name);
const pluginImpl = includeLoaded(pluginName, loadedPlugins, plugin.impl);
Expand Down
30 changes: 30 additions & 0 deletions web/client/utils/__tests__/PluginsUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,34 @@ describe('PluginsUtils', () => {
expect(result.loaded).toBe(true);

});
it('getPluginItems with alwaysRender', () => {
const plugins = {
Test1Plugin: {
Container1: {
priority: 1
},
Container2: {
priority: 2
},
Container3: {
alwaysRender: true
}
},
Container1Plugin: {},
Container2Plugin: {}
};

const pluginsConfig = [
{ name: "Test1" },
{ name: "Container1" },
{ name: "Container2" },
{ name: "Container3" }
];
const items1 = PluginsUtils.getPluginItems(defaultState, plugins, pluginsConfig, "Container1", "Container1", true, []);
expect(items1.length).toBe(0);
const items2 = PluginsUtils.getPluginItems(defaultState, plugins, pluginsConfig, "Container2", "Container2", true, []);
expect(items2.length).toBe(1);
const items3 = PluginsUtils.getPluginItems(defaultState, plugins, pluginsConfig, "Container3", "Container3", true, []);
expect(items3.length).toBe(1);
});
});

0 comments on commit bd02390

Please sign in to comment.