refactor: 💡 remove unnecessary sorting due to pagination change (#1996)

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11787
This commit is contained in:
Lisbet Alvarez authored and Zhihe Li committed 2024-01-16 10:17:45 -05:00
1 parent 459029530b
commit 6ae3067dd9
2 files changed
+8 -15

No files matched your search

+6 -10
View File
@@ -11,7 +11,7 @@ import runEvery from 'ember-pollster/decorators/route/run-every';
import { notifySuccess, notifyError } from 'core/decorators/notify';
import config from '../../../config/environment';
import { resourceFilter } from 'core/decorators/resource-filter';
import sortBy from 'lodash/sortBy';
const POLL_TIMEOUT_SECONDS = config.sessionPollingTimeoutSeconds;
export default class ScopesScopeSessionsRoute extends Route {
@@ -78,17 +78,13 @@ export default class ScopesScopeSessionsRoute extends Route {
}),
),
);
// Sort sessions by time created...
let sortedSessionAggregates = sortBy(
sessionAggregates,
'session.created_time',
).reverse();
// Then move active sessions to the top...
sortedSessionAggregates = [
...sortedSessionAggregates.filter(
// Move active sessions to the top...
const sortedSessionAggregates = [
...sessionAggregates.filter(
(aggregate) => aggregate.session.status === 'active',
),
...sortedSessionAggregates.filter(
...sessionAggregates.filter(
(aggregate) => aggregate.session.status !== 'active',
),
];
@@ -4,7 +4,6 @@
*/
import Controller from '@ember/controller';
import sortBy from 'lodash/sortBy';
export default class ScopesScopeProjectsSessionsIndexController extends Controller {
// =attributes
@@ -16,13 +15,11 @@ export default class ScopesScopeProjectsSessionsIndexController extends Controll
*/
get sorted() {
const sessions = this.model;
// sort by created time
const sortedSessions = sortBy(sessions, 'session.created_time').reverse();
return [
// then move active sessions to the top
...sortedSessions.filter((session) => session.isAvailable),
...sessions.filter((session) => session.isAvailable),
// and all others to the end
...sortedSessions.filter((session) => !session.isAvailable),
...sessions.filter((session) => !session.isAvailable),
];
}
}