UNPKG

kui-shell

Version:

This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool

50 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const debug_1 = require("debug"); const types_1 = require("../../../models/mmr/types"); const show_1 = require("../../../models/mmr/show"); const debug = debug_1.default('webapp/views/registrar/modes'); const registrar = []; function registerSidecarMode(registration) { registrar.push(registration); } exports.registerSidecarMode = registerSidecarMode; exports.default = registerSidecarMode; exports.registerModeWhen = (when) => (mode) => { registerSidecarMode({ when, mode }); }; function apply(tab, modes, command, resource) { registrar .filter(({ when }) => { try { return when(resource.resource); } catch (err) { debug('warning: registered mode threw an exception during filter', err); return false; } }) .forEach(({ mode }) => { const theModeOrButton = typeof mode === 'function' ? mode(command, resource) : mode; const theMode = types_1.isButton(theModeOrButton) ? show_1.formatButton(tab, resource.resource, theModeOrButton) : theModeOrButton; const idxOfPreexistingRegistrationForSameMode = modes.findIndex(({ mode }) => mode === theMode.mode); if (idxOfPreexistingRegistrationForSameMode < 0) { modes.push(theMode); } else { const oldMode = modes[idxOfPreexistingRegistrationForSameMode]; const prio1 = oldMode.priority || 0; const prio2 = theMode.priority || 0; if (prio2 > prio1) { if (oldMode.defaultMode && theMode.defaultMode !== false) { theMode.defaultMode = true; } modes.splice(idxOfPreexistingRegistrationForSameMode, 1, theMode); } } }); } exports.apply = apply; //# sourceMappingURL=modes.js.map