fix: do not show deleted reference (#2689)

This commit is contained in:
Peng Xiao 2023-06-06 10:36:58 +08:00 committed by GitHub
parent 3b4cfc642f
commit 8f5cd13e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 2 deletions

View File

@ -32,8 +32,12 @@ function FavoriteMenuItem({
const icon = record[pageId] === 'edgeless' ? <EdgelessIcon /> : <PageIcon />;
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;

View File

@ -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();
});