Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy management edges when pasting components #5005

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/sdf-server/src/service/diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub mod set_component_position;

pub mod delete_component;
pub mod delete_connection;
pub mod paste_component;
pub mod remove_delete_intent;

mod add_components_to_view;
Expand Down Expand Up @@ -155,7 +154,6 @@ impl IntoResponse for DiagramError {

pub fn routes() -> Router<AppState> {
Router::new()
.route("/paste_components", post(paste_component::paste_components))
.route(
"/add_components_to_view",
post(add_components_to_view::add_components_to_view),
Expand Down
176 changes: 0 additions & 176 deletions lib/sdf-server/src/service/diagram/paste_component.rs

This file was deleted.

54 changes: 41 additions & 13 deletions lib/sdf-server/src/service/v2/view/paste_component.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashMap;
use telemetry::prelude::*;

use super::{ViewError, ViewResult};
use crate::{
Expand Down Expand Up @@ -70,7 +71,7 @@ pub async fn paste_component(
&host_name,
"paste_component",
serde_json::json!({
"how": "/diagram/paste_component",
"how": "/v2/view/paste_component",
"component_id": pasted_comp.id(),
"component_schema_name": schema.name(),
}),
Expand All @@ -82,19 +83,19 @@ pub async fn paste_component(
for component_payload in &request.components {
let component_id = component_payload.id;

let pasted_component =
if let Some(component) = pasted_components_by_original.get(&component_id) {
component
} else {
return Err(ViewError::Paste);
};
let component = Component::get_by_id(&ctx, component_id).await?;
let pasted_component = pasted_components_by_original
.get(&component_id)
.ok_or(ViewError::Paste)?;
let original_component = Component::get_by_id(&ctx, component_id).await?;

// If component parent was also pasted on this batch, keep relationship between new components
if let Some(parent_id) = component.parent(&ctx).await? {
if let Some(pasted_parent) = pasted_components_by_original.get(&parent_id) {
Frame::upsert_parent(&ctx, pasted_component.id(), pasted_parent.id()).await?;
};

if let Some(pasted_parent) = original_component
.parent(&ctx)
.await?
.and_then(|parent_id| pasted_components_by_original.get(&parent_id))
{
Frame::upsert_parent(&ctx, pasted_component.id(), pasted_parent.id()).await?;
}

// If the pasted component didn't get a parent already, set the new parent
Expand All @@ -115,8 +116,35 @@ pub async fn paste_component(
.publish_on_commit(&ctx)
.await?;

for original_manager_id in original_component.managers(&ctx).await? {
let Some(pasted_manager) = pasted_components_by_original.get(&original_manager_id)
else {
continue;
};

match Component::manage_component(&ctx, pasted_manager.id(), pasted_component.id())
.await
{
Ok(edge) => {
WsEvent::connection_upserted(&ctx, edge.into())
.await?
.publish_on_commit(&ctx)
.await?;
}
Err(dal::ComponentError::ComponentNotManagedSchema(_, _, _)) => {
// This error should not occur, but we also don't want to
// fail the paste just because the managed schemas are out
// of sync
error!("Could not manage pasted component, but continuing paste");
}
Err(err) => {
return Err(err)?;
}
};
}

// Create on pasted components copies of edges that existed between original components
for connection in component.incoming_connections(&ctx).await? {
for connection in original_component.incoming_connections(&ctx).await? {
if let Some(from_component) =
pasted_components_by_original.get(&connection.from_component_id)
{
Expand Down