Skip to content

Commit 584d7c0

Browse files
committed
Handle sorting by PDL when the PDL for the report period is not the current PDL.
1 parent 5b75b33 commit 584d7c0

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

web-ui/src/components/reports-section/checkin-report/TeamMemberMap.jsx

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,38 @@ const TeamMemberMap = ({ members, closed, planned, reportDate }) => {
4949
}
5050
};
5151

52-
const sortByPDLName = (a, b) => sortByName(pdls[a.pdlId], pdls[b.pdlId]);
52+
const sortByPDLName = (a, b) =>
53+
sortByName(pdls[a.reportDatePDLId], pdls[b.reportDatePDLId]);
54+
55+
// We're going to cache the checkins into the member data structures so that
56+
// we can properly sort by PDL when the PDL, in the past, is different than
57+
// the current PDL.
58+
const { startOfQuarter, endOfQuarter } = getQuarterBeginEndWithGrace(reportDate);
59+
members.map(member => {
60+
const checkins = selectCheckinsForMember(
61+
state,
62+
member.id,
63+
).filter(checkin => closed || !checkin.completed)
64+
.filter(checkin => planned || isPastCheckin(checkin));
65+
member.checkins = checkins;
66+
67+
// If there are checkins, we're going to sort them with the latest
68+
// first. Since the member's PDL could have changed since the last
69+
// checkin, we are going to use the PDL id of the checkin instead
70+
// of the current PDL. They may be the same, but again they may not.
71+
member.reportDatePDLId = member.pdlId;
72+
if (checkins.length > 0) {
73+
checkins.sort((a, b) => getCheckinDate(b) - getCheckinDate(a));
74+
75+
for(let checkin of checkins) {
76+
const checkinDate = getCheckinDate(checkin);
77+
if (checkinDate >= startOfQuarter && checkinDate <= endOfQuarter) {
78+
member.reportDatePDLId = checkin.pdlId;
79+
break;
80+
}
81+
}
82+
}
83+
});
5384

5485
members.sort(sortBy == SortOption.BY_MEMBER ? sortByName : sortByPDLName);
5586

@@ -72,30 +103,8 @@ const TeamMemberMap = ({ members, closed, planned, reportDate }) => {
72103
</Box>
73104
{
74105
members.map(member => {
75-
let pdl = pdls[member.pdlId];
76-
const checkins = selectCheckinsForMember(
77-
state,
78-
member.id,
79-
).filter(checkin => closed || !checkin.completed)
80-
.filter(checkin => planned || isPastCheckin(checkin));
81-
82-
// If there are checkins, we're going to sort them with the latest
83-
// first. Since the member's PDL could have changed since the last
84-
// checkin, we are going to use the PDL id of the checkin instead
85-
// of the current PDL. They may be the same, but again they may not.
86-
if (checkins.length > 0) {
87-
checkins.sort((a, b) => getCheckinDate(b) - getCheckinDate(a));
88-
const latest = checkins[0];
89-
const { startOfQuarter, endOfQuarter } =
90-
getQuarterBeginEndWithGrace(reportDate);
91-
const checkinDate = getCheckinDate(latest);
92-
if (checkinDate >= startOfQuarter && checkinDate <= endOfQuarter) {
93-
console.log(member.firstName);
94-
console.log("Current PDL: " + JSON.stringify(pdl));
95-
pdl = pdls[checkins[0].pdlId];
96-
console.log("PDL at the time: " + JSON.stringify(pdl));
97-
}
98-
}
106+
const pdl = pdls[member.reportDatePDLId];
107+
const checkins = member.checkins;
99108

100109
return (
101110
<Accordion

0 commit comments

Comments
 (0)