@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.
@@ -1,230 +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
112
- className="no_shrink a_c bd_t_1 bd_t_bd"
113
- style={{ paddingTop: 6, paddingBottom: 6 }}
114
- >
115
- <span className="ft_tn cl_lt">{emptyText}</span>
116
- </div>
117
- );
118
- }
119
-
120
- return (
121
- <div className="no_shrink v_stretch bd_t_1 bd_t_bd">
122
- <div
123
- className="no_shrink h_spread gap_sm"
124
- style={{
125
- paddingLeft: 12,
126
- paddingRight: 12,
127
- paddingTop: 6,
128
- paddingBottom: 4,
129
- }}
130
- >
131
- <span className="f ellip ft_tn ft_bold">{summaryText}</span>
132
-
133
- {blockingHintText ? (
134
- <span className="no_shrink ft_tn cl_err">{blockingHintText}</span>
135
- ) : null}
136
- </div>
137
-
138
- <div className="app_scr auto_y" style={{ maxHeight: maxListHeight }}>
139
- {violations.map((violation) => {
140
- const isBlock = violation.severity === 'BLOCK';
141
- const isAcknowledged = !!acknowledgedKeys?.has(violation.key);
142
- const contextText = contextTextByKey?.get(violation.key);
143
-
144
- // The server's wording first, then the caller's per-kind
145
- // copy, then one generic sentence — never an empty row
146
- const messageText =
147
- violation.message ||
148
- fallbackMessageByKind[violation.kind] ||
149
- fallbackMessageText;
150
-
151
- return (
152
- <div
153
- key={violation.key}
154
- className={cn(
155
- 'h_item gap_sm bd_l_4',
156
- isBlock
157
- ? 'bg_red_alt_lt bd_red_md'
158
- : 'bg_amber_alt_lt bd_amber_md',
159
- selectedKey === violation.key ? 'ol_primary' : '',
160
- )}
161
- style={{ paddingRight: 12, marginBottom: 1 }}
162
- >
163
- <button
164
- type="button"
165
- className="f a_l h_item gap_sm"
166
- style={{ paddingLeft: 8, paddingTop: 5, paddingBottom: 5 }}
167
- onClick={onSelect ? () => onSelect(violation.key) : undefined}
168
- >
169
- <span
170
- className={cn(
171
- 'no_shrink h_center',
172
- isBlock ? 'cl_err' : 'cl_warn',
173
- )}
174
- >
175
- <Icon
176
- name={isBlock ? 'alert-circle-filled' : 'alert-circle'}
177
- height={15}
178
- width={15}
179
- />
180
- </span>
181
-
182
- <span className="f v_stretch of">
183
- <span
184
- className={cn(
185
- 'ellip ft_tn',
186
- // An acknowledged warning stays listed but stops
187
- // competing for attention with live ones
188
- isAcknowledged ? 'cl_lt strikethrough' : '',
189
- )}
190
- >
191
- {messageText}
192
- </span>
193
-
194
- <span className="ellip ft_tn cl_lt">
195
- {timeRangeByKey.get(violation.key) || ''}
196
- {contextText ? <span> · {contextText}</span> : null}
197
- </span>
198
- </span>
199
-
200
- <span
201
- className={cn(
202
- 'no_shrink ft_tn ft_bold',
203
- isBlock ? 'cl_err' : 'cl_warn',
204
- )}
205
- >
206
- {isBlock ? blockText : warnText}
207
- </span>
208
- </button>
209
-
210
- {/* A BLOCK is never acknowledgeable — the whole point of the
211
- severity is that no amount of agreeing lets it publish */}
212
- {!isBlock && onAcknowledge ? (
213
- <label className="no_shrink h_item gap_sm pointer unsel">
214
- <ToggleSwitch
215
- size="xs"
216
- checked={isAcknowledged}
217
- onChange={(event) =>
218
- onAcknowledge(violation.key, event.currentTarget.checked)
219
- }
220
- />
221
- <span className="ft_tn cl_md">{acknowledgeText}</span>
222
- </label>
223
- ) : null}
224
- </div>
225
- );
226
- })}
227
- </div>
228
- </div>
229
- );
230
- });