Skip to content

fix(kamelet-resource): access route.from instead of from in test - #3926

Open
lhein wants to merge 3 commits into
KaotoIO:mainfrom
lhein:fix/issue-3446-paste-pipe-kamelet
Open

lhein wants to merge 3 commits into
KaotoIO:mainfrom
lhein:fix/issue-3446-paste-pipe-kamelet

Conversation

@lhein

@lhein lhein commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #3446

Fixes the TypeScript build error reported in #3838.

The test in kamelet-resource.test.ts accessed .from directly on the result of toJSON(), but KameletVisualEntity.toJSON() returns { route: RouteDefinition } — so from is nested under route.

Fix:

- const from = resource.getVisualEntities()[0].toJSON().from;
+ const from = resource.getVisualEntities()[0].toJSON().route.from;

This is a companion fix to #3838 by @ThomasHartDev.

Summary by CodeRabbit

  • Bug Fixes
    • Improved pasting of Kamelet and Pipe templates so their definitions are applied correctly.
    • Pasted templates now rebuild visual flows and related configuration, including route-template beans and error handlers.
    • Removed stale visual elements when replacement content no longer includes them.
    • Resource metadata is refreshed after pasted content is applied.
    • Added coverage to verify template replacement and paste behavior across supported resource types.

ThomasHartDev and others added 3 commits September 9, 2026 06:33
Pipe and Kamelet resources inherit a no-op addNewEntity, so replacing
on paste left a blank template. Apply the copied definition and rebuild
child entities (beans, error handler, metadata).
…sue-3446-paste-pipe-kamelet

* fix/issue-3446-paste-pipe-kamelet-upstream:
  fix(canvas): Apply pasted Pipe and Kamelet templates
The toJSON() method of KameletVisualEntity returns { route: RouteDefinition },
so the from property is nested under route, not at the top level.

Relates to KaotoIO#3838
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4a1392c5-a2e3-4705-baa8-be1bb2977d52

📥 Commits

Reviewing files that changed from the base of the PR and between 1e4935d and 37894bb.

📒 Files selected for processing (8)
  • packages/ui/src/hooks/usePasteEntity.test.tsx
  • packages/ui/src/hooks/usePasteEntity.ts
  • packages/ui/src/models/camel/camel-k-resource.ts
  • packages/ui/src/models/camel/kamelet-binding-resource.ts
  • packages/ui/src/models/camel/kamelet-resource.test.ts
  • packages/ui/src/models/camel/kamelet-resource.ts
  • packages/ui/src/models/camel/pipe-resource.test.ts
  • packages/ui/src/models/camel/pipe-resource.ts
💤 Files with no reviewable changes (1)
  • packages/ui/src/models/camel/kamelet-binding-resource.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Paste handling now passes raw definitions for single-entity resources. Kamelet and Pipe resources rebuild visual entities and metadata from pasted templates. Tests cover replacement content and removed nested entities.

Changes

Paste entity replacement

Layer / File(s) Summary
Template shape selection
packages/ui/src/hooks/usePasteEntity.ts, packages/ui/src/hooks/usePasteEntity.test.tsx
usePasteEntity passes wrapped definitions for multi-entity resources and raw definitions for Kamelet and Pipe resources. Tests verify both argument shapes.
Resource visual entity rebuilding
packages/ui/src/models/camel/camel-k-resource.ts, packages/ui/src/models/camel/kamelet-resource.ts, packages/ui/src/models/camel/pipe-resource.ts, packages/ui/src/models/camel/kamelet-binding-resource.ts, packages/ui/src/models/camel/kamelet-resource.test.ts, packages/ui/src/models/camel/pipe-resource.test.ts
Kamelet and Pipe resources replace their templates, rebuild flow-related entities, synchronize metadata, and clear absent beans or error handlers. The unused Kamelet binding method is removed. Tests cover these replacement paths.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant usePasteEntity
  participant KameletResource
  participant PipeResource
  participant VisualEntities
  usePasteEntity->>KameletResource: addNewEntity(raw Kamelet definition)
  KameletResource->>VisualEntities: rebuild flow and beans
  KameletResource->>KameletResource: synchronize metadata
  usePasteEntity->>PipeResource: addNewEntity(raw Pipe definition)
  PipeResource->>VisualEntities: rebuild flow and error handler
  PipeResource->>PipeResource: synchronize metadata
Loading

Suggested reviewers: lordrip

Merge Risk: ⚪ Minimal · up to 37894

Single-entity paste replacement now supplies the template shape expected by Kamelet and Pipe resources, with coverage for rebuilding and clearing replacement state. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 7…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the Kamelet resource test fix identified in the objectives. It is narrower than the full changeset but remains clear and directly related.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

A rabbit pastes templates with care
Raw pipes hop through the air
Flows rebuild in rows
Old handlers doze
Metadata follows everywhere

Comment @coderabbitai help to get the list of available commands.

@lhein
lhein requested a review from PVinaches September 11, 2026 11:30
@PVinaches

Copy link
Copy Markdown
Member

I have noticed a small bug in the implementation: when copied a pipe or a kamelet and pasted again, the product is correct but it appears hidden. Check this video (it appears only the pipe case but with kamelet is the same):

Screen.Recording.2026-09-11.at.14.13.04.mov

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.

[Canvas] Pipes and kamelets are not pasting full routes but generating a new one

3 participants