-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4034: Clone or New Asset: provide an initial schema name in a modal r=vbustamante a=jobelenus This is in anticipation of making the schema name immutable after creation. Co-authored-by: John Obelenus <[email protected]> Co-authored-by: Victor Bustamante <[email protected]>
- Loading branch information
Showing
18 changed files
with
146 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<template> | ||
<Modal ref="modal" size="sm" :title="props.title"> | ||
<VormInput | ||
ref="assetNameVorm" | ||
v-model="assetName" | ||
type="text" | ||
label="Asset Name" | ||
required | ||
@enterPressed="submit" | ||
/> | ||
<VButton class="mt-md" @click="submit">{{ props.buttonLabel }}</VButton> | ||
</Modal> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref } from "vue"; | ||
import { Modal, VormInput, VButton } from "@si/vue-lib/design-system"; | ||
const props = defineProps<{ | ||
title: string; | ||
buttonLabel: string; | ||
}>(); | ||
const modal = ref<InstanceType<typeof Modal>>(); | ||
const assetName = ref(""); | ||
const assetNameVorm = ref<InstanceType<typeof VormInput>>(); | ||
const submit = () => { | ||
emit("submit", assetName.value); | ||
}; | ||
const setError = (msg: string) => { | ||
if (assetNameVorm.value) { | ||
assetNameVorm.value.validationState.isError = true; | ||
assetNameVorm.value.validationState.errorMessage = msg; | ||
} | ||
}; | ||
defineExpose({ | ||
modal, | ||
setError, | ||
}); | ||
const emit = defineEmits(["submit"]); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,8 @@ use crate::pkg::import::import_only_new_funcs; | |
use crate::pkg::{import_pkg_from_pkg, PkgError}; | ||
use crate::schema::variant::{SchemaVariantJson, SchemaVariantMetadataJson}; | ||
use crate::{ | ||
generate_unique_id, pkg, ComponentType, DalContext, Func, FuncBackendKind, | ||
FuncBackendResponseType, FuncError, FuncId, Schema, SchemaError, SchemaVariant, | ||
SchemaVariantError, SchemaVariantId, | ||
pkg, ComponentType, DalContext, Func, FuncBackendKind, FuncBackendResponseType, FuncError, | ||
FuncId, Schema, SchemaError, SchemaVariant, SchemaVariantError, SchemaVariantId, | ||
}; | ||
|
||
#[allow(missing_docs)] | ||
|
@@ -82,7 +81,7 @@ impl VariantAuthoringClient { | |
/// Creates a [`SchemaVariant`] and returns the [result](SchemaVariant). | ||
#[instrument(name = "variant.authoring.create_variant", level = "info", skip_all)] | ||
#[allow(clippy::too_many_arguments)] | ||
pub async fn create_variant( | ||
pub async fn create_schema_and_variant( | ||
ctx: &DalContext, | ||
name: impl Into<String>, | ||
display_name: Option<String>, | ||
|
@@ -112,7 +111,7 @@ impl VariantAuthoringClient { | |
let definition = execute_asset_func(ctx, &asset_func).await?; | ||
|
||
let metadata = SchemaVariantMetadataJson { | ||
name, | ||
schema_name: name, | ||
menu_name: display_name.clone(), | ||
category: category.into(), | ||
color: color.into(), | ||
|
@@ -159,23 +158,22 @@ impl VariantAuthoringClient { | |
pub async fn clone_variant( | ||
ctx: &DalContext, | ||
schema_variant_id: SchemaVariantId, | ||
name: String, | ||
) -> VariantAuthoringResult<(SchemaVariant, Schema)> { | ||
println!("clone variant"); | ||
let variant = SchemaVariant::get_by_id(ctx, schema_variant_id).await?; | ||
let schema = variant.schema(ctx).await?; | ||
|
||
let new_name = format!("{} Clone {}", schema.name(), generate_unique_id(4)); | ||
let menu_name = variant.display_name().map(|mn| format!("{mn} Clone")); | ||
let display_name = variant.display_name().map(|dn| format!("{dn} Clone")); | ||
|
||
if let Some(asset_func_id) = variant.asset_func_id() { | ||
let old_func = Func::get_by_id_or_error(ctx, asset_func_id).await?; | ||
|
||
let cloned_func = old_func.duplicate(ctx, new_name.clone()).await?; | ||
let cloned_func = old_func.duplicate(ctx, name.clone()).await?; | ||
let cloned_func_spec = build_asset_func_spec(&cloned_func)?; | ||
let definition = execute_asset_func(ctx, &cloned_func).await?; | ||
let metadata = SchemaVariantMetadataJson { | ||
name: new_name.clone(), | ||
menu_name: menu_name.clone(), | ||
schema_name: name, | ||
menu_name: display_name.clone(), | ||
category: variant.category().to_string(), | ||
color: variant.get_color(ctx).await?, | ||
component_type: variant.component_type(), | ||
|
@@ -331,7 +329,7 @@ impl VariantAuthoringClient { | |
let asset_func_spec = build_asset_func_spec(&asset_func)?; | ||
let definition = execute_asset_func(ctx, &asset_func).await?; | ||
let metadata = SchemaVariantMetadataJson { | ||
name: name.clone(), | ||
schema_name: name.clone(), | ||
menu_name: menu_name.clone(), | ||
category: category.clone(), | ||
color: color.clone(), | ||
|
@@ -350,10 +348,10 @@ impl VariantAuthoringClient { | |
) | ||
.await?; | ||
|
||
let schema_spec = metadata.to_spec(new_variant_spec)?; | ||
let schema_spec = metadata.to_schema_spec(new_variant_spec)?; | ||
//TODO @stack72 - figure out how we get the current user in this! | ||
let pkg_spec = PkgSpec::builder() | ||
.name(&metadata.name) | ||
.name(&metadata.schema_name) | ||
.created_by("[email protected]") | ||
.funcs(variant_funcs.clone()) | ||
.func(asset_func_spec) | ||
|
@@ -475,7 +473,7 @@ impl VariantAuthoringClient { | |
let definition = execute_asset_func(ctx, &new_asset_func).await?; | ||
|
||
let metadata = SchemaVariantMetadataJson { | ||
name: name.clone(), | ||
schema_name: name.clone(), | ||
menu_name: menu_name.clone(), | ||
category: category.into(), | ||
color: color.into(), | ||
|
@@ -494,11 +492,11 @@ impl VariantAuthoringClient { | |
) | ||
.await?; | ||
|
||
let schema_spec = metadata.to_spec(new_variant_spec)?; | ||
let schema_spec = metadata.to_schema_spec(new_variant_spec)?; | ||
|
||
//TODO @stack72 - figure out how we get the current user in this! | ||
let pkg_spec = PkgSpec::builder() | ||
.name(&metadata.name) | ||
.name(&metadata.schema_name) | ||
.created_by("[email protected]") | ||
.funcs(variant_funcs.clone()) | ||
.func(asset_func_spec) | ||
|
@@ -746,9 +744,9 @@ fn build_pkg_spec_for_variant( | |
&identity_func_spec.unique_id, | ||
&asset_func_spec.unique_id, | ||
)?; | ||
let schema_spec = metadata.to_spec(variant_spec)?; | ||
let schema_spec = metadata.to_schema_spec(variant_spec)?; | ||
Ok(PkgSpec::builder() | ||
.name(metadata.clone().name) | ||
.name(metadata.clone().schema_name) | ||
.created_by(user_email) | ||
.func(identity_func_spec) | ||
.func(asset_func_spec.clone()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.