From 8506b4267065caaab7c1aa7e2df62b58437b5925 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Wed, 17 Jul 2024 18:03:09 +0800 Subject: [PATCH] feat: optimize code Signed-off-by: SuZhou-Joe --- .../public/components/feature_cards/feature_cards.tsx | 2 ++ src/plugins/management/public/plugin.ts | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/management/public/components/feature_cards/feature_cards.tsx b/src/plugins/management/public/components/feature_cards/feature_cards.tsx index 3b262a62b877..57d7e128c928 100644 --- a/src/plugins/management/public/components/feature_cards/feature_cards.tsx +++ b/src/plugins/management/public/components/feature_cards/feature_cards.tsx @@ -43,6 +43,8 @@ export const FeatureCards = ({ const itemsPerRow = 4; const groupedCardForDisplay = useMemo(() => { const grouped: Array<{ category?: AppCategory; navLinks: ChromeNavLink[][] }> = []; + // The navLinks has already been sorted based on link / category's order, + // so it is safe to group the links here. navLinks.forEach((link) => { let lastGroup = grouped.length ? grouped[grouped.length - 1] : undefined; if (!lastGroup || lastGroup.category !== link.category) { diff --git a/src/plugins/management/public/plugin.ts b/src/plugins/management/public/plugin.ts index 2615ffe05ce8..6d33ccd7ce58 100644 --- a/src/plugins/management/public/plugin.ts +++ b/src/plugins/management/public/plugin.ts @@ -125,9 +125,9 @@ export class ManagementPlugin implements Plugin navLink.id !== settingsLandingPageId), + navLinks || [], coreStart.chrome.navLinks.getAll() - ); + ).filter((navLink) => navLink.id !== settingsLandingPageId && !navLink.hidden); return renderApp({ mountElement: params.element, @@ -157,9 +157,9 @@ export class ManagementPlugin implements Plugin navLink.id !== dataAdministrationLandingPageId), + navLinks || [], coreStart.chrome.navLinks.getAll() - ); + ).filter((navLink) => navLink.id !== dataAdministrationLandingPageId && !navLink.hidden); return renderApp({ mountElement: params.element,