diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 50be6de4d838..688e61bca48f 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -12,14 +12,12 @@ import { AppMountParameters, AppNavLinkStatus, LinksUpdater, - WorkspaceAttribute, } from '../../../core/public'; import { WORKSPACE_FATAL_ERROR_APP_ID, WORKSPACE_OVERVIEW_APP_ID } from '../common/constants'; import { getWorkspaceIdFromUrl } from '../../../core/public/utils'; import { Services } from './types'; import { WorkspaceClient } from './workspace_client'; import { WorkspaceMenu } from './components/workspace_menu/workspace_menu'; -import { NavLinkWrapper } from '../../../core/public/chrome/nav_links/nav_link'; import { featureMatchesConfig } from './utils'; type WorkspaceAppType = (params: AppMountParameters, services: Services) => () => void; @@ -41,16 +39,6 @@ export class WorkspacePlugin implements Plugin<{}, {}, {}> { return getWorkspaceIdFromUrl(window.location.href, basePath); } - /** - * Filter the nav links based on the feature configuration of workspace - */ - private filterByWorkspace(allNavLinks: NavLinkWrapper[], workspace: WorkspaceAttribute | null) { - if (!workspace || !workspace.features) return allNavLinks; - - const featureFilter = featureMatchesConfig(workspace.features); - return allNavLinks.filter((linkWrapper) => featureFilter(linkWrapper.properties)); - } - /** * Filter nav links by the current workspace, once the current workspace change, the nav links(left nav bar) * should also be updated according to the configured features of the current workspace @@ -76,8 +64,18 @@ export class WorkspacePlugin implements Plugin<{}, {}, {}> { * the nav links of Observability features should not be displayed in left nav bar */ filterLinksByWorkspace = (navLinks) => { - const filteredNavLinks = this.filterByWorkspace([...navLinks.values()], currentWorkspace); - const newNavLinks = new Map(); + /** + * Do not filter the nav links when currently not in a workspace, or the current workspace + * has no feature configured + */ + if (!currentWorkspace || !currentWorkspace.features) return navLinks; + + const featureFilter = featureMatchesConfig(currentWorkspace.features); + const filteredNavLinks = [...navLinks.values()].filter((linkWrapper) => + featureFilter(linkWrapper.properties) + ); + + const newNavLinks = new Map(); filteredNavLinks.forEach((chromeNavLink) => { newNavLinks.set(chromeNavLink.id, chromeNavLink); });