From a9a8feebfdf720f4a70d39e3a40ef8acadee9c62 Mon Sep 17 00:00:00 2001 From: Paul d'Aoust Date: Fri, 22 Sep 2023 11:04:27 -0700 Subject: [PATCH 1/7] 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" > - Date: Tue, 3 Oct 2023 11:50:58 -0700 Subject: [PATCH 2/7] fix bugs in Lit and Vue templates --- ...me}}.ts{{\302\241if}}{{\302\241each}}.hbs" | 16 ++++++++-- ...e}}.vue{{\302\241if}}{{\302\241each}}.hbs" | 29 ++++++++++++------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git "a/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" "b/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" index a84e1e04a..4e42fe1c1 100644 --- "a/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" +++ "b/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" @@ -14,7 +14,7 @@ export class {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_ client!: AppAgentClient; @property({ - hasChanged: (newVal: {{linked_from.hash_type}}, oldVal: {{linked_from.hash_type}}) => newVal.toString() !== oldVal.toString() + hasChanged: (newVal: {{linked_from.hash_type}}, oldVal: {{linked_from.hash_type}}) => newVal?.toString() !== oldVal?.toString() }) {{camel_case linked_from.singular_arg}}!: {{linked_from.hash_type}}; @@ -24,7 +24,17 @@ export class {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_ zome_name: '{{../coordinator_zome_manifest.name}}', fn_name: 'get_{{snake_case (plural ../entry_type.name)}}_for_{{snake_case linked_from.name}}', payload: {{camel_case linked_from.singular_arg}}, - }) as Promise>, () => [this.{{camel_case linked_from.singular_arg}}]); + }).then(v => + (v as Array) + .map(r => + {{#if ../entry_type.reference_entry_hash}} + (r.signed_action.hashed.content as NewEntryAction).entry_hash + {{else}} + r.signed_action.hashed.hash + {{/if}} + ) + ) as Promise>, + () => [this.{{camel_case linked_from.singular_arg}}]); firstUpdated() { if (this.{{camel_case linked_from.singular_arg}} === undefined) { @@ -34,7 +44,7 @@ export class {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_ renderList(hashes: Array<{{#if ../entry_type.reference_entry_hash}}EntryHash{{else}}ActionHash{{/if}}>) { if (hashes.length === 0) return html`No {{lower_case (plural ../entry_type.name)}} found for this {{lower_case linked_from.name}}.`; - + return html`
${hashes.map(hash => diff --git "a/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{pascal_case (plural ..\302\241entry_type.name)}}For{{pascal_case linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" "b/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{pascal_case (plural ..\302\241entry_type.name)}}For{{pascal_case linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" index 85116db5a..73e828548 100644 --- "a/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{pascal_case (plural ..\302\241entry_type.name)}}For{{pascal_case linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" +++ "b/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{pascal_case (plural ..\302\241entry_type.name)}}For{{pascal_case linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" @@ -2,13 +2,13 @@
- +
Error fetching the {{lower_case (plural ../entry_type.name)}}: {{{{raw}}}} {{error.data.data}}.{{{{/raw}}}}
- <{{pascal_case ../entry_type.name}}Detail - v-for="hash in hashes" - :{{kebab_case ../entry_type.name}}-hash="hash" + <{{pascal_case ../entry_type.name}}Detail + v-for="hash in hashes" + :{{kebab_case ../entry_type.name}}-hash="hash" >
@@ -29,7 +29,7 @@ export default defineComponent({ {{pascal_case ../entry_type.name}}Detail }, props: { - {{camel_case linked_from.singular_arg}}Hash: { + {{camel_case linked_from.singular_arg}}: { type: Object, required: true } @@ -42,18 +42,27 @@ export default defineComponent({ } }, async mounted() { - if (this.{{camel_case linked_from.singular_arg}}Hash === undefined) { - throw new Error(`The {{camel_case linked_from.singular_arg}}Hash input is required for the {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}} element`); + if (this.{{camel_case linked_from.singular_arg}} === undefined) { + throw new Error(`The {{camel_case linked_from.singular_arg}} input is required for the {{pascal_case (plural ../entry_type.name)}}For{{pascal_case linked_from.name}} element`); } try { this.hashes = await this.client.callZome({ cap_secret: null, - role_name: '{{dna_role_name}}', + role_name: '{{../dna_role_name}}', zome_name: '{{../coordinator_zome_manifest.name}}', fn_name: 'get_{{snake_case (plural ../entry_type.name)}}_for_{{snake_case linked_from.name}}', - payload: this.{{camel_case linked_from.singular_arg}}Hash, - }); + payload: this.{{camel_case linked_from.singular_arg}}, + }).then(v => + (v as Array) + .map(r => + {{#if ../entry_type.reference_entry_hash}} + (r.signed_action.hashed.content as NewEntryAction).entry_hash + {{else}} + r.signed_action.hashed.hash + {{/if}} + ) + ); } catch (e) { this.error = e; } From 56cb4dd685c548f662133dd89bc8f5226a4933fa Mon Sep 17 00:00:00 2001 From: Paul d'Aoust Date: Tue, 3 Oct 2023 13:00:27 -0700 Subject: [PATCH 3/7] import NewEntryAction into BarsForFoo templates (Lit, Vue) --- ...ase linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" | 2 +- ...se linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git "a/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" "b/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" index 4e42fe1c1..996a5899d 100644 --- "a/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" +++ "b/templates/lit/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{kebab_case (plural ..\302\241entry_type.name)}}-for-{{kebab_case linked_from.name}}.ts{{\302\241if}}{{\302\241each}}.hbs" @@ -1,6 +1,6 @@ import { LitElement, html } from 'lit'; import { state, customElement, property } from 'lit/decorators.js'; -import { InstalledCell, Record, AppAgentClient, EntryHash, ActionHash, AgentPubKey } from '@holochain/client'; +import { InstalledCell, Record, AppAgentClient, EntryHash, ActionHash, AgentPubKey, NewEntryAction } from '@holochain/client'; import { consume } from '@lit-labs/context'; import '@material/mwc-circular-progress'; import { Task } from '@lit-labs/task'; diff --git "a/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{pascal_case (plural ..\302\241entry_type.name)}}For{{pascal_case linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" "b/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{pascal_case (plural ..\302\241entry_type.name)}}For{{pascal_case linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" index 73e828548..6d0952d60 100644 --- "a/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{pascal_case (plural ..\302\241entry_type.name)}}For{{pascal_case linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" +++ "b/templates/vue/entry-type/ui/src/{{dna_role_name}}/{{coordinator_zome_manifest.name}}/{{#each entry_type.fields}}{{#if (and linked_from (not (eq linked_from.hash_type 'AgentPubKey') ) )}}{{pascal_case (plural ..\302\241entry_type.name)}}For{{pascal_case linked_from.name}}.vue{{\302\241if}}{{\302\241each}}.hbs" @@ -20,7 +20,7 @@