Repository navigation
Reactive collections sidebar updates on member_of changes - #833
Conversation
The collections sidebar now automatically refreshes when: - New collection nodes are created (via node:created event with nodeType) - Nodes are added to collections (via member_of relationship created) - Nodes are removed from collections (via member_of relationship deleted) ## Backend Changes - Added `node_type` field to `DomainEvent::NodeCreated` to enable reactive UI updates without requiring the frontend to fetch full node data - Updated domain event forwarder (Tauri) to include node_type in payload - Updated dev-proxy SSE events (browser mode) to include node_type ## Frontend Changes - Both sync services (tauri-sync-listener, browser-sync-service) now: - React to collection node creation by refreshing collections - React to member_of relationship changes by refreshing collections - Use debounced refresh (300ms) to handle bulk operations efficiently - Refresh selected collection's members if affected ## Design Decisions - node_type is only included in node:created events (not updated/deleted) since that's the only case where the frontend needs to know the type without already having the node in its store - Debouncing prevents excessive API calls during bulk imports (like the 30+ collections created during documentation import in #770) Closes #832 Co-Authored-By: Claude <[email protected]>
Code Review: Reactive Collections Sidebar (#832)Review Type: Initial Review Requirements CheckFrom Issue #832:
All acceptance criteria have been met. Code Review FindingsArchitecture & DesignNet Positive Assessment: This PR cleanly extends the existing event-driven architecture to support reactive collection updates. The implementation follows established patterns (ID-only events, debouncing for bulk operations) and maintains consistency between Tauri and browser sync services. Design Decision - Well Justified: Suggested Improvements1. [Improvement] Code Duplication - DRY Principle The Recommendation: Extract to a shared utility module: // packages/desktop-app/src/lib/utils/collection-refresh.ts
export function scheduleCollectionRefresh(affectedCollectionId?: string): void {
// ... shared implementation
}Both services could then import and use this shared function. This would:
2. [Nit] Module-level mutable state let collectionRefreshTimer: ReturnType<typeof setTimeout> | null = null;
const COLLECTION_REFRESH_DEBOUNCE_MS = 300;Module-level 3. [Nit] Comment notes potential improvement for The comment correctly identifies that deleted nodes may be collections, but the current implementation relies on "UI to handle stale data gracefully." This is acceptable for now, but consider a future enhancement: track node types in the collections store or include SecurityNo security concerns identified. The changes:
TestingTest Updates: All existing tests have been updated to include the new Test Coverage Assessment:
[Suggestion] Consider adding a dedicated test case for the debounce behavior: it('should debounce rapid collection refresh calls', async () => {
// Create multiple member_of relationships rapidly
// Verify loadCollections is called only once after debounce
});PerformancePositive: The 300ms debounce is appropriate for bulk operations. During the documentation import mentioned in Issue #770 (30+ collections), this prevents 30+ API calls from being made, reducing them to a single call after the batch completes. Observation: The implementation fetches ALL collections on any change ( SummaryThis is a well-implemented feature that cleanly addresses the issue requirements. The code follows existing architectural patterns, includes appropriate documentation (issue references, JSDoc comments), and maintains consistency between the two sync services. Minor improvements suggested:
Recommendation: APPROVE The changes are a clear net positive. The suggested improvements are minor and can be addressed in future PRs if desired. |
malibio
left a comment
There was a problem hiding this comment.
Review complete - see detailed findings above. This is a net positive change ready for merge. (Note: Cannot auto-approve own PR)
Addresses reviewer recommendation from PR #833: - Created shared collection-refresh.ts utility module - Updated browser-sync-service.ts to import from shared utility - Updated tauri-sync-listener.ts to import from shared utility This follows the DRY (Don't Repeat Yourself) principle by consolidating the duplicated debounce logic into a single source of truth. Reviewer suggestions NOT addressed (with justification): - Module-level mutable state: Reviewer noted this is "minor concern" for singleton services. Current implementation works correctly. - Test coverage for debounce: Valid future improvement but outside scope of addressing immediate review feedback. Simple timeout logic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Review Feedback AddressedSummary
Changes MadeCommit:
Verification
Skipped Recommendations (Justification)
|
* Reactive collections sidebar updates on member_of changes (#832) The collections sidebar now automatically refreshes when: - New collection nodes are created (via node:created event with nodeType) - Nodes are added to collections (via member_of relationship created) - Nodes are removed from collections (via member_of relationship deleted) ## Backend Changes - Added `node_type` field to `DomainEvent::NodeCreated` to enable reactive UI updates without requiring the frontend to fetch full node data - Updated domain event forwarder (Tauri) to include node_type in payload - Updated dev-proxy SSE events (browser mode) to include node_type ## Frontend Changes - Both sync services (tauri-sync-listener, browser-sync-service) now: - React to collection node creation by refreshing collections - React to member_of relationship changes by refreshing collections - Use debounced refresh (300ms) to handle bulk operations efficiently - Refresh selected collection's members if affected ## Design Decisions - node_type is only included in node:created events (not updated/deleted) since that's the only case where the frontend needs to know the type without already having the node in its store - Debouncing prevents excessive API calls during bulk imports (like the 30+ collections created during documentation import in #770) Closes #832 Co-Authored-By: Claude <[email protected]> * Address review: Extract scheduleCollectionRefresh to shared utility Addresses reviewer recommendation from PR #833: - Created shared collection-refresh.ts utility module - Updated browser-sync-service.ts to import from shared utility - Updated tauri-sync-listener.ts to import from shared utility This follows the DRY (Don't Repeat Yourself) principle by consolidating the duplicated debounce logic into a single source of truth. Reviewer suggestions NOT addressed (with justification): - Module-level mutable state: Reviewer noted this is "minor concern" for singleton services. Current implementation works correctly. - Test coverage for debounce: Valid future improvement but outside scope of addressing immediate review feedback. Simple timeout logic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Reactive collections sidebar updates on member_of changes (#832) The collections sidebar now automatically refreshes when: - New collection nodes are created (via node:created event with nodeType) - Nodes are added to collections (via member_of relationship created) - Nodes are removed from collections (via member_of relationship deleted) ## Backend Changes - Added `node_type` field to `DomainEvent::NodeCreated` to enable reactive UI updates without requiring the frontend to fetch full node data - Updated domain event forwarder (Tauri) to include node_type in payload - Updated dev-proxy SSE events (browser mode) to include node_type ## Frontend Changes - Both sync services (tauri-sync-listener, browser-sync-service) now: - React to collection node creation by refreshing collections - React to member_of relationship changes by refreshing collections - Use debounced refresh (300ms) to handle bulk operations efficiently - Refresh selected collection's members if affected ## Design Decisions - node_type is only included in node:created events (not updated/deleted) since that's the only case where the frontend needs to know the type without already having the node in its store - Debouncing prevents excessive API calls during bulk imports (like the 30+ collections created during documentation import in #770) Closes #832 Co-Authored-By: Claude <[email protected]> * Address review: Extract scheduleCollectionRefresh to shared utility Addresses reviewer recommendation from PR #833: - Created shared collection-refresh.ts utility module - Updated browser-sync-service.ts to import from shared utility - Updated tauri-sync-listener.ts to import from shared utility This follows the DRY (Don't Repeat Yourself) principle by consolidating the duplicated debounce logic into a single source of truth. Reviewer suggestions NOT addressed (with justification): - Module-level mutable state: Reviewer noted this is "minor concern" for singleton services. Current implementation works correctly. - Test coverage for debounce: Valid future improvement but outside scope of addressing immediate review feedback. Simple timeout logic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
* Reactive collections sidebar updates on member_of changes (#832) The collections sidebar now automatically refreshes when: - New collection nodes are created (via node:created event with nodeType) - Nodes are added to collections (via member_of relationship created) - Nodes are removed from collections (via member_of relationship deleted) ## Backend Changes - Added `node_type` field to `DomainEvent::NodeCreated` to enable reactive UI updates without requiring the frontend to fetch full node data - Updated domain event forwarder (Tauri) to include node_type in payload - Updated dev-proxy SSE events (browser mode) to include node_type ## Frontend Changes - Both sync services (tauri-sync-listener, browser-sync-service) now: - React to collection node creation by refreshing collections - React to member_of relationship changes by refreshing collections - Use debounced refresh (300ms) to handle bulk operations efficiently - Refresh selected collection's members if affected ## Design Decisions - node_type is only included in node:created events (not updated/deleted) since that's the only case where the frontend needs to know the type without already having the node in its store - Debouncing prevents excessive API calls during bulk imports (like the 30+ collections created during documentation import in #770) Closes #832 Co-Authored-By: Claude <[email protected]> * Address review: Extract scheduleCollectionRefresh to shared utility Addresses reviewer recommendation from PR #833: - Created shared collection-refresh.ts utility module - Updated browser-sync-service.ts to import from shared utility - Updated tauri-sync-listener.ts to import from shared utility This follows the DRY (Don't Repeat Yourself) principle by consolidating the duplicated debounce logic into a single source of truth. Reviewer suggestions NOT addressed (with justification): - Module-level mutable state: Reviewer noted this is "minor concern" for singleton services. Current implementation works correctly. - Test coverage for debounce: Valid future improvement but outside scope of addressing immediate review feedback. Simple timeout logic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
node_typetonode:createddomain events to enable reactive UI updates without fetching full node dataChanges
Backend:
node_typefield toDomainEvent::NodeCreatedFrontend:
Test plan
Closes #832
🤖 Generated with Claude Code