ICU-13883 add remove org modal (#2435)
* feat: 🎸 add remove org modal ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13883 --------- Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
This commit is contained in:
1 parent
0af81d9bc1
commit
79b06ee565
5 files changed
+320
-21
No files matched your search
@@ -69,7 +69,7 @@
|
||||
@iconPosition='trailing'
|
||||
@text={{t
|
||||
'resources.role.scope.actions.view-projects'
|
||||
selected=projectTotals.selected
|
||||
selected=projectTotals.selected.length
|
||||
total=projectTotals.total
|
||||
}}
|
||||
@route='scopes.scope.roles.role.manage-scopes.manage-org-projects'
|
||||
@@ -127,4 +127,63 @@
|
||||
/>
|
||||
</A.Footer>
|
||||
</Hds::ApplicationState>
|
||||
{{/if}}
|
||||
|
||||
{{#if this.selectedOrg}}
|
||||
<Hds::Modal
|
||||
@onClose={{this.toggleRemoveOrgModal}}
|
||||
data-test-manage-scopes-remove-org-modal
|
||||
as |M|
|
||||
>
|
||||
<M.Header>{{t 'resources.role.scope.remove-org.title'}}</M.Header>
|
||||
<M.Body>
|
||||
<Hds::Text::Body @tag='p' @color='primary'>
|
||||
{{t
|
||||
'resources.role.scope.remove-org.description'
|
||||
orgDisplayName=this.orgDisplayName
|
||||
}}
|
||||
</Hds::Text::Body>
|
||||
</M.Body>
|
||||
<M.Footer as |F|>
|
||||
<Hds::ButtonSet>
|
||||
<Hds::Button
|
||||
@text={{t 'resources.role.scope.actions.remove-org-and-projects'}}
|
||||
{{on 'click' (fn this.removeProjects false)}}
|
||||
/>
|
||||
<Hds::Button
|
||||
@color='secondary'
|
||||
@text={{t 'resources.role.scope.actions.remove-org-only'}}
|
||||
{{on 'click' F.close}}
|
||||
/>
|
||||
</Hds::ButtonSet>
|
||||
</M.Footer>
|
||||
</Hds::Modal>
|
||||
{{/if}}
|
||||
|
||||
{{#if this.selectedOrgs}}
|
||||
<Hds::Modal
|
||||
@onClose={{this.toggleRemoveAllModal}}
|
||||
data-test-manage-scopes-remove-all-orgs-modal
|
||||
as |M|
|
||||
>
|
||||
<M.Header>{{t 'resources.role.scope.remove-all-orgs.title'}}</M.Header>
|
||||
<M.Body>
|
||||
<Hds::Text::Body @tag='p' @color='primary'>
|
||||
{{t 'resources.role.scope.remove-all-orgs.description'}}
|
||||
</Hds::Text::Body>
|
||||
</M.Body>
|
||||
<M.Footer as |F|>
|
||||
<Hds::ButtonSet>
|
||||
<Hds::Button
|
||||
@text={{t 'resources.role.scope.actions.remove-orgs-and-projects'}}
|
||||
{{on 'click' (fn this.removeProjects true)}}
|
||||
/>
|
||||
<Hds::Button
|
||||
@color='secondary'
|
||||
@text={{t 'resources.role.scope.actions.remove-orgs-only'}}
|
||||
{{on 'click' F.close}}
|
||||
/>
|
||||
</Hds::ButtonSet>
|
||||
</M.Footer>
|
||||
</Hds::Modal>
|
||||
{{/if}}
|
||||
@@ -5,27 +5,108 @@
|
||||
|
||||
import Component from '@glimmer/component';
|
||||
import { action } from '@ember/object';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
|
||||
export default class FormRoleManageCustomScopesIndexComponent extends Component {
|
||||
// =attributes
|
||||
|
||||
@tracked selectedOrgs = [];
|
||||
@tracked selectedOrg = '';
|
||||
|
||||
/**
|
||||
* Returns the display name of the selectedOrg.
|
||||
* @type {string}
|
||||
*/
|
||||
get orgDisplayName() {
|
||||
const org = this.args.model.orgScopes.find(
|
||||
({ id }) => id === this.selectedOrg,
|
||||
);
|
||||
return org.displayName;
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Handles the selection changes for the paginated table.
|
||||
* @param {object} selectableRowsStates
|
||||
* @param {object} selectionKey
|
||||
*/
|
||||
@action
|
||||
selectionChange({ selectableRowsStates }) {
|
||||
const { role } = this.args.model;
|
||||
selectableRowsStates.forEach((row) => {
|
||||
const { isSelected, selectionKey: key } = row;
|
||||
const includesId = role.grant_scope_ids.includes(key);
|
||||
if (isSelected && !includesId) {
|
||||
role.grant_scope_ids = [...role.grant_scope_ids, key];
|
||||
} else if (!isSelected && includesId) {
|
||||
selectionChange({ selectableRowsStates, selectionKey }) {
|
||||
const { role, projectTotals } = this.args.model;
|
||||
|
||||
const addOrRemoveValues = (add, remove, orgId) => {
|
||||
let selectedOrg;
|
||||
const includesId = role.grant_scope_ids.includes(orgId);
|
||||
const selected = projectTotals[orgId]?.selected;
|
||||
if (add && !includesId) {
|
||||
role.grant_scope_ids = [...role.grant_scope_ids, orgId];
|
||||
} else if (remove && includesId) {
|
||||
if (selected?.length) {
|
||||
selectedOrg = orgId;
|
||||
}
|
||||
role.grant_scope_ids = role.grant_scope_ids.filter(
|
||||
(item) => item !== key,
|
||||
(item) => item !== orgId,
|
||||
);
|
||||
}
|
||||
return selectedOrg;
|
||||
};
|
||||
|
||||
if (selectionKey === 'all') {
|
||||
const selectedOrgs = [];
|
||||
selectableRowsStates.forEach(({ selectionKey, isSelected }) => {
|
||||
const selectedOrg = addOrRemoveValues(
|
||||
isSelected,
|
||||
!isSelected,
|
||||
selectionKey,
|
||||
);
|
||||
if (selectedOrg) {
|
||||
selectedOrgs.push(selectedOrg);
|
||||
}
|
||||
});
|
||||
this.selectedOrgs = selectedOrgs;
|
||||
} else {
|
||||
this.selectedOrg = addOrRemoveValues(true, true, selectionKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes projects from an org that was deselected and toggles the correct modal off.
|
||||
* @param {boolean} toggleRemoveAllModal
|
||||
*/
|
||||
@action
|
||||
removeProjects(toggleRemoveAllModal) {
|
||||
const selectedOrgs = toggleRemoveAllModal
|
||||
? this.selectedOrgs
|
||||
: [this.selectedOrg];
|
||||
const { role, projectTotals } = this.args.model;
|
||||
selectedOrgs.forEach((orgId) => {
|
||||
const { selected, total } = projectTotals[orgId];
|
||||
role.grant_scope_ids = role.grant_scope_ids.filter(
|
||||
(item) => !selected.includes(item),
|
||||
);
|
||||
projectTotals[orgId] = { selected: [], total };
|
||||
});
|
||||
if (toggleRemoveAllModal) {
|
||||
this.toggleRemoveAllModal();
|
||||
} else {
|
||||
this.toggleRemoveOrgModal();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the modal to remove an org and projects off.
|
||||
*/
|
||||
@action
|
||||
toggleRemoveOrgModal() {
|
||||
this.selectedOrg = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the modal to remove orgs and projects off.
|
||||
*/
|
||||
@action
|
||||
toggleRemoveAllModal() {
|
||||
this.selectedOrgs = [];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user