@jsb188/schedule 1.1.2

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.
Files changed (60) hide show
  1. package/package.json +62 -0
  2. package/src/constants/schedule.ts +549 -0
  3. package/src/css.d.ts +7 -0
  4. package/src/libs/gantt-geometry.ts +771 -0
  5. package/src/libs/gantt-histogram.ts +124 -0
  6. package/src/libs/gantt-keyboard.ts +113 -0
  7. package/src/libs/gantt-state.ts +57 -0
  8. package/src/libs/gantt-url.ts +63 -0
  9. package/src/modules/Gantt.helpers.ts +119 -0
  10. package/src/modules/Gantt.tsx +584 -0
  11. package/src/types/schedule.d.ts +1149 -0
  12. package/src/ui/ActivityFormUI.tsx +133 -0
  13. package/src/ui/GanttEditorsUI.tsx +102 -0
  14. package/src/ui/GanttHistogramUI.tsx +236 -0
  15. package/src/ui/GanttUI.tsx +792 -0
  16. package/src/ui/ProjectFormUI.tsx +250 -0
  17. package/src/ui/ProjectMobileListUI.tsx +80 -0
  18. package/src/ui/ProjectToolbarUI.tsx +54 -0
  19. package/src/ui/RelationshipListUI.tsx +176 -0
  20. package/src/ui/ScheduleRunUI.tsx +173 -0
  21. package/src/ui/ScheduleSettingsUI.tsx +420 -0
  22. package/src/utils/coverage.helpers.ts +679 -0
  23. package/src/utils/coverage.ts +630 -0
  24. package/src/utils/cpm.helpers.ts +674 -0
  25. package/src/utils/cpm.ts +907 -0
  26. package/src/utils/cpmLeveling.helpers.ts +564 -0
  27. package/src/utils/cpmLeveling.ts +367 -0
  28. package/src/utils/defaults.ts +8 -0
  29. package/src/utils/eligibility.ts +457 -0
  30. package/src/utils/planCsv.ts +344 -0
  31. package/src/utils/predecessorText.ts +96 -0
  32. package/src/utils/recurrence.ts +616 -0
  33. package/src/utils/request.ts +153 -0
  34. package/src/utils/resource.ts +182 -0
  35. package/src/utils/rule.ts +216 -0
  36. package/src/utils/run.ts +43 -0
  37. package/src/utils/series.ts +161 -0
  38. package/src/utils/slot.ts +208 -0
  39. package/src/utils/workTime.ts +1382 -0
  40. package/tests/coverage.fixtures.ts +111 -0
  41. package/tests/coverage.test.ts +503 -0
  42. package/tests/cpm.bench.test.ts +154 -0
  43. package/tests/cpm.test.ts +354 -0
  44. package/tests/cpmCorrectness.test.ts +327 -0
  45. package/tests/cpmLeveling.test.ts +471 -0
  46. package/tests/eligibility.test.ts +320 -0
  47. package/tests/gantt-geometry.test.ts +367 -0
  48. package/tests/gantt-histogram.test.ts +78 -0
  49. package/tests/gantt-keyboard.test.ts +69 -0
  50. package/tests/helpers/cpmFixtures.ts +101 -0
  51. package/tests/projectInputs.test.ts +165 -0
  52. package/tests/recurrence.test.ts +68 -0
  53. package/tests/request.test.ts +99 -0
  54. package/tests/resource.test.ts +95 -0
  55. package/tests/rule.test.ts +98 -0
  56. package/tests/series.test.ts +120 -0
  57. package/tests/workTime.test.ts +1007 -0
  58. package/tests/workTimeContracts.test.ts +111 -0
  59. package/tsconfig.json +13 -0
  60. package/vitest.config.ts +8 -0
