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 155c4bc2af
commit 50b85c3189
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}}
>
<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
Fieldsets=(component "consul/peer/form/generate/fieldsets"
item=@item
@ -43,6 +56,9 @@
@onchange
(pick 'data' (fn fsm.dispatch 'SUCCESS'))
}}
@onerror={{queue
(fn fsm.dispatch 'ERROR')
}}
/>
</fsm.State>

View File

@ -17,6 +17,19 @@
@label={{'peer'}}
@onchange={{fn (optional @onsubmit) @item}}
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">
{{#let
(unique-id)
@ -27,15 +40,15 @@ as |id|}}
>
{{yield (hash
Fieldsets=(component "consul/peer/form/initiate/fieldsets"
item=@item
item=@item
)
Actions=(component "consul/peer/form/initiate/actions"
item=@item
id=id
item=@item
id=id
)
)}}
</form>
{{/let}}
</BlockSlot>
</BlockSlot>
</DataWriter>
</div>

View File

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

View File

@ -21,5 +21,17 @@ export default Component.extend(Slotted, {
set(this, 'data', data);
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');
},
},
});