MINERVA
Platform Documentation

Context Menu#

Plugins can add their own entries to the right-click context menu that appears when a user clicks on a map element (e.g. a bioentity or reaction). The contextMenu object is returned by window.minerva.plugins.registerPlugin and is scoped to the registering plugin - the id of a menu item only needs to be unique within that plugin.

Add Menu#

To add an entry to the context menu, plugins can use the addMenu method in the contextMenu object. This method takes the following arguments:

addMenu returns a string id identifying the created entry. Save this id if you intend to update or remove the entry later.

Example of addMenu method usage:#
const {
  element,
  contextMenu: { addMenu },
} = minerva.plugins.registerPlugin({
  pluginName,
  pluginVersion,
  pluginUrl,
});

const menuItemId = addMenu('Show details', 'my-plugin-menu-item', true, (coordinates, element) => {
  console.log('Clicked at', coordinates, 'on element', element);
});

Update Menu#

To change the label, style, or enabled state of an existing entry, plugins can use the updateMenu method. This method takes the following arguments:

Calling updateMenu with an id that does not exist for the plugin throws an error.

Example of updateMenu method usage:#
const {
  element,
  contextMenu: { addMenu, updateMenu },
} = minerva.plugins.registerPlugin({
  pluginName,
  pluginVersion,
  pluginUrl,
});

const menuItemId = addMenu('Show details', 'my-plugin-menu-item', true, callback);

updateMenu(menuItemId, 'Show details (disabled)', 'my-plugin-menu-item', false);

Remove Menu#

To remove an entry from the context menu, plugins can use the removeMenu method. This method takes one argument:

Example of removeMenu method usage:#
const {
  element,
  contextMenu: { addMenu, removeMenu },
} = minerva.plugins.registerPlugin({
  pluginName,
  pluginVersion,
  pluginUrl,
});

const menuItemId = addMenu('Show details', 'my-plugin-menu-item', true, callback);

removeMenu(menuItemId);