From 8f5cd13e780fae31f2f2ebffd108d08868780bee Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Tue, 6 Jun 2023 10:36:58 +0800 Subject: [PATCH] fix: do not show deleted reference (#2689) --- .../favorite/favorite-list.tsx | 8 +++- .../local-first-favorites-items.spec.ts | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx b/apps/web/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx index 5c5a727690..78127ff627 100644 --- a/apps/web/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx +++ b/apps/web/src/components/pure/workspace-slider-bar/favorite/favorite-list.tsx @@ -32,8 +32,12 @@ function FavoriteMenuItem({ const icon = record[pageId] === 'edgeless' ? : ; const references = useBlockSuitePageReferences(workspace, pageId); const referencesToShow = useMemo(() => { - return [...new Set(references.filter(ref => !parentIds.has(ref)))]; - }, [references, parentIds]); + return [ + ...new Set( + references.filter(ref => !parentIds.has(ref) && !metaMapping[ref].trash) + ), + ]; + }, [references, parentIds, metaMapping]); const [collapsed, setCollapsed] = useState(true); const collapsible = referencesToShow.length > 0; const nestedItem = parentIds.size > 0; diff --git a/tests/parallels/local-first-favorites-items.spec.ts b/tests/parallels/local-first-favorites-items.spec.ts index 8a7ff5b646..44cf6aff0b 100644 --- a/tests/parallels/local-first-favorites-items.spec.ts +++ b/tests/parallels/local-first-favorites-items.spec.ts @@ -71,3 +71,50 @@ test('Show favorite reference in sidebar', async ({ page }) => { page.locator('[data-type="favorite-list-item"] >> text=Another page') ).toBeVisible(); }); + +test("Deleted page's reference will not be shown in sidebar", async ({ + page, +}) => { + await openHomePage(page); + await waitMarkdownImported(page); + await newPage(page); + await getBlockSuiteEditorTitle(page).click(); + await getBlockSuiteEditorTitle(page).fill('this is a new page to favorite'); + + const newPageId = page.url().split('/').reverse()[0]; + + // goes to main content + await page.keyboard.press('Enter', { delay: 50 }); + + await createLinkedPage(page, 'Another page'); + + await clickPageMoreActions(page); + + const favoriteBtn = page.getByTestId('editor-option-menu-favorite'); + await favoriteBtn.click(); + + // goto "Another page" + await page.locator('.affine-reference-title').click(); + + // delete the page + await clickPageMoreActions(page); + + const deleteBtn = page.getByTestId('editor-option-menu-delete'); + await deleteBtn.click(); + + // confirm delete + await page.locator('button >> text=Delete').click(); + + const favItemTestId = 'favorite-list-item-' + newPageId; + + const favoriteListItemInSidebar = page.getByTestId(favItemTestId); + expect(await favoriteListItemInSidebar.textContent()).toBe( + 'this is a new page to favorite' + ); + + const collapseButton = favoriteListItemInSidebar.locator( + '[data-testid="fav-collapsed-button"]' + ); + + await expect(collapseButton).not.toBeVisible(); +});