From e7950b8d0d8a625d357038b3d100f6e69aaa9175 Mon Sep 17 00:00:00 2001 From: tygao Date: Wed, 20 Nov 2024 17:36:53 +0800 Subject: [PATCH] seperate link Signed-off-by: tygao --- .../public/chrome/ui/header/recent_items.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/public/chrome/ui/header/recent_items.tsx b/src/core/public/chrome/ui/header/recent_items.tsx index 3194be43be9d..61ab5cc1ede1 100644 --- a/src/core/public/chrome/ui/header/recent_items.tsx +++ b/src/core/public/chrome/ui/header/recent_items.tsx @@ -2,7 +2,7 @@ * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ -import React, { useMemo, useState, useEffect, useRef } from 'react'; +import React, { useMemo, useState, useEffect } from 'react'; import * as Rx from 'rxjs'; import moment from 'moment'; import { @@ -122,7 +122,6 @@ export const RecentItems = ({ [] ); const navLinks = useObservable(navLinks$, []); - const prevNavLinksRef = useRef(); const loadingCount = useObservable(loadingCount$, 0); const handleItemClick = (link: string) => { @@ -226,13 +225,8 @@ export const RecentItems = ({ type: item.meta?.type || '', id: item.id, })); - // Deep compare navLinks to avoid unnecessary requests - if ( - savedObjects.length && - JSON.stringify(prevNavLinksRef.current) !== JSON.stringify(navLinks) - ) { + if (savedObjects.length) { bulkGetDetail(savedObjects, http).then((res) => { - const filteredNavLinks = navLinks.filter((link) => !link.hidden); const formatDetailedSavedObjects = res.flatMap((obj) => { const recentAccessItem = recentlyAccessedItems.find( (item) => item.id === obj.id @@ -253,16 +247,13 @@ export const RecentItems = ({ ...recentAccessItem.meta, updatedAt: moment(obj?.updated_at).valueOf(), workspaceName: findWorkspace?.name, - link: createRecentNavLink(recentAccessItem, filteredNavLinks, basePath, navigateToUrl) - .href, }, ]; }); setDetailedSavedObjects(formatDetailedSavedObjects); }); } - prevNavLinksRef.current = navLinks; - }, [navLinks, basePath, navigateToUrl, recentlyAccessedItems, http, workspaceList]); + }, [recentlyAccessedItems, http, workspaceList]); const selectedRecentItems = useMemo(() => { return detailedSavedObjects.slice(0, Number(recentsRadioIdSelected)); @@ -300,7 +291,16 @@ export const RecentItems = ({ {selectedRecentItems.map((item) => ( handleItemClick(item.link)} + onClick={() => + handleItemClick( + createRecentNavLink( + item, + navLinks.filter((link) => !link.hidden), + basePath, + navigateToUrl + ).href + ) + } key={item.link} style={{ padding: '1px' }} label={