Skip to content

Commit

Permalink
feat: wire up toast with data from response
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyhamm committed Dec 18, 2024
1 parent 184c923 commit b42c717
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 59 deletions.
112 changes: 56 additions & 56 deletions app/web/src/store/components.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,22 @@ const edgeFromRawEdge =
isInferred?: boolean;
isManagement?: boolean;
}) =>
(e: RawEdge): Edge => {
const edge = structuredClone(e) as Edge;
if (isManagement) {
edge.id = `mgmt-${edge.toComponentId}_${edge.fromComponentId}`;
} else {
edge.id = generateEdgeId(
edge.fromComponentId,
edge.toComponentId,
edge.fromSocketId,
edge.toSocketId,
);
}
edge.isInferred = isInferred ?? false;
edge.isManagement = isManagement ?? false;
return edge;
};
(e: RawEdge): Edge => {
const edge = structuredClone(e) as Edge;
if (isManagement) {
edge.id = `mgmt-${edge.toComponentId}_${edge.fromComponentId}`;
} else {
edge.id = generateEdgeId(
edge.fromComponentId,
edge.toComponentId,
edge.fromSocketId,
edge.toSocketId,
);
}
edge.isInferred = isInferred ?? false;
edge.isManagement = isManagement ?? false;
return edge;
};

export const loadCollapsedData = (
prefix: string,
Expand Down Expand Up @@ -294,19 +294,19 @@ export function getPossibleAndExistingPeerSockets(
.map((edge) =>
targetSocket.direction === "input"
? {
edge,
thisComponentId: edge.def.toComponentId,
thisSocketId: edge.def.toSocketId,
peerComponentId: edge.def.fromComponentId,
peerSocketId: edge.def.fromSocketId,
}
edge,
thisComponentId: edge.def.toComponentId,
thisSocketId: edge.def.toSocketId,
peerComponentId: edge.def.fromComponentId,
peerSocketId: edge.def.fromSocketId,
}
: {
edge,
thisComponentId: edge.def.fromComponentId,
thisSocketId: edge.def.fromSocketId,
peerComponentId: edge.def.toComponentId,
peerSocketId: edge.def.toSocketId,
},
edge,
thisComponentId: edge.def.fromComponentId,
thisSocketId: edge.def.fromSocketId,
peerComponentId: edge.def.toComponentId,
peerSocketId: edge.def.toSocketId,
},
)
// Get only edges relevant to this socket
.filter(
Expand Down Expand Up @@ -349,13 +349,13 @@ export function getPossibleAndExistingPeerSockets(
const [outputCAs, inputCAs] =
targetSocket.direction === "output"
? [
targetSocket.connectionAnnotations,
peerSocket.connectionAnnotations,
]
targetSocket.connectionAnnotations,
peerSocket.connectionAnnotations,
]
: [
peerSocket.connectionAnnotations,
targetSocket.connectionAnnotations,
];
peerSocket.connectionAnnotations,
targetSocket.connectionAnnotations,
];

// check socket connection annotations compatibility
for (const outputCA of outputCAs) {
Expand Down Expand Up @@ -745,22 +745,22 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
const edges =
response.edges && response.edges.length > 0
? response.edges.map(
edgeFromRawEdge({ isInferred: false, isManagement: false }),
)
edgeFromRawEdge({ isInferred: false, isManagement: false }),
)
: [];
const inferred =
response.inferredEdges && response.inferredEdges.length > 0
? response.inferredEdges.map(
edgeFromRawEdge({ isInferred: true, isManagement: false }),
)
edgeFromRawEdge({ isInferred: true, isManagement: false }),
)
: [];

const management =
response.managementEdges?.length > 0 &&
featureFlagsStore.MANAGEMENT_EDGES
featureFlagsStore.MANAGEMENT_EDGES
? response.managementEdges.map(
edgeFromRawEdge({ isInferred: false, isManagement: true }),
)
edgeFromRawEdge({ isInferred: false, isManagement: true }),
)
: [];

