From ee8116c2ee8b621212b3ae605947045d51377054 Mon Sep 17 00:00:00 2001 From: John Obelenus Date: Thu, 19 Dec 2024 12:02:58 -0500 Subject: [PATCH] BUG-652: send inferred edges along with created component --- app/web/src/store/components.store.ts | 10 ++++++++ app/web/src/store/realtime/realtime_events.ts | 1 + lib/dal-test/src/expected.rs | 2 +- lib/dal/src/component.rs | 18 +++++++++++++ lib/dal/src/component/frame.rs | 25 ++++++++----------- lib/dal/tests/integration_test/frame.rs | 2 +- .../src/service/v2/view/create_component.rs | 5 ++-- 7 files changed, 45 insertions(+), 18 deletions(-) diff --git a/app/web/src/store/components.store.ts b/app/web/src/store/components.store.ts index ede876e0b5..d908fc21ea 100644 --- a/app/web/src/store/components.store.ts +++ b/app/web/src/store/components.store.ts @@ -1269,6 +1269,16 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { if (data.changeSetId !== changeSetId) return; this.rawComponentsById[data.component.id] = data.component; this.processAndStoreRawComponent(data.component.id, {}); + + data.inferredEdges?.forEach((edge) => { + const e = edgeFromRawEdge({ + isManagement: false, + isInferred: true, + })(edge); + + this.rawEdgesById[e.id] = e; + this.processRawEdge(e.id); + }); }, }, { diff --git a/app/web/src/store/realtime/realtime_events.ts b/app/web/src/store/realtime/realtime_events.ts index 41cb073cbe..220d83e9fd 100644 --- a/app/web/src/store/realtime/realtime_events.ts +++ b/app/web/src/store/realtime/realtime_events.ts @@ -176,6 +176,7 @@ export type WsEventPayloadMap = { ComponentCreated: { component: RawComponent; + inferredEdges?: RawEdge[]; changeSetId: string; }; ComponentDeleted: { diff --git a/lib/dal-test/src/expected.rs b/lib/dal-test/src/expected.rs index a8be0e89cc..5f8dd5883a 100644 --- a/lib/dal-test/src/expected.rs +++ b/lib/dal-test/src/expected.rs @@ -471,7 +471,7 @@ impl ExpectComponent { pub async fn upsert_parent(self, ctx: &DalContext, parent_id: impl Into) { dal::component::frame::Frame::upsert_parent(ctx, self.0, parent_id.into()) .await - .expect("could not upsert parent") + .expect("could not upsert parent"); } } diff --git a/lib/dal/src/component.rs b/lib/dal/src/component.rs index a232bf698c..b67b994c4e 100644 --- a/lib/dal/src/component.rs +++ b/lib/dal/src/component.rs @@ -3646,6 +3646,7 @@ impl Component { #[serde(rename_all = "camelCase")] pub struct ComponentCreatedPayload { pub component: DiagramComponentView, + pub inferred_edges: Option>, change_set_id: ChangeSetId, } @@ -3852,6 +3853,23 @@ impl WsEvent { ctx, WsPayload::ComponentCreated(ComponentCreatedPayload { change_set_id: ctx.change_set_id(), + inferred_edges: None, + component, + }), + ) + .await + } + + pub async fn component_created_with_inferred_edges( + ctx: &DalContext, + component: DiagramComponentView, + inferred_edges: Option>, + ) -> WsEventResult { + WsEvent::new( + ctx, + WsPayload::ComponentCreated(ComponentCreatedPayload { + change_set_id: ctx.change_set_id(), + inferred_edges: inferred_edges, component, }), ) diff --git a/lib/dal/src/component/frame.rs b/lib/dal/src/component/frame.rs index c0b9e49771..7319c207d9 100644 --- a/lib/dal/src/component/frame.rs +++ b/lib/dal/src/component/frame.rs @@ -159,31 +159,28 @@ impl Frame { } /// Provides the ability to attach or replace a child [`Component`]'s parent - #[instrument(level = "info", skip(ctx))] + //#[instrument(level = "info", skip(ctx))] pub async fn upsert_parent( ctx: &DalContext, child_id: ComponentId, new_parent_id: ComponentId, - ) -> FrameResult<()> { + ) -> FrameResult>> { // let's see if we need to even do anything if let Some(current_parent_id) = Component::get_parent_by_id(ctx, child_id).await? { if current_parent_id == new_parent_id { - return Ok(()); + return Ok(None); } } match Component::get_type_by_id(ctx, new_parent_id).await? { - ComponentType::ConfigurationFrameDown | ComponentType::ConfigurationFrameUp => { - Self::attach_child_to_parent_inner(ctx, new_parent_id, child_id).await?; - } - ComponentType::Component => { - return Err(FrameError::ParentIsNotAFrame(child_id, new_parent_id)) - } + ComponentType::ConfigurationFrameDown | ComponentType::ConfigurationFrameUp => Ok( + Some(Self::attach_child_to_parent_inner(ctx, new_parent_id, child_id).await?), + ), + ComponentType::Component => Err(FrameError::ParentIsNotAFrame(child_id, new_parent_id)), ComponentType::AggregationFrame => { - return Err(FrameError::AggregateFramesUnsupported(new_parent_id)) + Err(FrameError::AggregateFramesUnsupported(new_parent_id)) } } - Ok(()) } /// Removes the existing parent connection if it exists and adds the new one. @@ -194,7 +191,7 @@ impl Frame { ctx: &DalContext, parent_id: ComponentId, child_id: ComponentId, - ) -> FrameResult<()> { + ) -> FrameResult> { // cache current map of input <-> output sockets based on what the parent knows about right now!!!! let initial_impacted_values: HashSet = Self::get_all_inferred_connections_for_component_tree(ctx, parent_id, child_id).await?; @@ -281,7 +278,7 @@ impl Frame { inferred_edges_to_upsert.push(edge); } } - WsEvent::upsert_inferred_edges(ctx, inferred_edges_to_upsert) + WsEvent::upsert_inferred_edges(ctx, inferred_edges_to_upsert.clone()) .await? .publish_on_commit(ctx) .await?; @@ -312,7 +309,7 @@ impl Frame { ) .await?; - Ok(()) + Ok(inferred_edges_to_upsert) } #[instrument( diff --git a/lib/dal/tests/integration_test/frame.rs b/lib/dal/tests/integration_test/frame.rs index eac96b1d0f..bf174307b5 100644 --- a/lib/dal/tests/integration_test/frame.rs +++ b/lib/dal/tests/integration_test/frame.rs @@ -163,7 +163,7 @@ async fn convert_component_to_frame_and_attach_no_nesting(ctx: &mut DalContext) // Attempt to attach a child to a parent that is a not a frame. match Frame::upsert_parent(ctx, fallout_component.id(), starfield_component.id()).await { - Ok(()) => panic!("attaching child to parent should fail if parent is not a frame"), + Ok(_) => panic!("attaching child to parent should fail if parent is not a frame"), Err(FrameError::ParentIsNotAFrame(..)) => {} Err(other_error) => panic!("unexpected error: {0}", other_error), } diff --git a/lib/sdf-server/src/service/v2/view/create_component.rs b/lib/sdf-server/src/service/v2/view/create_component.rs index dfd3d1c08b..072b18810b 100644 --- a/lib/sdf-server/src/service/v2/view/create_component.rs +++ b/lib/sdf-server/src/service/v2/view/create_component.rs @@ -181,8 +181,9 @@ pub async fn create_component( )); } + let mut maybe_inferred_edges = None; if let Some(frame_id) = request.parent_id { - Frame::upsert_parent(&ctx, component.id(), frame_id).await?; + maybe_inferred_edges = Frame::upsert_parent(&ctx, component.id(), frame_id).await?; track( &posthog_client, @@ -224,7 +225,7 @@ pub async fn create_component( &mut diagram_sockets, ) .await?; - WsEvent::component_created(&ctx, payload) + WsEvent::component_created_with_inferred_edges(&ctx, payload, maybe_inferred_edges) .await? .publish_on_commit(&ctx) .await?;