Skip to content

Custom main menu subitems

Tomas Machalek edited this page Sep 21, 2017 · 14 revisions

KonText recognizes the following sub-menu items:

  • core items are controlled by KonText core application and cannot be changed via a plug-in
    1. items with an action and args - where action specifies KonText's controller action (e.g. first_form, view) and args are respective URL arguments. These items are transformed into common HTML links (i.e. user clicks an item and browser navigates him to a new page within KonText)
    2. items with a message and args - where message specifies a Flux message to be dispatched once the item is clicked and args are its respective arguments. These custom items are always appended behind core items, i.e. it is not possible to add a custom item to a specified position within a menu item box (e.g. for 'Corpora', something like 'Available corpora', 'My custom item', 'My subcorpora', etc. cannot be done).
  • custom (plug-in) items are configured by an administrator of a concrete KonText installation
    1. static items are just URLs with localized text label
    2. dynamic items are server defined "anchors" with a respective client-side code which binds custom labels and event handlers

# Custom static items

Static items are useful for adding external links (e.g. an organization homepage, discussion/support forum etc.).

E.g. to add a custom item with two translations (English and Czech) to the "help" section:

{
  "menu-help": [
    {
      "type": "static",
      "data": {
        "en_US": {
          "url": "https://wiki.korpus.cz/doku.php/manualy:kontext:index",
          "label": "User manual (in Czech)",
          "openInBlank": true
        },
        "cs_CZ": {
          "url": "https://wiki.korpus.cz/doku.php/manualy:kontext:index",
          "label": "Uživatelská příručka",
          "openInBlank": true
        }
      }
    }
  ]
}

# Custom dynamic items

Dynamic items are suitable for cases when the item's functionality is based on current UI Flux stores state (i.e. it cannot be predefined as a bunch of constant arguments) and/or requires more complex behavior.

To define such an item, an "anchor" server item must be defined first. It is similar to the static items above, but there is just an ident and no URL, label, or arguments. This ident is then used by client-side code to refer to the item.

Please note that while core sub-menu items are identified by both menu section identifier (e.g. "menu-new-query", "menu-concordance") and sub-menu item identifier (e.g. "new-query", "shuffle"), custom dynamic items are expected to have an unique sub-menu item identifier (i.e. there is no menu section specification; see below).

{
  "menu-corpora": [
    {
      "type": "dynamic",
      "ident": "ucnk-get-a-similar-corpus"
    }
  ]
}
class SomePlugin {

  // constructor omitted

  this.pluginApi.getStores().mainMenuStore.bindDynamicItem(
    'ucnk-get-a-similar-corpus',
    'Find a similar corpus based on my last search',
    () => {
       // do stuff here
    }
  );
}
Clone this wiki locally