diff --git a/app/web/src/store/components.store.ts b/app/web/src/store/components.store.ts index ca66087de6..9b845d21ba 100644 --- a/app/web/src/store/components.store.ts +++ b/app/web/src/store/components.store.ts @@ -1686,11 +1686,15 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { { eventType: "ConnectionDeleted", callback: (edge, metadata) => { - // If the component that updated wasn't in this change set, - // don't update if (metadata.change_set_id !== changeSetId) return; - const e = edgeFromRawEdge(false)(edge); - // this.edgesById[e.id] = e; + // making TS happy, we don't need this data since we're just deleting + const _edge = edge as RawEdge; + _edge.toDelete = true; + _edge.createdInfo = { + actor: { kind: "system", label: "" }, + timestamp: "", + }; + const e = edgeFromRawEdge(false)(_edge); delete this.edgesById[e.id]; }, }, diff --git a/app/web/src/store/realtime/realtime_events.ts b/app/web/src/store/realtime/realtime_events.ts index 24b14b505e..1e1a236937 100644 --- a/app/web/src/store/realtime/realtime_events.ts +++ b/app/web/src/store/realtime/realtime_events.ts @@ -191,7 +191,12 @@ export type WsEventPayloadMap = { edges: RawEdge[]; }; ConnectionCreated: RawEdge; - ConnectionDeleted: RawEdge; + ConnectionDeleted: { + fromComponentId: string; + toComponentId: string; + fromSocketId: string; + toSocketId: string; + }; ModuleImported: SchemaVariant[]; WorkspaceImportBeginApprovalProcess: { workspacePk: WorkspacePk; diff --git a/lib/dal/src/component.rs b/lib/dal/src/component.rs index c3995b1351..6faec82ce9 100644 --- a/lib/dal/src/component.rs +++ b/lib/dal/src/component.rs @@ -3657,18 +3657,16 @@ impl Component { ) .await?; - let from_component = Component::get_by_id(ctx, incoming.from_component_id).await?; - let to_component = Component::get_by_id(ctx, incoming.to_component_id).await?; - let edge = SummaryDiagramEdge::assemble( - incoming.clone(), - &from_component, - &to_component, - ChangeStatus::Deleted, - )?; - WsEvent::connection_deleted(ctx, edge) - .await? - .publish_on_commit(ctx) - .await?; + WsEvent::connection_deleted( + ctx, + incoming.from_component_id, + incoming.to_component_id, + incoming.from_output_socket_id, + incoming.to_input_socket_id, + ) + .await? + .publish_on_commit(ctx) + .await?; } for outgoing in &original_outgoing_connections { @@ -3681,18 +3679,16 @@ impl Component { ) .await?; - let from_component = Component::get_by_id(ctx, outgoing.from_component_id).await?; - let to_component = Component::get_by_id(ctx, outgoing.to_component_id).await?; - let edge = SummaryDiagramEdge::assemble_outgoing( - outgoing.clone(), - &from_component, - &to_component, - ChangeStatus::Deleted, - )?; - WsEvent::connection_deleted(ctx, edge) - .await? - .publish_on_commit(ctx) - .await?; + WsEvent::connection_deleted( + ctx, + outgoing.from_component_id, + outgoing.to_component_id, + outgoing.from_output_socket_id, + outgoing.to_input_socket_id, + ) + .await? + .publish_on_commit(ctx) + .await?; } // Let's requeue any Actions for the component @@ -4157,8 +4153,6 @@ pub struct ConnectionDeletedPayload { to_component_id: ComponentId, from_socket_id: OutputSocketId, to_socket_id: InputSocketId, - change_set_id: ChangeSetId, - to_delete: bool, } #[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)] @@ -4321,9 +4315,21 @@ impl WsEvent { pub async fn connection_deleted( ctx: &DalContext, - edge: SummaryDiagramEdge, + from_component_id: ComponentId, + to_component_id: ComponentId, + from_socket_id: OutputSocketId, + to_socket_id: InputSocketId, ) -> WsEventResult { - WsEvent::new(ctx, WsPayload::ConnectionDeleted(edge)).await + WsEvent::new( + ctx, + WsPayload::ConnectionDeleted(ConnectionDeletedPayload { + from_component_id, + to_component_id, + from_socket_id, + to_socket_id, + }), + ) + .await } pub async fn component_updated( diff --git a/lib/dal/src/ws_event.rs b/lib/dal/src/ws_event.rs index 9868fa0a3f..4e6a71d453 100644 --- a/lib/dal/src/ws_event.rs +++ b/lib/dal/src/ws_event.rs @@ -12,8 +12,8 @@ use crate::change_set::event::{ }; use crate::component::{ ComponentCreatedPayload, ComponentDeletedPayload, ComponentSetPositionPayload, - ComponentUpdatedPayload, ComponentUpgradedPayload, InferredEdgeRemovePayload, - InferredEdgeUpsertPayload, + ComponentUpdatedPayload, ComponentUpgradedPayload, ConnectionDeletedPayload, + InferredEdgeRemovePayload, InferredEdgeUpsertPayload, }; use crate::diagram::SummaryDiagramEdge; use crate::func::runner::FuncRunLogUpdatedPayload; @@ -86,7 +86,7 @@ pub enum WsPayload { ComponentUpdated(ComponentUpdatedPayload), ComponentUpgraded(ComponentUpgradedPayload), ConnectionCreated(SummaryDiagramEdge), - ConnectionDeleted(SummaryDiagramEdge), + ConnectionDeleted(ConnectionDeletedPayload), Cursor(CursorPayload), FuncArgumentsSaved(FuncWsEventPayload), FuncCodeSaved(FuncWsEventCodeSaved), diff --git a/lib/sdf-server/src/server/service/diagram/delete_connection.rs b/lib/sdf-server/src/server/service/diagram/delete_connection.rs index 6cc9c0de83..42bd8b47cb 100644 --- a/lib/sdf-server/src/server/service/diagram/delete_connection.rs +++ b/lib/sdf-server/src/server/service/diagram/delete_connection.rs @@ -1,7 +1,5 @@ use axum::extract::{Host, OriginalUri}; use axum::{response::IntoResponse, Json}; -use dal::change_status::ChangeStatus; -use dal::diagram::SummaryDiagramEdge; use dal::{ ChangeSet, Component, ComponentId, InputSocket, InputSocketId, OutputSocket, OutputSocketId, Visibility, WsEvent, @@ -74,22 +72,16 @@ pub async fn delete_connection( }), ); - let from_component = Component::get_by_id(&ctx, request.from_component_id).await?; - let to_component = Component::get_by_id(&ctx, request.to_component_id).await?; - for incoming_connection in to_component.incoming_connections(&ctx).await? { - if incoming_connection.to_input_socket_id == request.to_socket_id { - let edge = SummaryDiagramEdge::assemble( - incoming_connection, - &from_component, - &to_component, - ChangeStatus::Deleted, - )?; - WsEvent::connection_deleted(&ctx, edge) - .await? - .publish_on_commit(&ctx) - .await?; - } - } + WsEvent::connection_deleted( + &ctx, + request.from_component_id, + request.to_component_id, + request.from_socket_id, + request.to_socket_id, + ) + .await? + .publish_on_commit(&ctx) + .await?; ctx.commit().await?;