@@ -0,0 +1,173 @@
1
+ import { VZTable } from '@jsb188/react-web/table/Table';
2
+ import { memo, type ReactNode } from 'react';
3
+
4
+ /* Render bounded, static schedule result rows with the shared table presentation. */
5
+ export const ScheduleTableUI = memo(
6
+ (p: {
7
+ headers: string[];
8
+ rows: Array<{ id: string; cells: ReactNode[] }>;
9
+ onSelect?: (id: string) => void;
10
+ }) => (
11
+ <VZTable
12
+ tableDesign={{
13
+ columns: p.headers.map((text, index) => ({
14
+ key: String(index),
15
+ width: index === p.headers.length - 1 ? '1fr' : 140,
16
+ header: { text },
17
+ })),
18
+ }}
19
+ listData={p.rows.map((row) => ({
20
+ item: row,
21
+ itemId: row.id,
22
+ lastItemIdOnMount: null,
23
+ }))}
24
+ mapListData={({ item }) => ({ __deleted: false, columns: item.cells })}
25
+ onClickRow={
26
+ p.onSelect
27
+ ? (row) => {
28
+ if (row?.itemId) p.onSelect?.(row.itemId);
29
+ }
30
+ : undefined
31
+ }
32
+ disableOnClickRow={!p.onSelect}
33
+ />
34
+ ),
35
+ );
36
+
37
+ export interface ScheduleRunStatObj {
38
+ key: string;
39
+ label: string;
40
+ value: string;
41
+ isAlert?: boolean;
42
+ }
43
+ export interface ScheduleRunDiagnosticObj {
44
+ key: string;
45
+ severity: 'ERROR' | 'WARN' | 'INFO';
46
+ severityText: string;
47
+ code?: string | null;
48
+ text: string;
49
+ activityId?: string | null;
50
+ resourceId?: string | null;
51
+ }
52
+ /* Show job state independently of network errors and offer explicit scheduling or cancellation. */
53
+ export const ScheduleRunStatusUI = memo(
54
+ (p: {
55
+ state: string;
56
+ text: string;
57
+ cancelText: string;
58
+ scheduleText: string;
59
+ onCancel?: () => void;
60
+ onSchedule?: () => void;
61
+ onOpen?: () => void;
62
+ }) => (
63
+ <div className="h_item gap_sm">
64
+ <button
65
+ type="button"
66
+ className={`pill ft_xxs ${p.state === 'FAILED' ? 'cl_err' : p.state === 'STALE' ? 'cl_warn' : 'cl_lt'}`}
67
+ onClick={p.onOpen}
68
+ >
69
+ {p.text}
70
+ </button>
71
+ {p.onCancel ? (
72
+ <button
73
+ type="button"
74
+ className="ft_xxs cl_lt"
75
+ onClick={p.onCancel}
76
+ >
77
+ {p.cancelText}
78
+ </button>
79
+ ) : null}
80
+ {p.state === 'STALE' && p.onSchedule ? (
81
+ <button
82
+ type="button"
83
+ className="ft_xxs cl_primary"
84
+ onClick={p.onSchedule}
85
+ >
86
+ {p.scheduleText}
87
+ </button>
88
+ ) : null}
89
+ </div>
90
+ ),
91
+ );
92
+ /* Render translated run metrics and bounded diagnostic rows; old runs never replace current chart dates. */
93
+ export const ScheduleRunUI = memo(
94
+ (p: {
95
+ headingText: string;
96
+ subText?: string | null;
97
+ stats: ScheduleRunStatObj[];
98
+ diagnostics: ScheduleRunDiagnosticObj[];
99
+ noRunText: string;
100
+ noDiagnosticsText: string;
101
+ headers: string[];
102
+ moreText?: string;
103
+ onMore?: () => void;
104
+ onSelectActivity?: (id: string) => void;
105
+ onSelectResource?: (id: string) => void;
106
+ }) => (
107
+ <div
108
+ className="v_stretch gap_sm"
109
+ style={{ padding: 12 }}
110
+ >
111
+ <span className="ft_sm ft_semibold">{p.headingText}</span>
112
+ {p.subText ? <span className="ft_xs cl_lt">{p.subText}</span> : null}
113
+ {!p.stats.length ? (
114
+ <span className="ft_xs cl_lt">{p.noRunText}</span>
115
+ ) : (
116
+ <div className="h_wrap gap_sm">
117
+ {p.stats.map((stat) => (
118
+ <div
119
+ key={stat.key}
120
+ className="v_stretch bg_alt r_sm"
121
+ style={{ padding: 8, minWidth: 88 }}
122
+ >
123
+ <span className="ft_xxs cl_lt">{stat.label}</span>
124
+ <span className={`ft_sm${stat.isAlert ? ' cl_err' : ''}`}>
125
+ {stat.value}
126
+ </span>
127
+ </div>
128
+ ))}
129
+ </div>
130
+ )}
131
+ {p.diagnostics.length ? (
132
+ <ScheduleTableUI
133
+ headers={p.headers}
134
+ rows={p.diagnostics.map((row) => ({
135
+ id: row.key,
136
+ cells: [
137
+ <span
138
+ className={
139
+ row.severity === 'ERROR'
140
+ ? 'cl_err'
141
+ : row.severity === 'WARN'
142
+ ? 'cl_warn'
143
+ : 'cl_lt'
144
+ }
145
+ >
146
+ {row.severityText}
147
+ </span>,
148
+ row.code,
149
+ row.text,
150
+ ],
151
+ }))}
152
+ onSelect={(id) => {
153
+ const row = p.diagnostics.find((item) => item.key === id);
154
+ if (row?.activityId) p.onSelectActivity?.(row.activityId);
155
+ if (row?.resourceId) p.onSelectResource?.(row.resourceId);
156
+ }}
157
+ />
158
+ ) : (
159
+ <span className="ft_xs cl_lt">{p.noDiagnosticsText}</span>
160
+ )}
161
+ {p.onMore ? (
162
+ <button
163
+ type="button"
164
+ className="ft_xs cl_primary"
165
+ onClick={p.onMore}
166
+ >
167
+ {p.moreText}
168
+ </button>
169
+ ) : null}
170
+ </div>
171
+ ),
172
+ );
173
+ ScheduleRunUI.displayName = 'ScheduleRunUI';
@@ -0,0 +1,420 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import { memo } from 'react';
3
+ import type { ScheduleResourceKindEnum } from '../types/schedule.d.ts';
4
+
5
+ export interface ScheduleResourceFormValues {
6
+ version?: string;
7
+ kind: ScheduleResourceKindEnum;
8
+ key: string;
9
+ name: string;
10
+ accountId: string;
11
+ workCalendarId: string;
12
+ maxUnitsPerDay: string;
13
+ capacity: string;
14
+ unitOfMeasure: string;
15
+ canLevel: boolean;
16
+ roles: string;
17
+ tags: string;
18
+ ageGroup: string;
19
+ qualifications: Array<{ key: string; expiresAt: string }>;
20
+ }
21
+
22
+ export interface ScheduleWorkCalendarFormValues {
23
+ version?: string;
24
+ name: string;
25
+ description: string;
26
+ timeZone: string;
27
+ minutesPerDay: number;
28
+ isDefault: boolean;
29
+ days: Array<Array<{ start: string; end: string }>>;
30
+ }
31
+
32
+ /* Render resource fields and dated qualifications without owning persistence or authorization. */
33
+ export const ScheduleResourceFormUI = memo(
34
+ (p: {
35
+ value: ScheduleResourceFormValues;
36
+ existing: boolean;
37
+ busy: boolean;
38
+ error: string | null;
39
+ accounts: Array<{ id: string; name: string }>;
40
+ calendars: Array<{ id: string; name: string }>;
41
+ onChange: (value: ScheduleResourceFormValues) => void;
42
+ onSave: () => void;
43
+ }) => {
44
+ const v = p.value;
45
+ /* Update one controlled resource field. */
46
+ const change = (key: keyof ScheduleResourceFormValues, value: unknown) =>
47
+ p.onChange({ ...v, [key]: value });
48
+ return (
49
+ <form
50
+ className="v_stretch gap_sm"
51
+ onSubmit={(event) => {
52
+ event.preventDefault();
53
+ p.onSave();
54
+ }}
55
+ >
56
+ <label>
57
+ {i18n.t('schedule.settings.kind')}
58
+ <select
59
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
60
+ disabled={p.existing}
61
+ value={v.kind}
62
+ onChange={(event) => change('kind', event.target.value)}
63
+ >
64
+ {['LABOR', 'EQUIPMENT', 'MATERIAL', 'SPACE'].map((kind) => (
65
+ <option
66
+ key={kind}
67
+ value={kind}
68
+ >
69
+ {i18n.t('schedule.settings.kind_' + kind)}
70
+ </option>
71
+ ))}
72
+ </select>
73
+ </label>
74
+ {(['key', 'name'] as const).map((key) => (
75
+ <label key={key}>
76
+ {i18n.t('schedule.settings.' + key)}
77
+ <input
78
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
79
+ required
80
+ disabled={key === 'key' && p.existing}
81
+ value={v[key]}
82
+ maxLength={key === 'key' ? 120 : 255}
83
+ onChange={(event) => change(key, event.target.value)}
84
+ />
85
+ </label>
86
+ ))}
87
+ {v.kind === 'LABOR' && (
88
+ <label>
89
+ {i18n.t('schedule.settings.account')}
90
+ <select
91
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
92
+ value={v.accountId}
93
+ onChange={(event) => change('accountId', event.target.value)}
94
+ >
95
+ <option value="">{i18n.t('schedule.settings.unlinked')}</option>
96
+ {p.accounts.map((account) => (
97
+ <option
98
+ key={account.id}
99
+ value={account.id}
100
+ >
101
+ {account.name}
102
+ </option>
103
+ ))}
104
+ </select>
105
+ </label>
106
+ )}
107
+ <label>
108
+ {i18n.t('schedule.settings.work_calendar')}
109
+ <select
110
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
111
+ value={v.workCalendarId}
112
+ onChange={(event) => change('workCalendarId', event.target.value)}
113
+ >
114
+ <option value="">{i18n.t('schedule.operation_default')}</option>
115
+ {p.calendars.map((calendar) => (
116
+ <option
117
+ key={calendar.id}
118
+ value={calendar.id}
119
+ >
120
+ {calendar.name}
121
+ </option>
122
+ ))}
123
+ </select>
124
+ </label>
125
+ {(v.kind === 'SPACE'
126
+ ? (['capacity'] as const)
127
+ : (['maxUnitsPerDay'] as const)
128
+ ).map((key) => (
129
+ <label key={key}>
130
+ {i18n.t('schedule.settings.' + key)}
131
+ <input
132
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
133
+ type="number"
134
+ min={key === 'capacity' ? 0 : 0.001}
135
+ step={key === 'capacity' ? 1 : 'any'}
136
+ value={v[key]}
137
+ onChange={(event) => change(key, event.target.value)}
138
+ />
139
+ </label>
140
+ ))}
141
+ <label>
142
+ {i18n.t('schedule.settings.unitOfMeasure')}
143
+ <input
144
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
145
+ value={v.unitOfMeasure}
146
+ onChange={(event) => change('unitOfMeasure', event.target.value)}
147
+ />
148
+ </label>
149
+ {v.kind !== 'SPACE' && (
150
+ <label>
151
+ <input
152
+ type="checkbox"
153
+ checked={v.canLevel}
154
+ onChange={(event) => change('canLevel', event.target.checked)}
155
+ />{' '}
156
+ {i18n.t('schedule.settings.can_level')}
157
+ </label>
158
+ )}
159
+ {(
160
+ [
161
+ 'roles',
162
+ 'tags',
163
+ ...(v.kind === 'SPACE' ? ['ageGroup'] : []),
164
+ ] as Array<'roles' | 'tags' | 'ageGroup'>
165
+ ).map((key) => (
166
+ <label key={key}>
167
+ {i18n.t('schedule.settings.' + key)}
168
+ <input
169
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
170
+ value={v[key]}
171
+ onChange={(event) => change(key, event.target.value)}
172
+ />
173
+ </label>
174
+ ))}
175
+ {v.kind === 'LABOR' && (
176
+ <fieldset className="v_stretch gap_xs">
177
+ <legend>{i18n.t('schedule.settings.qualifications')}</legend>
178
+ {v.qualifications.map((qualification, index) => (
179
+ <div
180
+ className="h_item f_wrap gap_xs"
181
+ key={index}
182
+ >
183
+ <input
184
+ aria-label={i18n.t('schedule.settings.qualification')}
185
+ className="f p_8 bd_1 bd_bd r_sm"
186
+ style={{ minWidth: 0, flexBasis: 120 }}
187
+ required
188
+ value={qualification.key}
189
+ onChange={(event) =>
190
+ change(
191
+ 'qualifications',
192
+ v.qualifications.map((row, i) =>
193
+ i === index ? { ...row, key: event.target.value } : row,
194
+ ),
195
+ )
196
+ }
197
+ />
198
+ <input
199
+ aria-label={i18n.t('schedule.settings.expires')}
200
+ className="p_8 bd_1 bd_bd r_sm"
201
+ type="datetime-local"
202
+ value={qualification.expiresAt}
203
+ onChange={(event) =>
204
+ change(
205
+ 'qualifications',
206
+ v.qualifications.map((row, i) =>
207
+ i === index
208
+ ? { ...row, expiresAt: event.target.value }
209
+ : row,
210
+ ),
211
+ )
212
+ }
213
+ />
214
+ <button
215
+ type="button"
216
+ className="p_8 cl_err"
217
+ onClick={() =>
218
+ change(
219
+ 'qualifications',
220
+ v.qualifications.filter((_, i) => i !== index),
221
+ )
222
+ }
223
+ >
224
+ {i18n.t('c.remove')}
225
+ </button>
226
+ </div>
227
+ ))}
228
+ <button
229
+ type="button"
230
+ className="p_8 bd_1 bd_bd r_sm"
231
+ onClick={() =>
232
+ change('qualifications', [
233
+ ...v.qualifications,
234
+ { key: '', expiresAt: '' },
235
+ ])
236
+ }
237
+ >
238
+ {i18n.t('schedule.settings.add_qualification')}
239
+ </button>
240
+ </fieldset>
241
+ )}
242
+ {p.error && (
243
+ <p
244
+ role="alert"
245
+ className="cl_err"
246
+ >
247
+ {p.error}
248
+ </p>
249
+ )}
250
+ <button
251
+ type="submit"
252
+ className="p_8 bg_primary cl_white r_sm"
253
+ disabled={p.busy}
254
+ >
255
+ {i18n.t('c.save')}
256
+ </button>
257
+ </form>
258
+ );
259
+ },
260
+ );
261
+
262
+ /* Edit a local week's working intervals, including split shifts and non-working days. */
263
+ export const ScheduleWeekHoursUI = memo(
264
+ (p: {
265
+ days: ScheduleWorkCalendarFormValues['days'];
266
+ onChange: (days: ScheduleWorkCalendarFormValues['days']) => void;
267
+ }) => {
268
+ /* Replace one day's ranges without modifying the other weekdays. */
269
+ const setDay = (
270
+ index: number,
271
+ ranges: ScheduleWorkCalendarFormValues['days'][number],
272
+ ) => p.onChange(p.days.map((day, i) => (i === index ? ranges : day)));
273
+ return (
274
+ <div className="v_stretch gap_sm">
275
+ {p.days.map((ranges, index) => (
276
+ <fieldset
277
+ className="v_stretch gap_xs"
278
+ key={index}
279
+ >
280
+ <legend>
281
+ {i18n.t('schedule.settings.weekday_' + (index + 1))}
282
+ </legend>
283
+ {ranges.map((range, rangeIndex) => (
284
+ <div
285
+ className="h_item f_wrap gap_xs"
286
+ key={rangeIndex}
287
+ >
288
+ {(['start', 'end'] as const).map((key) => (
289
+ <input
290
+ key={key}
291
+ aria-label={i18n.t('schedule.settings.' + key)}
292
+ type="time"
293
+ className="p_8 bd_1 bd_bd r_sm"
294
+ value={range[key]}
295
+ required
296
+ onChange={(event) =>
297
+ setDay(
298
+ index,
299
+ ranges.map((row, i) =>
300
+ i === rangeIndex
301
+ ? { ...row, [key]: event.target.value }
302
+ : row,
303
+ ),
304
+ )
305
+ }
306
+ />
307
+ ))}
308
+ <button
309
+ type="button"
310
+ className="p_8 cl_err"
311
+ onClick={() =>
312
+ setDay(
313
+ index,
314
+ ranges.filter((_, i) => i !== rangeIndex),
315
+ )
316
+ }
317
+ >
318
+ {i18n.t('c.remove')}
319
+ </button>
320
+ </div>
321
+ ))}
322
+ <button
323
+ type="button"
324
+ className="p_4 ft_sm cl_primary"
325
+ onClick={() =>
326
+ setDay(index, [...ranges, { start: '09:00', end: '17:00' }])
327
+ }
328
+ >
329
+ {i18n.t('schedule.settings.add_hours')}
330
+ </button>
331
+ </fieldset>
332
+ ))}
333
+ </div>
334
+ );
335
+ },
336
+ );
337
+
338
+ /* Render calendar metadata and weekly hours using the same controlled interval editor. */
339
+ export const ScheduleWorkCalendarFormUI = memo(
340
+ (p: {
341
+ value: ScheduleWorkCalendarFormValues;
342
+ busy: boolean;
343
+ error: string | null;
344
+ onChange: (value: ScheduleWorkCalendarFormValues) => void;
345
+ onSave: () => void;
346
+ }) => {
347
+ const v = p.value;
348
+ /* Update one controlled calendar field. */
349
+ const change = (
350
+ key: keyof ScheduleWorkCalendarFormValues,
351
+ value: unknown,
352
+ ) => p.onChange({ ...v, [key]: value });
353
+ return (
354
+ <form
355
+ className="v_stretch gap_sm"
356
+ onSubmit={(event) => {
357
+ event.preventDefault();
358
+ p.onSave();
359
+ }}
360
+ >
361
+ {(['name', 'description', 'timeZone'] as const).map((key) => (
362
+ <label key={key}>
363
+ {i18n.t('schedule.settings.' + key)}
364
+ <input
365
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
366
+ required={key !== 'description'}
367
+ value={v[key]}
368
+ onChange={(event) => change(key, event.target.value)}
369
+ />
370
+ </label>
371
+ ))}
372
+ <label>
373
+ {i18n.t('schedule.settings.minutes_per_day')}
374
+ <input
375
+ className="bl w_f p_8 bd_1 bd_bd r_sm"
376
+ type="number"
377
+ min={1}
378
+ max={1440}
379
+ required
380
+ value={v.minutesPerDay}
381
+ onChange={(event) =>
382
+ change('minutesPerDay', Number(event.target.value))
383
+ }
384
+ />
385
+ </label>
386
+ <label>
387
+ <input
388
+ type="checkbox"
389
+ checked={v.isDefault}
390
+ onChange={(event) => change('isDefault', event.target.checked)}
391
+ />{' '}
392
+ {i18n.t('schedule.settings.is_default')}
393
+ </label>
394
+ <ScheduleWeekHoursUI
395
+ days={v.days}
396
+ onChange={(days) => change('days', days)}
397
+ />
398
+ {p.error && (
399
+ <p
400
+ role="alert"
401
+ className="cl_err"
402
+ >
403
+ {p.error}
404
+ </p>
405
+ )}
406
+ <button
407
+ type="submit"
408
+ className="p_8 bg_primary cl_white r_sm"
409
+ disabled={p.busy}
410
+ >
411
+ {i18n.t('c.save')}
412
+ </button>
413
+ </form>
414
+ );
415
+ },
416
+ );
417
+
418
+ ScheduleResourceFormUI.displayName = 'ScheduleResourceFormUI';
419
+ ScheduleWeekHoursUI.displayName = 'ScheduleWeekHoursUI';
420
+ ScheduleWorkCalendarFormUI.displayName = 'ScheduleWorkCalendarFormUI';