Move aggregation code to dedicated function
This commit is contained in:
parent
484549e50b
commit
5dd1512ff2
2 changed files with 44 additions and 37 deletions
|
@ -301,6 +301,46 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getAggregate: function(userEvents) {
|
||||||
|
// A map of aggregate type to arrays of display names. Each aggregate type
|
||||||
|
// is a comma-delimited string of transitions, e.g. "joined,left,kicked".
|
||||||
|
// The array of display names is the array of users who went through that
|
||||||
|
// sequence during eventsToRender.
|
||||||
|
let aggregate = {
|
||||||
|
// $aggregateType : []:string
|
||||||
|
};
|
||||||
|
// A map of aggregate types to the indices that order them (the index of
|
||||||
|
// the first event for a given transition sequence)
|
||||||
|
let aggregateIndices = {
|
||||||
|
// $aggregateType : int
|
||||||
|
};
|
||||||
|
|
||||||
|
let users = Object.keys(userEvents);
|
||||||
|
users.forEach(
|
||||||
|
(userId) => {
|
||||||
|
let firstEvent = userEvents[userId][0];
|
||||||
|
let displayName = firstEvent.displayName;
|
||||||
|
|
||||||
|
let seq = this._getTransitionSequence(userEvents[userId]);
|
||||||
|
if (!aggregate[seq]) {
|
||||||
|
aggregate[seq] = [];
|
||||||
|
aggregateIndices[seq] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
aggregate[seq].push(displayName);
|
||||||
|
|
||||||
|
if (aggregateIndices[seq] === -1 || firstEvent.index < aggregateIndices[seq]) {
|
||||||
|
aggregateIndices[seq] = firstEvent.index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
names: aggregate,
|
||||||
|
indices: aggregateIndices,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
let eventsToRender = this.props.events;
|
let eventsToRender = this.props.events;
|
||||||
let fewEvents = eventsToRender.length < this.props.threshold;
|
let fewEvents = eventsToRender.length < this.props.threshold;
|
||||||
|
@ -346,46 +386,13 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// A map of aggregate type to arrays of display names. Each aggregate type
|
let aggregate = this._getAggregate(userEvents);
|
||||||
// is a comma-delimited string of transitions, e.g. "joined,left,kicked".
|
|
||||||
// The array of display names is the array of users who went through that
|
|
||||||
// sequence during eventsToRender.
|
|
||||||
let aggregate = {
|
|
||||||
// $aggregateType : []:string
|
|
||||||
};
|
|
||||||
// A map of aggregate types to the indices that order them (the index of
|
|
||||||
// the first event for a given transition sequence)
|
|
||||||
let aggregateIndices = {
|
|
||||||
// $aggregateType : int
|
|
||||||
};
|
|
||||||
|
|
||||||
let users = Object.keys(userEvents);
|
|
||||||
users.forEach(
|
|
||||||
(userId) => {
|
|
||||||
let firstEvent = userEvents[userId][0];
|
|
||||||
let displayName = firstEvent.displayName;
|
|
||||||
|
|
||||||
let seq = this._getTransitionSequence(userEvents[userId]);
|
|
||||||
if (!aggregate[seq]) {
|
|
||||||
aggregate[seq] = [];
|
|
||||||
aggregateIndices[seq] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aggregate[seq].indexOf(displayName) === -1) {
|
|
||||||
aggregate[seq].push(displayName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aggregateIndices[seq] === -1 || firstEvent.index < aggregateIndices[seq]) {
|
|
||||||
aggregateIndices[seq] = firstEvent.index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Sort types by order of lowest event index within sequence
|
// Sort types by order of lowest event index within sequence
|
||||||
let orderedTransitionSequences = Object.keys(aggregate).sort((seq1, seq2) => aggregateIndices[seq1] > aggregateIndices[seq2]);
|
let orderedTransitionSequences = Object.keys(aggregate.names).sort((seq1, seq2) => aggregate.indices[seq1] > aggregate.indices[seq2]);
|
||||||
|
|
||||||
let avatars = this._renderAvatars(avatarMembers);
|
let avatars = this._renderAvatars(avatarMembers);
|
||||||
let summary = this._renderSummary(aggregate, orderedTransitionSequences);
|
let summary = this._renderSummary(aggregate.names, orderedTransitionSequences);
|
||||||
let toggleButton = (
|
let toggleButton = (
|
||||||
<a className="mx_MemberEventListSummary_toggle" onClick={this._toggleSummary}>
|
<a className="mx_MemberEventListSummary_toggle" onClick={this._toggleSummary}>
|
||||||
{expanded ? 'collapse' : 'expand'}
|
{expanded ? 'collapse' : 'expand'}
|
||||||
|
|
|
@ -6,7 +6,7 @@ const sdk = require('matrix-react-sdk');
|
||||||
const MemberEventListSummary = sdk.getComponent('views.elements.MemberEventListSummary');
|
const MemberEventListSummary = sdk.getComponent('views.elements.MemberEventListSummary');
|
||||||
|
|
||||||
const testUtils = require('../../../test-utils');
|
const testUtils = require('../../../test-utils');
|
||||||
describe('MemberEventListSummary', function() {
|
describe.only('MemberEventListSummary', function() {
|
||||||
let sandbox;
|
let sandbox;
|
||||||
let parentDiv;
|
let parentDiv;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue