Skip to content

Commit

Permalink
update filter sequence
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Nov 22, 2024
1 parent e7950b8 commit f32ac92
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/core/public/chrome/ui/header/recent_items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,35 +220,36 @@ 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;

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);
});
Expand Down

0 comments on commit f32ac92

Please sign in to comment.