Skip to content

Commit 5b75b33

Browse files
committed
Account for a PDL being different in the past from the current PDL.
1 parent 8fa49ac commit 5b75b33

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
1212
import { getAvatarURL } from '../../../api/api.js';
1313
import { AppContext } from '../../../context/AppContext.jsx';
14+
import { selectCheckinsForMember } from '../../../context/selectors.js';
1415
import {
15-
selectCheckinsForMember,
16-
pastCheckin,
17-
} from '../../../context/selectors.js';
18-
import {
16+
isPastCheckin,
17+
getCheckinDate,
18+
getQuarterBeginEndWithGrace,
1919
getCheckinDateForPeriod,
2020
getLastCheckinDate,
2121
statusForPeriodByMemberScheduling
@@ -72,12 +72,30 @@ const TeamMemberMap = ({ members, closed, planned, reportDate }) => {
7272
</Box>
7373
{
7474
members.map(member => {
75-
const pdl = pdls[member.pdlId];
75+
let pdl = pdls[member.pdlId];
7676
const checkins = selectCheckinsForMember(
7777
state,
7878
member.id,
7979
).filter(checkin => closed || !checkin.completed)
80-
.filter(checkin => planned || pastCheckin(checkin));
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+
}
8199

82100
return (
83101
<Accordion

web-ui/src/components/reports-section/checkin-report/checkin-utils.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ export const getLastCheckinDate = checkins => {
2828
}, new Date(0));
2929
};
3030

31+
/**
32+
* Get the dates the reporting period including a grace period.
33+
* @param {Date} reportDate - The date of the report.
34+
* @returns {{ startOfQuarter: Date, endOfQuarter: Date }} The start and end dates of the quarter pluas a grace period.
35+
*/
36+
export const getQuarterBeginEndWithGrace = (reportDate) => {
37+
const { startOfQuarter, endOfQuarter } = getQuarterBeginEnd(reportDate);
38+
const endOfQuarterWithGrace = new Date(endOfQuarter);
39+
endOfQuarterWithGrace.setDate(endOfQuarter.getDate() + 30);
40+
return {
41+
startOfQuarter: startOfQuarter,
42+
endOfQuarter: endOfQuarterWithGrace
43+
};
44+
};
45+
3146
/**
3247
* Get the date of the last scheduled check-in for the reporting period.
3348
* Include the grace period for the end of the quarter.
@@ -36,13 +51,11 @@ export const getLastCheckinDate = checkins => {
3651
* @returns {Date} The date of the last scheduled check-in.
3752
*/
3853
export const getCheckinDateForPeriod = (checkins, reportDate) => {
39-
const { startOfQuarter, endOfQuarter } = getQuarterBeginEnd(reportDate);
40-
const endOfQuarterWithGrace = new Date(endOfQuarter);
41-
endOfQuarterWithGrace.setDate(endOfQuarter.getDate() + 30);
54+
const { startOfQuarter, endOfQuarter } = getQuarterBeginEndWithGrace(reportDate);
4255
const scheduled = checkins.filter(checkin => {
4356
const checkinDate = getCheckinDate(checkin);
4457
return (
45-
checkinDate >= startOfQuarter && checkinDate <= endOfQuarterWithGrace // Include grace period
58+
checkinDate >= startOfQuarter && checkinDate <= endOfQuarter // Include grace period
4659
);
4760
});
4861
return getLastCheckinDate(scheduled);
@@ -74,3 +87,11 @@ export const statusForPeriodByMemberScheduling = (
7487
if (completed.length === scheduled.length) return 'Completed';
7588
return 'Scheduled';
7689
};
90+
91+
/**
92+
* Returns true if the checkin was in the past.
93+
* @param {Checkin} checkin - A check-in.
94+
* @returns {bool} Status of boolean check.
95+
*/
96+
export const isPastCheckin = (checkin) => Date.now() >= getCheckinDate(checkin).getTime();
97+

web-ui/src/context/selectors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ const getCheckinDate = checkin => {
610610
return new Date(year, month - 1, day, hour, minute, 0);
611611
};
612612

613-
export const pastCheckin = checkin => Date.now() >= getCheckinDate(checkin).getTime();
613+
const pastCheckin = checkin => Date.now() >= getCheckinDate(checkin).getTime();
614614

615615
export const selectFilteredCheckinsForTeamMemberAndPDL = createSelector(
616616
selectCheckinsForTeamMemberAndPDL,

0 commit comments

Comments
 (0)