Skip to content

Commit

Permalink
keep the connection_deleted "simple" since the correct action is a ha…
Browse files Browse the repository at this point in the history
…rd delete
  • Loading branch information
jobelenus committed Aug 14, 2024
1 parent 29788c2 commit 60d41bc
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 54 deletions.
12 changes: 8 additions & 4 deletions app/web/src/store/components.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
},
},
Expand Down
7 changes: 6 additions & 1 deletion app/web/src/store/realtime/realtime_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 34 additions & 28 deletions lib/dal/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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<Self> {
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(
Expand Down
6 changes: 3 additions & 3 deletions lib/dal/src/ws_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,7 +86,7 @@ pub enum WsPayload {
ComponentUpdated(ComponentUpdatedPayload),
ComponentUpgraded(ComponentUpgradedPayload),
ConnectionCreated(SummaryDiagramEdge),
ConnectionDeleted(SummaryDiagramEdge),
ConnectionDeleted(ConnectionDeletedPayload),
Cursor(CursorPayload),
FuncArgumentsSaved(FuncWsEventPayload),
FuncCodeSaved(FuncWsEventCodeSaved),
Expand Down
28 changes: 10 additions & 18 deletions lib/sdf-server/src/server/service/diagram/delete_connection.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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?;

Expand Down

0 comments on commit 60d41bc

Please sign in to comment.