Skip to content

QueryNodeViewer with Multi-View Rendering Support - #961

Merged
malibio merged 2 commits into
mainfrom
feature/issue-441-query-node-viewer
Mar 16, 2026
Merged

malibio merged 2 commits into
mainfrom
feature/issue-441-query-node-viewer

Conversation

@malibio

@malibio malibio commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator

Closes #441

Implements QueryNodeViewer as a page-level viewer that loads a schema node
by nodeId, derives columns from its field definitions, executes a query for
all nodes of that type, and renders results in a TableView. Row clicks open
the node in another panel via navigateToNodeInOtherPane().

- QueryNodeViewer: loads schema, executes query, handles loading/error/empty states, refresh button
- TableView: schema-driven column derivation (not key enumeration), clickable title column
- Registered QueryNodeViewer in plugin registry for nodeType 'query'
- Updated core-plugins test to expect 4 viewers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

malibio commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

PR #961 implements QueryNodeViewer and TableView as described in issue #441. The implementation is clean, well-structured, and follows established patterns in the codebase (mirrors CollectionNodeViewer and DateNodeViewer faithfully). All ten acceptance criteria from the issue are satisfied. The change is a net positive and is ready to merge with one correctness concern that should be understood before merging.


Findings

Correctness Issue (Understand Before Merging)

query-node-viewer.svelte line 81 — Schema ID used as nodeType filter

The query call is:

backendAdapter.queryNodes({ nodeType: target.id });

target.id is the schema's ID (e.g., "task"). This works correctly only if the schema ID is identical to the node type string stored in each data node's nodeType field. The SchemaNode interface confirms id is documented as "same as schema type, e.g., 'task', 'person'", and the issue description says "nodeId IS the schema id (e.g. 'task')". So in the current data model this is intentional and correct.

However, the field being passed is named nodeType in NodeQuery while the variable in the component is called schemaId/target.id. There is no intermediate mapping through a targetType field (as the QueryNode type in query.ts defines), which would be the more explicit contract. This is a deliberate simplification consistent with the issue's "Everything is a Node" design decision. Worth a comment in the code to make the equivalence explicit for future readers, since the QueryNode type in query.ts uses a distinct targetType field that is separate from the schema's id.

