UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

38 lines 1.64 kB
import { EasyPagesSysTab } from "../interfaces/epTypes"; /** * This returns only tabs that were found and in the original order provided by props. * @param sourceProps * @param items * @returns */ export function getUsedTabs(sourceProps, items) { var _a; const foundTabs = []; let showOverFlow = false; let systemTab = false; // https://github.com/mikezimm/drilldown7/issues/280 items.map(item => { item.tabs.map(tab => { if (tab === EasyPagesSysTab) { systemTab = true; // https://github.com/mikezimm/drilldown7/issues/280 // Changed order of else if for: https://github.com/mikezimm/fps-library-v2/issues/179 } else if (tab === sourceProps.EasyPageOverflowTab) { showOverFlow = true; } else if (foundTabs.indexOf(tab) < 0) { foundTabs.push(tab); } }); }); const sortedTabs = []; (_a = sourceProps.meta1) === null || _a === void 0 ? void 0 : _a.map(tab => { if (foundTabs.indexOf(tab) > -1) sortedTabs.push(tab); }); if (showOverFlow === true && sourceProps.EasyPageOverflowTab) sortedTabs.push(sourceProps.EasyPageOverflowTab); if (systemTab === true) sortedTabs.push(EasyPagesSysTab); // https://github.com/mikezimm/drilldown7/issues/280 // Per chatGPT suggested link: https://www.technicalfeeder.com/2021/07/8-ways-to-remove-duplicates-from-an-array/#toc6 return Array.from(new Set(sortedTabs)); // return sortedTabs; } //# sourceMappingURL=getUsedTabs.js.map