feat: 🎸 add search and filtering to scopes tab in a role (#2371)
* feat: 🎸 add search and filtering to scopes tab in a role ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13886
This commit is contained in:
1 parent
3bcc5aabd8
commit
c340d9ab89
17 files changed
+638
-135
No files matched your search
@@ -14,6 +14,10 @@ export default class ScopesScopeRolesRoleManageScopesIndexController extends Con
|
||||
|
||||
@service router;
|
||||
|
||||
// =attributes
|
||||
|
||||
showCheckIcon = false;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
@@ -27,14 +31,14 @@ export default class ScopesScopeRolesRoleManageScopesIndexController extends Con
|
||||
@notifySuccess('notifications.add-success')
|
||||
async setGrantScopes(role, grantScopeIDs) {
|
||||
await role.setGrantScopes(grantScopeIDs);
|
||||
await this.router.replaceWith('scopes.scope.roles.role.scopes');
|
||||
this.router.replaceWith('scopes.scope.roles.role.scopes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to role scopes as if nothing ever happened.
|
||||
*/
|
||||
@action
|
||||
async cancel() {
|
||||
await this.router.replaceWith('scopes.scope.roles.role.scopes');
|
||||
cancel() {
|
||||
this.router.replaceWith('scopes.scope.roles.role.scopes');
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
@@ -12,6 +12,8 @@ import { debounce } from 'core/decorators/debounce';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeRolesRoleManageScopesManageCustomScopesController extends Controller {
|
||||
@controller('scopes/scope/roles/role/manage-scopes/index') manageScopes;
|
||||
|
||||
// =services
|
||||
|
||||
@service router;
|
||||
@@ -49,6 +51,7 @@ export default class ScopesScopeRolesRoleManageScopesManageCustomScopesControlle
|
||||
@notifySuccess('notifications.add-success')
|
||||
async setGrantScopes(role, grantScopeIDs) {
|
||||
await role.setGrantScopes(grantScopeIDs);
|
||||
this.manageScopes.showCheckIcon = true;
|
||||
await this.router.replaceWith('scopes.scope.roles.role.manage-scopes');
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
@@ -12,6 +12,8 @@ import { debounce } from 'core/decorators/debounce';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeRolesRoleManageScopesManageOrgProjectsController extends Controller {
|
||||
@controller('scopes/scope/roles/role/manage-scopes/index') manageScopes;
|
||||
|
||||
// =services
|
||||
|
||||
@service router;
|
||||
@@ -49,6 +51,7 @@ export default class ScopesScopeRolesRoleManageScopesManageOrgProjectsController
|
||||
@notifySuccess('notifications.add-success')
|
||||
async setGrantScopes(role, grantScopeIDs) {
|
||||
await role.setGrantScopes(grantScopeIDs);
|
||||
this.manageScopes.showCheckIcon = true;
|
||||
if (role.scope.isGlobal) {
|
||||
this.router.replaceWith(
|
||||
'scopes.scope.roles.role.manage-scopes.manage-custom-scopes',
|
||||
|
||||
@@ -4,15 +4,95 @@
|
||||
*/
|
||||
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { debounce } from 'core/decorators/debounce';
|
||||
import {
|
||||
GRANT_SCOPE_THIS,
|
||||
GRANT_SCOPE_CHILDREN,
|
||||
GRANT_SCOPE_DESCENDANTS,
|
||||
} from 'api/models/role';
|
||||
import { TYPE_SCOPE_ORG, TYPE_SCOPE_PROJECT } from 'api/models/scope';
|
||||
|
||||
export default class ScopesScopeRolesRoleScopesController extends Controller {
|
||||
@controller('scopes/scope/roles/index') roles;
|
||||
|
||||
// =services
|
||||
|
||||
@service intl;
|
||||
|
||||
// =attributes
|
||||
|
||||
queryParams = [
|
||||
'search',
|
||||
{ parentScopes: { type: 'array' } },
|
||||
{ types: { type: 'array' } },
|
||||
'page',
|
||||
'pageSize',
|
||||
];
|
||||
|
||||
@tracked search = '';
|
||||
@tracked parentScopes = [];
|
||||
@tracked types = [];
|
||||
@tracked page = 1;
|
||||
@tracked pageSize = 10;
|
||||
|
||||
/**
|
||||
* Returns parent scopes that are associated with all grant scopes for this role.
|
||||
* @type {[ScopeModel]}
|
||||
*/
|
||||
get availableParentScopes() {
|
||||
const uniqueParentScopeIds = [];
|
||||
const availableParentScopes = [];
|
||||
this.model.allGrantScopes.forEach((scope) => {
|
||||
if (!uniqueParentScopeIds.includes(scope.scope.id)) {
|
||||
uniqueParentScopeIds.push(scope.scope.id);
|
||||
const item = scope.scope.name
|
||||
? { id: scope.scope.id, name: scope.scope.name }
|
||||
: { id: scope.scope.id };
|
||||
availableParentScopes.push(item);
|
||||
}
|
||||
});
|
||||
return availableParentScopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns scope type options.
|
||||
* @type {object}
|
||||
*/
|
||||
get scopeTypeOptions() {
|
||||
return [
|
||||
{
|
||||
id: TYPE_SCOPE_ORG,
|
||||
name: this.intl.t(`resources.scope.types.${TYPE_SCOPE_ORG}`),
|
||||
},
|
||||
{
|
||||
id: TYPE_SCOPE_PROJECT,
|
||||
name: this.intl.t(`resources.scope.types.${TYPE_SCOPE_PROJECT}`),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filters object used for displaying filter tags.
|
||||
* @type {object}
|
||||
*/
|
||||
get filters() {
|
||||
return {
|
||||
allFilters: {
|
||||
parentScopes: this.availableParentScopes,
|
||||
types: this.scopeTypeOptions,
|
||||
},
|
||||
selectedFilters: {
|
||||
parentScopes: this.parentScopes,
|
||||
types: this.types,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// =methods
|
||||
|
||||
isKeywordThis(id) {
|
||||
return id === GRANT_SCOPE_THIS;
|
||||
}
|
||||
@@ -20,4 +100,30 @@ export default class ScopesScopeRolesRoleScopesController extends Controller {
|
||||
isKeywordChildrenOrDescendants(id) {
|
||||
return id === GRANT_SCOPE_CHILDREN || id === GRANT_SCOPE_DESCENDANTS;
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Handles input on each keystroke and the search queryParam
|
||||
* @param {object} event
|
||||
*/
|
||||
@action
|
||||
@debounce(250)
|
||||
handleSearchInput(event) {
|
||||
const { value } = event.target;
|
||||
this.search = value;
|
||||
this.page = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a query param to the value of selectedItems
|
||||
* and resets the page to 1.
|
||||
* @param {string} paramKey
|
||||
* @param {[string]} selectedItems
|
||||
*/
|
||||
@action
|
||||
applyFilter(paramKey, selectedItems) {
|
||||
this[paramKey] = [...selectedItems];
|
||||
this.page = 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user