diff --git a/src/domain/entities/LandingNode.ts b/src/domain/entities/LandingNode.ts index 1890ea2..c97e67e 100644 --- a/src/domain/entities/LandingNode.ts +++ b/src/domain/entities/LandingNode.ts @@ -71,11 +71,7 @@ export const buildOrderedLandingNodes = (nodes: LandingNode[]): OrderedLandingNo })); }; -export const updateLandingNodes = ( - nodes: LandingNode[], - permissions: LandingPagePermission[], - user: User -): LandingNode[] => { +function updateLandingNodes(nodes: LandingNode[], permissions: LandingPagePermission[], user: User): LandingNode[] { const updatedNodes = _(nodes) .map(node => { const pagePermission = permissions?.find(permission => permission.id === node.id); @@ -98,25 +94,24 @@ export const updateLandingNodes = ( .compact() .value(); - return updatedNodes.map(node => applyFavicon(node)); -}; + return updatedNodes; +} -const applyFavicon = (parent: LandingNode): LandingNode => { - const spreadFaviconToChildren = (children: LandingNode[], favicon: string): LandingNode[] => { - return _.map(children, child => { - return { - ...child, - favicon: favicon, - children: spreadFaviconToChildren(child.children, favicon), - }; - }); - }; +function applyFavicon(children: LandingNode[], favicon: string): LandingNode[] { + return _.map(children, child => { + return { + ...child, + favicon: favicon, + children: applyFavicon(child.children, favicon), + }; + }); +} - return { - ...parent, - children: spreadFaviconToChildren(parent.children, parent.favicon), - }; -}; +export function updateLandings(nodes: LandingNode[], permissions: LandingPagePermission[], user: User): LandingNode[] { + const landings = updateLandingNodes(nodes, permissions, user); + + return landings.map(landing => ({ ...landing, children: applyFavicon(landing.children, landing.favicon) })); +} // Return // a redirect URL if there is only one visible action on primary nodes diff --git a/src/webapp/pages/settings/useConfig.ts b/src/webapp/pages/settings/useConfig.ts index 4f92c77..c25bdd7 100644 --- a/src/webapp/pages/settings/useConfig.ts +++ b/src/webapp/pages/settings/useConfig.ts @@ -4,7 +4,7 @@ import { SharedUpdate } from "../../components/permissions-dialog/PermissionsDia import { useAppContext } from "../../contexts/app-context"; import { User } from "../../../domain/entities/User"; import { Maybe } from "../../../types/utils"; -import { LandingNode, updateLandingNodes } from "../../../domain/entities/LandingNode"; +import { LandingNode, updateLandings } from "../../../domain/entities/LandingNode"; export function useConfig(): useConfigPloc { const { compositionRoot, landings } = useAppContext(); @@ -17,7 +17,7 @@ export function useConfig(): useConfigPloc { const userLandings = useMemo(() => { if (!(landings && landingPagePermissions && user)) return undefined; - return updateLandingNodes(landings, landingPagePermissions, user); + return updateLandings(landings, landingPagePermissions, user); }, [landingPagePermissions, landings, user]); useEffect(() => {