Files
threshold-ui/ui/desktop/app/controllers/scopes/scope/projects/sessions/index.js
T

28 lines
834 B
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Controller from '@ember/controller';
import orderBy from 'lodash/orderBy';
export default class ScopesScopeProjectsSessionsIndexController extends Controller {
// =attributes
2021-02-11 10:44:48 -05:00
/**
* A list of sessions filtered to the current user and sorted by created time,
* and active/pending.
* @type {SessionModel[]}
*/
get sorted() {
const sessions = this.model;
// Sort sessions by created time descending (newest on top)
const sortedSessions = orderBy(sessions, 'created_time', 'desc');
return [
2021-02-11 10:44:48 -05:00
// then move active sessions to the top
...sortedSessions.filter((session) => session.isAvailable),
2021-02-11 10:44:48 -05:00
// and all others to the end
...sortedSessions.filter((session) => !session.isAvailable),
];
}
}