Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit a4d224f

Browse files
jobelenusjhelwig
authored andcommitted
renaming restore component route, impl removing to_delete from component, wip on edge restore
1 parent 238ad38 commit a4d224f

5 files changed

Lines changed: 101 additions & 167 deletions

File tree

lib/dal/src/attribute/prototype.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub enum AttributePrototypeError {
5151
LayerDb(#[from] LayerDbError),
5252
#[error("attribute prototype {0} is missing a function edge")]
5353
MissingFunction(AttributePrototypeId),
54+
#[error("No attribute values for: {0}")]
55+
NoAttributeValues(AttributePrototypeId),
5456
#[error("node weight error: {0}")]
5557
NodeWeight(#[from] NodeWeightError),
5658
#[error("Attribute Prototype not found: {0}")]

lib/sdf-server/src/server/service/diagram.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use axum::response::{IntoResponse, Response};
33
use axum::routing::{get, post};
44
use axum::Json;
55
use axum::Router;
6+
use dal::attribute::prototype::AttributePrototypeError;
67
use dal::component::ComponentError;
78
use dal::socket::input::InputSocketError;
89
use dal::workspace_snapshot::WorkspaceSnapshotError;
@@ -24,9 +25,9 @@ pub mod set_component_position;
2425

2526
// mod connect_component_to_frame;
2627
pub mod delete_component;
27-
// pub mod delete_connection;
28+
//pub mod delete_connection;
2829
// pub mod paste_component;
29-
// mod restore_component;
30+
pub mod remove_delete_intent;
3031
// pub mod restore_connection;
3132

3233
#[remain::sorted]
@@ -36,6 +37,8 @@ pub enum DiagramError {
3637
Action(#[from] ActionError),
3738
#[error("action: {0}")]
3839
ActionPrototype(#[from] ActionPrototypeError),
40+
#[error("prototype error: {0}")]
41+
AttributePrototype(#[from] AttributePrototypeError),
3942
#[error("changeset error: {0}")]
4043
ChangeSet(#[from] ChangeSetPointerError),
4144
#[error("change set not found")]
@@ -121,14 +124,10 @@ pub fn routes() -> Router<AppState> {
121124
"/delete_components",
122125
post(delete_component::delete_components),
123126
)
124-
// .route(
125-
// "/restore_component",
126-
// post(restore_component::restore_component),
127-
// )
128-
// .route(
129-
// "/restore_components",
130-
// post(restore_component::restore_components),
131-
// )
127+
.route(
128+
"/remove_delete_intent",
129+
post(remove_delete_intent::remove_delete_intent),
130+
)
132131
.route(
133132
"/connect_component_to_frame",
134133
post(connect_component_to_frame::connect_component_to_frame),

lib/sdf-server/src/server/service/diagram/delete_connection.rs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
use axum::extract::OriginalUri;
22
use axum::{response::IntoResponse, Json};
3-
use dal::edge::EdgeId;
4-
use dal::{ChangeSet, Component, Connection, Edge, Socket, Visibility};
3+
use dal::attribute::prototype::argument::{AttributePrototypeArgumentId, AttributePrototypeArgument };
4+
use dal::{AttributePrototype, ChangeSetPointer, Visibility, AttributeValue};
5+
use dal::attribute::prototype::AttributePrototypeError;
56
use serde::{Deserialize, Serialize};
67

78
use super::DiagramResult;
89
use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient};
910
use crate::server::tracking::track;
1011
use crate::service::diagram::DiagramError;
11-
use dal::standard_model::StandardModel;
1212

1313
#[derive(Deserialize, Serialize, Debug)]
1414
#[serde(rename_all = "camelCase")]
15+
1516
pub struct DeleteConnectionRequest {
16-
pub edge_id: EdgeId,
17+
pub edge_id: AttributePrototypeArgumentId,
1718
#[serde(flatten)]
1819
pub visibility: Visibility,
1920
}
@@ -29,46 +30,27 @@ pub async fn delete_connection(
2930
let mut ctx = builder.build(request_ctx.build(request.visibility)).await?;
3031

3132
let force_changeset_pk = ChangeSetPointer::force_new(&mut ctx).await?;
32-
let edge = Edge::get_by_id(&ctx, &request.edge_id)
33-
.await?
34-
.ok_or(DiagramError::EdgeNotFound)?;
35-
36-
let conn = Connection::from_edge(&edge);
37-
let from_component_schema = Component::get_by_id(&ctx, &conn.source.component_id)
38-
.await?
39-
.ok_or(DiagramError::ComponentNotFound)?
40-
.schema(&ctx)
41-
.await?
42-
.ok_or(DiagramError::SchemaNotFound)?;
43-
44-
let from_socket = Socket::get_by_id(&ctx, &conn.source.socket_id)
45-
.await?
46-
.ok_or(DiagramError::SocketNotFound)?;
47-
48-
let to_component_schema = Component::get_by_id(&ctx, &conn.destination.component_id)
49-
.await?
50-
.ok_or(DiagramError::ComponentNotFound)?
51-
.schema(&ctx)
52-
.await?
53-
.ok_or(DiagramError::SchemaNotFound)?;
5433

55-
let to_socket = Socket::get_by_id(&ctx, &conn.destination.socket_id)
56-
.await?
57-
.ok_or(DiagramError::SocketNotFound)?;
34+
let attribute_prototype_argument = AttributePrototypeArgument::get_by_id(&ctx, request.edge_id).await?;
35+
let targets = attribute_prototype_argument.targets();
36+
let source = attribute_prototype_argument.value_source(&ctx).await?;
37+
let prototype_id = attribute_prototype_argument.prototype_id(&ctx).await?;
38+
let value_id = AttributePrototype::attribute_value_ids(&ctx, prototype_id).await?.first().copied().ok_or(AttributePrototypeError::NoAttributeValues(prototype_id))?;
39+
let destination = AttributeValue::is_for(&ctx, value_id).await?;
5840

59-
Connection::delete_for_edge(&ctx, request.edge_id).await?;
41+
//attribute_prototype_argument.delete(&ctx).await?;
6042

6143
track(
6244
&posthog_client,
6345
&ctx,
6446
&original_uri,
6547
"delete_connection",
6648
serde_json::json!({
67-
"from_component_id": conn.source.component_id,
49+
"from_component_id": targets.source_component_id,
6850
"from_component_schema_name": from_component_schema.name(),
6951
"from_socket_id": conn.source.socket_id,
7052
"from_socket_name": &from_socket.name(),
71-
"to_component_id": conn.destination.component_id,
53+
"to_component_id": targets.destination_component_id,
7254
"to_component_schema_name": to_component_schema.name(),
7355
"to_socket_id": conn.destination.socket_id,
7456
"to_socket_name": &to_socket.name(),
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use axum::Json;
2+
use axum::{extract::OriginalUri, http::uri::Uri, response::IntoResponse};
3+
use dal::{ChangeSetPointer, Component, ComponentId, DalContext, Visibility};
4+
use serde::{Deserialize, Serialize};
5+
6+
use super::DiagramResult;
7+
use crate::server::extract::{AccessBuilder, HandlerContext, PosthogClient};
8+
use crate::server::tracking::track;
9+
10+
#[derive(Deserialize, Serialize, Debug)]
11+
#[serde(rename_all = "camelCase")]
12+
pub struct RestoreComponentRequest {
13+
pub component_id: ComponentId,
14+
#[serde(flatten)]
15+
pub visibility: Visibility,
16+
}
17+
18+
async fn remove_single_delete_intent(
19+
ctx: &DalContext,
20+
component_id: ComponentId,
21+
original_uri: &Uri,
22+
PosthogClient(posthog_client): &PosthogClient,
23+
) -> DiagramResult<()> {
24+
25+
let comp = Component::get_by_id(ctx, component_id).await?;
26+
27+
let comp_schema = comp.schema(ctx).await?;
28+
let comp = comp.set_to_delete(ctx, false).await?;
29+
30+
track(
31+
posthog_client,
32+
ctx,
33+
original_uri,
34+
"restore_component",
35+
serde_json::json!({
36+
"component_id": comp.id(),
37+
"component_schema_name": comp_schema.name(),
38+
}),
39+
);
40+
41+
Ok(())
42+
}
43+
44+
45+
#[derive(Deserialize, Serialize, Debug)]
46+
#[serde(rename_all = "camelCase")]
47+
pub struct RemoveDeleteIntentRequest {
48+
pub component_ids: Vec<ComponentId>,
49+
#[serde(flatten)]
50+
pub visibility: Visibility,
51+
}
52+
53+
/// Restore a set of [`Component`](dal::Component)s via their componentId. Creating change set if on head.
54+
pub async fn remove_delete_intent(
55+
HandlerContext(builder): HandlerContext,
56+
AccessBuilder(request_ctx): AccessBuilder,
57+
posthog_client: PosthogClient,
58+
OriginalUri(original_uri): OriginalUri,
59+
Json(request): Json<RemoveDeleteIntentRequest>,
60+
) -> DiagramResult<impl IntoResponse> {
61+
let mut ctx = builder.build(request_ctx.build(request.visibility)).await?;
62+
63+
let force_changeset_pk = ChangeSetPointer::force_new(&mut ctx).await?;
64+
65+
for component_id in request.component_ids {
66+
remove_single_delete_intent(&ctx, component_id, &original_uri, &posthog_client).await?;
67+
}
68+
69+
ctx.commit().await?;
70+
71+
let mut response = axum::response::Response::builder();
72+
if let Some(force_changeset_pk) = force_changeset_pk {
73+
response = response.header("force_changeset_pk", force_changeset_pk.to_string());
74+
}
75+
Ok(response.body(axum::body::Empty::new())?)
76+
}

lib/sdf-server/src/server/service/diagram/restore_component.rs

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)