Skip to content

Commit

Permalink
Added min & max period info for my premises ext resource reservation …
Browse files Browse the repository at this point in the history
…creation

Changes:
- selecting external resource slots will now display min and max period limits for the to be reservation in a popover element along reservation duration info
- external resource slot selecting will also apply red color to duration when min or max limit is not met
  • Loading branch information
SanttuA committed Feb 22, 2024
1 parent 17fbea8 commit 6da7f72
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class UninjectedReservationSlot extends React.Component {
hover: PropTypes.bool,
resourceId: PropTypes.string.isRequired,
}),
maxPeriod: PropTypes.string,
minPeriod: PropTypes.string,
hasStaffRights: PropTypes.bool,
};

constructor(props) {
Expand Down Expand Up @@ -107,6 +110,8 @@ export class UninjectedReservationSlot extends React.Component {
<ReservationPopover
begin={this.props.selection.begin}
end={this.props.selection.end}
maxPeriod={this.props.hasStaffRights ? null : this.props.maxPeriod}
minPeriod={this.props.hasStaffRights ? null : this.props.minPeriod}
onCancel={this.props.onSelectionCancel}
>
{slot}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ describe('shared/availability-view/ReservationSlot', () => {
});
expect(popover).toHaveLength(1);
});

test('renders with min and max prop when hasStaffRights is true', () => {
const popover = getPopover({
begin: '2016-01-01T10:00:00Z',
end: '2016-01-01T10:30:00Z',
selection: {
begin: '2016-01-01T10:00:00Z',
end: '2016-01-01T12:00:00Z',
resourceId: '1',
},
hasStaffRights: false,
minPeriod: '00:30:00',
maxPeriod: '01:00:00',
});
expect(popover).toHaveLength(1);
expect(popover.prop('minPeriod')).toBe('00:30:00');
expect(popover.prop('maxPeriod')).toBe('01:00:00');
});
});

describe('selection', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function getTimeSlotWidth({ startTime, endTime } = {}) {
}

function getTimelineItems(date, reservations, resourceId, timeRestrictions, hasStaffRights) {
const { cooldown } = timeRestrictions;
const { cooldown, minPeriod, maxPeriod } = timeRestrictions;
// skip getting cooldowns if user has perms
const cooldownRanges = hasStaffRights ? [] : getCooldownRanges(reservations, cooldown);
const items = [];
Expand Down Expand Up @@ -51,7 +51,9 @@ function getTimelineItems(date, reservations, resourceId, timeRestrictions, hasS
// addSelectionData to make some assumptions.
isSelectable: false,
isWithinCooldown,
hasStaffRights
hasStaffRights,
minPeriod,
maxPeriod
},
});
timePointer.add(slotSize, 'minutes');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -257,6 +259,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -269,6 +273,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -281,6 +287,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{ key: '4', type: 'reservation', data: reservations[0] },
Expand All @@ -294,6 +302,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -306,6 +316,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -318,6 +330,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -330,6 +344,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -342,6 +358,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{ key: '10', type: 'reservation', data: reservations[1] },
Expand All @@ -356,6 +374,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -368,6 +388,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -380,6 +402,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -392,6 +416,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -404,6 +430,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -416,6 +444,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
{
Expand All @@ -428,6 +458,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: true,
isWithinCooldown: false,
minPeriod: timeRestrictions.minPeriod,
maxPeriod: timeRestrictions.maxPeriod,
},
},
];
Expand All @@ -453,6 +485,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: false,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -465,6 +499,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: false,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -477,6 +513,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -489,6 +527,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{ key: '4', type: 'reservation', data: reservations[0] },
Expand All @@ -502,6 +542,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -514,6 +556,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -526,6 +570,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: false,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -538,6 +584,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -550,6 +598,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{ key: '10', type: 'reservation', data: reservations[1] },
Expand All @@ -564,6 +614,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -576,6 +628,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: !hasRights,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -588,6 +642,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: false,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -600,6 +656,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: false,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -612,6 +670,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: false,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -624,6 +684,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: false,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
{
Expand All @@ -636,6 +698,8 @@ describe('shared/availability-view/utils', () => {
isSelectable: false,
hasStaffRights: hasRights,
isWithinCooldown: false,
minPeriod: timeRestrictions2.minPeriod,
maxPeriod: timeRestrictions2.maxPeriod,
},
},
];
Expand Down
Loading

0 comments on commit 6da7f72

Please sign in to comment.