-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[PLT-7409] Channel Member List: show status icon and sort by user's status #421
Conversation
actionUserProps[user.id] = { | ||
channel: this.props.channel, | ||
teamMember: teamMembers[user.id], | ||
channelMember: channelMembers[user.id] | ||
}; | ||
} | ||
} | ||
|
||
usersToDisplay.sort((a, b) => { | ||
return UserStatusesWeight[a.status] - UserStatusesWeight[b.status] || Utils.sortUsersByDisplayName(a, b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand this - is it some kind of type coercion trick? It looks like you're subtracting the weighted values of the two users' statuses, and if that results in zero, we know that zero is falsy, so evaluate the OR condition, which sorts by name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's short-circuit evaluation. Your subsequent description is what I intend to do which I think works fine as I expected.
const status = UserStore.getStatus(member.id); | ||
return {...member, status}; | ||
}).sort((a, b) => { | ||
return UserStatusesWeight[a.status] - UserStatusesWeight[b.status] || Utils.sortUsersByDisplayName(a, b); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this sorting be generalized somewhere so that we aren't duplicating the code in the two components?
utils/utils.jsx
Outdated
const bName = displayUsernameForUser(b); | ||
|
||
return aName.localeCompare(bName); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps accept two user objects here, and do all the sorting, including the status weighting, so that the components can just call this function? If you do that, you could easily write unit tests for this function as well, so we'd know that it doesn't break in the future.
@MusikPolice updated PR per comments. Also added unit tests. |
@@ -144,14 +145,18 @@ export default class MemberListChannel extends React.Component { | |||
const user = users[i]; | |||
|
|||
if (teamMembers[user.id] && channelMembers[user.id] && user.delete_at === 0) { | |||
usersToDisplay.push(user); | |||
const status = UserStore.getStatus(user.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be using anything not in props or state to render. We should pull the statuses when we set the users in state or we should rewrite this component to be more redux friendly and pass it in as props
actionUserProps[user.id] = { | ||
channel: this.props.channel, | ||
teamMember: teamMembers[user.id], | ||
channelMember: channelMembers[user.id] | ||
}; | ||
} | ||
} | ||
|
||
usersToDisplay.sort(Utils.sortUsersByStatusAndDisplayName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably look into moving a bunch of this logic out of the render function if possible. It's possible that we'll render multiple times without the usersToDisplay changing, so rebuilding and sorting, and setting the result to state (or props even) might be worthwhile here. I'm only 1/5 on this though, it's going a bit beyond the scope of the ticket but if a user list is 1000+ in length this could potentially help performance a lot
Turning it into a selector would be even better (though more work)
const bName = Utils.displayUsernameForUser(b); | ||
if (this.props.members && teamMembers) { | ||
const sortedMembers = this.props.members.map((member) => { | ||
const status = UserStore.getStatus(member.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue here, needs to be in state or props if it's used for rendering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saturninoabril it looks like the status icon component is incorrectly positioned and sized as compared to the center channel or LHS header profile icons:
Other than that it looks good, it will be for 4.6.
@jwilander @esethna Thanks! I'll address your comments. |
@saturninoabril let me know if you have any questions about the items I brought up? |
Hey @saturninoabril, wondering if there's a chance we'd be able to get this in for v4.6? Would be a nice UX improvement. |
@jasonblais Kindly check whether the comments made by @esethna is satisfied. Also I've made some CSS change that @asaadmahmood might need to take a look. @jwilander I initially tried to make use of selector but it's taking so long on me. That's why I ended up just moving some of the logics out of render function. |
Thanks! Position looks good. At the moment, the order is online/away/offline/dnd. Have asked @esethna to confirm whether that's the expected order for DND status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DND below offline makes sense since the real time notifications are disabled. Thanks guys!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'm OK with it since it's not introducing any imports of the flux stores but these components would be much cleaner if they were using redux for everything
@saturninoabril after a rebase it should be good to merge |
I'll merge this first and then will try to convert the components using redux. Thanks! |
* Add typing selector based on channelId and postId * changing getUsersTyping... selector to makeGetUsersTyping...
* Add typing selector based on channelId and postId * changing getUsersTyping... selector to makeGetUsersTyping...
Summary
Show status icon and sort by user's status (in the order of online > away > offline > dnd) to the following components:
@jasonblais @esethna You might want to check this out if according to ticket specs. (I'm not really sure about the coverage). Also not sure if this should be for v4.5 as stated in Jira ticket.
Ticket Link
Jira ticket: PLT-7409
Checklist
[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]
make check-style
to check for style errors (required for all pull requests)make test
to ensure unit and component tests passed