Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template sweep -- fix bugs in Vue and Lit #130

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
10 changes: 10 additions & 0 deletions src/scaffold/entry_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
pdaoust marked this conversation as resolved.
Show resolved Hide resolved

let reference_entry_hash = match maybe_reference_entry_hash {
Some(r) => r.clone(),
None => {
Expand Down Expand Up @@ -147,6 +156,7 @@ pub fn scaffold_entry_type(
let entry_def = EntryDefinition {
name: name.clone(),
fields,
widget_fields,
reference_entry_hash,
};

Expand Down
1 change: 1 addition & 0 deletions src/scaffold/entry_type/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ impl Referenceable {
pub struct EntryDefinition {
pub name: String,
pub fields: Vec<FieldDefinition>,
pub widget_fields: Vec<FieldDefinition>,
pub reference_entry_hash: bool,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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}};

Expand All @@ -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<Array<{{#if ../entry_type.reference_entry_hash}}EntryHash{{else}}ActionHash{{/if}}>>, () => [this.{{camel_case linked_from.singular_arg}}]);
}).then(v =>
(v as Array<Record>)
.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<Array<{{#if ../entry_type.reference_entry_hash}}EntryHash{{else}}ActionHash{{/if}}>>,
() => [this.{{camel_case linked_from.singular_arg}}]);

firstUpdated() {
if (this.{{camel_case linked_from.singular_arg}} === undefined) {
Expand All @@ -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`<span>No {{lower_case (plural ../entry_type.name)}} found for this {{lower_case linked_from.name}}.</span>`;

return html`
<div style="display: flex; flex-direction: column">
${hashes.map(hash =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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") }}
Expand Down Expand Up @@ -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}`;
Expand All @@ -99,7 +99,7 @@ async function update{{pascal_case entry_type.name}}() {
</mwc-snackbar>
<div style="display: flex; flex-direction: column">
<span style="font-size: 18px">Edit {{pascal_case entry_type.name}}</span>

{{#each entry_type.fields}}
{{#if widget}}
<div style="margin-bottom: 16px">
Expand All @@ -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}}

</div>

{{/if}}
Expand All @@ -121,7 +121,7 @@ async function update{{pascal_case entry_type.name}}() {
on:click={() => dispatch('edit-canceled')}
style="flex: 1; margin-right: 16px"
></mwc-button>
<mwc-button
<mwc-button
raised
label="Save"
disabled={!is{{pascal_case entry_type.name}}Valid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<div v-if="loading" style="display: flex; flex: 1; align-items: center; justify-content: center">
<mwc-circular-progress indeterminate></mwc-circular-progress>
</div>

<div v-else style="display: flex; flex-direction: column">
<span v-if="error">Error fetching the {{lower_case (plural ../entry_type.name)}}: {{{{raw}}}} {{error.data.data}}.{{{{/raw}}}}</span>
<div v-else-if="hashes && hashes.length > 0" style="margin-bottom: 8px">
<{{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"
>
</{{pascal_case ../entry_type.name}}Detail>
</div>
Expand All @@ -20,7 +20,7 @@
<script lang="ts">
import { defineComponent, inject, ComputedRef } from 'vue';
import { decode } from '@msgpack/msgpack';
import { AppAgentClient, Record, AgentPubKey, EntryHash, ActionHash } from '@holochain/client';
import { AppAgentClient, Record, AgentPubKey, EntryHash, ActionHash, NewEntryAction } from '@holochain/client';
import '@material/mwc-circular-progress';
import {{pascal_case ../entry_type.name}}Detail from './{{pascal_case ../entry_type.name}}Detail.vue';

Expand All @@ -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
}
Expand All @@ -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<Record>)
.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;
}
Expand Down