Icu 9020 move connection channel sorting to model (#217)
* test: 💍 add tests for sorted connection and channels * feat: 🎸 Add sorted property for connections and channels ✅ Closes: ICU-9020
This commit is contained in:
1 parent
05830925d5
commit
1717968e59
6 files changed
+61
-17
No files matched your search
@@ -1,7 +1,12 @@
|
||||
import GeneratedConnectionRecordingModel from '../generated/models/connection-recording';
|
||||
import { belongsTo, hasMany } from '@ember-data/model';
|
||||
import { sort } from '@ember/object/computed';
|
||||
|
||||
export default class ConnectionRecordingModel extends GeneratedConnectionRecordingModel {
|
||||
@belongsTo('session-recording', { async: false }) session_recording;
|
||||
@hasMany('channel-recording', { async: false }) channel_recordings;
|
||||
|
||||
startTimeSortingDesc = ['start_time:desc'];
|
||||
@sort('channel_recordings', 'startTimeSortingDesc')
|
||||
sortedChannelsByStartTimeDesc;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import GeneratedSessionRecordingModel from '../generated/models/session-recording';
|
||||
import { hasMany } from '@ember-data/model';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { sort } from '@ember/object/computed';
|
||||
|
||||
export const TYPE_SESSION_RECORDING_SSH = 'ssh';
|
||||
export const TYPES_SESSION_RECORDING = Object.freeze([
|
||||
@@ -12,6 +13,10 @@ export default class SessionRecordingModel extends GeneratedSessionRecordingMode
|
||||
|
||||
@service store;
|
||||
|
||||
startTimeSortingDesc = ['start_time:desc'];
|
||||
@sort('connection_recordings', 'startTimeSortingDesc')
|
||||
sortedConnectionsByStartTimeDesc;
|
||||
|
||||
/**
|
||||
* True if the session recording type is `ssh`.
|
||||
* @type {boolean}
|
||||
|
||||
@@ -20,4 +20,23 @@ module('Unit | Model | connection-recording', function (hooks) {
|
||||
const channel_recordings = await model.channel_recordings;
|
||||
assert.strictEqual(channel_recordings.length, 1);
|
||||
});
|
||||
|
||||
test('it has sortedChannelsByStartTimeDesc property and returns the expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const newestChannel = store.createRecord('channel-recording', {
|
||||
start_time: new Date('2023-01-02T00:00:00.999Z'),
|
||||
});
|
||||
const oldestChannel = store.createRecord('channel-recording', {
|
||||
start_time: new Date('2023-01-01T00:00:00.999Z'),
|
||||
});
|
||||
const model = store.createRecord('connection-recording', {
|
||||
channel_recordings: [oldestChannel, newestChannel],
|
||||
});
|
||||
|
||||
const sortedChannels = await model.sortedChannelsByStartTimeDesc;
|
||||
assert.strictEqual(sortedChannels.length, 2);
|
||||
assert.strictEqual(sortedChannels[0].start_time, newestChannel.start_time);
|
||||
assert.strictEqual(sortedChannels[1].start_time, oldestChannel.start_time);
|
||||
});
|
||||
});
|
||||
@@ -51,6 +51,32 @@ module('Unit | Model | session-recording', function (hooks) {
|
||||
assert.strictEqual(connection_recordings.length, 1);
|
||||
});
|
||||
|
||||
test('it has sortedConnectionsByStartTimeDesc property and returns the expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const newestConnection = store.createRecord('connection-recording', {
|
||||
start_time: new Date('2023-01-02T00:00:00.999Z'),
|
||||
});
|
||||
const oldestConnection = store.createRecord('connection-recording', {
|
||||
start_time: new Date('2023-01-01T00:00:00.999Z'),
|
||||
});
|
||||
const model = store.createRecord('session-recording', {
|
||||
type: TYPE_SESSION_RECORDING_SSH,
|
||||
connection_recordings: [oldestConnection, newestConnection],
|
||||
});
|
||||
|
||||
const sortedConnections = await model.sortedConnectionsByStartTimeDesc;
|
||||
assert.strictEqual(sortedConnections.length, 2);
|
||||
assert.strictEqual(
|
||||
sortedConnections[0].start_time,
|
||||
newestConnection.start_time
|
||||
);
|
||||
assert.strictEqual(
|
||||
sortedConnections[1].start_time,
|
||||
oldestConnection.start_time
|
||||
);
|
||||
});
|
||||
|
||||
test('it has targetScopeDisplayName and returns the expected values', async function (assert) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
|
||||
@@ -40,22 +40,8 @@ export default class ScopesScopeSessionRecordingsSessionRecordingRoute extends R
|
||||
// no op
|
||||
}
|
||||
|
||||
const sortedConnections = sessionRecording.connection_recordings
|
||||
.sortBy('start_time')
|
||||
.reverse()
|
||||
.map((connection) => {
|
||||
const sortedChannels = connection.channel_recordings
|
||||
.sortBy('start_time')
|
||||
.reverse();
|
||||
return {
|
||||
connection,
|
||||
channels: sortedChannels,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
sessionRecording,
|
||||
sortedConnections,
|
||||
storageBucket,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,15 +11,18 @@
|
||||
<div class='channels-by-connection'>
|
||||
<Layout::Sidebar as |sb|>
|
||||
<sb.Body>
|
||||
{{#each @model.sortedConnections as |connection|}}
|
||||
{{#each
|
||||
@model.sessionRecording.sortedConnectionsByStartTimeDesc
|
||||
as |connection|
|
||||
}}
|
||||
<div class='channels-by-connection-connection-header'>
|
||||
<p class='hds-typography-display-300 hds-font-weight-semibold'>
|
||||
{{t 'resources.session-recording.connection.title'}}
|
||||
{{connection.connection.id}}
|
||||
{{connection.id}}
|
||||
</p>
|
||||
</div>
|
||||
<Hds::Table
|
||||
@model={{connection.channels}}
|
||||
@model={{connection.sortedChannelsByStartTimeDesc}}
|
||||
@density='tall'
|
||||
@columns={{array
|
||||
(hash
|
||||
|
||||
Reference in new issue
Block a user