From 44bd5ee1c6b43b3f2fd76c1cb1deb45baf2b92be Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Wed, 21 May 2025 12:20:48 -0700 Subject: [PATCH] Icu 16786 implement sort for targets (#2830) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 add sorting for targets ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16786 --- .../controllers/scopes/scope/targets/index.js | 13 +- .../app/routes/scopes/scope/targets/index.js | 17 ++- .../templates/scopes/scope/targets/index.hbs | 98 ++++++--------- .../tests/acceptance/groups/members-test.js | 18 +-- .../acceptance/roles/global-scope-test.js | 38 +++--- .../tests/acceptance/roles/org-scope-test.js | 18 +-- .../tests/acceptance/roles/principals-test.js | 16 +-- .../acceptance/roles/project-scope-test.js | 2 +- .../session-recordings/list-test.js | 16 +-- .../tests/acceptance/sessions/list-test.js | 8 +- .../tests/acceptance/targets/list-test.js | 113 +++++++++++++++++- .../tests/acceptance/users/accounts-test.js | 26 ++-- .../acceptance/workers/create-tags-test.js | 4 +- .../tests/acceptance/workers/list-test.js | 4 +- .../tests/acceptance/workers/tags-test.js | 12 +- ui/admin/tests/helpers/selectors.js | 11 +- 16 files changed, 264 insertions(+), 150 deletions(-) diff --git a/ui/admin/app/controllers/scopes/scope/targets/index.js b/ui/admin/app/controllers/scopes/scope/targets/index.js index c99384fb4..da677a447 100644 --- a/ui/admin/app/controllers/scopes/scope/targets/index.js +++ b/ui/admin/app/controllers/scopes/scope/targets/index.js @@ -28,6 +28,8 @@ export default class ScopesScopeTargetsIndexController extends Controller { { types: { type: 'array' } }, 'page', 'pageSize', + 'sortAttribute', + 'sortDirection', ]; @tracked search; @@ -37,6 +39,8 @@ export default class ScopesScopeTargetsIndexController extends Controller { @tracked page = 1; @tracked pageSize = 10; @tracked selectedTarget; + @tracked sortAttribute; + @tracked sortDirection; get availableSessionOptions() { return [ @@ -301,7 +305,7 @@ export default class ScopesScopeTargetsIndexController extends Controller { } /** - * Remove destaination_id from alias + * Remove destination_id from alias * @param {AliasModel} alias */ @action @@ -363,4 +367,11 @@ export default class ScopesScopeTargetsIndexController extends Controller { target.rollbackAttributes(); await this.router.replaceWith('scopes.scope.targets.target.workers'); } + + @action + onSort(sortBy, sortOrder) { + this.sortAttribute = sortBy; + this.sortDirection = sortOrder; + this.page = 1; + } } diff --git a/ui/admin/app/routes/scopes/scope/targets/index.js b/ui/admin/app/routes/scopes/scope/targets/index.js index 23fb3e897..f6e8d2ba9 100644 --- a/ui/admin/app/routes/scopes/scope/targets/index.js +++ b/ui/admin/app/routes/scopes/scope/targets/index.js @@ -39,6 +39,14 @@ export default class ScopesScopeTargetsIndexRoute extends Route { pageSize: { refreshModel: true, }, + sortAttribute: { + refreshModel: true, + replace: true, + }, + sortDirection: { + refreshModel: true, + replace: true, + }, }; // =methods @@ -61,6 +69,8 @@ export default class ScopesScopeTargetsIndexRoute extends Route { types, page, pageSize, + sortAttribute, + sortDirection, useDebounce, }) => { if (useDebounce) { @@ -99,16 +109,19 @@ export default class ScopesScopeTargetsIndexRoute extends Route { let totalItems = 0; let doTargetsExist = false; if (this.can.can('list model', scope, { collection: 'targets' })) { + const sort = { + attribute: sortAttribute, + direction: sortDirection, + }; targets = await this.store.query('target', { scope_id, - query: { search, filters }, + query: { search, filters, sort }, page, pageSize, }); totalItems = targets.meta?.totalItems; doTargetsExist = await this.getDoTargetsExist(scope_id, totalItems); } - return { targets, doTargetsExist, totalItems }; }, ); diff --git a/ui/admin/app/templates/scopes/scope/targets/index.hbs b/ui/admin/app/templates/scopes/scope/targets/index.hbs index 6f0c2eb3d..ebccce137 100644 --- a/ui/admin/app/templates/scopes/scope/targets/index.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/index.hbs @@ -69,103 +69,73 @@ {{#if @model.targets}} + <:head as |H|> + + {{t 'form.name.label'}} + {{t 'form.type.label'}} + {{t 'resources.target.titles.active-sessions'}} + {{t 'form.id.label'}} + + <:body as |B|> - {{#if (feature-flag 'ssh-target')}} - - - {{#if (can 'read model' B.data)}} - - {{B.data.displayName}} - - {{else}} - {{B.data.displayName}} - {{/if}} - - {{B.data.description}} - - - - {{#if B.data.type}} - - {{/if}} - - - {{#if B.data.isActive}} - - {{/if}} - - - - - - {{else}} - {{#if B.data.isTCP}} - + {{#each @model.targets as |data|}} + {{#if (or (feature-flag 'ssh-target') data.isTCP)}} + - {{#if (can 'read model' B.data)}} + {{#if (can 'read model' data)}} - {{B.data.displayName}} + {{data.displayName}} {{else}} - {{B.data.displayName}} + {{data.displayName}} {{/if}} - {{B.data.description}} + {{data.description}} - {{#if B.data.type}} + {{#if data.type}} {{/if}} - {{#if B.data.isActive}} + {{#if data.isActive}} {{/if}} {{/if}} - {{/if}} + {{/each}}