Commit c6665b62 authored by David O'Regan's avatar David O'Regan

Fix(oncallschedules): update grid starttime and midnight edge case

Update the grid start time and allow
for midnight shift edge case
in weekly grid draw for shifts less
than 24 hours
parent 83af89ed
...@@ -73,7 +73,7 @@ export default { ...@@ -73,7 +73,7 @@ export default {
rotations: { rotations: {
query: getShiftsForRotations, query: getShiftsForRotations,
variables() { variables() {
this.timeframeStartDate.setHours(0, 0, 0, 0); this.timeframeStartDate.setHours(1, 0, 0, 0);
const startsAt = this.timeframeStartDate; const startsAt = this.timeframeStartDate;
const endsAt = nWeeksAfter(startsAt, 2); const endsAt = nWeeksAfter(startsAt, 2);
......
...@@ -39,32 +39,32 @@ export default { ...@@ -39,32 +39,32 @@ export default {
}, },
}, },
computed: { computed: {
assigneeName() {
if (this.shiftWidth <= SHIFT_WIDTHS.sm) {
return truncate(this.assignee.user.username, 3);
}
return this.assignee.user.username;
},
chevronClass() { chevronClass() {
return `gl-bg-data-viz-${this.assignee.colorPalette}-${this.assignee.colorWeight}`; return `gl-bg-data-viz-${this.assignee.colorPalette}-${this.assignee.colorWeight}`;
}, },
startsAt() { endsAt() {
return sprintf(__('Starts: %{startsAt}'), { return sprintf(__('Ends: %{endsAt}'), {
startsAt: formatDate(this.rotationAssigneeStartsAt, 'mmmm d, yyyy, h:MMtt Z'), endsAt: formatDate(this.rotationAssigneeEndsAt, 'mmmm d, yyyy, h:MMtt Z'),
}); });
}, },
rotationAssigneeUniqueID() { rotationAssigneeUniqueID() {
const { _uid } = this; const { _uid } = this;
return `${this.assignee.user.id}-${_uid}`; return `${this.assignee.user.id}-${_uid}`;
}, },
endsAt() {
return sprintf(__('Ends: %{endsAt}'), {
endsAt: formatDate(this.rotationAssigneeEndsAt, 'mmmm d, yyyy, h:MMtt Z'),
});
},
rotationMobileView() { rotationMobileView() {
return this.shiftWidth <= SHIFT_WIDTHS.xs; return this.shiftWidth <= SHIFT_WIDTHS.xs;
}, },
assigneeName() { startsAt() {
if (this.shiftWidth <= SHIFT_WIDTHS.sm) { return sprintf(__('Starts: %{startsAt}'), {
return truncate(this.assignee.user.username, 3); startsAt: formatDate(this.rotationAssigneeStartsAt, 'mmmm d, yyyy, h:MMtt Z'),
} });
return this.assignee.user.username;
}, },
}, },
}; };
......
...@@ -50,8 +50,8 @@ export const currentTimeframeEndsAt = (timeframeStart, presetType) => { ...@@ -50,8 +50,8 @@ export const currentTimeframeEndsAt = (timeframeStart, presetType) => {
* => true * => true
* *
*/ */
export const shiftShouldRender = (shiftRangeOverlap = {}) => { export const shiftShouldRender = (shiftRangeOverlap) => {
return Boolean(shiftRangeOverlap?.hoursOverlap); return Boolean(shiftRangeOverlap.hoursOverlap);
}; };
/** /**
...@@ -225,7 +225,7 @@ export const weekDisplayShiftLeft = ( ...@@ -225,7 +225,7 @@ export const weekDisplayShiftLeft = (
* @returns {Number} * @returns {Number}
* *
* @example * @example
* weekDisplayShiftWidth(false, { daysOverlap: 3 }, false , 50) * weekDisplayShiftWidth(false, { daysOverlap: 3, hoursOverlap: 72, overlapEndDate: 1610496000000 }, false , 50)
* => 148 * => 148
* *
*/ */
...@@ -242,7 +242,7 @@ export const weekDisplayShiftWidth = ( ...@@ -242,7 +242,7 @@ export const weekDisplayShiftWidth = (
); );
} }
const widthOffset = shiftStartDateOutOfRange ? 1 : 0; const shiftEndsAtMidnight = new Date(shiftRangeOverlap.overlapEndDate).getHours() === 0;
const widthOffset = shiftStartDateOutOfRange && !shiftEndsAtMidnight ? 1 : 0;
return shiftTimeUnitWidth * (shiftRangeOverlap.daysOverlap - widthOffset) - ASSIGNEE_SPACER; return shiftTimeUnitWidth * (shiftRangeOverlap.daysOverlap - widthOffset) - ASSIGNEE_SPACER;
}; };
...@@ -209,9 +209,10 @@ describe('~ee/oncall_schedules/components/schedule/components/shifts/components/ ...@@ -209,9 +209,10 @@ describe('~ee/oncall_schedules/components/schedule/components/shifts/components/
describe('weekDisplayShiftWidth', () => { describe('weekDisplayShiftWidth', () => {
const shiftTimeUnitWidth = 50; const shiftTimeUnitWidth = 50;
const mockTimeframeInitialDate = new Date('2018-01-01T00:00:00');
it.each` it.each`
shiftUnitIsHour | shiftRangeOverlap | shiftStartDateOutOfRange | value shiftUnitIsHour | shiftRangeOverlapObject | shiftStartDateOutOfRange | value
${true} | ${{ daysOverlap: 1, hoursOverlap: 4 }} | ${false} | ${6} ${true} | ${{ daysOverlap: 1, hoursOverlap: 4 }} | ${false} | ${6}
${true} | ${{ daysOverlap: 1, hoursOverlap: 8 }} | ${false} | ${14} ${true} | ${{ daysOverlap: 1, hoursOverlap: 8 }} | ${false} | ${14}
${true} | ${{ daysOverlap: 1, hoursOverlap: 24 }} | ${false} | ${48} ${true} | ${{ daysOverlap: 1, hoursOverlap: 24 }} | ${false} | ${48}
...@@ -219,14 +220,23 @@ describe('~ee/oncall_schedules/components/schedule/components/shifts/components/ ...@@ -219,14 +220,23 @@ describe('~ee/oncall_schedules/components/schedule/components/shifts/components/
${false} | ${{ daysOverlap: 1, hoursOverlap: 24 }} | ${false} | ${48} ${false} | ${{ daysOverlap: 1, hoursOverlap: 24 }} | ${false} | ${48}
${false} | ${{ daysOverlap: 2, hoursOverlap: 48 }} | ${false} | ${98} ${false} | ${{ daysOverlap: 2, hoursOverlap: 48 }} | ${false} | ${98}
${false} | ${{ daysOverlap: 3, hoursOverlap: 72 }} | ${false} | ${148} ${false} | ${{ daysOverlap: 3, hoursOverlap: 72 }} | ${false} | ${148}
${false} | ${{ daysOverlap: 3, hoursOverlap: 72 }} | ${true} | ${98} ${false} | ${{ daysOverlap: 3, hoursOverlap: 72 }} | ${true} | ${148}
`( `(
`returns $value px as the rotation width when shiftUnitIsHour is $shiftUnitIsHour, shiftStartDateOutOfRange is $shiftStartDateOutOfRange and shiftTimeUnitWidth is ${shiftTimeUnitWidth}`, `returns $value px as the rotation width when shiftUnitIsHour is $shiftUnitIsHour, shiftStartDateOutOfRange is $shiftStartDateOutOfRange and shiftTimeUnitWidth is ${shiftTimeUnitWidth}`,
({ shiftUnitIsHour, shiftRangeOverlap, shiftStartDateOutOfRange, value }) => { ({
shiftUnitIsHour,
shiftRangeOverlapObject: { daysOverlap, hoursOverlap },
shiftStartDateOutOfRange,
value,
}) => {
expect( expect(
weekDisplayShiftWidth( weekDisplayShiftWidth(
shiftUnitIsHour, shiftUnitIsHour,
shiftRangeOverlap, {
overlapEndDate: mockTimeStamp(mockTimeframeInitialDate, daysOverlap),
daysOverlap,
hoursOverlap,
},
shiftStartDateOutOfRange, shiftStartDateOutOfRange,
shiftTimeUnitWidth, shiftTimeUnitWidth,
), ),
...@@ -234,4 +244,17 @@ describe('~ee/oncall_schedules/components/schedule/components/shifts/components/ ...@@ -234,4 +244,17 @@ describe('~ee/oncall_schedules/components/schedule/components/shifts/components/
}, },
); );
}); });
it('returns with an offset of 1 day width less only when the shift start date is before the timeframe start and the shift does not end at midnight', () => {
const mockOverlapEndDateNotAtMidnight = new Date('2018-01-01T03:02:01');
expect(
weekDisplayShiftWidth(
false,
{ overlapEndDate: mockOverlapEndDateNotAtMidnight, daysOverlap: 3, hoursOverlap: 72 },
true,
50,
),
).toBe(98);
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment