diff --git a/src/Board.js b/src/Board.js index ffd04ec1e58ed4604d9c7a9bf1d4669b717f9949..c276a86f38b5a102867376d20cd32c6a6fd5bbdb 100755 --- a/src/Board.js +++ b/src/Board.js @@ -122,38 +122,31 @@ class Board extends React.Component { RenderTabsetHandle(node, renderValues) { // The node could be either a tab set or a border if (node.getType() === "tabset") { - function settingsToggleHandle() { - // `this` is bound to the button's tabset - const tab = this.getSelectedNode() - const config = tab.getConfig() - if ((!("displayMode" in config)) || (config.displayMode !== "settings")) { - config.displayMode = "settings" - this._model.doAction( - FlexLayout.Actions.updateNodeAttributes(tab.getId(), {config: config})); - } - - else { - delete config.displayMode - this._model.doAction( - FlexLayout.Actions.updateNodeAttributes(tab.getId(), {config: config})); + /** + * Switch in and out of a display mode (for a widget in the dashboard). This function returns a fuction + * that does the real switching for a given mode. + * + * This mode is handled through a configuration object handled by FlexLayout. + * @param {String} modeName name of the mode to be switched + * @return function + */ + function modeToggle(modeName) { + return function() { + // `this` is bound to the button's tabset + const tab = this.getSelectedNode(); // retrieve the selected tab + const config = tab.getConfig(); // get the configuration of this tab + if (!("displayMode" in config) || (config.displayMode !== modeName)) { + config.displayMode = modeName; + this._model.doAction( + FlexLayout.Actions.updateNodeAttributes(tab.getId(), {config: config})); + } else { + delete config.displayMode; + this._model.doAction( + FlexLayout.Actions.updateNodeAttributes(tab.getId(), {config: config})); + } } } - function readmeToggleHandle() { - const tab = this.getSelectedNode() - const config = tab.getConfig() - if ((!("displayMode" in config)) || (config.displayMode !== "readme")) { - config.displayMode = "readme" - this._model.doAction( - FlexLayout.Actions.updateNodeAttributes(tab.getId(), {config: config})); - } - else { - delete config.displayMode - this._model.doAction( - FlexLayout.Actions.updateNodeAttributes(tab.getId(), {config: config})); - } - } - const selected = node.getSelectedNode() // did we actually get a node? if (typeof selected !== 'undefined') { @@ -164,7 +157,7 @@ class Board extends React.Component { <img src="images/baseline-settings-20px.svg" alt="settings" key="settings" - onClick={settingsToggleHandle.bind(node)}/> + onClick={modeToggle("settings").bind(node)}/> ) } // is the active (selected) tab declared as having a readme? @@ -173,7 +166,7 @@ class Board extends React.Component { <img src="images/readme-grey.svg" alt="readme" key="readme" - onClick={readmeToggleHandle.bind(node)}/> + onClick={modeToggle("readme").bind(node)}/> ) } }