"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.subscribeNavigationTree = exports.getFormatChromeProjectNavNodes = void 0; var _defaultNavMl = require("@kbn/default-nav-ml"); var _defaultNavDevtools = require("@kbn/default-nav-devtools"); var _securitySolutionNavigation = require("@kbn/security-solution-navigation"); var _util = require("./links/util"); var _constants = require("./links/constants"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ // We need to hide breadcrumbs for some pages (tabs) because they appear duplicated. // These breadcrumbs are incorrectly processed as trailing breadcrumbs in SecuritySolution, because of `SpyRoute` architecture limitations. // They are navLinks tree with a SecurityPageName, so they should be treated as leading breadcrumbs in ESS as well. // TODO: Improve the breadcrumbs logic in `use_breadcrumbs_nav` to avoid this workaround. const HIDDEN_BREADCRUMBS = new Set([_securitySolutionNavigation.SecurityPageName.networkDns, _securitySolutionNavigation.SecurityPageName.networkHttp, _securitySolutionNavigation.SecurityPageName.networkTls, _securitySolutionNavigation.SecurityPageName.networkAnomalies, _securitySolutionNavigation.SecurityPageName.networkEvents, _securitySolutionNavigation.SecurityPageName.usersAuthentications, _securitySolutionNavigation.SecurityPageName.usersAnomalies, _securitySolutionNavigation.SecurityPageName.usersRisk, _securitySolutionNavigation.SecurityPageName.usersEvents, _securitySolutionNavigation.SecurityPageName.uncommonProcesses, _securitySolutionNavigation.SecurityPageName.hostsAnomalies, _securitySolutionNavigation.SecurityPageName.hostsEvents, _securitySolutionNavigation.SecurityPageName.hostsRisk, _securitySolutionNavigation.SecurityPageName.sessions]); const subscribeNavigationTree = services => { const { serverless, getProjectNavLinks$ } = services; const formatChromeProjectNavNodes = getFormatChromeProjectNavNodes(services); // projectNavLinks$ updates when chrome.navLinks changes, no need to subscribe chrome.navLinks.getNavLinks$() again. getProjectNavLinks$().subscribe(projectNavLinks => { const navigationTree = formatChromeProjectNavNodes(projectNavLinks); serverless.setNavigation({ navigationTree }); }); }; // Closure to access the up to date chrome.navLinks from services exports.subscribeNavigationTree = subscribeNavigationTree; const getFormatChromeProjectNavNodes = services => { const formatChromeProjectNavNodes = (projectNavLinks, path = []) => { const { chrome } = services; return projectNavLinks.reduce((navNodes, navLink) => { const { id, title, links } = navLink; const navLinkId = (0, _util.getNavLinkIdFromProjectPageName)(id); if (chrome.navLinks.has(navLinkId)) { const breadcrumbHidden = HIDDEN_BREADCRUMBS.has(id); const link = { id: navLinkId, title, path: [...path, navLinkId], deepLink: chrome.navLinks.get(navLinkId), ...(breadcrumbHidden && { breadcrumbStatus: 'hidden' }) }; // check default navigation for children const defaultChildrenNav = getDefaultChildrenNav(id, link); if (defaultChildrenNav) { link.children = defaultChildrenNav; } else if (links !== null && links !== void 0 && links.length) { link.children = formatChromeProjectNavNodes(links, link.path); } navNodes.push(link); } return navNodes; }, []); }; const getDefaultChildrenNav = (id, link) => { if (id === _securitySolutionNavigation.SecurityPageName.mlLanding) { return processDefaultNav(_defaultNavMl.defaultNavigation.children, link.path); } if (id === _constants.ExternalPageName.devTools) { return processDefaultNav(_defaultNavDevtools.defaultNavigation.children, link.path); } return undefined; }; const processDefaultNav = (children, path) => { const { chrome } = services; return children.reduce((navNodes, node) => { var _node$id, _node$children; const id = (_node$id = node.id) !== null && _node$id !== void 0 ? _node$id : node.link; if (!id) { return navNodes; } if (id === 'root') { if (node.children) { navNodes.push(...processDefaultNav(node.children, path)); } return navNodes; } const navNode = { id, title: node.title || '', path: [...path, id] }; if (chrome.navLinks.has(id)) { const deepLink = chrome.navLinks.get(id); navNode.deepLink = deepLink; if (!navNode.title) { navNode.title = (deepLink === null || deepLink === void 0 ? void 0 : deepLink.title) || ''; } } if ((_node$children = node.children) !== null && _node$children !== void 0 && _node$children.length) { navNode.children = processDefaultNav(node.children, navNode.path); } navNodes.push(navNode); return navNodes; }, []); }; return formatChromeProjectNavNodes; }; exports.getFormatChromeProjectNavNodes = getFormatChromeProjectNavNodes;