chore: 🤖 add skip prompts toggle (#2036)
* chore: 🤖 add skip prompts toggle
This commit is contained in:
1 parent
77f8235ebf
commit
751b5bef78
7 files changed
+83
-28
No files matched your search
@@ -528,33 +528,57 @@
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<Hds::Form::Checkbox::Group
|
||||
class='oidc-prompts'
|
||||
@isOptional={{true}}
|
||||
@name='prompts'
|
||||
disabled={{form.disabled}}
|
||||
as |G|
|
||||
>
|
||||
<G.Legend>{{t 'form.prompts.label'}}</G.Legend>
|
||||
<G.HelperText>{{t 'form.prompts.help'}}</G.HelperText>
|
||||
|
||||
{{#each this.prompts as |prompt|}}
|
||||
<G.Checkbox::Field
|
||||
@id={{prompt}}
|
||||
checked={{includes prompt this.selectedPrompts}}
|
||||
{{on 'change' (fn this.updatePrompt prompt)}}
|
||||
<Hds::Form::Fieldset @isOptional={{true}} as |F|>
|
||||
<F.Legend>{{t 'form.prompts.label'}}</F.Legend>
|
||||
<F.HelperText>{{t 'form.prompts.help'}}</F.HelperText>
|
||||
<F.Control>
|
||||
<Hds::Form::Toggle::Field
|
||||
name='prompts'
|
||||
checked={{this.skipPromptsList}}
|
||||
disabled={{form.disabled}}
|
||||
{{on 'change' (fn this.toggleField 'none')}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>
|
||||
{{t (concat 'resources.auth-method.form.' prompt '.label')}}
|
||||
{{t 'resources.auth-method.form.none.label'}}
|
||||
</F.Label>
|
||||
<F.HelperText>
|
||||
{{t (concat 'resources.auth-method.form.' prompt '.help')}}
|
||||
{{t 'resources.auth-method.form.none.help'}}
|
||||
</F.HelperText>
|
||||
</G.Checkbox::Field>
|
||||
{{/each}}
|
||||
|
||||
</Hds::Form::Checkbox::Group>
|
||||
</Hds::Form::Toggle::Field>
|
||||
{{#unless this.skipPromptsList}}
|
||||
<Hds::Form::Checkbox::Group
|
||||
class='oidc-prompts'
|
||||
@name='prompts'
|
||||
disabled={{form.disabled}}
|
||||
as |G|
|
||||
>
|
||||
{{#each this.prompts as |prompt|}}
|
||||
<G.Checkbox::Field
|
||||
@id={{prompt}}
|
||||
checked={{includes prompt this.selectedPrompts}}
|
||||
{{on 'change' (fn this.updatePrompt prompt)}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>
|
||||
{{t (concat 'resources.auth-method.form.' prompt '.label')}}
|
||||
</F.Label>
|
||||
<F.HelperText>
|
||||
{{t (concat 'resources.auth-method.form.' prompt '.help')}}
|
||||
</F.HelperText>
|
||||
</G.Checkbox::Field>
|
||||
{{/each}}
|
||||
</Hds::Form::Checkbox::Group>
|
||||
{{/unless}}
|
||||
</F.Control>
|
||||
{{#if @model.errors.prompts}}
|
||||
<F.Error as |E|>
|
||||
{{#each @model.errors.prompts as |error|}}
|
||||
<E.Message>{{error.message}}</E.Message>
|
||||
{{/each}}
|
||||
</F.Error>
|
||||
{{/if}}
|
||||
</Hds::Form::Fieldset>
|
||||
|
||||
{{#unless @model.isNew}}
|
||||
<form.input
|
||||
|
||||
@@ -36,6 +36,7 @@ export default class FormAuthMethodOidcComponent extends Component {
|
||||
prompts = options.oidc.prompts;
|
||||
|
||||
@tracked selectedPrompts = this.parsePromptsArray();
|
||||
@tracked skipPromptsList = this.isToggleChecked();
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
@@ -44,8 +45,29 @@ export default class FormAuthMethodOidcComponent extends Component {
|
||||
return this.args.model.prompts?.map((item) => item.value) ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isToggleChecked() {
|
||||
return this.args.model.prompts?.find((i) => i.value === 'none');
|
||||
}
|
||||
|
||||
//actions
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
*/
|
||||
@action
|
||||
toggleField(value) {
|
||||
this.skipPromptsList = !this.skipPromptsList;
|
||||
//If toggle is on, then add `none` to model, else remove it
|
||||
if (this.skipPromptsList) {
|
||||
this.args.model.prompts = [{ value }];
|
||||
} else {
|
||||
this.args.model.prompts = [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} option
|
||||
* @param {object} event
|
||||
@@ -54,7 +76,6 @@ export default class FormAuthMethodOidcComponent extends Component {
|
||||
updatePrompt(value, event) {
|
||||
const currentSelection = { value };
|
||||
const previousSelection = this.args.model.prompts || [];
|
||||
|
||||
// Add the selected option to the model, only when the checkbox is in checked state
|
||||
if (event.target.checked) {
|
||||
this.args.model.prompts = [...previousSelection, currentSelection];
|
||||
@@ -63,6 +84,7 @@ export default class FormAuthMethodOidcComponent extends Component {
|
||||
const removeSelection = previousSelection.filter(
|
||||
(prompt) => prompt.value !== value,
|
||||
);
|
||||
|
||||
this.args.model.prompts = [...removeSelection];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user