ui: Add peer token generation form (#13755)
* ui: Add peer token generation form
This commit is contained in:
parent
539abdf60f
commit
987b6255fb
|
@ -0,0 +1,28 @@
|
|||
# Consul::Peer::Form::Generate
|
||||
|
||||
```hbs preview-template
|
||||
|
||||
<DataSource @src={{
|
||||
uri '/${partition/${nspace}/${dc}/peer/${name}'
|
||||
(hash
|
||||
partition=''
|
||||
nspace=''
|
||||
dc='dc1'
|
||||
name=''
|
||||
)
|
||||
}}
|
||||
as |source|>
|
||||
{{#if source.data}}
|
||||
<Consul::Peer::Form::Generate
|
||||
@item={{source.data}}
|
||||
@onchange={{noop}}
|
||||
@regenerate={{false}}
|
||||
as |form|>
|
||||
<form.Fieldsets />
|
||||
<form.Actions
|
||||
@onclose={{noop}}
|
||||
/>
|
||||
</Consul::Peer::Form::Generate>
|
||||
{{/if}}
|
||||
</DataSource>
|
||||
```
|
|
@ -0,0 +1,10 @@
|
|||
<Action
|
||||
form={{@id}}
|
||||
@type="submit"
|
||||
{{disabled (or
|
||||
(eq @item.Name.length 0)
|
||||
)}}
|
||||
...attributes
|
||||
>
|
||||
Generate token
|
||||
</Action>
|
|
@ -0,0 +1,26 @@
|
|||
export default {
|
||||
id: 'consul-peer-generate-form',
|
||||
initial: 'idle',
|
||||
states: {
|
||||
idle: {
|
||||
on: {
|
||||
LOAD: {
|
||||
target: 'loading'
|
||||
}
|
||||
}
|
||||
},
|
||||
loading: {
|
||||
on: {
|
||||
SUCCESS: {
|
||||
target: 'success'
|
||||
},
|
||||
ERROR: {
|
||||
target: 'error'
|
||||
}
|
||||
}
|
||||
},
|
||||
success: {
|
||||
},
|
||||
error: {},
|
||||
},
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
<div
|
||||
class={{class-map
|
||||
'consul-peer-form-generate-fieldsets'
|
||||
}}
|
||||
...attributes
|
||||
>
|
||||
<StateMachine
|
||||
@src={{require '/machines/validate.xstate' from="/components/consul/peer/form/generate/fieldsets"}}
|
||||
as |fsm|>
|
||||
{{#let
|
||||
(hash
|
||||
help=(concat
|
||||
(t 'common.validations.dns-hostname.help')
|
||||
(t 'common.validations.immutable.help')
|
||||
)
|
||||
Name=(array
|
||||
(hash
|
||||
test=(t 'common.validations.dns-hostname.test')
|
||||
error=(t 'common.validations.dns-hostname.error' name="Name")
|
||||
)
|
||||
)
|
||||
)
|
||||
as |Name|}}
|
||||
<fieldset>
|
||||
<TextInput
|
||||
@label="Name of peer"
|
||||
@name="Name"
|
||||
@item={{@item}}
|
||||
@validations={{Name}}
|
||||
@chart={{fsm}}
|
||||
@oninput={{pick 'target.value' (set @item 'Name')}}
|
||||
/>
|
||||
{{yield (hash
|
||||
valid=(not (state-matches fsm.state 'error'))
|
||||
)}}
|
||||
</fieldset>
|
||||
|
||||
{{/let}}
|
||||
</StateMachine>
|
||||
</div>
|
|
@ -0,0 +1,56 @@
|
|||
<div
|
||||
class={{class-map
|
||||
'consul-peer-form-generate'
|
||||
}}
|
||||
...attributes
|
||||
>
|
||||
<StateMachine
|
||||
@src={{require './chart.xstate' from="/components/consul/peer/form/generate"}}
|
||||
@initial={{if @regenerate 'loading' 'idle'}}
|
||||
as |fsm|>
|
||||
|
||||
{{#let
|
||||
(unique-id)
|
||||
as |id reset|}}
|
||||
<form
|
||||
{{on 'submit' (fn fsm.dispatch 'LOAD')}}
|
||||
id={{id}}
|
||||
>
|
||||
|
||||
<fsm.State @matches={{array 'idle'}}>
|
||||
{{yield (hash
|
||||
Fieldsets=(component "consul/peer/form/generate/fieldsets"
|
||||
item=@item
|
||||
)
|
||||
Actions=(component "consul/peer/form/generate/actions"
|
||||
item=@item
|
||||
id=id
|
||||
)
|
||||
)}}
|
||||
</fsm.State>
|
||||
|
||||
<fsm.State @matches={{'loading'}}>
|
||||
<DataSource
|
||||
@src={{uri '/${partition}/${nspace}/${dc}/peering/token-for/${name}'
|
||||
(hash
|
||||
partition=@item.Partition
|
||||
nspace=''
|
||||
dc=@item.Datacenter
|
||||
name=@item.Name
|
||||
)
|
||||
}}
|
||||
@onchange={{queue
|
||||
@onchange
|
||||
(pick 'data' (fn fsm.dispatch 'SUCCESS'))
|
||||
}}
|
||||
/>
|
||||
</fsm.State>
|
||||
|
||||
<fsm.State @matches={{'success'}}>
|
||||
</fsm.State>
|
||||
|
||||
</form>
|
||||
{{/let}}
|
||||
|
||||
</StateMachine>
|
||||
</div>
|
Loading…
Reference in New Issue