@jsb188/calendar 1.1.12 → 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.
@@ -16,10 +16,12 @@ export interface CalendarToolbarUIProps {
16
16
  compact?: boolean;
17
17
  // The range heading, e.g. "Jul 19 – 25, 2026"
18
18
  title: string;
19
+ // The view picker is shown only when there are two or more views
19
20
  viewOptions: SegmentedControlOption[];
20
21
  selectedView: string;
21
- mineOnly: boolean;
22
- mineOnlyText: string;
22
+ // The "mine only" switch is shown only with onToggleMineOnly
23
+ mineOnly?: boolean;
24
+ mineOnlyText?: string;
23
25
  todayText: string;
24
26
  previousText: string;
25
27
  nextText: string;
@@ -28,7 +30,7 @@ export interface CalendarToolbarUIProps {
28
30
  onSelectView: (value: string) => void;
29
31
  onStep: (direction: 1 | -1) => void;
30
32
  onToday: () => void;
31
- onToggleMineOnly: (nextValue: boolean) => void;
33
+ onToggleMineOnly?: (nextValue: boolean) => void;
32
34
  }
33
35
 
34
36
  export const CalendarToolbarUI = memo((p: CalendarToolbarUIProps) => {
@@ -89,16 +91,18 @@ export const CalendarToolbarUI = memo((p: CalendarToolbarUIProps) => {
89
91
 
90
92
  <span className="f ellip ft_md ft_bold">{title}</span>
91
93
 
92
- <label className="h_item gap_sm pointer unsel no_shrink">
93
- <ToggleSwitch
94
- size="sm"
95
- checked={mineOnly}
96
- onChange={(event) => onToggleMineOnly(event.currentTarget.checked)}
97
- />
98
- <span className="ft_xxs cl_md">{mineOnlyText}</span>
99
- </label>
94
+ {onToggleMineOnly ? (
95
+ <label className="h_item gap_sm pointer unsel no_shrink">
96
+ <ToggleSwitch
97
+ size="sm"
98
+ checked={!!mineOnly}
99
+ onChange={(event) => onToggleMineOnly(event.currentTarget.checked)}
100
+ />
101
+ <span className="ft_xxs cl_md">{mineOnlyText}</span>
102
+ </label>
103
+ ) : null}
100
104
 
101
- {p.compact ? (
105
+ {viewOptions.length < 2 ? null : p.compact ? (
102
106
  <select
103
107
  className="p_8 bd_1 bd_bd r_sm"
104
108
  aria-label={p.title}
@@ -1,28 +1,82 @@
1
1
  import i18n from '@jsb188/app/i18n/index.ts';
2
2
  import { cn } from '@jsb188/app/utils/string.ts';
3
3
  import { memo } from 'react';
4
- import type { RosterLayoutObj } from '../libs/roster-layout.ts';
4
+ import { CALENDAR_DRAFT_PATTERN_CLASS_NAME } from '../constants/calendar.ts';
5
+ import type {
6
+ RosterChipObj,
7
+ RosterRowObj,
8
+ RosterLayoutObj,
9
+ } from '../libs/roster-layout.ts';
5
10
 
6
- /* Render an accessible people-by-day grid with one row per worker and visible open staffing seats. */
11
+ /*
12
+ * Return the colour class for a finding's severity.
13
+ */
14
+ function getRosterBreachClassName(
15
+ breach: RosterChipObj['breach'],
16
+ block: string,
17
+ warn: string,
18
+ ): string {
19
+ return breach === 'BLOCK' ? block : breach === 'WARN' ? warn : '';
20
+ }
21
+
22
+ /*
23
+ * Return the text of a row header.
24
+ */
25
+ function getRosterRowName(row: RosterRowObj): string {
26
+ if (row.kind === 'OPEN') return i18n.t('calendar.roster_open_row');
27
+ if (row.kind === 'GROUP') return row.name || i18n.t('calendar.no_room');
28
+ return row.name || i18n.t('c.unknown');
29
+ }
30
+
31
+ /* Draw one seat: role, times, room, and a visible draft or canceled mark. */
32
+ const RosterChipUI = memo((p: { chip: RosterChipObj }) => {
33
+ const { chip } = p;
34
+ const title = chip.roleName || chip.label;
35
+ return (
36
+ <div
37
+ data-status={chip.status}
38
+ className={cn(
39
+ 'bl w_f a_l r_sm px_4 py_2 ft_xxs bd_1 bd_bd',
40
+ chip.status === 'DRAFT'
41
+ ? `${CALENDAR_DRAFT_PATTERN_CLASS_NAME} rel`
42
+ : '',
43
+ chip.status === 'CANCELED' ? 'strikethrough op_50' : '',
44
+ chip.isMine ? 'bg_active' : 'bg_alt',
45
+ getRosterBreachClassName(chip.breach, 'bd_red_md', 'bd_amber_md'),
46
+ )}
47
+ style={
48
+ chip.roleColor
49
+ ? { borderLeftWidth: 3, borderLeftColor: chip.roleColor }
50
+ : undefined
51
+ }
52
+ >
53
+ {title ? <span className="bl ellip ft_bold">{title}</span> : null}
54
+ <span className="bl">
55
+ {chip.startLabel}–{chip.endLabel}
56
+ {chip.overnight ? ' →' : ''}
57
+ </span>
58
+ {chip.roleName && chip.label ? (
59
+ <span className="bl ellip">{chip.label}</span>
60
+ ) : null}
61
+ {chip.roomName ? (
62
+ <span className="bl ellip cl_md">{chip.roomName}</span>
63
+ ) : null}
64
+ {chip.status === 'DRAFT' ? (
65
+ <span className="bl cl_md">{i18n.t('calendar.draft')}</span>
66
+ ) : chip.status === 'CANCELED' ? (
67
+ <span className="bl">{i18n.t('calendar.canceled')}</span>
68
+ ) : null}
69
+ </div>
70
+ );
71
+ });
72
+
73
+ /* Render a read-only people-by-day grid: one row per person plus the open seats. */
7
74
  export const RosterUI = memo(
8
75
  (p: {
9
76
  layout: RosterLayoutObj;
10
- editable: boolean;
11
77
  narrow?: boolean;
12
78
  selectedDay?: string;
13
79
  onSelectDay: (dateKey: string) => void;
14
- onSelectOccurrence: (id: string) => void;
15
- onCreate: (
16
- dateKey: string,
17
- resourceId: string | null,
18
- roomId: string | null,
19
- ) => void;
20
- onReassign?: (
21
- occurrenceId: string,
22
- assignmentId: string,
23
- resourceId: string,
24
- ) => void;
25
- onOpenShifts: (roomId: string | null, dateKey: string) => void;
26
80
  }) => {
27
81
  const indexes = p.narrow
28
82
  ? [
@@ -53,6 +107,7 @@ export const RosterUI = memo(
53
107
  ) : null}
54
108
  <div
55
109
  role="grid"
110
+ aria-readonly="true"
56
111
  aria-label={i18n.t('calendar.roster')}
57
112
  style={{
58
113
  display: 'grid',
@@ -62,61 +117,74 @@ export const RosterUI = memo(
62
117
  minWidth: p.narrow ? 0 : 1000,
63
118
  }}
64
119
  >
65
- <div className="sticky_top sticky_left bg z3 p_8 ft_bold">
66
- {i18n.t('schedule.resources')}
67
- </div>
68
- {indexes.map((index) => (
69
- <button
70
- key={index}
71
- className="sticky_top bg z2 p_8 bd_b_1 bd_b_bd"
72
- type="button"
73
- onClick={() => p.onSelectDay(p.layout.days[index].dateKey)}
74
- >
75
- <span className="ft_bold">{p.layout.days[index].label}</span>
76
- <span
77
- className={cn(
78
- 'bl ft_xxs',
79
- p.layout.days[index].breach === 'BLOCK' ? 'cl_err' : 'cl_md',
80
- )}
81
- >
82
- {i18n.t('calendar.staff_count', {
83
- count: p.layout.days[index].staffCount,
84
- })}{' '}
85
- ·{' '}
86
- {i18n.t('calendar.open_count', {
87
- count: p.layout.days[index].openCount,
88
- })}
89
- </span>
90
- </button>
91
- ))}
92
120
  <div
93
- className="sticky_top bg z2 p_4 ft_xxs"
94
- style={{ whiteSpace: 'nowrap' }}
121
+ role="row"
122
+ style={{ display: 'contents' }}
95
123
  >
96
- {i18n.t('calendar.hours_week')}
124
+ <div
125
+ role="columnheader"
126
+ className="sticky_top sticky_left bg z3 p_8 ft_bold"
127
+ >
128
+ {i18n.t('schedule.resources')}
129
+ </div>
130
+ {indexes.map((index) => {
131
+ const day = p.layout.days[index];
132
+ return (
133
+ <div
134
+ key={day.dateKey}
135
+ role="columnheader"
136
+ className="sticky_top bg z2 bd_b_1 bd_b_bd"
137
+ >
138
+ <button
139
+ className="w_f p_8"
140
+ type="button"
141
+ onClick={() => p.onSelectDay(day.dateKey)}
142
+ >
143
+ <span className="ft_bold">{day.label}</span>
144
+ <span
145
+ className={cn(
146
+ 'bl ft_xxs',
147
+ getRosterBreachClassName(
148
+ day.breach,
149
+ 'cl_err',
150
+ 'cl_warn',
151
+ ) || 'cl_md',
152
+ )}
153
+ >
154
+ {i18n.t('calendar.staff_count', {
155
+ count: day.staffCount,
156
+ })}{' '}
157
+ ·{' '}
158
+ {i18n.t('calendar.open_count', { count: day.openCount })}
159
+ </span>
160
+ </button>
161
+ </div>
162
+ );
163
+ })}
164
+ <div
165
+ role="columnheader"
166
+ className="sticky_top bg z2 p_4 ft_xxs"
167
+ style={{ whiteSpace: 'nowrap' }}
168
+ >
169
+ {i18n.t('calendar.hours_week')}
170
+ </div>
97
171
  </div>
98
172
  {p.layout.rows.map((row) => (
99
173
  <div
100
174
  key={row.key}
101
175
  role="row"
176
+ data-kind={row.kind}
102
177
  style={{ display: 'contents' }}
103
178
  >
104
179
  <div
105
180
  role="rowheader"
106
- style={{ top: 'auto', bottom: 'auto' }}
107
181
  className={cn(
108
182
  'sticky_left bg z1 p_8 bd_b_1 bd_b_bd ellip',
109
183
  row.kind === 'GROUP' ? 'ft_bold bg_alt' : 'ft_sm',
110
- row.breach === 'BLOCK'
111
- ? 'cl_err'
112
- : row.breach === 'WARN'
113
- ? 'cl_warn'
114
- : '',
184
+ getRosterBreachClassName(row.breach, 'cl_err', 'cl_warn'),
115
185
  )}
116
186
  >
117
- {row.kind === 'OPEN'
118
- ? i18n.t('calendar.roster_open_row')
119
- : row.name || i18n.t('calendar.no_room')}
187
+ {getRosterRowName(row)}
120
188
  </div>
121
189
  {indexes.map((index) => {
122
190
  const cell = row.cells[index];
@@ -124,39 +192,14 @@ export const RosterUI = memo(
124
192
  <div
125
193
  key={cell.dateKey}
126
194
  role="gridcell"
127
- onDragOver={(event) => {
128
- if (p.editable && row.kind === 'PERSON')
129
- event.preventDefault();
130
- }}
131
- onDrop={(event) => {
132
- event.preventDefault();
133
- if (!p.editable || !row.resourceId) return;
134
- try {
135
- const drag = JSON.parse(
136
- event.dataTransfer.getData(
137
- 'application/x-schedule-assignment',
138
- ),
139
- );
140
- if (
141
- drag.dateKey === cell.dateKey &&
142
- drag.resourceId !== row.resourceId &&
143
- typeof drag.occurrenceId === 'string' &&
144
- typeof drag.assignmentId === 'string'
145
- )
146
- p.onReassign?.(
147
- drag.occurrenceId,
148
- drag.assignmentId,
149
- row.resourceId,
150
- );
151
- } catch {}
152
- }}
195
+ data-date={cell.dateKey}
153
196
  className={cn(
154
- 'p_4 bd_b_1 bd_b_bd bd_l_1 bd_l_bd',
197
+ 'v_stretch gap_xs p_4 bd_b_1 bd_b_bd bd_l_1 bd_l_bd',
155
198
  row.kind === 'GROUP' ? 'bg_alt' : '',
156
199
  cell.timeOff?.status === 'APPROVED'
157
200
  ? 'bg_alt'
158
201
  : cell.timeOff
159
- ? 'pattern_stripes medium_bf rel'
202
+ ? `${CALENDAR_DRAFT_PATTERN_CLASS_NAME} rel`
160
203
  : '',
161
204
  )}
162
205
  style={{ minHeight: 48 }}
@@ -166,97 +209,17 @@ export const RosterUI = memo(
166
209
  {i18n.t('schedule.time_off')}
167
210
  </span>
168
211
  ) : null}
169
- {row.kind === 'OPEN' ? (
170
- cell.openCount > 0 ? (
171
- <button
172
- type="button"
173
- className={cn(
174
- 'pill p_8',
175
- cell.breach === 'BLOCK'
176
- ? 'bg_red_alt_lt'
177
- : 'bg_amber_alt_lt',
178
- )}
179
- onClick={() =>
180
- p.onOpenShifts(row.roomId, cell.dateKey)
181
- }
182
- >
183
- {i18n.t('calendar.open_count', {
184
- count: cell.openCount,
185
- })}
186
- </button>
187
- ) : null
188
- ) : (
189
- cell.chips.map((chip) => (
190
- <button
191
- type="button"
192
- key={chip.assignmentId || chip.occurrenceId}
193
- draggable={
194
- p.editable &&
195
- !!chip.assignmentId &&
196
- chip.status !== 'CANCELED'
197
- }
198
- onDragStart={(event) => {
199
- event.dataTransfer.setData(
200
- 'application/x-schedule-assignment',
201
- JSON.stringify({
202
- occurrenceId: chip.occurrenceId,
203
- assignmentId: chip.assignmentId,
204
- resourceId: row.resourceId,
205
- dateKey: cell.dateKey,
206
- }),
207
- );
208
- event.dataTransfer.effectAllowed = 'move';
209
- }}
210
- className={cn(
211
- 'bl w_f a_l r_sm px_4 py_2 ft_xxs bd_1 bd_bd',
212
- chip.status === 'DRAFT'
213
- ? 'pattern_stripes medium_bf rel'
214
- : '',
215
- chip.status === 'CANCELED'
216
- ? 'strikethrough op_50'
217
- : '',
218
- chip.isMine ? 'bg_active' : 'bg_alt',
219
- chip.breach === 'BLOCK'
220
- ? 'bd_red_md'
221
- : chip.breach === 'WARN'
222
- ? 'bd_amber_md'
223
- : '',
224
- )}
225
- onClick={() =>
226
- p.onSelectOccurrence(chip.occurrenceId)
227
- }
228
- >
229
- <span className="bl ellip ft_bold">{chip.title}</span>
230
- <span>
231
- {chip.startLabel}–{chip.endLabel}
232
- {chip.overnight ? ' →' : ''}
233
- </span>
234
- {chip.roomName ? (
235
- <span className="bl ellip cl_md">
236
- {chip.roomName}
237
- </span>
238
- ) : null}
239
- </button>
240
- ))
241
- )}
242
- {row.kind === 'PERSON' &&
243
- p.editable &&
244
- !cell.chips.length ? (
245
- <button
246
- type="button"
247
- className="w_f p_8 cl_lt"
248
- aria-label={i18n.t('calendar.new_shift')}
249
- onClick={() =>
250
- p.onCreate(cell.dateKey, row.resourceId, row.roomId)
251
- }
252
- >
253
- +
254
- </button>
255
- ) : null}
212
+ {cell.chips.map((chip) => (
213
+ <RosterChipUI
214
+ key={chip.shiftId}
215
+ chip={chip}
216
+ />
217
+ ))}
256
218
  </div>
257
219
  );
258
220
  })}
259
221
  <div
222
+ role="gridcell"
260
223
  className={cn(
261
224
  'p_8 bd_b_1 bd_b_bd ft_xxs',
262
225
  row.kind === 'GROUP' ? 'bg_alt' : '',
@@ -271,3 +234,6 @@ export const RosterUI = memo(
271
234
  );
272
235
  },
273
236
  );
237
+
238
+ RosterChipUI.displayName = 'RosterChipUI';
239
+ RosterUI.displayName = 'RosterUI';
@@ -1,19 +0,0 @@
1
- import type { ScheduleSlotInput } from '@jsb188/graphql/schedule.d';
2
- export interface ShiftFormValues {
3
- kind: 'SHIFT' | 'EVENT' | 'BLOCK';
4
- title: string;
5
- roomId: string;
6
- start: string;
7
- end: string;
8
- allDay: boolean;
9
- note: string;
10
- location: string;
11
- slots: ScheduleSlotInput[];
12
- repeat: '' | 'DAILY' | 'WEEKLY' | 'MONTHLY';
13
- interval: number;
14
- weekdays: number[];
15
- monthDay: number;
16
- count: string;
17
- until: string;
18
- future: boolean;
19
- }