Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
Signed-off-by: Yulong Ruan <[email protected]>
  • Loading branch information
ruanyl committed Mar 21, 2024
1 parent b6d9750 commit 7c6b1e9
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<string, NavLinkWrapper>();
/**
* 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);
});
Expand Down

0 comments on commit 7c6b1e9

Please sign in to comment.