@jsb188/calendar 1.1.10
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/package.json +44 -0
- package/src/constants/calendar.ts +139 -0
- package/src/css.d.ts +7 -0
- package/src/libs/calendar-geometry.ts +426 -0
- package/src/libs/calendar-gesture.ts +298 -0
- package/src/libs/calendar-range.ts +340 -0
- package/src/libs/calendar-state.ts +161 -0
- package/src/libs/calendar-url.ts +144 -0
- package/src/main.ts +29 -0
- package/src/modules/Calendar.tsx +648 -0
- package/src/types/calendar.d.ts +122 -0
- package/src/ui/CalendarAgendaUI.tsx +86 -0
- package/src/ui/CalendarCoverageUI.tsx +199 -0
- package/src/ui/CalendarEventDetailUI.tsx +260 -0
- package/src/ui/CalendarEventFormUI.tsx +239 -0
- package/src/ui/CalendarMonthUI.tsx +130 -0
- package/src/ui/CalendarRailUI.tsx +282 -0
- package/src/ui/CalendarRequestUI.tsx +537 -0
- package/src/ui/CalendarToolbarUI.tsx +110 -0
- package/src/ui/CalendarUI.tsx +347 -0
- package/src/ui/CalendarViolationUI.tsx +207 -0
- package/src/ui/CalendarYearUI.tsx +81 -0
- package/tests/calendar-geometry.test.ts +403 -0
- package/tests/calendar-gesture.test.ts +309 -0
- package/tests/calendar-range.test.ts +232 -0
- package/tests/calendar-url.test.ts +124 -0
- package/tsconfig.json +13 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
CALENDAR_ALL_DAY_ROW_HEIGHT,
|
|
5
|
+
CALENDAR_DRAFT_PATTERN_CLASS_NAME,
|
|
6
|
+
CALENDAR_GUTTER_WIDTH,
|
|
7
|
+
} from '../constants/calendar.ts';
|
|
8
|
+
import type { CalendarAllDayBarObj } from '../libs/calendar-geometry.ts';
|
|
9
|
+
import type { CalendarDayObj, CalendarEventLayoutObj } from '../types/calendar.d.ts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Stateless calendar UI.
|
|
13
|
+
*
|
|
14
|
+
* Nothing here fetches, mutates, or holds state — every component takes what
|
|
15
|
+
* it draws and reports what was clicked. The geometry arrives as numbers
|
|
16
|
+
* already computed by calendar-geometry, so these components never do date
|
|
17
|
+
* math either.
|
|
18
|
+
*
|
|
19
|
+
* Positions are inline styles rather than classes on purpose: an event's top
|
|
20
|
+
* and height are DATA (a function of when it happens and how tall an hour is),
|
|
21
|
+
* and no utility class can express "17.3% from the top". Everything that IS
|
|
22
|
+
* design — colour, weight, radius, spacing, borders — uses the existing global
|
|
23
|
+
* utility classes, and no new CSS is introduced.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The left-hand hour labels.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export const CalendarTimeGutterUI = memo((p: {
|
|
31
|
+
hourHeight: number;
|
|
32
|
+
// Labels for hours 0..23, already formatted and localized by the caller
|
|
33
|
+
hourLabels: string[];
|
|
34
|
+
}) => {
|
|
35
|
+
const { hourHeight, hourLabels } = p;
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
className='no_shrink rel'
|
|
40
|
+
style={{ width: CALENDAR_GUTTER_WIDTH }}
|
|
41
|
+
>
|
|
42
|
+
{hourLabels.map((label, hour) => (
|
|
43
|
+
<div
|
|
44
|
+
key={hour}
|
|
45
|
+
className='abs w_f a_r ft_tn cl_lt'
|
|
46
|
+
// Pulled up by half a line so the label sits ON its gridline
|
|
47
|
+
// rather than hanging below it. Midnight is unlabelled: it is
|
|
48
|
+
// the day boundary the header already names.
|
|
49
|
+
style={{ top: hour * hourHeight - 7, paddingRight: 6 }}
|
|
50
|
+
>
|
|
51
|
+
{hour === 0 ? null : label}
|
|
52
|
+
</div>
|
|
53
|
+
))}
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The horizontal hour lines behind the day columns.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
export const CalendarHourLinesUI = memo((p: {
|
|
63
|
+
hourCount: number;
|
|
64
|
+
hourHeight: number;
|
|
65
|
+
}) => {
|
|
66
|
+
const { hourCount, hourHeight } = p;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
{Array.from({ length: hourCount }, (_unused, hour) => (
|
|
71
|
+
<div
|
|
72
|
+
key={hour}
|
|
73
|
+
className='abs w_f bd_t_1 bd_t_bd'
|
|
74
|
+
style={{ top: hour * hourHeight }}
|
|
75
|
+
/>
|
|
76
|
+
))}
|
|
77
|
+
</>
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The "now" line, drawn only on the day that is actually today.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
export const CalendarNowLineUI = memo((p: {
|
|
86
|
+
topOffset: number;
|
|
87
|
+
}) => {
|
|
88
|
+
return (
|
|
89
|
+
<div
|
|
90
|
+
className='abs w_f z3'
|
|
91
|
+
style={{ top: p.topOffset }}
|
|
92
|
+
>
|
|
93
|
+
<div className='bg_red' style={{ height: 2 }} />
|
|
94
|
+
</div>
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* Return the classes that carry an occurrence's status.
|
|
100
|
+
*
|
|
101
|
+
* A DRAFT is striped rather than merely faded: faded reads as "still loading",
|
|
102
|
+
* and a schedule that has not been published yet is a different thing from one
|
|
103
|
+
* that is still arriving. CANCELED stays on the calendar struck through,
|
|
104
|
+
* because somebody hunting for a shift that was cancelled has to find it
|
|
105
|
+
* rather than wonder whether they imagined it.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
function getCalendarEventStatusClassName(status: string): string {
|
|
109
|
+
switch (status) {
|
|
110
|
+
case 'DRAFT':
|
|
111
|
+
return CALENDAR_DRAFT_PATTERN_CLASS_NAME;
|
|
112
|
+
case 'CANCELED':
|
|
113
|
+
return 'strikethrough';
|
|
114
|
+
default:
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface CalendarEventUIProps {
|
|
120
|
+
layout: CalendarEventLayoutObj;
|
|
121
|
+
hourHeight: number;
|
|
122
|
+
selected: boolean;
|
|
123
|
+
// Offers the resize grips; a viewer without edit rights gets a block that
|
|
124
|
+
// can be opened but not dragged
|
|
125
|
+
editable: boolean;
|
|
126
|
+
timeLabel: string;
|
|
127
|
+
onSelect: (eventId: string) => void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* One event block in the time grid.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
export const CalendarEventUI = memo((p: CalendarEventUIProps) => {
|
|
135
|
+
const { layout, hourHeight, selected, editable, timeLabel, onSelect } = p;
|
|
136
|
+
const { event } = layout;
|
|
137
|
+
|
|
138
|
+
const top = (layout.startMinute / 60) * hourHeight;
|
|
139
|
+
// Never shorter than a line of text, or it stops being clickable
|
|
140
|
+
const height = Math.max(((layout.endMinute - layout.startMinute) / 60) * hourHeight, 16);
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<button
|
|
144
|
+
type='button'
|
|
145
|
+
className={cn(
|
|
146
|
+
'abs of a_l r_xs bd_1 bd_bd',
|
|
147
|
+
// A stacked event has to paint over the ones behind it, and the
|
|
148
|
+
// selected one over everything
|
|
149
|
+
selected ? 'z3' : 'z2',
|
|
150
|
+
getCalendarEventStatusClassName(event.status),
|
|
151
|
+
event.isMine ? 'bg_active' : 'bg_alt',
|
|
152
|
+
)}
|
|
153
|
+
style={{
|
|
154
|
+
top,
|
|
155
|
+
height,
|
|
156
|
+
left: `${layout.left * 100}%`,
|
|
157
|
+
width: `calc(${layout.width * 100}% - 2px)`,
|
|
158
|
+
paddingLeft: 4,
|
|
159
|
+
paddingRight: 4,
|
|
160
|
+
// A continued block keeps square edges where it was cut, so the
|
|
161
|
+
// user can see it runs off the end of the day
|
|
162
|
+
borderTopLeftRadius: layout.continuesFromPreviousDay ? 0 : undefined,
|
|
163
|
+
borderTopRightRadius: layout.continuesFromPreviousDay ? 0 : undefined,
|
|
164
|
+
borderBottomLeftRadius: layout.continuesToNextDay ? 0 : undefined,
|
|
165
|
+
borderBottomRightRadius: layout.continuesToNextDay ? 0 : undefined,
|
|
166
|
+
borderLeftColor: event.color || undefined,
|
|
167
|
+
borderLeftWidth: event.color ? 3 : undefined,
|
|
168
|
+
}}
|
|
169
|
+
onClick={() => onSelect(event.id)}
|
|
170
|
+
aria-current={selected ? 'true' : undefined}
|
|
171
|
+
data-calendar-event-id={event.id}
|
|
172
|
+
>
|
|
173
|
+
<span className='ellip ft_tn ft_bold'>{event.title}</span>
|
|
174
|
+
|
|
175
|
+
{/* Below roughly 40 minutes there is only room for one line */}
|
|
176
|
+
{height >= 32 ? <span className='ellip ft_tn cl_lt'>{timeLabel}</span> : null}
|
|
177
|
+
|
|
178
|
+
{/* Resize grips. Only offered when the block is tall enough to leave
|
|
179
|
+
a middle over to grab for moving — on a short block the grips
|
|
180
|
+
would cover the whole thing and moving would become impossible */}
|
|
181
|
+
{editable && height >= 28
|
|
182
|
+
? (
|
|
183
|
+
<>
|
|
184
|
+
<span
|
|
185
|
+
className='abs w_f'
|
|
186
|
+
style={{ top: 0, left: 0, height: 6, cursor: 'ns-resize', touchAction: 'none' }}
|
|
187
|
+
data-calendar-edge='START'
|
|
188
|
+
/>
|
|
189
|
+
<span
|
|
190
|
+
className='abs w_f'
|
|
191
|
+
style={{ bottom: 0, left: 0, height: 6, cursor: 'ns-resize', touchAction: 'none' }}
|
|
192
|
+
data-calendar-edge='END'
|
|
193
|
+
/>
|
|
194
|
+
</>
|
|
195
|
+
)
|
|
196
|
+
: null}
|
|
197
|
+
</button>
|
|
198
|
+
);
|
|
199
|
+
}, (prev, next) => (
|
|
200
|
+
// The layout objects are rebuilt on every data change, so comparing them by
|
|
201
|
+
// identity would defeat the memo; compare what is actually drawn
|
|
202
|
+
prev.layout.event === next.layout.event &&
|
|
203
|
+
prev.layout.startMinute === next.layout.startMinute &&
|
|
204
|
+
prev.layout.endMinute === next.layout.endMinute &&
|
|
205
|
+
prev.layout.left === next.layout.left &&
|
|
206
|
+
prev.layout.width === next.layout.width &&
|
|
207
|
+
prev.layout.continuesFromPreviousDay === next.layout.continuesFromPreviousDay &&
|
|
208
|
+
prev.layout.continuesToNextDay === next.layout.continuesToNextDay &&
|
|
209
|
+
prev.hourHeight === next.hourHeight &&
|
|
210
|
+
prev.selected === next.selected &&
|
|
211
|
+
prev.editable === next.editable &&
|
|
212
|
+
prev.timeLabel === next.timeLabel &&
|
|
213
|
+
prev.onSelect === next.onSelect
|
|
214
|
+
));
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The all-day band above the time grid.
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
export const CalendarAllDayBandUI = memo((p: {
|
|
221
|
+
bars: CalendarAllDayBarObj[];
|
|
222
|
+
dayCount: number;
|
|
223
|
+
selectedEventId: string | null;
|
|
224
|
+
onSelect: (eventId: string) => void;
|
|
225
|
+
}) => {
|
|
226
|
+
const { bars, dayCount, selectedEventId, onSelect } = p;
|
|
227
|
+
|
|
228
|
+
if (!bars.length) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const rowCount = Math.max(...bars.map((bar) => bar.row)) + 1;
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<div
|
|
236
|
+
className='no_shrink rel bd_b_1 bd_b_bd'
|
|
237
|
+
style={{
|
|
238
|
+
marginLeft: CALENDAR_GUTTER_WIDTH,
|
|
239
|
+
height: rowCount * (CALENDAR_ALL_DAY_ROW_HEIGHT + 2) + 4,
|
|
240
|
+
}}
|
|
241
|
+
>
|
|
242
|
+
{bars.map((bar) => (
|
|
243
|
+
<button
|
|
244
|
+
key={bar.event.id}
|
|
245
|
+
type='button'
|
|
246
|
+
className={cn(
|
|
247
|
+
'abs of a_l r_xs ellip ft_tn',
|
|
248
|
+
getCalendarEventStatusClassName(bar.event.status),
|
|
249
|
+
bar.event.isMine ? 'bg_active' : 'bg_alt',
|
|
250
|
+
selectedEventId === bar.event.id ? 'z3' : 'z2',
|
|
251
|
+
)}
|
|
252
|
+
style={{
|
|
253
|
+
top: bar.row * (CALENDAR_ALL_DAY_ROW_HEIGHT + 2) + 2,
|
|
254
|
+
height: CALENDAR_ALL_DAY_ROW_HEIGHT,
|
|
255
|
+
left: `${(bar.startDayIndex / dayCount) * 100}%`,
|
|
256
|
+
width: `calc(${((bar.endDayIndex - bar.startDayIndex + 1) / dayCount) * 100}% - 2px)`,
|
|
257
|
+
paddingLeft: 4,
|
|
258
|
+
paddingRight: 4,
|
|
259
|
+
borderTopLeftRadius: bar.continuesFromPreviousDay ? 0 : undefined,
|
|
260
|
+
borderBottomLeftRadius: bar.continuesFromPreviousDay ? 0 : undefined,
|
|
261
|
+
borderTopRightRadius: bar.continuesToNextDay ? 0 : undefined,
|
|
262
|
+
borderBottomRightRadius: bar.continuesToNextDay ? 0 : undefined,
|
|
263
|
+
}}
|
|
264
|
+
onClick={() => onSelect(bar.event.id)}
|
|
265
|
+
aria-current={selectedEventId === bar.event.id ? 'true' : undefined}
|
|
266
|
+
>
|
|
267
|
+
{bar.event.title}
|
|
268
|
+
</button>
|
|
269
|
+
))}
|
|
270
|
+
</div>
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The day-of-week header row above the grid.
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
export const CalendarDayHeaderUI = memo((p: {
|
|
279
|
+
days: CalendarDayObj[];
|
|
280
|
+
// Pre-formatted per day: the weekday abbreviation and the day number
|
|
281
|
+
dayLabels: Array<{ weekday: string; dayNumber: string }>;
|
|
282
|
+
onSelectDay?: (dateKey: string) => void;
|
|
283
|
+
}) => {
|
|
284
|
+
const { days, dayLabels, onSelectDay } = p;
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<div
|
|
288
|
+
className='no_shrink h_stretch bd_b_1 bd_b_bd'
|
|
289
|
+
style={{ marginLeft: CALENDAR_GUTTER_WIDTH }}
|
|
290
|
+
>
|
|
291
|
+
{days.map((day, index) => (
|
|
292
|
+
<button
|
|
293
|
+
key={day.dateKey}
|
|
294
|
+
type='button'
|
|
295
|
+
className={cn('f a_c', day.isWeekend ? 'bg_alt' : '')}
|
|
296
|
+
style={{ paddingTop: 4, paddingBottom: 4 }}
|
|
297
|
+
disabled={!onSelectDay}
|
|
298
|
+
onClick={onSelectDay ? () => onSelectDay(day.dateKey) : undefined}
|
|
299
|
+
>
|
|
300
|
+
<span className='ellip ft_tn cl_lt'>{dayLabels[index]?.weekday}</span>
|
|
301
|
+
<span className={cn('ellip ft_sm', day.isToday ? 'ft_bold' : 'cl_md')}>
|
|
302
|
+
{dayLabels[index]?.dayNumber}
|
|
303
|
+
</span>
|
|
304
|
+
</button>
|
|
305
|
+
))}
|
|
306
|
+
</div>
|
|
307
|
+
);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* The ghost block shown while a range is being drawn, moved, or resized.
|
|
312
|
+
*
|
|
313
|
+
* Deliberately not an event: it carries no id, cannot be clicked, and is not
|
|
314
|
+
* part of the overlap layout, because it is a preview of an intention rather
|
|
315
|
+
* than something that exists yet.
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
export const CalendarDraftBlockUI = memo((p: {
|
|
319
|
+
startMinute: number;
|
|
320
|
+
endMinute: number;
|
|
321
|
+
hourHeight: number;
|
|
322
|
+
label: string;
|
|
323
|
+
}) => {
|
|
324
|
+
const { startMinute, endMinute, hourHeight, label } = p;
|
|
325
|
+
|
|
326
|
+
const top = (startMinute / 60) * hourHeight;
|
|
327
|
+
const height = Math.max(((endMinute - startMinute) / 60) * hourHeight, 16);
|
|
328
|
+
|
|
329
|
+
return (
|
|
330
|
+
<div
|
|
331
|
+
className='abs of a_l r_xs bd_1 bd_bd bg_active z4'
|
|
332
|
+
style={{
|
|
333
|
+
top,
|
|
334
|
+
height,
|
|
335
|
+
left: 0,
|
|
336
|
+
width: 'calc(100% - 2px)',
|
|
337
|
+
paddingLeft: 4,
|
|
338
|
+
paddingRight: 4,
|
|
339
|
+
opacity: 0.8,
|
|
340
|
+
// The ghost must never eat the pointer stream that is drawing it
|
|
341
|
+
pointerEvents: 'none',
|
|
342
|
+
}}
|
|
343
|
+
>
|
|
344
|
+
<span className='ellip ft_tn ft_bold'>{label}</span>
|
|
345
|
+
</div>
|
|
346
|
+
);
|
|
347
|
+
});
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { Icon } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
+
import { ToggleSwitch } from '@jsb188/react-web/ui/Form';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The violation strip.
|
|
8
|
+
*
|
|
9
|
+
* Lists what the constraint engine found wrong with the window currently on
|
|
10
|
+
* screen. Three decisions shape it:
|
|
11
|
+
*
|
|
12
|
+
* - **The wording is the server's, not ours.** Each violation arrives with a
|
|
13
|
+
* `message` already rendered from this organization's rule-template
|
|
14
|
+
* registry, so a daycare reads "Room 3 needs another teacher" and a farm
|
|
15
|
+
* reads something else for the very same rule kind. `message` is null only
|
|
16
|
+
* when nothing is registered, and the caller's generic copy fills in.
|
|
17
|
+
*
|
|
18
|
+
* - **BLOCK and WARN are never the same shape.** A BLOCK stops the publish
|
|
19
|
+
* outright, so it gets the error colour, a filled icon and a red accent
|
|
20
|
+
* bar; a WARN is amber and outlined. Somebody scanning this strip has to be
|
|
21
|
+
* able to tell "I cannot ship this" from "I can ship this if I say so"
|
|
22
|
+
* without reading a word.
|
|
23
|
+
*
|
|
24
|
+
* - **Only WARNs can be acknowledged**, and only when the caller passes a
|
|
25
|
+
* handler — a viewer without publish rights gets the list with no toggles
|
|
26
|
+
* rather than toggles that fail.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* One breach, as the strip draws it.
|
|
31
|
+
*
|
|
32
|
+
* NOTE: `detail` is delivered by the API as a JSON *string* and must already
|
|
33
|
+
* have been JSON.parsed by the caller. It is carried here only so a click
|
|
34
|
+
* handler can act on it — nothing in this component reads it, because any copy
|
|
35
|
+
* derived from it would be copy living inside this package.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export interface CalendarViolationObj {
|
|
39
|
+
// Stable server-side identity; the key for selection and acknowledgement
|
|
40
|
+
key: string;
|
|
41
|
+
ruleId: string | null;
|
|
42
|
+
templateKey: string | null;
|
|
43
|
+
// One of SCHEDULE_RULE_SEVERITY_ENUMS: BLOCK | WARN
|
|
44
|
+
severity: string;
|
|
45
|
+
// One of SCHEDULE_RULE_KIND_ENUMS
|
|
46
|
+
kind: string;
|
|
47
|
+
// Rendered by the server; null when the org has no template for the kind
|
|
48
|
+
message: string | null;
|
|
49
|
+
resourceId: string | null;
|
|
50
|
+
occurrenceId: string | null;
|
|
51
|
+
actorAccountId: string | null;
|
|
52
|
+
segmentStart: Date;
|
|
53
|
+
segmentEnd: Date;
|
|
54
|
+
detail: Record<string, unknown> | null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface CalendarViolationUIProps {
|
|
58
|
+
violations: CalendarViolationObj[];
|
|
59
|
+
// Generic copy per rule kind, used when the server sent no message
|
|
60
|
+
fallbackMessageByKind: Record<string, string>;
|
|
61
|
+
// Last resort, when the kind is not in the map either
|
|
62
|
+
fallbackMessageText: string;
|
|
63
|
+
// Severity badges, e.g. "Blocking" and "Warning"
|
|
64
|
+
blockText: string;
|
|
65
|
+
warnText: string;
|
|
66
|
+
// Header line; the caller has already counted and localized it
|
|
67
|
+
summaryText: string;
|
|
68
|
+
// Sits beside the summary, e.g. "2 blocking issues must be fixed to publish"
|
|
69
|
+
blockingHintText?: string | null;
|
|
70
|
+
acknowledgeText: string;
|
|
71
|
+
emptyText: string;
|
|
72
|
+
// Formatted time range per violation key, e.g. "Wed 8:00 – 10:00 AM"
|
|
73
|
+
timeRangeByKey: Map<string, string>;
|
|
74
|
+
// Optional second line of context per key: resource name, shortfall counts,
|
|
75
|
+
// whatever the caller composed from `detail`
|
|
76
|
+
contextTextByKey?: Map<string, string> | null;
|
|
77
|
+
acknowledgedKeys?: Set<string> | null;
|
|
78
|
+
selectedKey?: string | null;
|
|
79
|
+
// How tall the list may grow before it scrolls; the strip is a footer, and
|
|
80
|
+
// a long list of warnings must not eat the calendar above it
|
|
81
|
+
maxListHeight?: number;
|
|
82
|
+
onSelect?: (key: string) => void;
|
|
83
|
+
// Absent means acknowledgement is not offered to this viewer at all
|
|
84
|
+
onAcknowledge?: (key: string, nextValue: boolean) => void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const CalendarViolationUI = memo((p: CalendarViolationUIProps) => {
|
|
88
|
+
const {
|
|
89
|
+
violations,
|
|
90
|
+
fallbackMessageByKind,
|
|
91
|
+
fallbackMessageText,
|
|
92
|
+
blockText,
|
|
93
|
+
warnText,
|
|
94
|
+
summaryText,
|
|
95
|
+
blockingHintText,
|
|
96
|
+
acknowledgeText,
|
|
97
|
+
emptyText,
|
|
98
|
+
timeRangeByKey,
|
|
99
|
+
contextTextByKey,
|
|
100
|
+
acknowledgedKeys,
|
|
101
|
+
selectedKey,
|
|
102
|
+
maxListHeight = 168,
|
|
103
|
+
onSelect,
|
|
104
|
+
onAcknowledge,
|
|
105
|
+
} = p;
|
|
106
|
+
|
|
107
|
+
if (!violations.length) {
|
|
108
|
+
// A clean window is worth stating: an empty strip would read as a
|
|
109
|
+
// surface that failed to load rather than a schedule that is fine
|
|
110
|
+
return (
|
|
111
|
+
<div className='no_shrink a_c bd_t_1 bd_t_bd' style={{ paddingTop: 6, paddingBottom: 6 }}>
|
|
112
|
+
<span className='ft_tn cl_lt'>{emptyText}</span>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<div className='no_shrink v_stretch bd_t_1 bd_t_bd'>
|
|
119
|
+
<div
|
|
120
|
+
className='no_shrink h_spread gap_sm'
|
|
121
|
+
style={{ paddingLeft: 12, paddingRight: 12, paddingTop: 6, paddingBottom: 4 }}
|
|
122
|
+
>
|
|
123
|
+
<span className='f ellip ft_tn ft_bold'>{summaryText}</span>
|
|
124
|
+
|
|
125
|
+
{blockingHintText ? <span className='no_shrink ft_tn cl_err'>{blockingHintText}</span> : null}
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<div className='app_scr auto_y' style={{ maxHeight: maxListHeight }}>
|
|
129
|
+
{violations.map((violation) => {
|
|
130
|
+
const isBlock = violation.severity === 'BLOCK';
|
|
131
|
+
const isAcknowledged = !!acknowledgedKeys?.has(violation.key);
|
|
132
|
+
const contextText = contextTextByKey?.get(violation.key);
|
|
133
|
+
|
|
134
|
+
// The server's wording first, then the caller's per-kind
|
|
135
|
+
// copy, then one generic sentence — never an empty row
|
|
136
|
+
const messageText = violation.message
|
|
137
|
+
|| fallbackMessageByKind[violation.kind]
|
|
138
|
+
|| fallbackMessageText;
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<div
|
|
142
|
+
key={violation.key}
|
|
143
|
+
className={cn(
|
|
144
|
+
'h_item gap_sm bd_l_4',
|
|
145
|
+
isBlock ? 'bg_red_alt_lt bd_red_md' : 'bg_amber_alt_lt bd_amber_md',
|
|
146
|
+
selectedKey === violation.key ? 'ol_primary' : '',
|
|
147
|
+
)}
|
|
148
|
+
style={{ paddingRight: 12, marginBottom: 1 }}
|
|
149
|
+
>
|
|
150
|
+
<button
|
|
151
|
+
type='button'
|
|
152
|
+
className='f a_l h_item gap_sm'
|
|
153
|
+
style={{ paddingLeft: 8, paddingTop: 5, paddingBottom: 5 }}
|
|
154
|
+
onClick={onSelect ? () => onSelect(violation.key) : undefined}
|
|
155
|
+
>
|
|
156
|
+
<span className={cn('no_shrink h_center', isBlock ? 'cl_err' : 'cl_warn')}>
|
|
157
|
+
<Icon
|
|
158
|
+
name={isBlock ? 'alert-circle-filled' : 'alert-circle'}
|
|
159
|
+
height={15}
|
|
160
|
+
width={15}
|
|
161
|
+
/>
|
|
162
|
+
</span>
|
|
163
|
+
|
|
164
|
+
<span className='f v_stretch of'>
|
|
165
|
+
<span
|
|
166
|
+
className={cn(
|
|
167
|
+
'ellip ft_tn',
|
|
168
|
+
// An acknowledged warning stays listed but stops
|
|
169
|
+
// competing for attention with live ones
|
|
170
|
+
isAcknowledged ? 'cl_lt strikethrough' : '',
|
|
171
|
+
)}
|
|
172
|
+
>
|
|
173
|
+
{messageText}
|
|
174
|
+
</span>
|
|
175
|
+
|
|
176
|
+
<span className='ellip ft_tn cl_lt'>
|
|
177
|
+
{timeRangeByKey.get(violation.key) || ''}
|
|
178
|
+
{contextText ? <span> · {contextText}</span> : null}
|
|
179
|
+
</span>
|
|
180
|
+
</span>
|
|
181
|
+
|
|
182
|
+
<span className={cn('no_shrink ft_tn ft_bold', isBlock ? 'cl_err' : 'cl_warn')}>
|
|
183
|
+
{isBlock ? blockText : warnText}
|
|
184
|
+
</span>
|
|
185
|
+
</button>
|
|
186
|
+
|
|
187
|
+
{/* A BLOCK is never acknowledgeable — the whole point of the
|
|
188
|
+
severity is that no amount of agreeing lets it publish */}
|
|
189
|
+
{!isBlock && onAcknowledge
|
|
190
|
+
? (
|
|
191
|
+
<label className='no_shrink h_item gap_sm pointer unsel'>
|
|
192
|
+
<ToggleSwitch
|
|
193
|
+
size='xs'
|
|
194
|
+
checked={isAcknowledged}
|
|
195
|
+
onChange={(event) => onAcknowledge(violation.key, event.currentTarget.checked)}
|
|
196
|
+
/>
|
|
197
|
+
<span className='ft_tn cl_md'>{acknowledgeText}</span>
|
|
198
|
+
</label>
|
|
199
|
+
)
|
|
200
|
+
: null}
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
})}
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
);
|
|
207
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
2
|
+
import { memo } from 'react';
|
|
3
|
+
import type { CalendarDayObj } from '../types/calendar.d.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The year view: twelve mini month grids.
|
|
7
|
+
*
|
|
8
|
+
* This is a NAVIGATION surface, not a display one. It deliberately draws no
|
|
9
|
+
* events — a year of shifts is far more than any window query should return,
|
|
10
|
+
* and a grid built from a truncated list would quietly show empty days that
|
|
11
|
+
* are not empty. Clicking a day jumps into it, which is what a year view is
|
|
12
|
+
* actually for.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface CalendarYearMonthObj {
|
|
16
|
+
// Localized month name
|
|
17
|
+
label: string;
|
|
18
|
+
// Leading blanks before the first day, so the 1st lands under its weekday
|
|
19
|
+
leadingBlankCount: number;
|
|
20
|
+
days: CalendarDayObj[];
|
|
21
|
+
dayNumberLabels: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CalendarYearUIProps {
|
|
25
|
+
months: CalendarYearMonthObj[];
|
|
26
|
+
// Single-letter weekday initials for each mini grid's header
|
|
27
|
+
weekdayInitials: string[];
|
|
28
|
+
onSelectDay: (dateKey: string) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const CalendarYearUI = memo((p: CalendarYearUIProps) => {
|
|
32
|
+
const { months, weekdayInitials, onSelectDay } = p;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div className='f h_0 app_scr auto_y'>
|
|
36
|
+
<div
|
|
37
|
+
style={{
|
|
38
|
+
display: 'grid',
|
|
39
|
+
// Three across on a laptop, collapsing to one on a phone,
|
|
40
|
+
// without a media query or a new class
|
|
41
|
+
gridTemplateColumns: 'repeat(auto-fill, minmax(200px, 1fr))',
|
|
42
|
+
gap: 16,
|
|
43
|
+
padding: 16,
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{months.map((month) => (
|
|
47
|
+
<div key={month.label}>
|
|
48
|
+
<div className='ft_sm ft_bold cl_md' style={{ marginBottom: 4 }}>
|
|
49
|
+
{month.label}
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(7, minmax(0, 1fr))' }}>
|
|
53
|
+
{weekdayInitials.map((initial, index) => (
|
|
54
|
+
<div key={index} className='a_c ft_tn cl_lt'>
|
|
55
|
+
{initial}
|
|
56
|
+
</div>
|
|
57
|
+
))}
|
|
58
|
+
|
|
59
|
+
{Array.from({ length: month.leadingBlankCount }, (_unused, index) => <div key={`blank${index}`} />)}
|
|
60
|
+
|
|
61
|
+
{month.days.map((day, index) => (
|
|
62
|
+
<button
|
|
63
|
+
key={day.dateKey}
|
|
64
|
+
type='button'
|
|
65
|
+
className={cn(
|
|
66
|
+
'a_c ft_tn r_xs',
|
|
67
|
+
day.isToday ? 'ft_bold bg_active' : 'cl_md',
|
|
68
|
+
)}
|
|
69
|
+
style={{ paddingTop: 2, paddingBottom: 2 }}
|
|
70
|
+
onClick={() => onSelectDay(day.dateKey)}
|
|
71
|
+
>
|
|
72
|
+
{month.dayNumberLabels[index]}
|
|
73
|
+
</button>
|
|
74
|
+
))}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
))}
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
});
|