Skip to content

Commit

Permalink
merge: #4000
Browse files Browse the repository at this point in the history
4000: fix(dal, sdf): Ensure we can save changes to variant details without regenerating r=stack72 a=stack72



Co-authored-by: stack72 <[email protected]>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Jun 20, 2024
2 parents 7e1a933 + c33b4f1 commit e0c2c44
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/web/src/store/asset.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ export const useAssetStore = () => {
return new ApiRequest<null>({
method: "post",
url: "/variant/update_variant",
keyRequestStatusBy: assetId,
params: {
...visibility,
..._.omit(asset, ["hasComponents", "createdAt", "updatedAt"]),
Expand Down
36 changes: 33 additions & 3 deletions lib/dal/src/schema/variant/authoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,25 +562,55 @@ impl VariantAuthoringClient {
pub async fn save_variant_content(
ctx: &DalContext,
current_schema_variant_id: SchemaVariantId,
name: impl Into<String>,
content_name: impl Into<String>,
menu_name: Option<String>,
link: Option<String>,
code: impl Into<String>,
description: Option<String>,
category: impl Into<String>,
component_type: ComponentType,
color: impl Into<String>,
) -> VariantAuthoringResult<()> {
let current_schema_variant =
SchemaVariant::get_by_id(ctx, current_schema_variant_id).await?;

let current_schema = current_schema_variant.schema(ctx).await?;

let asset_func_id = current_schema_variant.asset_func_id.ok_or(
VariantAuthoringError::SchemaVariantAssetNotFound(current_schema_variant_id),
)?;

let code_base64 = general_purpose::STANDARD_NO_PAD.encode(code.into());
let name: String = content_name.into();
let name = &name;

current_schema
.modify(ctx, |s| {
s.name = name.to_string();
Ok(())
})
.await?;

let variant_description = description.clone();
let variant_link = link.clone();
let variant_display_name = menu_name.clone();

current_schema_variant
.modify(ctx, |sv| {
sv.description = variant_description;
sv.link = variant_link;
sv.category.clone_from(&category.into());
sv.component_type = component_type;
sv.color.clone_from(&color.into());
sv.display_name = variant_display_name;
Ok(())
})
.await?;

let code_base64 = general_purpose::STANDARD_NO_PAD.encode(code.into());
let current_func = Func::get_by_id_or_error(ctx, asset_func_id).await?;
current_func
.modify(ctx, |func| {
func.name = name.into();
func.name = name.to_string();
func.backend_kind = FuncBackendKind::JsSchemaVariantDefinition;
func.backend_response_type = FuncBackendResponseType::SchemaVariantDefinition;
func.display_name = menu_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ async fn save_variant(ctx: &mut DalContext) {
link.clone(),
updated_func_content.clone(),
updated_description.clone(),
category.clone(),
variant.component_type(),
color.clone(),
)
.await
.expect("Unable to save the func");
Expand Down
3 changes: 3 additions & 0 deletions lib/sdf-server/src/server/service/variant/save_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub async fn save_variant(
request.link.clone(),
request.code.clone(),
request.description.clone(),
request.category.clone(),
request.component_type,
request.color,
)
.await?;

Expand Down

0 comments on commit e0c2c44

Please sign in to comment.