@jsb188/calendar 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +22 -17
- package/src/constants/calendar.ts +10 -7
- package/src/libs/calendar-geometry.ts +2 -4
- package/src/libs/calendar-range.ts +4 -3
- package/src/libs/calendar-state.ts +21 -163
- package/src/libs/calendar-url.ts +21 -20
- package/src/libs/roster-layout.ts +457 -0
- package/src/modules/Calendar.tsx +26 -32
- package/src/modules/MiniCalendar.tsx +9 -3
- package/src/types/calendar.d.ts +7 -1
- package/src/ui/CalendarAgendaUI.tsx +26 -17
- package/src/ui/CalendarMonthUI.tsx +17 -9
- package/src/ui/CalendarToolbarUI.tsx +48 -30
- package/src/ui/CalendarUI.tsx +37 -9
- package/src/ui/RosterUI.tsx +239 -0
- package/src/ui/CalendarCoverageUI.tsx +0 -242
- package/src/ui/CalendarEventDetailUI.tsx +0 -265
- package/src/ui/CalendarEventFormUI.tsx +0 -266
- package/src/ui/CalendarRailUI.tsx +0 -342
- package/src/ui/CalendarRequestUI.tsx +0 -576
- package/src/ui/CalendarViolationUI.tsx +0 -230
- package/tests/calendar-geometry.test.ts +0 -551
- package/tests/calendar-gesture.test.ts +0 -340
- package/tests/calendar-range.test.ts +0 -358
- package/tests/calendar-url.test.ts +0 -167
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -11
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ScheduleResourceGQL,
|
|
3
|
+
ScheduleRoleGQL,
|
|
4
|
+
ScheduleShiftGQL,
|
|
5
|
+
ScheduleShiftStatus,
|
|
6
|
+
ScheduleTimeOffGQL,
|
|
7
|
+
ScheduleViolationGQL,
|
|
8
|
+
} from '@jsb188/graphql/schedule.d';
|
|
9
|
+
import { DateTime } from 'luxon';
|
|
10
|
+
import type { CalendarDayObj } from '../types/calendar.d.ts';
|
|
11
|
+
|
|
12
|
+
type Breach = 'BLOCK' | 'WARN' | null;
|
|
13
|
+
type RosterPerson = Pick<
|
|
14
|
+
ScheduleResourceGQL,
|
|
15
|
+
'id' | 'name' | 'ordinal' | 'retiredAt'
|
|
16
|
+
>;
|
|
17
|
+
type RosterRoom = Pick<ScheduleResourceGQL, 'id' | 'name' | 'ordinal'>;
|
|
18
|
+
type RosterRole = Pick<ScheduleRoleGQL, 'id' | 'name' | 'color'>;
|
|
19
|
+
type RosterShift = Pick<
|
|
20
|
+
ScheduleShiftGQL,
|
|
21
|
+
| 'id'
|
|
22
|
+
| 'shiftDate'
|
|
23
|
+
| 'startAt'
|
|
24
|
+
| 'endAt'
|
|
25
|
+
| 'roleId'
|
|
26
|
+
| 'locationResourceId'
|
|
27
|
+
| 'assigneeResourceId'
|
|
28
|
+
| 'unpaidBreakMinutes'
|
|
29
|
+
| 'label'
|
|
30
|
+
| 'status'
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
// One seat drawn in a roster cell
|
|
34
|
+
export interface RosterChipObj {
|
|
35
|
+
shiftId: string;
|
|
36
|
+
roleName: string | null;
|
|
37
|
+
roleColor: string | null;
|
|
38
|
+
label: string | null;
|
|
39
|
+
roomId: string | null;
|
|
40
|
+
roomName: string | null;
|
|
41
|
+
startLabel: string;
|
|
42
|
+
endLabel: string;
|
|
43
|
+
status: ScheduleShiftStatus;
|
|
44
|
+
// Ends on a later calendar day than its shiftDate
|
|
45
|
+
overnight: boolean;
|
|
46
|
+
breach: Breach;
|
|
47
|
+
isMine: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface RosterCellObj {
|
|
50
|
+
dateKey: string;
|
|
51
|
+
chips: RosterChipObj[];
|
|
52
|
+
timeOff: ScheduleTimeOffGQL | null;
|
|
53
|
+
// Worked minutes (duration minus unpaid break) of the live seats
|
|
54
|
+
minutes: number;
|
|
55
|
+
// Live open seats (OPEN rows only)
|
|
56
|
+
openCount: number;
|
|
57
|
+
breach: Breach;
|
|
58
|
+
}
|
|
59
|
+
export interface RosterRowObj {
|
|
60
|
+
key: string;
|
|
61
|
+
kind: 'GROUP' | 'OPEN' | 'PERSON';
|
|
62
|
+
roomId: string | null;
|
|
63
|
+
resourceId: string | null;
|
|
64
|
+
// '' = a group without a room, or a seat's assignee outside the loaded people
|
|
65
|
+
name: string;
|
|
66
|
+
cells: RosterCellObj[];
|
|
67
|
+
weekMinutes: number;
|
|
68
|
+
breach: Breach;
|
|
69
|
+
}
|
|
70
|
+
export interface RosterDayObj {
|
|
71
|
+
dateKey: string;
|
|
72
|
+
label: string;
|
|
73
|
+
staffCount: number;
|
|
74
|
+
openCount: number;
|
|
75
|
+
breach: Breach;
|
|
76
|
+
}
|
|
77
|
+
export interface RosterLayoutObj {
|
|
78
|
+
rows: RosterRowObj[];
|
|
79
|
+
days: RosterDayObj[];
|
|
80
|
+
openTotal: number;
|
|
81
|
+
breachTotal: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* Keep the more severe of two issues.
|
|
86
|
+
*/
|
|
87
|
+
function worst(a: Breach, b: Breach): Breach {
|
|
88
|
+
return a === 'BLOCK' || b === 'BLOCK' ? 'BLOCK' : a || b;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* Order catalog rows by their ordinal, then by name.
|
|
93
|
+
*/
|
|
94
|
+
function compareRosterOrdinal(
|
|
95
|
+
a: { ordinal: number; name: string },
|
|
96
|
+
b: { ordinal: number; name: string },
|
|
97
|
+
): number {
|
|
98
|
+
return a.ordinal - b.ordinal || a.name.localeCompare(b.name);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* Index the worst finding per seat and per person.
|
|
103
|
+
*/
|
|
104
|
+
function getRosterBreachIndex(violations: ScheduleViolationGQL[]) {
|
|
105
|
+
const byShift = new Map<string, Breach>();
|
|
106
|
+
const byResource = new Map<string, Breach>();
|
|
107
|
+
for (const violation of violations) {
|
|
108
|
+
if (violation.shiftId)
|
|
109
|
+
byShift.set(
|
|
110
|
+
violation.shiftId,
|
|
111
|
+
worst(byShift.get(violation.shiftId) || null, violation.severity),
|
|
112
|
+
);
|
|
113
|
+
if (violation.resourceId)
|
|
114
|
+
byResource.set(
|
|
115
|
+
violation.resourceId,
|
|
116
|
+
worst(byResource.get(violation.resourceId) || null, violation.severity),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return { byShift, byResource };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/*
|
|
123
|
+
* Return a seat's worked minutes: its duration minus its unpaid break.
|
|
124
|
+
*/
|
|
125
|
+
export function getRosterWorkedMinutes(
|
|
126
|
+
shift: Pick<RosterShift, 'startAt' | 'endAt' | 'unpaidBreakMinutes'>,
|
|
127
|
+
): number {
|
|
128
|
+
const minutes =
|
|
129
|
+
(+new Date(shift.endAt) - +new Date(shift.startAt)) / 60000 -
|
|
130
|
+
(shift.unpaidBreakMinutes || 0);
|
|
131
|
+
return Math.max(0, minutes);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/*
|
|
135
|
+
* Build the day headers, with the worst finding that overlaps each day.
|
|
136
|
+
*/
|
|
137
|
+
function buildRosterDays(
|
|
138
|
+
days: CalendarDayObj[],
|
|
139
|
+
timeZone: string,
|
|
140
|
+
locale: string | null,
|
|
141
|
+
violations: ScheduleViolationGQL[],
|
|
142
|
+
): RosterDayObj[] {
|
|
143
|
+
return days.map((day) => {
|
|
144
|
+
let breach: Breach = null;
|
|
145
|
+
for (const violation of violations)
|
|
146
|
+
if (
|
|
147
|
+
+new Date(violation.startAt) < +day.endAt &&
|
|
148
|
+
+new Date(violation.endAt) > +day.startAt
|
|
149
|
+
)
|
|
150
|
+
breach = worst(breach, violation.severity);
|
|
151
|
+
return {
|
|
152
|
+
dateKey: day.dateKey,
|
|
153
|
+
label: DateTime.fromJSDate(day.startAt, { zone: timeZone })
|
|
154
|
+
.setLocale(locale || 'en')
|
|
155
|
+
.toFormat('ccc d'),
|
|
156
|
+
staffCount: 0,
|
|
157
|
+
openCount: 0,
|
|
158
|
+
breach,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
* Create one row with its own cells, so no two rows share a cell.
|
|
165
|
+
*/
|
|
166
|
+
function createRosterRow(
|
|
167
|
+
kind: RosterRowObj['kind'],
|
|
168
|
+
key: string,
|
|
169
|
+
roomId: string | null,
|
|
170
|
+
days: CalendarDayObj[],
|
|
171
|
+
person?: RosterPerson,
|
|
172
|
+
): RosterRowObj {
|
|
173
|
+
return {
|
|
174
|
+
key,
|
|
175
|
+
kind,
|
|
176
|
+
roomId,
|
|
177
|
+
resourceId: person?.id || null,
|
|
178
|
+
name: person?.name || '',
|
|
179
|
+
cells: days.map((day) => ({
|
|
180
|
+
dateKey: day.dateKey,
|
|
181
|
+
chips: [],
|
|
182
|
+
timeOff: null,
|
|
183
|
+
minutes: 0,
|
|
184
|
+
openCount: 0,
|
|
185
|
+
breach: null,
|
|
186
|
+
})),
|
|
187
|
+
weekMinutes: 0,
|
|
188
|
+
breach: null,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/*
|
|
193
|
+
* Draw one seat: role, times in the calendar's zone, room, status and findings.
|
|
194
|
+
*/
|
|
195
|
+
function buildRosterChip(
|
|
196
|
+
shift: RosterShift,
|
|
197
|
+
ctx: {
|
|
198
|
+
timeZone: string;
|
|
199
|
+
roleById: Map<string, RosterRole>;
|
|
200
|
+
roomById: Map<string, RosterRoom>;
|
|
201
|
+
breachByShift: Map<string, Breach>;
|
|
202
|
+
viewerResourceId: string | null;
|
|
203
|
+
formatTime: (at: Date, timeZone: string) => string;
|
|
204
|
+
},
|
|
205
|
+
): RosterChipObj {
|
|
206
|
+
const role = shift.roleId ? ctx.roleById.get(shift.roleId) : null;
|
|
207
|
+
const start = new Date(shift.startAt),
|
|
208
|
+
end = new Date(shift.endAt);
|
|
209
|
+
// A seat ending exactly at midnight still ends on its own day
|
|
210
|
+
const endDate = DateTime.fromMillis(+end - 1, {
|
|
211
|
+
zone: ctx.timeZone,
|
|
212
|
+
}).toISODate();
|
|
213
|
+
return {
|
|
214
|
+
shiftId: shift.id,
|
|
215
|
+
roleName: role?.name || null,
|
|
216
|
+
roleColor: role?.color || null,
|
|
217
|
+
label: shift.label || null,
|
|
218
|
+
roomId: shift.locationResourceId,
|
|
219
|
+
roomName: ctx.roomById.get(shift.locationResourceId || '')?.name || null,
|
|
220
|
+
startLabel: ctx.formatTime(start, ctx.timeZone),
|
|
221
|
+
endLabel: ctx.formatTime(end, ctx.timeZone),
|
|
222
|
+
status: shift.status,
|
|
223
|
+
overnight: endDate !== shift.shiftDate,
|
|
224
|
+
breach: ctx.breachByShift.get(shift.id) || null,
|
|
225
|
+
isMine:
|
|
226
|
+
!!ctx.viewerResourceId &&
|
|
227
|
+
shift.assigneeResourceId === ctx.viewerResourceId,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/*
|
|
232
|
+
* Return the room a person worked the most minutes in (ties: room ordinal, then id).
|
|
233
|
+
*/
|
|
234
|
+
function getRosterPrimaryRoomId(
|
|
235
|
+
totals: Map<string, number> | undefined,
|
|
236
|
+
roomById: Map<string, RosterRoom>,
|
|
237
|
+
): string | null {
|
|
238
|
+
const sorted = [...(totals || [])].sort(
|
|
239
|
+
(a, b) =>
|
|
240
|
+
b[1] - a[1] ||
|
|
241
|
+
(roomById.get(a[0])?.ordinal ?? Infinity) -
|
|
242
|
+
(roomById.get(b[0])?.ordinal ?? Infinity) ||
|
|
243
|
+
a[0].localeCompare(b[0]),
|
|
244
|
+
);
|
|
245
|
+
return sorted[0]?.[0] || null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/*
|
|
249
|
+
* Return the time off shown in one day cell: approved before pending.
|
|
250
|
+
*/
|
|
251
|
+
function getRosterDayTimeOff(
|
|
252
|
+
rows: ScheduleTimeOffGQL[],
|
|
253
|
+
day: CalendarDayObj,
|
|
254
|
+
): ScheduleTimeOffGQL | null {
|
|
255
|
+
return (
|
|
256
|
+
rows
|
|
257
|
+
.filter(
|
|
258
|
+
(row) =>
|
|
259
|
+
+new Date(row.startAt) < +day.endAt &&
|
|
260
|
+
+new Date(row.endAt) > +day.startAt,
|
|
261
|
+
)
|
|
262
|
+
.sort(
|
|
263
|
+
(a, b) =>
|
|
264
|
+
Number(b.status === 'APPROVED') - Number(a.status === 'APPROVED'),
|
|
265
|
+
)[0] || null
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/*
|
|
270
|
+
* Group pending and approved time off by person.
|
|
271
|
+
*/
|
|
272
|
+
function getRosterTimeOffByResource(timeOff: ScheduleTimeOffGQL[]) {
|
|
273
|
+
const result = new Map<string, ScheduleTimeOffGQL[]>();
|
|
274
|
+
for (const row of timeOff)
|
|
275
|
+
if (row.status === 'PENDING' || row.status === 'APPROVED') {
|
|
276
|
+
const list = result.get(row.resourceId) || [];
|
|
277
|
+
list.push(row);
|
|
278
|
+
result.set(row.resourceId, list);
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/*
|
|
284
|
+
* Build a read-only people-by-day roster from seats: one row per person, an
|
|
285
|
+
* "Open" row for seats with no assignee, each seat placed on its shiftDate
|
|
286
|
+
* (the calendar-local day it starts). Optionally grouped by room.
|
|
287
|
+
*/
|
|
288
|
+
export function buildRosterLayout(p: {
|
|
289
|
+
days: CalendarDayObj[];
|
|
290
|
+
timeZone: string;
|
|
291
|
+
locale: string | null;
|
|
292
|
+
people: RosterPerson[];
|
|
293
|
+
rooms: RosterRoom[];
|
|
294
|
+
roles: RosterRole[];
|
|
295
|
+
shifts: RosterShift[];
|
|
296
|
+
timeOff: ScheduleTimeOffGQL[];
|
|
297
|
+
violations: ScheduleViolationGQL[];
|
|
298
|
+
groupByRoom: boolean;
|
|
299
|
+
roomFilterId: string | null;
|
|
300
|
+
viewerResourceId: string | null;
|
|
301
|
+
formatTime: (at: Date, timeZone: string) => string;
|
|
302
|
+
}): RosterLayoutObj {
|
|
303
|
+
const dayIndex = new Map(p.days.map((day, index) => [day.dateKey, index]));
|
|
304
|
+
const rooms = [...p.rooms].sort(compareRosterOrdinal);
|
|
305
|
+
const roomById = new Map(rooms.map((room) => [room.id, room]));
|
|
306
|
+
const breaches = getRosterBreachIndex(p.violations);
|
|
307
|
+
const chipContext = {
|
|
308
|
+
timeZone: p.timeZone,
|
|
309
|
+
roleById: new Map(p.roles.map((role) => [role.id, role])),
|
|
310
|
+
roomById,
|
|
311
|
+
breachByShift: breaches.byShift,
|
|
312
|
+
viewerResourceId: p.viewerResourceId,
|
|
313
|
+
formatTime: p.formatTime,
|
|
314
|
+
};
|
|
315
|
+
const result: RosterLayoutObj = {
|
|
316
|
+
rows: [],
|
|
317
|
+
days: buildRosterDays(p.days, p.timeZone, p.locale, p.violations),
|
|
318
|
+
openTotal: 0,
|
|
319
|
+
breachTotal: p.violations.length,
|
|
320
|
+
};
|
|
321
|
+
const personById = new Map<string, RosterPerson>(
|
|
322
|
+
p.people.map((person) => [person.id, person]),
|
|
323
|
+
);
|
|
324
|
+
const people = new Map<string, RosterRowObj>(
|
|
325
|
+
p.people.map((person) => [
|
|
326
|
+
person.id,
|
|
327
|
+
createRosterRow('PERSON', person.id, null, p.days, person),
|
|
328
|
+
]),
|
|
329
|
+
);
|
|
330
|
+
const dayStaff = p.days.map(() => new Set<string>());
|
|
331
|
+
const roomMinutes = new Map<string, Map<string, number>>();
|
|
332
|
+
const openRows = new Map<string, RosterRowObj>();
|
|
333
|
+
const shifts = [...p.shifts].sort(
|
|
334
|
+
(a, b) =>
|
|
335
|
+
+new Date(a.startAt) - +new Date(b.startAt) || a.id.localeCompare(b.id),
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
for (const shift of shifts) {
|
|
339
|
+
if (p.roomFilterId && shift.locationResourceId !== p.roomFilterId) continue;
|
|
340
|
+
const index = dayIndex.get(shift.shiftDate);
|
|
341
|
+
if (index === undefined) continue;
|
|
342
|
+
const chip = buildRosterChip(shift, chipContext);
|
|
343
|
+
const live = shift.status !== 'CANCELED';
|
|
344
|
+
// A room outside the loaded rooms groups as "no room"
|
|
345
|
+
const roomKey = roomById.has(shift.locationResourceId || '')
|
|
346
|
+
? shift.locationResourceId!
|
|
347
|
+
: '';
|
|
348
|
+
|
|
349
|
+
if (!shift.assigneeResourceId) {
|
|
350
|
+
const groupKey = p.groupByRoom ? roomKey : '';
|
|
351
|
+
const open =
|
|
352
|
+
openRows.get(groupKey) ||
|
|
353
|
+
createRosterRow('OPEN', `open:${groupKey}`, groupKey || null, p.days);
|
|
354
|
+
openRows.set(groupKey, open);
|
|
355
|
+
const cell = open.cells[index];
|
|
356
|
+
cell.chips.push(chip);
|
|
357
|
+
if (live) {
|
|
358
|
+
cell.openCount += 1;
|
|
359
|
+
cell.breach = worst(cell.breach, chip.breach);
|
|
360
|
+
result.days[index].openCount += 1;
|
|
361
|
+
result.openTotal += 1;
|
|
362
|
+
}
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const assigneeId = shift.assigneeResourceId;
|
|
367
|
+
let person = people.get(assigneeId);
|
|
368
|
+
if (!person) {
|
|
369
|
+
// A seat names someone outside the loaded people (another organization's
|
|
370
|
+
// shared calendar, or a catalog the viewer cannot read)
|
|
371
|
+
const unknown = {
|
|
372
|
+
id: assigneeId,
|
|
373
|
+
name: '',
|
|
374
|
+
ordinal: Number.MAX_SAFE_INTEGER,
|
|
375
|
+
retiredAt: null,
|
|
376
|
+
};
|
|
377
|
+
personById.set(assigneeId, unknown);
|
|
378
|
+
person = createRosterRow('PERSON', assigneeId, null, p.days, unknown);
|
|
379
|
+
people.set(assigneeId, person);
|
|
380
|
+
}
|
|
381
|
+
const cell = person.cells[index];
|
|
382
|
+
cell.chips.push(chip);
|
|
383
|
+
person.breach = worst(person.breach, chip.breach);
|
|
384
|
+
if (live) {
|
|
385
|
+
const minutes = getRosterWorkedMinutes(shift);
|
|
386
|
+
person.weekMinutes += minutes;
|
|
387
|
+
cell.minutes += minutes;
|
|
388
|
+
dayStaff[index].add(assigneeId);
|
|
389
|
+
const totals = roomMinutes.get(assigneeId) || new Map<string, number>();
|
|
390
|
+
totals.set(roomKey, (totals.get(roomKey) || 0) + minutes);
|
|
391
|
+
roomMinutes.set(assigneeId, totals);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const timeOffByResource = getRosterTimeOffByResource(p.timeOff);
|
|
396
|
+
const assignedAnywhere = new Set(
|
|
397
|
+
p.shifts.map((shift) => shift.assigneeResourceId).filter(Boolean),
|
|
398
|
+
);
|
|
399
|
+
const visiblePeople = [...people.values()]
|
|
400
|
+
.filter((row) => {
|
|
401
|
+
const person = personById.get(row.resourceId!)!;
|
|
402
|
+
const hasChip = row.cells.some((cell) => cell.chips.length);
|
|
403
|
+
if (person.retiredAt && !hasChip) return false;
|
|
404
|
+
// With a room filter, hide people whose seats this week are all elsewhere
|
|
405
|
+
if (p.roomFilterId && !hasChip && assignedAnywhere.has(person.id))
|
|
406
|
+
return false;
|
|
407
|
+
return true;
|
|
408
|
+
})
|
|
409
|
+
.sort((a, b) =>
|
|
410
|
+
compareRosterOrdinal(
|
|
411
|
+
personById.get(a.resourceId!)!,
|
|
412
|
+
personById.get(b.resourceId!)!,
|
|
413
|
+
),
|
|
414
|
+
);
|
|
415
|
+
for (const row of visiblePeople) {
|
|
416
|
+
const resourceId = row.resourceId!;
|
|
417
|
+
row.roomId = getRosterPrimaryRoomId(roomMinutes.get(resourceId), roomById);
|
|
418
|
+
row.breach = worst(row.breach, breaches.byResource.get(resourceId) || null);
|
|
419
|
+
const timeOff = timeOffByResource.get(resourceId) || [];
|
|
420
|
+
row.cells.forEach((cell, i) => {
|
|
421
|
+
cell.timeOff = getRosterDayTimeOff(timeOff, p.days[i]);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (p.groupByRoom) {
|
|
426
|
+
for (const roomId of [...rooms.map((room) => room.id), '']) {
|
|
427
|
+
if (p.roomFilterId && roomId !== p.roomFilterId) continue;
|
|
428
|
+
const members = visiblePeople.filter(
|
|
429
|
+
(row) => (row.roomId || '') === roomId,
|
|
430
|
+
);
|
|
431
|
+
if (!members.length && !openRows.has(roomId)) continue;
|
|
432
|
+
const group = createRosterRow(
|
|
433
|
+
'GROUP',
|
|
434
|
+
`group:${roomId}`,
|
|
435
|
+
roomId || null,
|
|
436
|
+
p.days,
|
|
437
|
+
);
|
|
438
|
+
group.name = roomById.get(roomId)?.name || '';
|
|
439
|
+
group.breach = breaches.byResource.get(roomId) || null;
|
|
440
|
+
result.rows.push(
|
|
441
|
+
group,
|
|
442
|
+
openRows.get(roomId) ||
|
|
443
|
+
createRosterRow('OPEN', `open:${roomId}`, roomId || null, p.days),
|
|
444
|
+
...members,
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
} else {
|
|
448
|
+
result.rows = [
|
|
449
|
+
openRows.get('') || createRosterRow('OPEN', 'open:', null, p.days),
|
|
450
|
+
...visiblePeople,
|
|
451
|
+
];
|
|
452
|
+
}
|
|
453
|
+
result.days.forEach((day, i) => {
|
|
454
|
+
day.staffCount = dayStaff[i].size;
|
|
455
|
+
});
|
|
456
|
+
return result;
|
|
457
|
+
}
|
package/src/modules/Calendar.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
|
-
import { useAtom
|
|
3
|
+
import { useAtom } from 'jotai';
|
|
4
4
|
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import {
|
|
6
6
|
CALENDAR_GUTTER_WIDTH,
|
|
@@ -31,9 +31,7 @@ import {
|
|
|
31
31
|
normalizeCalendarWeekStartsOn,
|
|
32
32
|
} from '../libs/calendar-range.ts';
|
|
33
33
|
import {
|
|
34
|
-
applyCalendarOptimisticOverlays,
|
|
35
34
|
createCalendarStateAtoms,
|
|
36
|
-
getCalendarStateScopeKey,
|
|
37
35
|
type CalendarStateAtoms,
|
|
38
36
|
} from '../libs/calendar-state.ts';
|
|
39
37
|
import type { CalendarEventObj } from '../types/calendar.d.ts';
|
|
@@ -108,12 +106,15 @@ export function Calendar(p: CalendarProps) {
|
|
|
108
106
|
// Created in a ref, never inline in the render body: creating atoms inline
|
|
109
107
|
// would hand every render a fresh bag and reset all state
|
|
110
108
|
if (!stateAtomsRef.current) {
|
|
111
|
-
stateAtomsRef.current = createCalendarStateAtoms(
|
|
112
|
-
getCalendarStateScopeKey(),
|
|
113
|
-
);
|
|
109
|
+
stateAtomsRef.current = createCalendarStateAtoms();
|
|
114
110
|
}
|
|
115
111
|
|
|
116
|
-
return
|
|
112
|
+
return (
|
|
113
|
+
<CalendarContent
|
|
114
|
+
{...p}
|
|
115
|
+
stateAtoms={stateAtomsRef.current}
|
|
116
|
+
/>
|
|
117
|
+
);
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
type CalendarContentProps = CalendarProps & {
|
|
@@ -171,10 +172,8 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
171
172
|
stateAtoms,
|
|
172
173
|
} = p;
|
|
173
174
|
|
|
174
|
-
const [
|
|
175
|
-
|
|
176
|
-
const removedEventIds = useAtomValue(
|
|
177
|
-
stateAtoms.optimisticallyRemovedEventIdsAtom,
|
|
175
|
+
const [selectedEventId, setSelectedEventId] = useAtom(
|
|
176
|
+
stateAtoms.selectedEventIdAtom,
|
|
178
177
|
);
|
|
179
178
|
|
|
180
179
|
// "now" ticks every minute to move the now line, but the range only uses it
|
|
@@ -191,15 +190,7 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
191
190
|
);
|
|
192
191
|
|
|
193
192
|
// One pass over the week per data change, not per subscriber
|
|
194
|
-
const visibleEvents =
|
|
195
|
-
() =>
|
|
196
|
-
applyCalendarOptimisticOverlays(
|
|
197
|
-
events,
|
|
198
|
-
optimisticEvents,
|
|
199
|
-
removedEventIds,
|
|
200
|
-
),
|
|
201
|
-
[events, optimisticEvents, removedEventIds],
|
|
202
|
-
);
|
|
193
|
+
const visibleEvents = events;
|
|
203
194
|
|
|
204
195
|
const isTimeGrid = !!CALENDAR_VIEW_DAY_COUNTS[view];
|
|
205
196
|
|
|
@@ -207,12 +198,23 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
207
198
|
// running the overlap sweep over it to draw a grid that shows no events
|
|
208
199
|
// would be pure waste on every render.
|
|
209
200
|
const timedLayout = useMemo(
|
|
210
|
-
() =>
|
|
201
|
+
() =>
|
|
202
|
+
isTimeGrid
|
|
203
|
+
? getCalendarTimedLayout(
|
|
204
|
+
visibleEvents.filter((event) => !event.allDay),
|
|
205
|
+
range.days,
|
|
206
|
+
)
|
|
207
|
+
: [],
|
|
211
208
|
[isTimeGrid, visibleEvents, range.days],
|
|
212
209
|
);
|
|
213
210
|
const allDayBars = useMemo(
|
|
214
211
|
() =>
|
|
215
|
-
isTimeGrid
|
|
212
|
+
isTimeGrid
|
|
213
|
+
? getCalendarAllDayLayout(
|
|
214
|
+
visibleEvents.filter((event) => event.allDay),
|
|
215
|
+
range.days,
|
|
216
|
+
)
|
|
217
|
+
: [],
|
|
216
218
|
[isTimeGrid, visibleEvents, range.days],
|
|
217
219
|
);
|
|
218
220
|
const monthCells = useMemo(
|
|
@@ -287,17 +289,11 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
287
289
|
|
|
288
290
|
const handleSelectEvent = useCallback(
|
|
289
291
|
(eventId: string) => {
|
|
290
|
-
|
|
291
|
-
// Clicking the open event again closes it, and returning the same
|
|
292
|
-
// reference on a no-op keeps subscribers from re-rendering
|
|
293
|
-
current?.eventId === eventId
|
|
294
|
-
? null
|
|
295
|
-
: { eventId, anchorRect: { top: 0, left: 0, width: 0, height: 0 } },
|
|
296
|
-
);
|
|
292
|
+
setSelectedEventId((current) => (current === eventId ? null : eventId));
|
|
297
293
|
|
|
298
294
|
onSelectEvent?.(eventId);
|
|
299
295
|
},
|
|
300
|
-
[onSelectEvent
|
|
296
|
+
[onSelectEvent],
|
|
301
297
|
);
|
|
302
298
|
|
|
303
299
|
/*
|
|
@@ -599,8 +595,6 @@ const CalendarContent = memo((p: CalendarContentProps) => {
|
|
|
599
595
|
CALENDAR_HOUR_HEIGHT
|
|
600
596
|
: -1;
|
|
601
597
|
|
|
602
|
-
const selectedEventId = popoverState?.eventId || null;
|
|
603
|
-
|
|
604
598
|
// The ghost's own label, so a drag reads as a time range while it is being
|
|
605
599
|
// drawn rather than as an unlabelled rectangle
|
|
606
600
|
const draftTimeLabel = useMemo(() => {
|
|
@@ -266,7 +266,10 @@ export const MiniCalendar = memo((p: MiniCalendarProps) => {
|
|
|
266
266
|
return (
|
|
267
267
|
<div className={cn('unsel', className)}>
|
|
268
268
|
{title || onStepMonth ? (
|
|
269
|
-
<div
|
|
269
|
+
<div
|
|
270
|
+
className="h_spread"
|
|
271
|
+
style={FILE_CONSTANTS.headerStyle}
|
|
272
|
+
>
|
|
270
273
|
<span className="f ellip ft_sm ft_bold cl_md">{title || ''}</span>
|
|
271
274
|
|
|
272
275
|
{onStepMonth ? (
|
|
@@ -305,7 +308,7 @@ export const MiniCalendar = memo((p: MiniCalendarProps) => {
|
|
|
305
308
|
{columnLabels.map((label, index) => (
|
|
306
309
|
<div
|
|
307
310
|
key={index}
|
|
308
|
-
className="a_c
|
|
311
|
+
className="a_c ft_xxs cl_lt"
|
|
309
312
|
style={FILE_CONSTANTS.columnLabelStyle}
|
|
310
313
|
>
|
|
311
314
|
{label}
|
|
@@ -314,7 +317,10 @@ export const MiniCalendar = memo((p: MiniCalendarProps) => {
|
|
|
314
317
|
</div>
|
|
315
318
|
|
|
316
319
|
{weeks.map((week, weekIndex) => (
|
|
317
|
-
<div
|
|
320
|
+
<div
|
|
321
|
+
key={weekIndex}
|
|
322
|
+
style={FILE_CONSTANTS.gridStyle}
|
|
323
|
+
>
|
|
318
324
|
{week.map((day, dayIndex) => {
|
|
319
325
|
const isHighlighted = highlightedSet.has(day.dateKey);
|
|
320
326
|
const isSelected = selectedSet.has(day.dateKey);
|
package/src/types/calendar.d.ts
CHANGED
|
@@ -30,7 +30,13 @@ export interface CalendarEventObj {
|
|
|
30
30
|
note?: string | null;
|
|
31
31
|
color?: string | null;
|
|
32
32
|
// Everyone working this entry, for the assignee chips and "my calendar only"
|
|
33
|
-
|
|
33
|
+
assigneeResourceIds: string[];
|
|
34
|
+
assigneeNames?: string[];
|
|
35
|
+
roomId?: string | null;
|
|
36
|
+
roomName?: string | null;
|
|
37
|
+
breach?: 'BLOCK' | 'WARN' | null;
|
|
38
|
+
version?: string;
|
|
39
|
+
pending?: boolean;
|
|
34
40
|
// How many people the entry still needs; drives the "open shift" treatment
|
|
35
41
|
openCount?: number;
|
|
36
42
|
// Set when the viewer is one of the assignees, so the grid can mark it
|
|
@@ -3,6 +3,22 @@ import { memo } from 'react';
|
|
|
3
3
|
import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
|
|
4
4
|
import type { CalendarEventObj } from '../types/calendar.d.ts';
|
|
5
5
|
|
|
6
|
+
const FILE_CONSTANTS = {
|
|
7
|
+
dayHeaderStyle: {
|
|
8
|
+
paddingLeft: 12,
|
|
9
|
+
paddingRight: 12,
|
|
10
|
+
paddingTop: 6,
|
|
11
|
+
paddingBottom: 2,
|
|
12
|
+
},
|
|
13
|
+
eventStyle: {
|
|
14
|
+
paddingLeft: 12,
|
|
15
|
+
paddingRight: 12,
|
|
16
|
+
paddingTop: 4,
|
|
17
|
+
paddingBottom: 4,
|
|
18
|
+
},
|
|
19
|
+
timeLabelStyle: { width: 104 },
|
|
20
|
+
};
|
|
21
|
+
|
|
6
22
|
/**
|
|
7
23
|
* The agenda ("Schedule") list.
|
|
8
24
|
*
|
|
@@ -50,15 +66,13 @@ export const CalendarAgendaUI = memo((p: CalendarAgendaUIProps) => {
|
|
|
50
66
|
return (
|
|
51
67
|
<div className="f h_0 app_scr auto_y">
|
|
52
68
|
{days.map((day) => (
|
|
53
|
-
<div
|
|
69
|
+
<div
|
|
70
|
+
key={day.dateKey}
|
|
71
|
+
className="bd_t_1 bd_t_bd"
|
|
72
|
+
>
|
|
54
73
|
<div
|
|
55
|
-
className={cn('
|
|
56
|
-
style={
|
|
57
|
-
paddingLeft: 12,
|
|
58
|
-
paddingRight: 12,
|
|
59
|
-
paddingTop: 6,
|
|
60
|
-
paddingBottom: 2,
|
|
61
|
-
}}
|
|
74
|
+
className={cn('ft_xxs', day.isToday ? 'ft_bold' : 'cl_lt')}
|
|
75
|
+
style={FILE_CONSTANTS.dayHeaderStyle}
|
|
62
76
|
>
|
|
63
77
|
{day.label}
|
|
64
78
|
</div>
|
|
@@ -72,22 +86,17 @@ export const CalendarAgendaUI = memo((p: CalendarAgendaUIProps) => {
|
|
|
72
86
|
event.status === 'CANCELED' ? 'strikethrough' : '',
|
|
73
87
|
selectedEventId === event.id ? 'bg_active' : '',
|
|
74
88
|
)}
|
|
75
|
-
style={
|
|
76
|
-
paddingLeft: 12,
|
|
77
|
-
paddingRight: 12,
|
|
78
|
-
paddingTop: 4,
|
|
79
|
-
paddingBottom: 4,
|
|
80
|
-
}}
|
|
89
|
+
style={FILE_CONSTANTS.eventStyle}
|
|
81
90
|
onClick={() => onSelectEvent(event.id)}
|
|
82
91
|
>
|
|
83
92
|
<span
|
|
84
93
|
className={cn(
|
|
85
|
-
'no_shrink
|
|
94
|
+
'no_shrink ft_xxs cl_lt rel of',
|
|
86
95
|
event.status === 'DRAFT'
|
|
87
96
|
? CALENDAR_DRAFT_PATTERN_CLASS_NAME
|
|
88
97
|
: '',
|
|
89
98
|
)}
|
|
90
|
-
style={
|
|
99
|
+
style={FILE_CONSTANTS.timeLabelStyle}
|
|
91
100
|
>
|
|
92
101
|
{timeLabelByEventId.get(event.id) || ''}
|
|
93
102
|
</span>
|
|
@@ -95,7 +104,7 @@ export const CalendarAgendaUI = memo((p: CalendarAgendaUIProps) => {
|
|
|
95
104
|
<span className="f ellip ft_sm">{event.title}</span>
|
|
96
105
|
|
|
97
106
|
{event.isMine ? (
|
|
98
|
-
<span className="no_shrink
|
|
107
|
+
<span className="no_shrink ft_xxs cl_lt">•</span>
|
|
99
108
|
) : null}
|
|
100
109
|
</button>
|
|
101
110
|
))}
|