this.rawEdgesById = _.keyBy(
Expand Down Expand Up @@ -873,7 +873,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
toSocketId: to.socketId,
...visibilityParams,
},
onSuccess: () => {},
onSuccess: () => { },
optimistic: () => {
this.rawEdgesById[newEdge.id] = newEdge;
this.processRawEdge(newEdge.id);
Expand Down Expand Up @@ -1003,17 +1003,17 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
const edge = this.rawEdgesById[edgeId];
const params = edge?.isManagement
? {
managedComponentId: toComponentId,
managerComponentId: fromComponentId,
...visibilityParams,
}
managedComponentId: toComponentId,
managerComponentId: fromComponentId,
...visibilityParams,
}
: {
fromSocketId,
toSocketId,
toComponentId,
fromComponentId,
...visibilityParams,
};
fromSocketId,
toSocketId,
toComponentId,
fromComponentId,
...visibilityParams,
};

const url = edge?.isManagement
? "component/unmanage"
Expand Down Expand Up @@ -1201,7 +1201,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
},
);

const req = new ApiRequest({
const req = new ApiRequest<{ schemaVariantId: string, funcId: string }>({
method: "post",
url: `v2/workspaces/${workspaceId}/change-sets/${changeSetId}/management/generate_template/${viewId}`,
params: {
Expand All @@ -1211,14 +1211,14 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
category,
color,
},
onSuccess: (_response) => {
onSuccess: (response) => {
toast.update(toastID, {
content: {
props: {
updating: false,
templateName: assetName,
schemaVariantId: "01JFDHKWS25B432S1T8H8B3JA5", // TODO(ZACK) - put real data here!
funcId: "01JFDJAS8V6WXW9PBDQH9Y9AAG", // TODO(ZACK) - put real data here!
schemaVariantId: response.schemaVariantId,
funcId: response.funcId,
router: (s: string) => {
router.push({
name: "workspace-lab-assets",
Expand Down
19 changes: 16 additions & 3 deletions lib/sdf-server/src/service/v2/management/generate_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{
use dal::{
diagram::view::ViewId, func::authoring::FuncAuthoringClient,
management::prototype::ManagementPrototype, schema::variant::authoring::VariantAuthoringClient,
ChangeSet, ChangeSetId, ComponentId, WorkspacePk, WsEvent,
ChangeSet, ChangeSetId, ComponentId, FuncId, SchemaVariantId, WorkspacePk, WsEvent,
};
use serde::{Deserialize, Serialize};

Expand All @@ -24,6 +24,13 @@ pub struct GenerateTemplateRequest {
color: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GenerateTemplateResponse {
schema_variant_id: SchemaVariantId,
func_id: FuncId,
}

pub async fn generate_template(
HandlerContext(builder): HandlerContext,
AccessBuilder(access_builder): AccessBuilder,
Expand All @@ -32,7 +39,7 @@ pub async fn generate_template(
Host(_host_name): Host,
Path((_workspace_pk, change_set_id, view_id)): Path<(WorkspacePk, ChangeSetId, ViewId)>,
Json(request): Json<GenerateTemplateRequest>,
) -> ManagementApiResult<ForceChangeSetResponse<()>> {
) -> ManagementApiResult<ForceChangeSetResponse<GenerateTemplateResponse>> {
let mut ctx = builder
.build(access_builder.build(change_set_id.into()))
.await?;
Expand Down Expand Up @@ -106,7 +113,13 @@ pub async fn generate_template(

ctx.commit().await?;

Ok(ForceChangeSetResponse::empty(force_change_set_id))
Ok(ForceChangeSetResponse::new(
force_change_set_id,
GenerateTemplateResponse {
schema_variant_id: new_variant.id,
func_id: func.id,
},
))
}

const MAX_DEPTH: usize = 2048;
Expand Down

0 comments on commit b42c717

Please sign in to comment.