open-consul/ui/packages/consul-ui/app/components/data-writer/index.hbs

124 lines
2.9 KiB
Handlebars

<StateChart @src={{chart}} as |State Guard Action dispatch state|>
<Ref @target={{this}} @name="dispatch" @value={{dispatch}} />
{{#let (hash
data=data
error=error
persist=(action "persist")
delete=(queue (action (mut data)) (action dispatch "REMOVE"))
inflight=(state-matches state (array "persisting" "removing"))
disabled=(state-matches state (array "persisting" "removing"))
) as |api|}}
{{yield api}}
<State @matches="removing">
<DataSink
@sink={{sink}}
@item={{data}}
@data={{null}}
@onchange={{action dispatch "SUCCESS"}}
@onerror={{queue (action (mut error) value="error.errors.firstObject") (action dispatch "ERROR")}}
/>
</State>
<State @matches="persisting">
<DataSink
@sink={{sink}}
@item={{data}}
@onchange={{action dispatch "SUCCESS"}}
@onerror={{queue (action (mut error) value="error.errors.firstObject") (action dispatch "ERROR")}}
/>
</State>
<State @matches="removed">
{{#let
(queue (action dispatch "RESET") (action ondelete))
as |after|}}
{{#yield-slot name="removed" params=(block-params after)}}
{{yield api}}
{{else}}
<Notice
{{notification
after=(action after)
}}
class="notification-delete"
@type="success"
as |notice|>
<notice.Header>
<strong>Success!</strong>
</notice.Header>
<notice.Body>
<p>
Your {{or label type}} has been deleted.
</p>
</notice.Body>
</Notice>
{{/yield-slot}}
{{/let}}
</State>
<State @matches="persisted">
{{#let
(action onchange)
as |after|}}
{{#yield-slot name="persisted" params=(block-params after)}}
{{yield api}}
{{else}}
<Notice
{{notification
after=(action after)
}}
class="notification-update"
@type="success"
as |notice|>
<notice.Header>
<strong>Success!</strong>
</notice.Header>
<notice.Body>
<p>
Your {{or label type}} has been saved.
</p>
</notice.Body>
</Notice>
{{/yield-slot}}
{{/let}}
</State>
<State @matches="error">
{{#let
(action dispatch "RESET")
as |after|}}
{{#yield-slot name="error" params=(block-params after api.error)}}
{{yield api}}
{{else}}
<Notice
{{notification
after=(action after)
}}
class="notification-update"
@type="error"
as |notice|>
<notice.Header>
<strong>Error!</strong>
</notice.Header>
<notice.Body>
<p>
There was an error saving your {{or label type}}.
{{#if (and api.error.status api.error.detail)}}
<br />{{api.error.status}}: {{api.error.detail}}
{{/if}}
</p>
</notice.Body>
</Notice>
{{/yield-slot}}
{{/let}}
</State>
<YieldSlot @name="content">
{{yield api}}
</YieldSlot>
{{/let}}
</StateChart>