Recommendation: Add a one-line comment above line 81 explaining that target.id equals the node type string (e.g., // target.id === nodeType for schema nodes (e.g., "task")).


Improvement

query-node-viewer.svelte lines 41–43 — Race condition on rapid nodeId prop changes

$effect(() => {
  loadAndQuery(nodeId);
});

loadAndQuery is async. If nodeId changes while a previous load is still in-flight (e.g., user navigates quickly between schema types), two concurrent requests will both write to schemaNode, results, and queryState. The last one to resolve wins, which could display results for the wrong schema. This is a known class of bug in reactive UI code.

CollectionNodeViewer (the reference component) has the same pattern with loadCollectionData, so this is consistent with the established codebase convention. But since QueryNodeViewer is designed specifically for rapid navigation (sidenav clicks), it is more exposed to this scenario than the collection viewer.

A minimal mitigation is to track a currentSchemaId sentinel inside loadAndQuery and bail out if it no longer matches nodeId after each await. Given CLAUDE.md's no-complexity philosophy, this is flagged as an improvement rather than a blocker, but it is worth addressing before the navigation UX is wired up.


Nitpicks

  • Nit: table-view.svelte line 32 — the label capitalization is inline: field.name.charAt(0).toUpperCase() + field.name.slice(1). This would be cleaner as a named helper toLabel(name: string) for readability, especially since getCellValue already has a similar dedicated helper pattern.

  • Nit: table-view.svelte line 64 — the clickable column is determined by positional index (i === 0) rather than col.field === 'content'. Both are equivalent given the content column is always prepended first, but the field-name check would be more self-documenting and robust against future column reordering.

  • Nit: query-node-viewer.svelte line 108 — "Loading..." is shown as the h1 title while the schema is loading. Because onTitleChange fires only after the schema loads, the tab title and the h1 are briefly out of sync on first render. A neutral placeholder like "Query" instead of "Loading..." in the h1 would better match what the tab title shows.

  • Nit: No dedicated unit tests exist for QueryNodeViewer or TableView logic (column derivation, getCellValue edge cases, loading state transitions). The core-plugins.test.ts update covers registration. Given the project's test-file convention, a src/tests/components/query-node-viewer.test.ts covering getCellValue with null/object/primitive values and columns derivation with and without schema fields would be a worthwhile addition.


Requirements Validation

Criterion Status
Loads schema node by nodeId, displays content as page title Met
Executes query for all nodes matching schema's type id Met
TableView derives columns from schema field definitions, not key enumeration Met
First column is always content (title), clickable Met
Row click calls navigateToNodeInOtherPane() Met
Loading, error, and empty states handled Met
Refresh button re-executes query Met
QueryNodeViewer registered in plugin registry for nodeType: 'query' Met
List and Kanban views not in scope Met (correctly omitted)
Tests pass / code passes quality:fix Assumed passing (test update present, no new unit tests for the components themselves)

@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.

Review complete. See detailed findings in the comment above. All acceptance criteria are met; the implementation is clean and follows the established viewer pattern. The race condition note and the schema-ID/nodeType equivalence comment are the items worth addressing before or after merge.

…aceholder

- Add loadId sentinel to discard stale async responses on rapid nodeId changes
- Add comment explaining target.id === nodeType equivalence for schema nodes
- Fix clickable column detection: i === 0 → col.field === 'content' (semantic)
- Fix h1 placeholder: 'Loading...' → 'Query' (consistent with tab title)

Skipped:
- toLabel() helper extraction: one-liner in $derived, not worth abstracting
- Unit tests for getCellValue/columns: trivial string coercion, low ROI

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

malibio commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator Author

Review Feedback Addressed

Addressed (4):

  • ✅ Added loadId sentinel to discard stale async responses on rapid nodeId changes (race condition)
  • ✅ Added comment explaining target.id === nodeType equivalence for schema nodes
  • ✅ Fixed clickable column detection: i === 0 → col.field === 'content' (semantic check)
  • ✅ Fixed h1 placeholder: 'Loading...' → 'Query' (consistent with tab title on first render)

Skipped (2):

  • ⏭️ toLabel() helper extraction — one-liner inside a $derived, extracting adds indirection without benefit
  • ⏭️ Unit tests for getCellValue/columns — trivial null/string coercion with no branching logic worth isolating; low ROI

@malibio
malibio merged commit 8076a97 into main Mar 16, 2026
@malibio
malibio deleted the feature/issue-441-query-node-viewer branch March 16, 2026 21:31
malibio added a commit that referenced this pull request Jun 22, 2026
* feat: QueryNodeViewer with TableView rendering support (closes #441)

Implements QueryNodeViewer as a page-level viewer that loads a schema node
by nodeId, derives columns from its field definitions, executes a query for
all nodes of that type, and renders results in a TableView. Row clicks open
the node in another panel via navigateToNodeInOtherPane().

- QueryNodeViewer: loads schema, executes query, handles loading/error/empty states, refresh button
- TableView: schema-driven column derivation (not key enumeration), clickable title column
- Registered QueryNodeViewer in plugin registry for nodeType 'query'
- Updated core-plugins test to expect 4 viewers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

* Address review: race condition sentinel, semantic column check, h1 placeholder

- Add loadId sentinel to discard stale async responses on rapid nodeId changes
- Add comment explaining target.id === nodeType equivalence for schema nodes
- Fix clickable column detection: i === 0 → col.field === 'content' (semantic)
- Fix h1 placeholder: 'Loading...' → 'Query' (consistent with tab title)

Skipped:
- toLabel() helper extraction: one-liner in $derived, not worth abstracting
- Unit tests for getCellValue/columns: trivial string coercion, low ROI

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

---------

Co-authored-by: Claude Sonnet 4.6 <[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.

QueryNodeViewer with Multi-View Rendering Support

1 participant