Icu 13880 create manage scopes route and view with keyword values (#2342)
* feat: 🎸 manage scopes route and page ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13880 * Update addons/core/translations/resources/en-us.yaml Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * Update ui/admin/app/abilities/role.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * Update ui/admin/app/components/form/role/manage-scopes/index.hbs Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
This commit is contained in:
1 parent
85bce84356
commit
89e072401c
18 files changed
+536
-16
No files matched your search
@@ -0,0 +1,83 @@
|
||||
<Rose::Form
|
||||
class='full-width role-manage-scopes-form'
|
||||
@onSubmit={{fn @submit this.selectedItems}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
as |form|
|
||||
>
|
||||
|
||||
<Hds::Form::Toggle::Field
|
||||
@value={{this.keywords.keyThis}}
|
||||
name={{this.keywords.keyThis}}
|
||||
checked={{includes this.keywords.keyThis this.selectedItems}}
|
||||
disabled={{form.disabled}}
|
||||
{{on 'change' this.toggleField}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'resources.role.scope.form.this.label'}}</F.Label>
|
||||
<F.HelperText>{{t 'resources.role.scope.form.this.help'}}</F.HelperText>
|
||||
</Hds::Form::Toggle::Field>
|
||||
|
||||
<Hds::Form::Toggle::Field
|
||||
@value={{this.keywords.keyChildren}}
|
||||
name={{this.keywords.keyChildren}}
|
||||
checked={{includes this.keywords.keyChildren this.selectedItems}}
|
||||
disabled={{form.disabled}}
|
||||
{{on 'change' this.toggleField}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'resources.role.scope.form.children.label'}}</F.Label>
|
||||
<F.HelperText>{{if
|
||||
@model.scope.isGlobal
|
||||
(t 'resources.role.scope.form.children.help.0')
|
||||
(t 'resources.role.scope.form.children.help.1')
|
||||
}}</F.HelperText>
|
||||
</Hds::Form::Toggle::Field>
|
||||
|
||||
{{#if @model.scope.isGlobal}}
|
||||
<Hds::Form::Toggle::Field
|
||||
@value={{this.keywords.keyDescendants}}
|
||||
name={{this.keywords.keyDescendants}}
|
||||
checked={{includes this.keywords.keyDescendants this.selectedItems}}
|
||||
disabled={{form.disabled}}
|
||||
{{on 'change' this.toggleField}}
|
||||
as |F|
|
||||
>
|
||||
<F.Label>{{t 'resources.role.scope.form.descendants.label'}}</F.Label>
|
||||
<F.HelperText>{{t
|
||||
'resources.role.scope.form.descendants.help'
|
||||
}}</F.HelperText>
|
||||
</Hds::Form::Toggle::Field>
|
||||
{{/if}}
|
||||
|
||||
{{! TODO: Add correct href value inline link}}
|
||||
{{#if this.showAlert}}
|
||||
<Hds::Alert @type='compact' as |A|>
|
||||
<A.Description>
|
||||
{{t 'resources.role.scope.messages.keywords-selected.description'}}
|
||||
<Hds::Link::Inline @color='secondary' @href={{(doc-url 'role')}}>
|
||||
{{t 'resources.role.scope.messages.keywords-selected.link'}}
|
||||
</Hds::Link::Inline>
|
||||
</A.Description>
|
||||
</Hds::Alert>
|
||||
{{/if}}
|
||||
|
||||
{{! TODO: Add correct route string once route is created}}
|
||||
<Hds::Button
|
||||
@text={{t 'resources.role.scope.actions.add-custom-scopes.text'}}
|
||||
@color='secondary'
|
||||
@route='scopes.scope.roles.role'
|
||||
/>
|
||||
|
||||
<Hds::Form::HelperText
|
||||
@controlId='for-add-custom-scopes-button'
|
||||
class='add-custom-scopes-helper-text'
|
||||
>
|
||||
{{t 'resources.role.scope.actions.add-custom-scopes.help'}}
|
||||
</Hds::Form::HelperText>
|
||||
|
||||
<form.actions
|
||||
@submitText={{t 'actions.save'}}
|
||||
@cancelText={{t 'actions.cancel'}}
|
||||
/>
|
||||
</Rose::Form>
|
||||
@@ -0,0 +1,58 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import {
|
||||
GRANT_SCOPE_THIS,
|
||||
GRANT_SCOPE_CHILDREN,
|
||||
GRANT_SCOPE_DESCENDANTS,
|
||||
} from 'api/models/role';
|
||||
|
||||
export default class FormRoleManageScopesIndexComponent extends Component {
|
||||
// =attributes
|
||||
|
||||
keywords = {
|
||||
keyThis: GRANT_SCOPE_THIS,
|
||||
keyChildren: GRANT_SCOPE_CHILDREN,
|
||||
keyDescendants: GRANT_SCOPE_DESCENDANTS,
|
||||
};
|
||||
|
||||
@tracked selectedItems = [...this.args.model.grant_scope_ids];
|
||||
|
||||
/**
|
||||
* Returns true if role is global level and either
|
||||
* "children" or "descendants" is toggled on.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get showAlert() {
|
||||
return (
|
||||
this.args.model.scope.isGlobal &&
|
||||
(this.selectedItems.includes(GRANT_SCOPE_CHILDREN) ||
|
||||
this.selectedItems.includes(GRANT_SCOPE_DESCENDANTS))
|
||||
);
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Handles toggle event changes for selectedGrantScopeIDs
|
||||
* @param {object} event
|
||||
*/
|
||||
@action
|
||||
toggleField(event) {
|
||||
const { checked, value } = event.target;
|
||||
const removeValue = (value) => {
|
||||
this.selectedItems = this.selectedItems.filter((item) => item !== value);
|
||||
};
|
||||
if (checked) {
|
||||
this.selectedItems = [...this.selectedItems, value];
|
||||
if (value === GRANT_SCOPE_CHILDREN) {
|
||||
removeValue(GRANT_SCOPE_DESCENDANTS);
|
||||
}
|
||||
if (value === GRANT_SCOPE_DESCENDANTS) {
|
||||
removeValue(GRANT_SCOPE_CHILDREN);
|
||||
}
|
||||
} else {
|
||||
removeValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,30 @@
|
||||
SPDX-License-Identifier: BUSL-1.1
|
||||
}}
|
||||
|
||||
{{!TODO Refactor page to use hds dropdown in ICU-13879}}
|
||||
<Rose::Dropdown
|
||||
@text={{t 'actions.manage'}}
|
||||
@dropdownRight={{true}}
|
||||
as |dropdown|
|
||||
>
|
||||
{{#if (can 'addPrincipals role' @model)}}
|
||||
<dropdown.link @route='scopes.scope.roles.role.add-principals'>
|
||||
<dropdown.link
|
||||
@route='scopes.scope.roles.role.add-principals'
|
||||
data-test-manage-dropdown-principals
|
||||
>
|
||||
{{t 'resources.role.principal.actions.add-principals'}}
|
||||
</dropdown.link>
|
||||
{{/if}}
|
||||
|
||||
{{#if (can 'setGrantScopes role' @model)}}
|
||||
<dropdown.link
|
||||
@route='scopes.scope.roles.role.manage-scopes'
|
||||
data-test-manage-dropdown-scopes
|
||||
>
|
||||
{{t 'resources.role.scope.actions.manage-scopes'}}
|
||||
</dropdown.link>
|
||||
{{/if}}
|
||||
|
||||
{{#if (can 'delete model' @model)}}
|
||||
<dropdown.separator />
|
||||
<dropdown.button
|
||||
|
||||
Reference in new issue
Block a user