ui: Make DataWriter also deal with more standard shaped errors (#14025)

* ui: Make DataWriter also deal with more standard shaped errors

* ui: Add error states/messages for peering establishment (#14026)

* ui: Add error states/messages for peering establishment

* Inspect state instead of asking about existence of error
This commit is contained in:
John Cowen 2022-08-08 10:51:02 +01:00 committed by GitHub
parent c5b8b60e26
commit d7ed357b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 7 deletions

View File

@ -17,7 +17,20 @@
id={{id}} id={{id}}
> >
<fsm.State @matches={{array 'idle'}}> <fsm.State @matches={{array 'idle' 'error'}}>
<fsm.State @matches={{'error'}}>
<Notice
@type="error"
role="alert"
as |notice|>
<notice.Body>
<p>
<strong>Error</strong><br />
{{fsm.state.context.error.message}}
</p>
</notice.Body>
</Notice>
</fsm.State>
{{yield (hash {{yield (hash
Fieldsets=(component "consul/peer/form/generate/fieldsets" Fieldsets=(component "consul/peer/form/generate/fieldsets"
item=@item item=@item
@ -43,6 +56,9 @@
@onchange @onchange
(pick 'data' (fn fsm.dispatch 'SUCCESS')) (pick 'data' (fn fsm.dispatch 'SUCCESS'))
}} }}
@onerror={{queue
(fn fsm.dispatch 'ERROR')
}}
/> />
</fsm.State> </fsm.State>

View File

@ -17,6 +17,19 @@
@label={{'peer'}} @label={{'peer'}}
@onchange={{fn (optional @onsubmit) @item}} @onchange={{fn (optional @onsubmit) @item}}
as |writer|> as |writer|>
<BlockSlot @name="error" as |after error|>
<Notice
@type="error"
role="alert"
as |notice|>
<notice.Body>
<p>
<strong>Error</strong><br />
{{error.message}}
</p>
</notice.Body>
</Notice>
</BlockSlot>
<BlockSlot @name="content"> <BlockSlot @name="content">
{{#let {{#let
(unique-id) (unique-id)

View File

@ -19,7 +19,7 @@
@item={{data}} @item={{data}}
@data={{null}} @data={{null}}
@onchange={{action dispatch "SUCCESS"}} @onchange={{action dispatch "SUCCESS"}}
@onerror={{queue (action (mut error) value="error.errors.firstObject") (action dispatch "ERROR")}} @onerror={{action "error"}}
/> />
</State> </State>
@ -28,7 +28,7 @@
@sink={{sink}} @sink={{sink}}
@item={{data}} @item={{data}}
@onchange={{action dispatch "SUCCESS"}} @onchange={{action dispatch "SUCCESS"}}
@onerror={{queue (action (mut error) value="error.errors.firstObject") (action dispatch "ERROR")}} @onerror={{action "error"}}
/> />
</State> </State>

View File

@ -21,5 +21,17 @@ export default Component.extend(Slotted, {
set(this, 'data', data); set(this, 'data', data);
this.dispatch('PERSIST'); this.dispatch('PERSIST');
}, },
error: function(data, e) {
if (e && typeof e.preventDefault === 'function') {
e.preventDefault();
}
set(
this,
'error',
typeof data.error.errors !== 'undefined' ?
data.error.errors.firstObject : data.error
);
this.dispatch('ERROR');
},
}, },
}); });