2023-03-14 13:18:55 +00:00
|
|
|
{{!
|
|
|
|
Copyright (c) HashiCorp, Inc.
|
|
|
|
SPDX-License-Identifier: MPL-2.0
|
|
|
|
}}
|
|
|
|
|
2020-07-09 09:08:47 +00:00
|
|
|
{{yield}}
|
|
|
|
<StateChart @src={{chart}} as |State Guard Action dispatch state|>
|
|
|
|
<Ref @target={{this}} @name="dispatch" @value={{dispatch}} />
|
|
|
|
<Guard @name="loaded" @cond={{action "isLoaded"}} />
|
|
|
|
|
|
|
|
|
|
|
|
{{#let (hash
|
|
|
|
data=data
|
|
|
|
error=error
|
2022-07-14 08:30:35 +00:00
|
|
|
invalidate=this.invalidate
|
2020-07-17 13:42:45 +00:00
|
|
|
dispatchError=(queue (action (mut error) value="error.errors.firstObject") (action dispatch "ERROR"))
|
2020-07-09 09:08:47 +00:00
|
|
|
) as |api|}}
|
|
|
|
|
2020-07-17 13:42:45 +00:00
|
|
|
{{#yield-slot name="data"}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
|
|
|
{{! if we didn't specify any data}}
|
|
|
|
{{#if (not items)}}
|
|
|
|
{{! try and load the data if we aren't in an error state}}
|
2022-07-14 08:30:35 +00:00
|
|
|
<State @notMatches={{array "error" "disconnected"}}>
|
2020-07-17 13:42:45 +00:00
|
|
|
{{! but only if we only asked for a single load and we are in loading state}}
|
|
|
|
{{#if (and src (or (not once) (state-matches state "loading")))}}
|
|
|
|
<DataSource
|
|
|
|
@open={{open}}
|
|
|
|
@src={{src}}
|
|
|
|
@onchange={{queue (action "change" value="data") (action dispatch "SUCCESS")}}
|
|
|
|
@onerror={{api.dispatchError}}
|
2022-07-14 08:30:35 +00:00
|
|
|
as |source|>
|
|
|
|
{{did-insert (set this 'invalidate' source.invalidate)}}
|
|
|
|
</DataSource>
|
2020-07-17 13:42:45 +00:00
|
|
|
{{/if}}
|
|
|
|
</State>
|
|
|
|
{{/if}}
|
|
|
|
{{/yield-slot}}
|
2020-07-09 09:08:47 +00:00
|
|
|
|
|
|
|
<State @matches="loading">
|
|
|
|
{{#yield-slot name="loading"}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
2020-10-14 08:03:39 +00:00
|
|
|
<Consul::Loader />
|
2020-07-09 09:08:47 +00:00
|
|
|
{{/yield-slot}}
|
|
|
|
</State>
|
|
|
|
|
|
|
|
<State @matches="error">
|
|
|
|
{{#yield-slot name="error"}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
|
|
|
<ErrorState @error={{error}} />
|
|
|
|
{{/yield-slot}}
|
|
|
|
</State>
|
|
|
|
|
2022-07-14 08:30:35 +00:00
|
|
|
<State @matches={{array "idle" "disconnected"}}>
|
2020-07-09 09:08:47 +00:00
|
|
|
|
|
|
|
<State @matches="disconnected">
|
2022-01-04 14:55:32 +00:00
|
|
|
{{#if (not (eq error.status '401'))}}
|
2021-11-24 18:14:07 +00:00
|
|
|
{{#yield-slot name="disconnected" params=(block-params (action dispatch "RESET"))}}
|
2022-01-04 14:55:32 +00:00
|
|
|
{{yield api}}
|
2020-07-09 09:08:47 +00:00
|
|
|
{{else}}
|
2023-03-06 22:10:09 +00:00
|
|
|
<Hds::Toast @color='warning'
|
2021-11-24 18:14:07 +00:00
|
|
|
{{notification
|
|
|
|
sticky=true
|
2023-03-06 22:10:09 +00:00
|
|
|
}} as |T|>
|
|
|
|
<T.Title>Warning!</T.Title>
|
|
|
|
<T.Description>An error was returned whilst loading this data, refresh to try again.</T.Description>
|
|
|
|
</Hds::Toast>
|
2020-07-09 09:08:47 +00:00
|
|
|
{{/yield-slot}}
|
2022-01-04 14:55:32 +00:00
|
|
|
{{/if}}
|
2020-07-09 09:08:47 +00:00
|
|
|
</State>
|
2021-02-19 16:42:16 +00:00
|
|
|
{{#if (eq error.status "403")}}
|
|
|
|
{{#yield-slot name="error"}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
|
|
|
<ErrorState @error={{error}} />
|
|
|
|
{{/yield-slot}}
|
|
|
|
{{else}}
|
|
|
|
<YieldSlot @name="loaded">
|
|
|
|
{{yield api}}
|
|
|
|
</YieldSlot>
|
|
|
|
{{/if}}
|
2020-07-09 09:08:47 +00:00
|
|
|
|
|
|
|
</State>
|
|
|
|
|
|
|
|
{{/let}}
|
2021-10-07 11:38:04 +00:00
|
|
|
{{did-update (fn dispatch "LOAD") src=src}}
|
2020-07-09 09:08:47 +00:00
|
|
|
</StateChart>
|