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: Restore geometries too #5108

Merged
merged 1 commit into from
Dec 11, 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
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason you went here vs. expanding the import_component_subgraph is because the geometries aren't in the subgraph of the component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@britmyerss yeah, the subgraph code is very generic. Since we've structured our geometries the other way around I had to implement a special case here

.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
Loading