From f32ac92bc09d1900a65417b14c94b293826a05cc Mon Sep 17 00:00:00 2001 From: tygao Date: Fri, 22 Nov 2024 13:34:25 +0800 Subject: [PATCH] update filter sequence Signed-off-by: tygao --- .../public/chrome/ui/header/recent_items.tsx | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/core/public/chrome/ui/header/recent_items.tsx b/src/core/public/chrome/ui/header/recent_items.tsx index 61ab5cc1ede..298bf51d2bc 100644 --- a/src/core/public/chrome/ui/header/recent_items.tsx +++ b/src/core/public/chrome/ui/header/recent_items.tsx @@ -220,14 +220,21 @@ export const RecentItems = ({ useEffect(() => { const savedObjects = recentlyAccessedItems - .filter((item) => item.meta?.type) + .filter( + (item) => + item.meta?.type && + (!item.workspaceId || + // If the workspace id is existing but the workspace is deleted, filter the item + (item.workspaceId && + !!workspaceList.find((workspace) => workspace.id === item.workspaceId))) + ) .map((item) => ({ type: item.meta?.type || '', id: item.id, })); if (savedObjects.length) { bulkGetDetail(savedObjects, http).then((res) => { - const formatDetailedSavedObjects = res.flatMap((obj) => { + const formatDetailedSavedObjects = res.map((obj) => { const recentAccessItem = recentlyAccessedItems.find( (item) => item.id === obj.id ) as ChromeRecentlyAccessedHistoryItem; @@ -235,20 +242,14 @@ export const RecentItems = ({ const findWorkspace = workspaceList.find( (workspace) => workspace.id === recentAccessItem.workspaceId ); - // If the workspace id is existing but the workspace is deleted, filter the item - if (recentAccessItem.workspaceId && !findWorkspace) { - return []; - } - return [ - { - ...recentAccessItem, - ...obj, - ...recentAccessItem.meta, - updatedAt: moment(obj?.updated_at).valueOf(), - workspaceName: findWorkspace?.name, - }, - ]; + return { + ...recentAccessItem, + ...obj, + ...recentAccessItem.meta, + updatedAt: moment(obj?.updated_at).valueOf(), + workspaceName: findWorkspace?.name, + }; }); setDetailedSavedObjects(formatDetailedSavedObjects); });