Skip to content

Commit

Permalink
guard against trailing non-widget fields in EditFoo.svelte template
Browse files Browse the repository at this point in the history
  • Loading branch information
pdaoust authored and ThetaSinner committed Nov 3, 2023
1 parent 5709f58 commit fe16ddd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
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();

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
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

0 comments on commit fe16ddd

Please sign in to comment.