From f801f595f756cfa4c54579e83a31a7c19060bc92 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Tue, 12 Dec 2023 17:38:18 -0800 Subject: [PATCH] Icu 11915 add session in progress field to the table and populate it (#2028) * initial support for sessions in targets list view --- addons/core/translations/resources/en-us.yaml | 1 + .../scopes/scope/projects/targets/index.js | 6 +++ .../scopes/scope/projects/targets/index.js | 25 ++++++++- .../scopes/scope/projects/targets/index.hbs | 51 ++++++++++++------- .../acceptance/projects/targets/index-test.js | 2 +- .../projects/targets/target-test.js | 9 +++- ui/desktop/tests/acceptance/scopes-test.js | 10 +++- 7 files changed, 81 insertions(+), 23 deletions(-) diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index 9a7956824..f17a9fd3d 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -569,6 +569,7 @@ target: description: Sorry, we weren't able to find any targets for "{query}". titles: new: New Target + active-sessions: Active sessions actions: create: New Target delete: Delete Target diff --git a/ui/desktop/app/controllers/scopes/scope/projects/targets/index.js b/ui/desktop/app/controllers/scopes/scope/projects/targets/index.js index e1a58f5ab..05c0b72b9 100644 --- a/ui/desktop/app/controllers/scopes/scope/projects/targets/index.js +++ b/ui/desktop/app/controllers/scopes/scope/projects/targets/index.js @@ -27,6 +27,7 @@ export default class ScopesScopeProjectsTargetsIndexController extends Controlle @tracked scopes = []; @tracked page = 1; @tracked pageSize = 10; + @tracked sessionsFlyoutActive = false; // =methods @@ -159,6 +160,11 @@ export default class ScopesScopeProjectsTargetsIndexController extends Controlle this.page = 1; } + @action + toggleSessionsFlyout() { + this.sessionsFlyoutActive = !this.sessionsFlyoutActive; + } + /** * Sets the scopes query param to value of selectedScopes * to trigger a query and closes the dropdown diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/index.js b/ui/desktop/app/routes/scopes/scope/projects/targets/index.js index 2544d82a3..06f9bcec3 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/index.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/index.js @@ -5,6 +5,11 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +import orderBy from 'lodash/orderBy'; +import { + STATUS_SESSION_ACTIVE, + STATUS_SESSION_PENDING, +} from 'api/models/session'; export default class ScopesScopeProjectsTargetsIndexRoute extends Route { // =services @@ -73,6 +78,24 @@ export default class ScopesScopeProjectsTargetsIndexRoute extends Route { this.can.can('connect target', target), ); + // Retrieve all the 'active' and 'pending' sessions associated with each target. + let targetsWithSessions = []; + for (const target of targets) { + let sessions = await this.store.query('session', { + query: { + filters: { + target_id: { equals: target.id }, + status: [ + { equals: STATUS_SESSION_ACTIVE }, + { equals: STATUS_SESSION_PENDING }, + ], + }, + }, + }); + sessions = orderBy(sessions, 'created_time', 'desc'); + targetsWithSessions.push({ target, sessions }); + } + // Query all targets for defining filtering values const options = { pushToStore: false }; let allTargets = await this.store.query('target', {}, options); @@ -82,6 +105,6 @@ export default class ScopesScopeProjectsTargetsIndexRoute extends Route { target.authorized_actions.includes('authorize-session'), ); - return { targets, projects, allTargets, totalItems }; + return { targets: targetsWithSessions, projects, allTargets, totalItems }; } } diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/index.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/index.hbs index c22282ee7..5b4589c7d 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/index.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/index.hbs @@ -68,6 +68,7 @@ @columns={{array (hash label=(t 'form.name.label')) (hash label=(t 'form.id.label')) + (hash label=(t 'resources.target.titles.active-sessions')) (hash label=(t 'form.type.label')) (hash label=(t 'resources.project.title')) (hash label='') @@ -78,47 +79,59 @@ - {{#if (can 'read model' B.data)}} + {{#if (can 'read model' B.data.target)}} - {{B.data.displayName}} + {{B.data.target.displayName}} {{else}} - {{B.data.displayName}} + {{B.data.target.displayName}} {{/if}} - {{#if B.data.description}} -

{{B.data.description}}

+ {{#if B.data.target.description}} +

{{B.data.target.description}}

{{/if}}
- {{B.data.id}} + {{B.data.target.id}} - {{#if B.data.type}} + {{#if B.data.sessions.length}} + + {{/if}} + + + {{#if B.data.target.type}} {{/if}}
- {{B.data.project.id}} + {{B.data.target.project.id}}
{{#if B.data.project.name}} @@ -126,22 +139,22 @@ {{/if}}
- {{#if (can 'connect target' B.data)}} - {{#if (can 'read target' B.data)}} + {{#if (can 'connect target' B.data.target)}} + {{#if (can 'read target' B.data.target)}} {{else}} {{/if}} {{/if}} diff --git a/ui/desktop/tests/acceptance/projects/targets/index-test.js b/ui/desktop/tests/acceptance/projects/targets/index-test.js index 4e4826d0c..f699beb4b 100644 --- a/ui/desktop/tests/acceptance/projects/targets/index-test.js +++ b/ui/desktop/tests/acceptance/projects/targets/index-test.js @@ -131,7 +131,7 @@ module('Acceptance | projects | targets | index', function (hooks) { setDefaultClusterUrl(this); this.ipcStub.withArgs('isClientDaemonRunning').returns(true); - this.stubClientDaemonSearch('targets', 'targets'); + this.stubClientDaemonSearch('targets', 'targets', 'sessions'); }); test('visiting index while unauthenticated redirects to global authenticate method', async function (assert) { diff --git a/ui/desktop/tests/acceptance/projects/targets/target-test.js b/ui/desktop/tests/acceptance/projects/targets/target-test.js index 01f868ac9..00fcb00ed 100644 --- a/ui/desktop/tests/acceptance/projects/targets/target-test.js +++ b/ui/desktop/tests/acceptance/projects/targets/target-test.js @@ -124,7 +124,14 @@ module('Acceptance | projects | targets | target', function (hooks) { setDefaultClusterUrl(this); this.ipcStub.withArgs('isClientDaemonRunning').returns(true); - this.stubClientDaemonSearch('targets', 'targets'); + this.stubClientDaemonSearch( + 'targets', + 'targets', + 'targets', + 'sessions', + 'sessions', + 'sessions', + ); }); test('user can connect to a target with an address', async function (assert) { diff --git a/ui/desktop/tests/acceptance/scopes-test.js b/ui/desktop/tests/acceptance/scopes-test.js index ae5821ea7..edf9bd823 100644 --- a/ui/desktop/tests/acceptance/scopes-test.js +++ b/ui/desktop/tests/acceptance/scopes-test.js @@ -129,7 +129,7 @@ module('Acceptance | scopes', function (hooks) { setDefaultClusterUrl(this); this.ipcStub.withArgs('isClientDaemonRunning').returns(true); - this.stubClientDaemonSearch('targets', 'targets'); + this.stubClientDaemonSearch('targets', 'targets', 'sessions'); }); test('visiting index', async function (assert) { @@ -189,6 +189,14 @@ module('Acceptance | scopes', function (hooks) { 'targets', 'targets', 'targets', + 'sessions', + 'sessions', + 'sessions', + 'sessions', + 'sessions', + 'sessions', + 'sessions', + 'sessions', ); await visit(urls.targets);