diff --git a/ui/core/app/routes/scopes/scope/projects/project/sessions.js b/ui/core/app/routes/scopes/scope/projects/project/sessions.js index c5f7c8004..d157fe3aa 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/sessions.js +++ b/ui/core/app/routes/scopes/scope/projects/project/sessions.js @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import { all, hash } from 'rsvp'; import { task, timeout } from 'ember-concurrency'; +import { A } from '@ember/array'; const POLL_TIMEOUT_SECONDS = 2.5; @@ -42,17 +43,32 @@ export default class ScopesScopeProjectsProjectSessionsRoute extends Route { async model() { const { id: scope_id } = this.modelFor('scopes.scope.projects.project'); const sessions = await this.store.query('session', { scope_id }); - return all( + const sessionAggregates = await all( sessions.map(session => hash({ session, user: session.user_id - ? this.store.findRecord('user', session.user_id) + ? ( + this.store.peekRecord('user', session.user_id) || + this.store.findRecord('user', session.user_id) + ) : null, target: session.target_id - ? this.store.findRecord('target', session.target_id) + ? ( + this.store.peekRecord('target', session.target_id) || + this.store.findRecord('target', session.target_id) + ) : null, })) ); + // Sort sessions by time created... + let sortedSessionAggregates = + A(sessionAggregates).sortBy('session.created_time').reverse(); + // Then move active sessions to the top... + sortedSessionAggregates = [ + ...sortedSessionAggregates.filter((aggregate) => aggregate.session.status === 'active'), + ...sortedSessionAggregates.filter((aggregate) => aggregate.session.status !== 'active'), + ]; + return sortedSessionAggregates; } /**