Adds a helper function, to process component visiblity

This commit is contained in:
Alicia Sykes 2021-07-04 09:01:56 +01:00
parent a27316d597
commit ec95fafe04
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
import ConfigAccumulator from '@/utils/ConfigAccumalator';
import { visibleComponents } from '@/utils/defaults';
/**
* Initiates the Accumulator class and generates a complete config object
* Self-executing function, returns the full user config as a JSON object
*/
export const config = (() => {
const Accumulator = new ConfigAccumulator();
return Accumulator.config();
})();
/**
* Generates an object containing booleans indicating which
* components should be hidden. This enables the user to hide
* parts of the page and disable functionality that they don't need/ want
* All options fallback on the values defined in the defaults
* @param {object} appConfig The full app config
* @returns {object} result
*/
export const componentVisibility = (appConfig) => {
// Get users choice from app config
const usersChoice = appConfig.hideComponents || {};
// Checks if value is defined, and is a boolean
const isThere = (userValue) => typeof userValue === 'boolean';
// For each option, return users choice (if specified), else use the default
return {
pageTitle: isThere(usersChoice.hideHeading)
? !usersChoice.hideHeading : visibleComponents.pageTitle,
navigation: isThere(usersChoice.hideNav)
? !usersChoice.hideNav : visibleComponents.navigation,
searchBar: isThere(usersChoice.hideSearch)
? !usersChoice.hideSearch : visibleComponents.searchBar,
settings: isThere(usersChoice.hideSettings)
? !usersChoice.hideSettings : visibleComponents.settings,
footer: isThere(usersChoice.hideFooter)
? !usersChoice.hideFooter : visibleComponents.footer,
splashScreen: isThere(usersChoice.hideSplashScreen)
? !usersChoice.hideSplashScreen : visibleComponents.splashScreen,
};
};