@jsb188/calendar 1.1.11 → 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.
@@ -1,242 +0,0 @@
1
- import { cn } from '@jsb188/app/utils/string.ts';
2
- import { memo } from 'react';
3
- import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
4
-
5
- /**
6
- * The coverage board.
7
- *
8
- * A manager staffing a week does not want a list of shifts, they want the one
9
- * question answered everywhere at once: where am I short? So this is a matrix
10
- * — resources down, time buckets across — and every cell says the same two
11
- * numbers, "how many are on" over "how many are needed".
12
- *
13
- * Three things it deliberately does NOT do:
14
- *
15
- * - **It does not compute anything.** Buckets, counts, shortfalls, severities
16
- * and every label arrive as props. The same board draws an hour-by-hour day
17
- * and a day-by-day month purely by being handed different buckets.
18
- *
19
- * - **It does not hide a fully-staffed cell.** A blank grid with a few red
20
- * squares reads as "loading"; a full grid with a few red squares reads as
21
- * "checked, and here is the problem".
22
- *
23
- * - **It does not fold draft into published.** Unpublished coverage is drawn
24
- * with the same stripe pattern the grid uses for draft entries, so nobody
25
- * counts staff who have not actually been told they are working.
26
- */
27
-
28
- /**
29
- * One column: a slice of the visible window.
30
- */
31
-
32
- export interface CalendarCoverageBucketObj {
33
- key: string;
34
- // Localized column heading, e.g. "8a" or "Mon"
35
- label: string;
36
- // Optional second heading line, e.g. the date under the weekday
37
- subLabel?: string | null;
38
- // Outside the operating window — drawn dimmer, because being "short" in a
39
- // bucket nobody operates in is not a fact worth alarming anyone with
40
- isMuted?: boolean;
41
- }
42
-
43
- /**
44
- * One resource × one bucket.
45
- */
46
-
47
- export interface CalendarCoverageCellObj {
48
- key: string;
49
- bucketKey: string;
50
- required: number;
51
- actual: number;
52
- // Nothing at all is scheduled here; drawn blank rather than as "0/0"
53
- isEmpty?: boolean;
54
- // Every occurrence behind this cell is still unpublished
55
- isDraft?: boolean;
56
- // The violation strip's entry this cell belongs to, when there is one
57
- violationKey?: string | null;
58
- // BLOCK | WARN | null — decides red versus amber when the cell is short
59
- severity?: string | null;
60
- }
61
-
62
- /**
63
- * One row: a room, a position, a vehicle — whatever this calendar staffs.
64
- */
65
-
66
- export interface CalendarCoverageRowObj {
67
- resourceId: string;
68
- name: string;
69
- // Optional second line under the name, e.g. a location or a capacity
70
- subName?: string | null;
71
- // Aligned index-for-index with `buckets`
72
- cells: CalendarCoverageCellObj[];
73
- }
74
-
75
- export interface CalendarCoverageUIProps {
76
- rows: CalendarCoverageRowObj[];
77
- buckets: CalendarCoverageBucketObj[];
78
- // Heading of the left-hand column, e.g. "Resource"
79
- resourceHeaderText: string;
80
- emptyText: string;
81
- // Formats a cell, e.g. "2/3". The package holds no copy, so even the
82
- // separator is the caller's decision
83
- countText: (actual: number, required: number) => string;
84
- // Geometry, in px. The caller sizes the board to its container and to how
85
- // many buckets the window produced
86
- resourceColumnWidth?: number;
87
- bucketWidth?: number;
88
- rowHeight?: number;
89
- // Highlights every cell belonging to the violation the strip has selected
90
- selectedViolationKey?: string | null;
91
- onSelectCell?: (resourceId: string, cell: CalendarCoverageCellObj) => void;
92
- }
93
-
94
- export const CalendarCoverageUI = memo((p: CalendarCoverageUIProps) => {
95
- const {
96
- rows,
97
- buckets,
98
- resourceHeaderText,
99
- emptyText,
100
- countText,
101
- resourceColumnWidth = 168,
102
- bucketWidth = 56,
103
- rowHeight = 34,
104
- selectedViolationKey,
105
- onSelectCell,
106
- } = p;
107
-
108
- if (!rows.length || !buckets.length) {
109
- return (
110
- <div className="f h_0 v_center a_c">
111
- <span className="ft_sm cl_lt">{emptyText}</span>
112
- </div>
113
- );
114
- }
115
-
116
- // The board is wider than its container by design; the scroller needs a
117
- // real width to scroll to, and both sticky edges hang off it
118
- const boardWidth = resourceColumnWidth + buckets.length * bucketWidth;
119
-
120
- return (
121
- <div className="f h_0 w_f app_scr of_x auto_x auto_y">
122
- <div className="v_stretch" style={{ width: boardWidth }}>
123
- <div
124
- className="no_shrink h_item sticky bg bd_b_1 bd_b_bd"
125
- style={{ top: 0, zIndex: 30 }}
126
- >
127
- <div
128
- className="no_shrink v_stretch sticky bg ellip bd_r_1 bd_r_bd"
129
- style={{
130
- left: 0,
131
- width: resourceColumnWidth,
132
- zIndex: 20,
133
- paddingLeft: 8,
134
- }}
135
- >
136
- <span className="ellip ft_tn cl_lt">{resourceHeaderText}</span>
137
- </div>
138
-
139
- {buckets.map((bucket) => (
140
- <div
141
- key={bucket.key}
142
- className={cn(
143
- 'no_shrink v_stretch a_c of',
144
- bucket.isMuted ? 'bg_alt' : '',
145
- )}
146
- style={{ width: bucketWidth, paddingTop: 3, paddingBottom: 3 }}
147
- >
148
- <span
149
- className={cn(
150
- 'ellip ft_tn',
151
- bucket.isMuted ? 'cl_lt' : 'cl_md',
152
- )}
153
- >
154
- {bucket.label}
155
- </span>
156
-
157
- {bucket.subLabel ? (
158
- <span className="ellip ft_tn cl_lt">{bucket.subLabel}</span>
159
- ) : null}
160
- </div>
161
- ))}
162
- </div>
163
-
164
- {rows.map((row) => (
165
- <div
166
- key={row.resourceId}
167
- className="no_shrink h_item bd_b_1 bd_b_bd"
168
- style={{ height: rowHeight }}
169
- >
170
- <div
171
- className="no_shrink v_center h_f sticky bg of bd_r_1 bd_r_bd"
172
- style={{
173
- left: 0,
174
- width: resourceColumnWidth,
175
- zIndex: 20,
176
- paddingLeft: 8,
177
- paddingRight: 6,
178
- }}
179
- >
180
- <span className="w_f ellip ft_tn">{row.name}</span>
181
-
182
- {row.subName ? (
183
- <span className="w_f ellip ft_tn cl_lt">{row.subName}</span>
184
- ) : null}
185
- </div>
186
-
187
- {row.cells.map((cell) => {
188
- // Short is short whatever the engine called it; the
189
- // severity only decides how loudly it is said
190
- const isShort = !cell.isEmpty && cell.actual < cell.required;
191
- const isBlocking = isShort && cell.severity === 'BLOCK';
192
- const isSelected =
193
- !!selectedViolationKey &&
194
- cell.violationKey === selectedViolationKey;
195
-
196
- return (
197
- <button
198
- key={cell.key}
199
- type="button"
200
- className={cn(
201
- 'no_shrink h_center h_f rel bd_l_1 bd_l_bd',
202
- isBlocking
203
- ? 'bg_red_alt_lt'
204
- : isShort
205
- ? 'bg_amber_alt_lt'
206
- : '',
207
- // The stripe needs a relative parent and a colour
208
- // for its overlay; `medium_bf` is the neutral one
209
- cell.isDraft
210
- ? `${CALENDAR_DRAFT_PATTERN_CLASS_NAME} medium_bf`
211
- : '',
212
- isSelected ? 'ol_primary' : '',
213
- )}
214
- style={{ width: bucketWidth }}
215
- onClick={
216
- onSelectCell
217
- ? () => onSelectCell(row.resourceId, cell)
218
- : undefined
219
- }
220
- >
221
- {/* Positioned so it paints above the stripe overlay */}
222
- <span
223
- className={cn(
224
- 'rel ellip ft_tn',
225
- isBlocking
226
- ? 'cl_err ft_bold'
227
- : isShort
228
- ? 'cl_warn ft_bold'
229
- : 'cl_md',
230
- )}
231
- >
232
- {cell.isEmpty ? '' : countText(cell.actual, cell.required)}
233
- </span>
234
- </button>
235
- );
236
- })}
237
- </div>
238
- ))}
239
- </div>
240
- </div>
241
- );
242
- });
@@ -1,265 +0,0 @@
1
- import { cn } from '@jsb188/app/utils/string.ts';
2
- import { AvatarImg } from '@jsb188/react-web/ui/Avatar';
3
- import { Button, SimpleLabel } from '@jsb188/react-web/ui/Button';
4
- import { Icon } from '@jsb188/react-web/svgs/Icon';
5
- import { memo } from 'react';
6
- import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
7
-
8
- /**
9
- * The bubble that opens when one occurrence is selected.
10
- *
11
- * Everything arrives already formatted — no Date, no zone, no plural rules
12
- * cross this boundary. The grid and this bubble must agree about what "9:00 AM
13
- * – 5:00 PM" means, and the only way to guarantee that is for one place to do
14
- * the formatting and both to render the same string.
15
- *
16
- * Actions are opt-in: a button appears only when its handler was passed. That
17
- * is what lets the same bubble serve a manager (edit, cancel, delete) and a
18
- * worker (give away this shift) without either of them being handed a control
19
- * that would fail on the server.
20
- */
21
-
22
- export interface CalendarEventDetailUIProps {
23
- className?: string;
24
- title: string;
25
- // e.g. "Wed, Jul 22 · 9:00 AM – 5:00 PM", or the all-day wording
26
- timeRangeText: string;
27
- // DRAFT | PUBLISHED | CANCELED — drives the strike-through and the stripes
28
- status: string;
29
- statusText: string;
30
- // A ColorEnum name; SimpleLabel only honors this on its outline preset
31
- statusColor?: string | null;
32
- location?: string | null;
33
- note?: string | null;
34
- // Display names, already resolved from the assignee account ids
35
- assigneeNames: string[];
36
- // Rendered only when there are open slots left, e.g. "2 spots open"
37
- openCountText?: string | null;
38
- closeText: string;
39
- editText: string;
40
- cancelOccurrenceText: string;
41
- deleteText: string;
42
- releaseText: string;
43
- // Surfaced under the actions when the last mutation failed
44
- errorText?: string | null;
45
- // Disables every action while a mutation is in flight
46
- busy?: boolean;
47
- onEdit?: () => void;
48
- onCancelOccurrence?: () => void;
49
- onDelete?: () => void;
50
- // "Give away this shift" — opens a release request rather than unassigning
51
- onRelease?: () => void;
52
- onClose: () => void;
53
- }
54
-
55
- /**
56
- * One labelled line inside the bubble: an icon in a fixed gutter, the value
57
- * beside it. The caller decides whether a row exists at all, so an occurrence
58
- * with no location leaves no empty line behind.
59
- */
60
-
61
- function CalendarEventDetailRow(p: {
62
- iconName: string;
63
- children: React.ReactNode;
64
- }) {
65
- const { iconName, children } = p;
66
-
67
- return (
68
- <div className="h_item gap_sm" style={{ paddingTop: 3, paddingBottom: 3 }}>
69
- <span className="no_shrink cl_lt h_center" style={{ width: 18 }}>
70
- <Icon name={iconName} />
71
- </span>
72
-
73
- <span className="f ft_sm cl_df">{children}</span>
74
- </div>
75
- );
76
- }
77
-
78
- export const CalendarEventDetailUI = memo((p: CalendarEventDetailUIProps) => {
79
- const {
80
- className,
81
- title,
82
- timeRangeText,
83
- status,
84
- statusText,
85
- statusColor,
86
- location,
87
- note,
88
- assigneeNames,
89
- openCountText,
90
- closeText,
91
- editText,
92
- cancelOccurrenceText,
93
- deleteText,
94
- releaseText,
95
- errorText,
96
- busy,
97
- onEdit,
98
- onCancelOccurrence,
99
- onDelete,
100
- onRelease,
101
- onClose,
102
- } = p;
103
-
104
- const hasActions = !!(onEdit || onCancelOccurrence || onDelete || onRelease);
105
-
106
- return (
107
- <div className={cn('bg bd_1 bd_bd r_df of', className)}>
108
- <div
109
- className="h_item gap_sm bd_b_1 bd_b_bd"
110
- style={{
111
- paddingLeft: 12,
112
- paddingRight: 8,
113
- paddingTop: 8,
114
- paddingBottom: 8,
115
- }}
116
- >
117
- <span
118
- className={cn(
119
- 'f ft_md ft_bold ellip',
120
- status === 'CANCELED' ? 'strikethrough cl_lt' : '',
121
- )}
122
- >
123
- {title}
124
- </span>
125
-
126
- <SimpleLabel
127
- className="no_shrink"
128
- preset="outline"
129
- color={statusColor || 'medium'}
130
- text={statusText}
131
- />
132
-
133
- {/* No IconButton exists in the kit, so this is the documented raw
134
- pattern: a bare button wrapping an Icon */}
135
- <button
136
- type="button"
137
- className="av_sm h_center no_shrink cl_lt"
138
- aria-label={closeText}
139
- title={closeText}
140
- onClick={onClose}
141
- >
142
- <Icon name="x" />
143
- </button>
144
- </div>
145
-
146
- <div
147
- style={{
148
- paddingLeft: 12,
149
- paddingRight: 12,
150
- paddingTop: 8,
151
- paddingBottom: 8,
152
- }}
153
- >
154
- <CalendarEventDetailRow iconName="clock-hour-4">
155
- <span
156
- className={cn(
157
- status === 'DRAFT' ? CALENDAR_DRAFT_PATTERN_CLASS_NAME : '',
158
- )}
159
- >
160
- {timeRangeText}
161
- </span>
162
- </CalendarEventDetailRow>
163
-
164
- {location ? (
165
- <CalendarEventDetailRow iconName="pin-location-1">
166
- {location}
167
- </CalendarEventDetailRow>
168
- ) : null}
169
-
170
- {assigneeNames.length ? (
171
- <CalendarEventDetailRow iconName="multiple-neutral-circle">
172
- {/* Wrapping is structural here: the chip count is data, so the
173
- row has to be able to run onto a second line */}
174
- <span className="h_item gap_sm" style={{ flexWrap: 'wrap' }}>
175
- {assigneeNames.map((name) => (
176
- <span key={name} className="h_item gap_xs no_shrink">
177
- <AvatarImg size="tiny" displayName={name} />
178
- <span className="ellip">{name}</span>
179
- </span>
180
- ))}
181
- </span>
182
- </CalendarEventDetailRow>
183
- ) : null}
184
-
185
- {openCountText ? (
186
- <CalendarEventDetailRow iconName="single-neutral-actions-add">
187
- <span className="cl_md">{openCountText}</span>
188
- </CalendarEventDetailRow>
189
- ) : null}
190
-
191
- {note ? (
192
- <CalendarEventDetailRow iconName="notes-paper-text">
193
- <span className="cl_md">{note}</span>
194
- </CalendarEventDetailRow>
195
- ) : null}
196
- </div>
197
-
198
- {errorText ? (
199
- <div
200
- className="ft_xs cl_err"
201
- style={{ paddingLeft: 12, paddingRight: 12, paddingBottom: 8 }}
202
- >
203
- {errorText}
204
- </div>
205
- ) : null}
206
-
207
- {hasActions ? (
208
- <div
209
- className="h_item gap_sm bd_t_1 bd_t_bd"
210
- style={{
211
- paddingLeft: 8,
212
- paddingRight: 8,
213
- paddingTop: 8,
214
- paddingBottom: 8,
215
- flexWrap: 'wrap',
216
- }}
217
- >
218
- {onEdit ? (
219
- <Button
220
- preset="bg_secondary"
221
- size="sm"
222
- disabled={busy}
223
- leftIconName="pencil-write-2"
224
- text={editText}
225
- onClick={onEdit}
226
- />
227
- ) : null}
228
-
229
- {onRelease ? (
230
- <Button
231
- preset="bg"
232
- size="sm"
233
- disabled={busy}
234
- leftIconName="switch-account-1"
235
- text={releaseText}
236
- onClick={onRelease}
237
- />
238
- ) : null}
239
-
240
- {onCancelOccurrence ? (
241
- <Button
242
- preset="outline_subtle"
243
- size="sm"
244
- disabled={busy}
245
- leftIconName="cancel"
246
- text={cancelOccurrenceText}
247
- onClick={onCancelOccurrence}
248
- />
249
- ) : null}
250
-
251
- {onDelete ? (
252
- <Button
253
- preset="cl_err"
254
- size="sm"
255
- disabled={busy}
256
- leftIconName="bin"
257
- text={deleteText}
258
- onClick={onDelete}
259
- />
260
- ) : null}
261
- </div>
262
- ) : null}
263
- </div>
264
- );
265
- });