Skip to content

Refactor UI components to be props-driven and Tauri-independent - #1391

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1384-props-driven-components
Jun 8, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1384-props-driven-components

Conversation

@malibio

@malibio malibio commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Closes #1384

#1384)

- TextNode, TaskNode, DateNode: remove sharedNodeStore/structureTree reads; accept
  content/nodeType/children purely as props (base-node-viewer already passes them)
- TaskNode taskState now derives from metadata.taskState (pre-computed by
  extractNodeMetadata) falling back to content-based syntax detection
- BacklinksPanel: replace nodeId+sharedNodeStore subscription with backlinks prop;
  base-node-viewer passes currentViewedNode.mentionedIn
- NavigationSidebar: remove @tauri-apps/api/event import; pro:tier-detected handler
  moved to app-shell.svelte where Tauri API already lives
- Add props-driven-components.test.ts with 15 tests verifying props contracts and
  business logic for each refactored component
- Update backlinks-panel.test.ts to reflect props-driven API

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This PR delivers a well-scoped refactoring that meaningfully improves testability and component isolation. The core approach — removing store reads from leaf components and flowing data down through the visibleNodesFromStores derived in base-node-viewer — is architecturally sound and aligned with Svelte 5 runes patterns. All 3847 tests pass. The PR is a net positive and the acceptance criteria are largely met, but there is one correctness regression and several secondary issues that should be addressed.


Findings

Critical Issues

[Critical/Blocker] task-node.svelte — cancelled task status now renders as pending instead of completed

The old code path went through the now-deleted taskStatusToNodeState() function, which explicitly mapped 'cancelled' → 'completed':

case 'done':
case 'cancelled':
  return 'completed';

The new path relies on metadata.taskState, which is pre-computed by extractNodeMetadata in core-plugins.ts. That function only handles 'in_progress', 'done', and 'open' — 'cancelled' falls through to the default 'pending':

// core-plugins.ts extractMetadata
if (status === 'IN_PROGRESS' || status === 'in_progress') { taskState = 'inProgress'; }
else if (status === 'DONE' || status === 'done') { taskState = 'completed'; }
else if (status === 'OPEN' || status === 'open') { taskState = 'pending'; }
// 'cancelled' → falls through → taskState = 'pending'

CoreTaskStatus includes 'cancelled' as a first-class status value (type CoreTaskStatus = 'open' | 'in_progress' | 'done' | 'cancelled'), and TaskNodeHelpers.isCompleted() explicitly treats both done and cancelled as complete. Any task node previously stored with status='cancelled' will now visually regress from checked-off (completed icon) to unchecked (pending icon).

Fix: Add the missing case to core-plugins.ts extractMetadata:

} else if (status === 'CANCELLED' || status === 'cancelled') {
  taskState = 'completed';
}

This also removes a pre-existing gap that the old taskStatusToNodeState was silently patching.


Suggested Improvements

[Improvement] backlinks-panel.svelte — Component docblock is stale

The <!-- block at the top of the file still reads:

"Uses SharedNodeStore subscription pattern — Subscribes to node changes via store.subscribe() for reliable updates"

This is now false — the component is purely props-driven. The docblock should be updated to reflect the new props interface. Stale comments erode trust in documentation.

[Improvement] TaskNode — nodeType = $bindable('task') has no active consumers

$bindable is declared on both nodeType and content in TaskNode. content is legitimately $bindable because task-node.svelte itself uses bind:content on BaseNode. However, no parent component calls bind:nodeType on TaskNode. This is harmless but misleading — it implies a two-way binding contract that isn't consumed. Since the project standard is no #[deprecated] stale code, simplifying nodeType = $bindable('task') to nodeType = 'task' would be cleaner.

[Improvement] Test coverage gap — cancelled status not exercised

The new props-driven-components.test.ts tests the deriveTaskState logic inline but the test fixture only covers 'completed', 'inProgress', 'pending', and content-based detection. 'cancelled' is a real status value in the type system and is the root cause of the critical issue above. A test case asserting cancelled → completed would have caught this regression.

[Improvement] Minor test duplication between the two test files

backlinks-panel.test.ts now contains a describe('BacklinksPanel Props API (Issue #1384)') block with three tests that overlap conceptually with the describe('BacklinksPanel props contract') block in props-driven-components.test.ts. These are close enough in intent that merging them or keeping the comprehensive coverage in one file would reduce maintenance surface.


Nitpicks

  • Nit: app-shell.svelte guard differs from removed navigation-sidebar.svelte guard. The old sidebar checked '__TAURI__' in window || '__TAURI_INTERNALS__' in window; the app-shell guard only checks __TAURI_INTERNALS__. This was a pre-existing condition in app-shell, so the PR didn't introduce a regression, but it's worth noting that __TAURI__ presence is no longer checked for the tier-reload path.

  • Nit: Stale REFACTOR comments in task-node.svelte. Lines 67, 126, 187, and 221 still reference Issue #316 with "will use bind:content instead" framing, which reads as a future TODO that has already been completed. These could be simplified or removed.

  • Nit: PaneManager and TabSystem were listed in the issue scope but are not included in this PR. Neither component has Tauri dependencies (confirmed by inspection), so the omission is correct. A brief note in the PR body documenting this would reduce future confusion.


Acceptance Criteria Status

  • Audited components render without Tauri runtime (verified in unit tests)
  • [~] All data and callbacks passed via props — no direct store or Tauri imports in component bodies (met for the refactored components; base-node-viewer retains sharedNodeStore as expected per its design role)
  • TypeScript prop interfaces documented for each refactored component
  • Existing tests pass; new tests added for previously untestable components
  • [~] No behavior change in the running app (partially broken: cancelled tasks display as pending)

