Skip to content

Commit

Permalink
Merge pull request #4737 from systeminit/victor/bug-620-when-upgradin…
Browse files Browse the repository at this point in the history
…g-new-components-in-the-same-change-set-they

fix: Don't reset change status icon on changes to component
  • Loading branch information
vbustamante authored Oct 3, 2024
2 parents eb28171 + 3068008 commit ee51b1d
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 52 deletions.
20 changes: 20 additions & 0 deletions lib/dal/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,26 @@ impl Component {
self.to_delete
}

pub async fn change_status(&self, ctx: &DalContext) -> ComponentResult<ChangeStatus> {
let status = if self.exists_in_head(ctx).await? {
if self.to_delete() {
ChangeStatus::Deleted
} else {
ChangeStatus::Unmodified
}
} else {
ChangeStatus::Added
};

Ok(status)
}

pub async fn exists_in_head(&self, ctx: &DalContext) -> ComponentResult<bool> {
let head_ctx = ctx.clone_with_head().await?;

Ok(Self::try_get_by_id(&head_ctx, self.id).await?.is_some())
}

pub async fn view(&self, ctx: &DalContext) -> ComponentResult<Option<serde_json::Value>> {
Self::view_by_id(ctx, self.id).await
}
Expand Down
16 changes: 1 addition & 15 deletions lib/dal/src/diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,7 @@ impl Diagram {
let mut precomputed_incoming_connections = HashMap::with_capacity(components.len());

for component in components.values() {
let exists_in_base = base_snapshot
.get_node_index_by_id_opt(component.id())
.await
.is_some();

let change_status = if exists_in_base {
if component.to_delete() {
ChangeStatus::Deleted
} else {
ChangeStatus::Unmodified
}
} else {
ChangeStatus::Added
};

let change_status = component.change_status(ctx).await?;
component_views.push(
component
.into_frontend_type(ctx, change_status, diagram_sockets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashMap;

use axum::{response::IntoResponse, Json};
use dal::{
change_status::ChangeStatus, AttributeValue, AttributeValueId, ChangeSet, Component,
ComponentId, PropId, Visibility, WsEvent,
AttributeValue, AttributeValueId, ChangeSet, Component, ComponentId, PropId, Visibility,
WsEvent,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -37,7 +37,7 @@ pub async fn delete_property_editor_value(
let component = Component::get_by_id(&ctx, request.component_id).await?;
let mut socket_map = HashMap::new();
let payload = component
.into_frontend_type(&ctx, ChangeStatus::Unmodified, &mut socket_map)
.into_frontend_type(&ctx, component.change_status(&ctx).await?, &mut socket_map)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashMap;

use axum::{response::IntoResponse, Json};
use dal::{
change_status::ChangeStatus, AttributeValue, AttributeValueId, ChangeSet, Component,
ComponentId, PropId, Visibility, WsEvent,
AttributeValue, AttributeValueId, ChangeSet, Component, ComponentId, PropId, Visibility,
WsEvent,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -52,7 +52,7 @@ pub async fn insert_property_editor_value(
let component: Component = Component::get_by_id(&ctx, request.component_id).await?;
let mut socket_map = HashMap::new();
let payload = component
.into_frontend_type(&ctx, ChangeStatus::Unmodified, &mut socket_map)
.into_frontend_type(&ctx, component.change_status(&ctx).await?, &mut socket_map)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
Expand Down
6 changes: 2 additions & 4 deletions lib/sdf-server/src/service/component/set_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::{
response::IntoResponse,
Json,
};
use dal::{change_status::ChangeStatus, ChangeSet, Component, ComponentId, Visibility, WsEvent};
use dal::{ChangeSet, Component, ComponentId, Visibility, WsEvent};
use serde::{Deserialize, Serialize};

use super::ComponentResult;
Expand Down Expand Up @@ -43,11 +43,9 @@ pub async fn set_name(
component.set_name(&ctx, &name).await?;

let component = Component::get_by_id(&ctx, component_id).await?;
// TODO: We'll want to figure out whether this component is Added/Modified, depending on
// whether it existed in the base change set already or not.
let mut socket_map = HashMap::new();
let payload = component
.into_frontend_type(&ctx, ChangeStatus::Unmodified, &mut socket_map)
.into_frontend_type(&ctx, component.change_status(&ctx).await?, &mut socket_map)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
Expand Down
8 changes: 3 additions & 5 deletions lib/sdf-server/src/service/component/set_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use axum::{
Json,
};
use dal::{
change_status::ChangeStatus, component::ComponentGeometry, ChangeSet, Component, ComponentId,
ComponentType, Visibility, WsEvent,
component::ComponentGeometry, ChangeSet, Component, ComponentId, ComponentType, Visibility,
WsEvent,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -60,11 +60,9 @@ pub async fn set_type(
}

let component = Component::get_by_id(&ctx, component_id).await?;
// TODO: We'll want to figure out whether this component is Added/Modified, depending on
// whether it existed in the base change set already or not.
let mut socket_map = HashMap::new();
let payload = component
.into_frontend_type(&ctx, ChangeStatus::Unmodified, &mut socket_map)
.into_frontend_type(&ctx, component.change_status(&ctx).await?, &mut socket_map)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use axum::{
Json,
};
use dal::{
change_status::ChangeStatus, AttributeValue, AttributeValueId, ChangeSet, Component,
ComponentId, Prop, PropId, Secret, SecretId, Visibility, WsEvent,
AttributeValue, AttributeValueId, ChangeSet, Component, ComponentId, Prop, PropId, Secret,
SecretId, Visibility, WsEvent,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -95,7 +95,7 @@ pub async fn update_property_editor_value(

let mut socket_map = HashMap::new();
let payload = component
.into_frontend_type(&ctx, ChangeStatus::Unmodified, &mut socket_map)
.into_frontend_type(&ctx, component.change_status(&ctx).await?, &mut socket_map)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
Expand Down
10 changes: 6 additions & 4 deletions lib/sdf-server/src/service/diagram/remove_delete_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use axum::{
response::IntoResponse,
Json,
};
use dal::{
change_status::ChangeStatus, ChangeSet, Component, ComponentId, DalContext, Visibility, WsEvent,
};
use dal::{ChangeSet, Component, ComponentId, DalContext, Visibility, WsEvent};
use serde::{Deserialize, Serialize};

use super::DiagramResult;
Expand Down Expand Up @@ -130,7 +128,11 @@ pub async fn remove_delete_intent(
for component_id in request.components {
let component = Component::get_by_id(&ctx, component_id).await?;
let payload = component
.into_frontend_type(&ctx, ChangeStatus::Unmodified, &mut diagram_sockets)
.into_frontend_type(
&ctx,
component.change_status(&ctx).await?,
&mut diagram_sockets,
)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
Expand Down
29 changes: 14 additions & 15 deletions lib/sdf-server/src/service/diagram/set_component_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;

use axum::{response::IntoResponse, Json};
use dal::{
change_status::ChangeStatus,
component::{frame::Frame, ComponentGeometry},
diagram::SummaryDiagramInferredEdge,
ChangeSet, Component, ComponentId, ComponentType, Visibility, WsEvent,
Expand Down Expand Up @@ -53,24 +52,14 @@ pub async fn set_component_position(
for (id, update) in request.data_by_component_id {
let mut component = Component::get_by_id(&ctx, id).await?;

let mut component_updated = false;

if update.detach {
Frame::orphan_child(&ctx, component.id()).await?;
let payload = component
.into_frontend_type(&ctx, ChangeStatus::Unmodified, &mut socket_map)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
.publish_on_commit(&ctx)
.await?;
component_updated = true;
} else if let Some(new_parent) = update.new_parent {
Frame::upsert_parent(&ctx, component.id(), new_parent).await?;
let payload = component
.into_frontend_type(&ctx, ChangeStatus::Unmodified, &mut socket_map)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
.publish_on_commit(&ctx)
.await?;
component_updated = true;

// Queue new implicit edges to send to frontend
{
Expand All @@ -92,6 +81,16 @@ pub async fn set_component_position(
}
}

if component_updated {
let payload = component
.into_frontend_type(&ctx, component.change_status(&ctx).await?, &mut socket_map)
.await?;
WsEvent::component_updated(&ctx, payload)
.await?
.publish_on_commit(&ctx)
.await?;
}

let (width, height) = {
let mut size = (None, None);

Expand Down

0 comments on commit ee51b1d

Please sign in to comment.