@shopgate/engage
Version:
Shopgate's ENGAGE library.
10 lines • 1.6 kB
JavaScript
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}/**
* Collects all display groups from the properties.
* @param {Array} [properties=null] The properties to parse.
* @returns {Array}
*/export function getGroupsFromProperties(){var properties=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var groups=[];if(properties===null){return groups;}properties.forEach(function(property){if(!property.displayGroup){// Do not proceed when not displayGroup is available
return;}var key=property.displayGroup;var label=null;if(property.displayGroup==='custom'){key="".concat(property.displayGroup,"-").concat(property.customDisplayGroupName);if(property.customDisplayGroupName){label=property.customDisplayGroupName;}}// Check if the groups array already contains a group with the key
var existingGroup=groups.find(function(group){return group.key===key;});if(!existingGroup){// Add a new group storage when there isn't one already
existingGroup={key:key,label:label,properties:[]};groups.push(existingGroup);}// Add current property to the storage
existingGroup.properties.push(property);});return groups.map(function(group){return _extends({},group,{// Check if the current group just contains html properties to allow special handling
htmlOnly:group.properties.length?group.properties.every(function(_ref){var type=_ref.type;return type==='html';}):false});});}