Skip to content

Add view parameter to NodeSpec#31

Merged
philippjfr merged 9 commits intomainfrom
copilot/add-view-parameter-to-nodespec
Feb 11, 2026
Merged

Add view parameter to NodeSpec#31
philippjfr merged 9 commits intomainfrom
copilot/add-view-parameter-to-nodespec

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 8, 2026

Summary

Adds a view parameter to the NodeSpec dataclass, eliminating the need for the workaround of serializing to dict and merging to add views to nodes.

Changes

Core Feature

  • NodeSpec: Added view: Any | None = None field to the dataclass
  • NodeSpec.to_dict(): Includes view in the output when not None
  • Documentation: Added comprehensive numpy-style docstrings for the new parameter with examples

Merged with main

  • Rebased on top of updated main branch (aed7160)
  • Incorporated comprehensive numpy-style docstrings from main

Implementation Simplification (Review Feedback)

After initial implementation, the approach was simplified based on review feedback (commit 752978d):

  • Removed sentinel value complexity from add_node()
  • Removed separate view parameter from add_node() method
  • Users now simply pass NodeSpec with view included - cleaner and more intuitive
  • Updated documentation and examples to reflect streamlined approach

Usage

Before:

nodes = [
    NodeSpec(id="loader", position={"x": 0, "y": 80}, label="Data Loader").to_dict() | {"view": loader.__panel__()},
    NodeSpec(id="filter", position={"x": 400, "y": 50}, label="Column Filter").to_dict() | {"view": filter_node.__panel__()},
]

After:

from panel_reactflow import NodeSpec

nodes = [
    NodeSpec(id="loader", position={"x": 0, "y": 80}, label="Data Loader", view=loader.__panel__()),
    NodeSpec(id="filter", position={"x": 400, "y": 50}, label="Column Filter", view=filter_node.__panel__()),
]

# Or pass directly to add_node
flow.add_node(NodeSpec(
    id="live",
    label="Live Feed",
    position={"x": 600, "y": 0},
    view=pn.indicators.Number(value=42, name="Metric")
))

Testing

✅ All validation tests pass:

  • NodeSpec with view parameter
  • NodeSpec without view parameter
  • NodeSpec roundtrip with view
  • Integration with ReactFlow.add_node()

Files Changed

  • src/panel_reactflow/base.py: Added view parameter to NodeSpec with improved docstrings
  • tests/test_api.py: Tests for NodeSpec view parameter
  • docs/how-to/embed-views-in-nodes.md: Updated examples to show simplified approach
Original prompt

This section details on the original issue you should resolve

<issue_title>NodeSpec does not have view parameter</issue_title>
<issue_description>The NodeSpec dataclass is hard to use because it does not have view attribute. Please add.

I end up having to serialize to add the view

nodes=[
    NodeSpec(id="loader", position={"x": 0, "y": 80}, label="Data Loader").to_dict() | {"view": loader.__panel__()},
    NodeSpec(id="filter", position={"x": 400, "y": 50}, label="Column Filter").to_dict() | {"view": filter_node.__panel__()},
    NodeSpec(id="chart", position={"x": 850, "y": 0}, label="Scatter Chart").to_dict() | {"view": chart.__panel__()},
],
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 8, 2026 21:36
Co-authored-by: MarcSkovMadsen <42288570+MarcSkovMadsen@users.noreply.github.com>
Co-authored-by: MarcSkovMadsen <42288570+MarcSkovMadsen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add view parameter to NodeSpec dataclass Add view parameter to NodeSpec Feb 8, 2026
Copilot AI requested a review from MarcSkovMadsen February 8, 2026 21:43
Copy link
Copy Markdown
Contributor

@MarcSkovMadsen MarcSkovMadsen left a comment

Choose a reason for hiding this comment

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

Please merge with updated main and fix any issues. Including docstring issues as docstrings have been significantly improved.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 9, 2026

Please merge with updated main and fix any issues. Including docstring issues as docstrings have been significantly improved.

Done! Successfully rebased on updated main (commit aed7160) and updated all docstrings.

Changes:

  • Rebased on top of main with comprehensive numpy-style docstrings
  • Updated NodeSpec docstring to document the new view parameter
  • Updated add_node docstring to clarify view parameter behavior (preserves vs overrides)
  • Added example showing NodeSpec with embedded view

Implementation:

  • NodeSpec now has view: Any | None = None field
  • to_dict() includes view when not None
  • add_node() uses sentinel value to preserve view from NodeSpec when not explicitly overridden

All tests passing locally (commit 953f15b).

Note: The rebase created new commits, so this will need a force push to update the PR.

MarcSkovMadsen and others added 3 commits February 9, 2026 06:59
…-to-nodespec

Copilot/add view parameter to nodespec
Co-authored-by: MarcSkovMadsen <42288570+MarcSkovMadsen@users.noreply.github.com>
@MarcSkovMadsen MarcSkovMadsen marked this pull request as ready for review February 9, 2026 07:25
@MarcSkovMadsen
Copy link
Copy Markdown
Contributor

@copilot. Please update the summary in the first post in this PR with the changes I merged into this branch.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 9, 2026

@copilot. Please update the summary in the first post in this PR with the changes I merged into this branch.

Updated the PR description to reflect the simplified implementation after review feedback (commit 752978d).

Key changes in the final implementation:

  • NodeSpec now has a view parameter for embedding Panel viewables
  • Simplified add_node() - no separate view parameter needed, just pass NodeSpec with view
  • Updated documentation and examples to show the streamlined approach
  • Removed complexity of sentinel values and parameter overriding

@philippjfr philippjfr merged commit 13b5fdd into main Feb 11, 2026
18 checks passed
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.

NodeSpec does not have view parameter

3 participants