@jsb188/calendar 1.1.10 → 1.1.12
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 +16 -15
- package/src/constants/calendar.ts +17 -3
- package/src/libs/calendar-geometry.ts +165 -91
- package/src/libs/calendar-gesture.ts +58 -15
- package/src/libs/calendar-now.ts +39 -0
- package/src/libs/calendar-range.ts +88 -27
- package/src/libs/calendar-state.ts +21 -156
- package/src/libs/calendar-url.ts +55 -8
- package/src/libs/roster-layout.ts +388 -0
- package/src/main.ts +3 -0
- package/src/modules/Calendar.tsx +375 -287
- package/src/modules/MiniCalendar.tsx +376 -0
- package/src/types/calendar.d.ts +7 -1
- package/src/types/shift-form.d.ts +19 -0
- package/src/ui/CalendarAgendaUI.tsx +43 -14
- package/src/ui/CalendarMonthUI.tsx +38 -26
- package/src/ui/CalendarToolbarUI.tsx +50 -27
- package/src/ui/CalendarUI.tsx +280 -226
- package/src/ui/CalendarYearUI.tsx +36 -50
- package/src/ui/RosterUI.tsx +273 -0
- package/src/ui/ShiftFormUI.tsx +333 -0
- package/tests/calendar-geometry.test.ts +230 -84
- package/tests/calendar-gesture.test.ts +43 -12
- package/tests/calendar-range.test.ts +159 -33
- package/tests/calendar-url.test.ts +77 -12
- package/tests/roster-layout.test.ts +210 -0
- package/src/ui/CalendarCoverageUI.tsx +0 -199
- package/src/ui/CalendarEventDetailUI.tsx +0 -260
- package/src/ui/CalendarEventFormUI.tsx +0 -239
- package/src/ui/CalendarRailUI.tsx +0 -282
- package/src/ui/CalendarRequestUI.tsx +0 -537
- package/src/ui/CalendarViolationUI.tsx +0 -207
|
@@ -1,207 +0,0 @@
|
|
|
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
|
-
});
|