feat(core): add unlink action for linked docs in sidebar - #15360
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughAdds an “Unlink” sidebar action for linked documents. The action removes matching references from the parent document, preserves the child document, adds localized labels, and includes an end-to-end test. ChangesDocument unlinking
Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to This PR adds an authorized Unlink action that removes linked-document references while preserving the child document; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant User
participant Sidebar
participant DocsService
participant ParentDocument
User->>Sidebar: Select Unlink
Sidebar->>DocsService: removeLinkedDoc(parentDocId, docId)
DocsService->>ParentDocument: Remove matching references
ParentDocument-->>DocsService: Return removed count
DocsService-->>Sidebar: Complete unlink
Sidebar-->>User: Show Unlinked status
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/frontend/core/src/modules/doc/services/docs.ts (1)
238-244: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winEmpty-block cleanup only handles
affine:paragraph.References can be typed anywhere text exists (e.g. list items, headings), not only paragraphs. If a reference-only list item/heading becomes empty after removal, it's left behind as a stray empty block instead of being cleaned up, unlike paragraphs.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/frontend/core/src/modules/doc/services/docs.ts` around lines 238 - 244, Update the empty-block cleanup condition in the surrounding removal logic to apply to any text-bearing block, not only models with flavour affine:paragraph. Preserve the existing removed-count and text.length checks, and continue deleting the block through bsDoc.deleteBlock(model.id).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/frontend/core/src/modules/doc/services/docs.ts`:
- Around line 212-217: Wrap the mutation and deletion work in removeLinkedDoc,
after open and priority-load setup, in a try/finally block; invoke release() in
the finally clause so it always runs if text.delete or bsDoc.deleteBlock throws.
Preserve the existing cleanup of disposePriorityLoad and follow the release
pattern used by duplicate and duplicateFromTemplate.
---
Nitpick comments:
In `@packages/frontend/core/src/modules/doc/services/docs.ts`:
- Around line 238-244: Update the empty-block cleanup condition in the
surrounding removal logic to apply to any text-bearing block, not only models
with flavour affine:paragraph. Preserve the existing removed-count and
text.length checks, and continue deleting the block through
bsDoc.deleteBlock(model.id).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3bd34343-aaaf-4f33-9671-c8685bef2770
📒 Files selected for processing (8)
packages/frontend/core/src/desktop/components/navigation-panel/nodes/doc/index.tsxpackages/frontend/core/src/desktop/components/navigation-panel/nodes/doc/operations.tsxpackages/frontend/core/src/modules/doc/services/docs.tspackages/frontend/i18n/src/i18n.gen.tspackages/frontend/i18n/src/resources/en.jsonpackages/frontend/i18n/src/resources/zh-Hans.jsonpackages/frontend/i18n/src/resources/zh-Hant.jsontests/affine-local/e2e/unlink-doc.spec.ts
95ec323 to
885c8ab
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
…g#13511) Drag-and-drop creates a linked-doc relationship by inserting a page reference into the parent doc content, with no way to undo it short of manually editing the parent doc. - add DocsService.removeLinkedDoc(targetDocId, linkedDocId): removes all reference deltas pointing at the linked doc from the target doc content (inverse of addLinkedDoc), deleting paragraphs left empty afterwards - expose an "Unlink" item in the context menu of linked doc nodes in the navigation panel, guarded by Doc_Update on the parent doc - e2e coverage: link via drag-and-drop, unlink via context menu, assert the child doc is unlinked but not deleted Fixes toeverything#13511
70b1648 to
aec5026
Compare
Summary
Fixes #13511
Drag-and-drop creates a linked-doc relationship by inserting a page reference into the parent doc content, with no way to undo it short of manually editing the parent doc.
DocsService.removeLinkedDoc(targetDocId, linkedDocId): removes all reference deltas pointing at the linked doc from the target doc content (inverse ofaddLinkedDoc), deleting paragraphs left empty afterwardsDoc_Updateon the parent docTest plan
tests/affine-local/e2e/unlink-doc.spec.ts— link via drag-and-drop, unlink via context menu, assert the child doc is unlinked but not deletedtsc -b packages/frontend/corecleanSummary by CodeRabbit