The cancelled status regression must be fixed before merge. The fix is a one-liner in core-plugins.ts.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a self-review. Recommendation: REQUEST CHANGES before merge. See full findings in the comment above. The critical blocker is the cancelled task status regression in core-plugins.ts — one-liner fix required.

…anup

- Fix core-plugins.ts: map cancelled/CANCELLED task status to 'completed' taskState
  (was falling through to default 'pending' — regression introduced when removing
   taskStatusToNodeState from task-node.svelte)
- Remove $bindable from nodeType in task-node.svelte (no parent binds to it)
- Update core-plugins.test.ts: correct stale expectation that cancelled → 'pending'
- Add cancelled status test in props-driven-components.test.ts
- Fix stale docblock in backlinks-panel.svelte (no longer uses SharedNodeStore)
- Remove stale REFACTOR (Issue #316) comments from task-node.svelte

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator Author

Re-Review — PR #1391 (Issue #1384)

All findings from the initial review have been addressed. Below is the verification of each item.


Critical Issue — Resolved

cancelled status regression in core-plugins.ts

The fix is correctly placed within the extractMetadata function's status-mapping block (line 163-164), after the existing OPEN/open branch and before the closing of the if-else chain:

} else if (status === 'CANCELLED' || status === 'cancelled') {
  taskState = 'completed';
}

Both lowercase and uppercase variants are handled consistently with the pattern used for the other status values in the same block. The placement is correct — it participates in the if-else if chain that short-circuits, so it will never conflict with the other branches.

One behavioral note worth documenting: mapStateToSchema maps 'completed' → 'done', so if a user toggles a cancelled task's checkbox in the UI, it will be written back to the backend as done rather than cancelled. This is a pre-existing design decision in the toggle UX and is not a regression introduced by this PR — the raw status field is passed through return { ...properties, taskState, status, priority } so the original value is preserved for display purposes.


Suggested Improvements — All Resolved

  • backlinks-panel.svelte docblock — Updated to accurately describe the props-driven contract. No lingering references to SharedNodeStore or store.subscribe().

  • nodeType = $bindable('task') in task-node.svelte — Correctly simplified to nodeType = 'task'. content = $bindable('') is correctly retained since task-node.svelte uses bind:content on BaseNode.

  • Test coverage gap for cancelled status — Two locations now cover this:

    1. core-plugins.test.ts: the statusMappings table now includes both { status: 'cancelled', expectedTaskState: 'completed' } and { status: 'CANCELLED', expectedTaskState: 'completed' }, replacing the stale // Unknown status defaults to pending expectation.
    2. props-driven-components.test.ts: a new extractMetadata maps cancelled status to completed taskState test exercises the full mapping function inline, asserting all status values remain correct after the fix.

Nitpicks — All Resolved

  • All four stale REFACTOR (Issue #316) comments removed from task-node.svelte (lines 67, 126, 187, 221 of the original). grep confirms no remaining occurrences.

New Issues Introduced

None. The fix commit is tightly scoped to the five files identified in the initial review. No unrelated files were modified. The logic change in core-plugins.ts is a one-liner addition with no side effects on other status mappings.


Verdict: APPROVED

All critical and improvement-level findings are addressed. The codebase is in a better state than before — the cancelled status regression is fixed, stale comments are gone, and test coverage now guards against the same regression recurring. The PR is a net positive and is ready to merge.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review complete. All findings addressed — see full report in the comment above. Verdict: APPROVE (GitHub blocks self-approval, but this PR is clear to merge).

@malibio
malibio merged commit 80c92ba into main Jun 8, 2026
@malibio
malibio deleted the worktree-issue-1384-props-driven-components branch June 8, 2026 17:56
malibio added a commit that referenced this pull request Jun 22, 2026
* Refactor UI components to be props-driven and Tauri-independent (closes #1384)

- TextNode, TaskNode, DateNode: remove sharedNodeStore/structureTree reads; accept
  content/nodeType/children purely as props (base-node-viewer already passes them)
- TaskNode taskState now derives from metadata.taskState (pre-computed by
  extractNodeMetadata) falling back to content-based syntax detection
- BacklinksPanel: replace nodeId+sharedNodeStore subscription with backlinks prop;
  base-node-viewer passes currentViewedNode.mentionedIn
- NavigationSidebar: remove @tauri-apps/api/event import; pro:tier-detected handler
  moved to app-shell.svelte where Tauri API already lives
- Add props-driven-components.test.ts with 15 tests verifying props contracts and
  business logic for each refactored component
- Update backlinks-panel.test.ts to reflect props-driven API

Co-Authored-By: Claude <[email protected]>

* Address review feedback: fix cancelled task status regression and cleanup

- Fix core-plugins.ts: map cancelled/CANCELLED task status to 'completed' taskState
  (was falling through to default 'pending' — regression introduced when removing
   taskStatusToNodeState from task-node.svelte)
- Remove $bindable from nodeType in task-node.svelte (no parent binds to it)
- Update core-plugins.test.ts: correct stale expectation that cancelled → 'pending'
- Add cancelled status test in props-driven-components.test.ts
- Fix stale docblock in backlinks-panel.svelte (no longer uses SharedNodeStore)
- Remove stale REFACTOR (Issue #316) comments from task-node.svelte

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor UI components to be props-driven and Tauri-independent

1 participant