Skip to content

Commit

Permalink
Fix: Restore geometries too
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Bustamante <victor@systeminit.com>
  • Loading branch information
vbustamante committed Dec 11, 2024
1 parent 1f1c136 commit d74717e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/dal/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3332,6 +3332,10 @@ impl Component {
ctx.add_dependent_values_and_enqueue(component.input_socket_attribute_values(ctx).await?)
.await?;

Geometry::restore_all_for_component_id(ctx, component_id)
.await
.map_err(|e| ComponentError::Diagram(Box::new(e)))?;

Ok(())
}

Expand Down
37 changes: 35 additions & 2 deletions lib/dal/src/diagram/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ impl Geometry {
Ok(geo_represents)
}

pub async fn get_by_id(ctx: &DalContext, component_id: GeometryId) -> DiagramResult<Self> {
let (node_weight, content) = Self::get_node_weight_and_content(ctx, component_id).await?;
pub async fn get_by_id(ctx: &DalContext, geometry_id: GeometryId) -> DiagramResult<Self> {
let (node_weight, content) = Self::get_node_weight_and_content(ctx, geometry_id).await?;
Ok(Self::assemble(node_weight, content))
}

Expand Down Expand Up @@ -528,4 +528,37 @@ impl Geometry {

Ok(())
}

pub async fn restore_all_for_component_id(
ctx: &DalContext,
component_id: ComponentId,
) -> DiagramResult<()> {
let base_change_set_ctx = ctx.clone_with_base().await?;

for geo_id in Self::list_ids_by_component(&base_change_set_ctx, component_id).await? {
let view_id = Self::get_view_id_by_id(&base_change_set_ctx, geo_id).await?;

// Check if view exists on this changeset
if View::try_get_by_id(ctx, view_id).await?.is_none() {
continue;
};

let head_geometry = Self::get_by_id(&base_change_set_ctx, geo_id).await?;

Self::new_for_component(ctx, component_id, view_id)
.await?
.update(
ctx,
RawGeometry {
x: head_geometry.x(),
y: head_geometry.y(),
width: head_geometry.width(),
height: head_geometry.height(),
},
)
.await?;
}

Ok(())
}
}
23 changes: 12 additions & 11 deletions lib/dal/src/diagram/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ impl View {
}

pub async fn get_by_id(ctx: &DalContext, view_id: ViewId) -> DiagramResult<Self> {
let (node_weight, content) = Self::get_node_weight_and_content(ctx, view_id).await?;
Ok(Self::assemble(node_weight, content))
Self::try_get_by_id(ctx, view_id)
.await?
.ok_or(DiagramError::ViewNotFound(view_id))
}

pub async fn try_get_by_id(ctx: &DalContext, view_id: ViewId) -> DiagramResult<Option<Self>> {
let Some((node_weight, content)) =
Self::try_get_node_weight_and_content(ctx, view_id).await?
else {
return Ok(None);
};
Ok(Some(Self::assemble(node_weight, content)))
}

pub async fn find_by_name(ctx: &DalContext, name: &str) -> DiagramResult<Option<Self>> {
Expand Down Expand Up @@ -206,15 +216,6 @@ impl View {
Ok(default_view.into())
}

async fn get_node_weight_and_content(
ctx: &DalContext,
view_id: ViewId,
) -> DiagramResult<(ViewNodeWeight, ViewContent)> {
Self::try_get_node_weight_and_content(ctx, view_id)
.await?
.ok_or(DiagramError::ViewNotFound(view_id))
}

async fn try_get_node_weight_and_content(
ctx: &DalContext,
view_id: ViewId,
Expand Down

0 comments on commit d74717e

Please sign in to comment.