Skip to content

fix(canvas): support pasting single-entity resources - #3515

Closed
bissamiftikhar wants to merge 1 commit into
KaotoIO:mainfrom
bissamiftikhar:fix-issues-3445-3446
Closed

fix(canvas): support pasting single-entity resources#3515
bissamiftikhar wants to merge 1 commit into
KaotoIO:mainfrom
bissamiftikhar:fix-issues-3445-3446

Conversation

@bissamiftikhar

@bissamiftikhar bissamiftikhar commented Jul 20, 2026

Copy link
Copy Markdown

Fixes #3445 and #3446 by passing the raw entity template instead of wrapping it in an object literal, and implementing addNewEntity to actually apply the template for Pipe and Kamelet resources.

Summary by CodeRabbit

  • Bug Fixes
    • Improved pasting entities into resources that support multiple visual entities.
    • Preserved the correct entity structure when adding pasted definitions to single-entity resources.
    • Added support for creating and refreshing visual entities when adding new Kamelet and Pipe resources.
    • Improved reliability of visual entity identification after pasted or newly added content is applied.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The paste flow now chooses the appropriate entity template shape and uses new Kamelet and Pipe resource methods to rebuild their visual entities and return their ids.

Changes

Paste entity reconstruction

Layer / File(s) Summary
Resource rebuild methods
packages/ui/src/models/camel/kamelet-resource.ts, packages/ui/src/models/camel/pipe-resource.ts
Kamelet and Pipe resources now accept optional templates, update their underlying definitions, recreate visual entities, and return the resulting ids.
Paste template wiring
packages/ui/src/hooks/usePasteEntity.ts
Pasted definitions are passed directly for multiple-entity resources and wrapped by name for single-entity resources.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: lordrip

Poem

A rabbit pasted routes with care,
Direct shapes hopping everywhere.
Kamelets bloom, pipes redraw,
Fresh IDs twitch their whiskers raw—
The canvas springs from copied fare.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the paste-support change for single-entity resources.
Linked Issues check ✅ Passed The changes address #3445 by applying pasted templates via addNewEntity, which should update both the canvas visualization and source code.
Out of Scope Changes check ✅ Passed All changes are scoped to paste handling and resource entity creation, with no unrelated functionality introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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

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

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ui/src/models/camel/kamelet-resource.ts`:
- Around line 53-59: Update KameletResource.addNewEntity to rebuild beans from
the replacement Kamelet template, or clear beans when the template has none;
update PipeResource.addNewEntity to rebuild errorHandler from the replacement
Pipe specification, or clear it when absent. Apply the corresponding
synchronization at packages/ui/src/models/camel/kamelet-resource.ts:53-59 and
packages/ui/src/models/camel/pipe-resource.ts:58-65 so child entities no longer
reference stale resources.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8a4ec3a6-92d6-45dd-9e10-e4cbe5118860

📥 Commits

Reviewing files that changed from the base of the PR and between 4f515f7 and f0a0144.

📒 Files selected for processing (3)
  • packages/ui/src/hooks/usePasteEntity.ts
  • packages/ui/src/models/camel/kamelet-resource.ts
  • packages/ui/src/models/camel/pipe-resource.ts

Comment on lines +53 to +59
addNewEntity(_entityType?: EntityType, entityTemplate?: unknown): string {
if (entityTemplate) {
this.resource = entityTemplate as IKameletDefinition;
this.flow = new KameletVisualEntity(this.resource as IKameletDefinition);
}
return this.flow?.id ?? '';
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Synchronize dependent entities when replacing pasted resources.

Both implementations replace the underlying resource but retain child entities bound to the previous resource, which can overwrite pasted data or apply later edits to stale state.

  • packages/ui/src/models/camel/kamelet-resource.ts#L53-L59: rebuild beans from the new Kamelet template, or clear it when absent.
  • packages/ui/src/models/camel/pipe-resource.ts#L58-L65: rebuild errorHandler from the new Pipe specification, or clear it when absent.
📍 Affects 2 files
  • packages/ui/src/models/camel/kamelet-resource.ts#L53-L59 (this comment)
  • packages/ui/src/models/camel/pipe-resource.ts#L58-L65
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/models/camel/kamelet-resource.ts` around lines 53 - 59,
Update KameletResource.addNewEntity to rebuild beans from the replacement
Kamelet template, or clear beans when the template has none; update
PipeResource.addNewEntity to rebuild errorHandler from the replacement Pipe
specification, or clear it when absent. Apply the corresponding synchronization
at packages/ui/src/models/camel/kamelet-resource.ts:53-59 and
packages/ui/src/models/camel/pipe-resource.ts:58-65 so child entities no longer
reference stale resources.

@PVinaches

PVinaches commented Jul 22, 2026

Copy link
Copy Markdown
Member

Hello! Thanks for taking the time to look at this. Could you provide a video of how it works? It is marked that it solves two issues, but I am not seeing the code related to #3445, only #3446

@PVinaches

Copy link
Copy Markdown
Member

Thank you for your interest in contributing to Kaoto!
As outlined in our Contributing Guidelines, we welcome AI-assisted contributions, but they must be submitted by a human contributor who can:
Review and take responsibility for the code quality
Respond to maintainer feedback
Follow up on PR discussions
Since this PR appears to be submitted directly by an AI agent without human oversight, I'll be closing it. If you're a human contributor using AI assistance, please feel free to review this code, make any necessary adjustments, and resubmit the PR with your approval and sign-off.
We appreciate your understanding and look forward to future contributions!

@PVinaches PVinaches closed this Jul 27, 2026
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.

[Citrus testing] Paste a complete test route does not update source code nor visualisation

2 participants