Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
48 lines
2.1 KiB
TypeScript
48 lines
2.1 KiB
TypeScript
import type { SidebarLink } from "@/app/lib/aclSidebar";
|
|
import { INVENTORY_MODULE_NAMES } from "@/app/lib/inventoryModules";
|
|
|
|
// Presentation merges over the aclMenu-derived sidebar (module-id-category-order). Order and
|
|
// grouping come from the module tree as given (siblings in id order); this never reorders and
|
|
// never grants access.
|
|
//
|
|
// Merged entries (consolidate-admin-settings-nav): paired pages collapse into one link to the first
|
|
// granted member, at the first present member's position; the pages link to each other through
|
|
// SectionTabs.
|
|
|
|
const MERGES: { merge: string[]; label: string }[] = [
|
|
{ merge: ["Locations & Warehouses", "BO_WAREHOUSE_SETUP"], label: "BO_NAV_LOCATIONS_WAREHOUSES" },
|
|
{ merge: ["BO_LOCALES", "BO_MESSAGES"], label: "BO_NAV_LANGUAGES" },
|
|
];
|
|
|
|
const INVENTORY_LINK: SidebarLink = { name: "BO_NAV_INVENTORY", url: "/inventory", iconName: "Box", exact: true, children: [] };
|
|
|
|
/** merge-inventory-page: a group holding only inventory modules is one top-level Inventory link. */
|
|
const isInventoryGroup = (l: SidebarLink) =>
|
|
l.url === "" && l.children.length > 0 && l.children.every((c) => INVENTORY_MODULE_NAMES.includes(c.name));
|
|
|
|
/** Collapses the granted members into one link to the first; the rest become activeUrls. */
|
|
function mergedLink(label: string, granted: SidebarLink[]): SidebarLink {
|
|
const [first, ...rest] = granted;
|
|
return {
|
|
name: label,
|
|
url: first.url,
|
|
...(first.iconName && { iconName: first.iconName }),
|
|
children: [],
|
|
activeUrls: rest.map((l) => l.url),
|
|
};
|
|
}
|
|
|
|
/** Applies the presentation merges at every level, preserving input order. */
|
|
export function applySidebarLayout(links: SidebarLink[]): SidebarLink[] {
|
|
const emitted = new Set<string>();
|
|
return links.flatMap((l) => {
|
|
if (isInventoryGroup(l)) return [INVENTORY_LINK];
|
|
if (l.url === "") return [{ ...l, children: applySidebarLayout(l.children) }];
|
|
const m = MERGES.find((e) => e.merge.includes(l.name));
|
|
if (!m) return [l];
|
|
if (emitted.has(m.label)) return [];
|
|
emitted.add(m.label);
|
|
return [mergedLink(m.label, links.filter((s) => m.merge.includes(s.name)))];
|
|
});
|
|
}
|