Files
threshold-ui/ui/desktop/app/controllers/scopes/scope/projects/sessions/index.js
T
Lisbet AlvarezandZhihe Li 550dee9ae0 Icu 11861 add sorting to session recording (#2005)
* refactor: 💡 add sorting to session recordings & sessions

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11861

* Update ui/admin/app/routes/scopes/scope/session-recordings.js

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>

---------

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
2024-01-16 10:17:45 -05:00

29 lines
834 B
JavaScript

/**
* 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
/**
* 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 [
// then move active sessions to the top
...sortedSessions.filter((session) => session.isAvailable),
// and all others to the end
...sortedSessions.filter((session) => !session.isAvailable),
];
}
}