From a9a8feebfdf720f4a70d39e3a40ef8acadee9c62 Mon Sep 17 00:00:00 2001 From: Paul d'Aoust Date: Fri, 22 Sep 2023 11:04:27 -0700 Subject: [PATCH] guard against trailing non-widget fields in EditFoo.svelte template --- src/scaffold/entry_type.rs | 10 ++++++++++ src/scaffold/entry_type/definitions.rs | 1 + ..._case entry_type.name}}.svelte{{\302\241if}}.hbs" | 12 ++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/scaffold/entry_type.rs b/src/scaffold/entry_type.rs index 4fc148bf7..78d58b769 100644 --- a/src/scaffold/entry_type.rs +++ b/src/scaffold/entry_type.rs @@ -101,6 +101,15 @@ pub fn scaffold_entry_type( } }; + let widget_fields = fields + .iter() + .map(|f| f.clone()) + .filter(|f| match f.widget { + Some(_) => true, + None => false + }) + .collect(); + let reference_entry_hash = match maybe_reference_entry_hash { Some(r) => r.clone(), None => { @@ -147,6 +156,7 @@ pub fn scaffold_entry_type( let entry_def = EntryDefinition { name: name.clone(), fields, + widget_fields, reference_entry_hash, }; diff --git a/src/scaffold/entry_type/definitions.rs b/src/scaffold/entry_type/definitions.rs index 04cf9507e..d262545de 100644 --- a/src/scaffold/entry_type/definitions.rs +++ b/src/scaffold/entry_type/definitions.rs @@ -298,6 +298,7 @@ impl Referenceable { pub struct EntryDefinition { pub name: String, pub fields: Vec, + pub widget_fields: Vec, pub reference_entry_hash: bool, } diff --git "a/templates/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if crud.update}}Edit{{pascal_case entry_type.name}}.svelte{{\302\241if}}.hbs" "b/templates/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if crud.update}}Edit{{pascal_case entry_type.name}}.svelte{{\302\241if}}.hbs" index 5e8ec4dea..45917c7ff 100644 --- "a/templates/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if crud.update}}Edit{{pascal_case entry_type.name}}.svelte{{\302\241if}}.hbs" +++ "b/templates/svelte/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#if crud.update}}Edit{{pascal_case entry_type.name}}.svelte{{\302\241if}}.hbs" @@ -39,7 +39,7 @@ let {{camel_case field_name}}: Array<{{> (concat field_type.type "/type")}} | un let errorSnackbar: Snackbar; -$: {{#each entry_type.fields}}{{#if widget}}{{camel_case field_name}}{{#unless @last}}, {{/unless}}{{/if}}{{/each}}; +$: {{#each entry_type.widget_fields}}{{camel_case field_name}}{{#unless @last}}, {{/unless}}{{/each}}; $: is{{pascal_case entry_type.name}}Valid = true{{#each entry_type.fields}}{{#if widget}}{{#if (eq cardinality "single")}} && {{> (concat field_type.type "/" widget "/is-valid") variable_to_validate=(camel_case field_name) }}{{/if}}{{#if (eq cardinality "vector")}} && {{camel_case field_name}}.every(e => {{> (concat field_type.type "/" widget "/is-valid") variable_to_validate="e" }}){{/if}}{{/if}}{{/each}}; onMount(() => { @@ -55,7 +55,7 @@ onMount(() => { async function update{{pascal_case entry_type.name}}() { - const {{camel_case entry_type.name}}: {{pascal_case entry_type.name}} = { + const {{camel_case entry_type.name}}: {{pascal_case entry_type.name}} = { {{#each entry_type.fields}} {{#if widget}} {{#if (eq cardinality "single") }} @@ -86,7 +86,7 @@ async function update{{pascal_case entry_type.name}}() { updated_{{snake_case entry_type.name}}: {{camel_case entry_type.name}} } }); - + dispatch('{{kebab_case entry_type.name}}-updated', { actionHash: updateRecord.signed_action.hashed.hash }); } catch (e) { errorSnackbar.labelText = `Error updating the {{lower_case entry_type.name}}: ${e.data.data}`; @@ -99,7 +99,7 @@ async function update{{pascal_case entry_type.name}}() {
Edit {{pascal_case entry_type.name}} - + {{#each entry_type.fields}} {{#if widget}}
@@ -108,7 +108,7 @@ async function update{{pascal_case entry_type.name}}() { {{else}} {{> Vec/edit/render field_name=field_name field_type=field_type widget=widget }} {{/if}} - +
{{/if}} @@ -121,7 +121,7 @@ async function update{{pascal_case entry_type.name}}() { on:click={() => dispatch('edit-canceled')} style="flex: 1; margin-right: 16px" > -