@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,250 @@
1
+ import { cn } from '@jsb188/app/utils/string.ts';
2
+ import { Input, Select, type SelectOptionType, Textarea } from '@jsb188/form/modules/Form';
3
+ import { Button } from '@jsb188/react-web/ui/Button';
4
+ import { memo } from 'react';
5
+
6
+ /**
7
+ * The create / edit form for one project. Controlled, like the activity
8
+ * form; dates are "yyyy-MM-dd" and the zone is the caller's problem.
9
+ */
10
+
11
+ export interface ProjectFormValuesObj {
12
+ code: string;
13
+ name: string;
14
+ description: string;
15
+ status: string;
16
+ timeZone: string;
17
+ workCalendarId: string;
18
+ plannedStartDate: string;
19
+ mustFinishByDate: string;
20
+ dataDate: string;
21
+ }
22
+
23
+ export type ProjectFormFieldEnum = keyof ProjectFormValuesObj;
24
+
25
+ export interface ProjectFormUIProps {
26
+ className?: string;
27
+ values: ProjectFormValuesObj;
28
+ isNew: boolean;
29
+ headingText: string;
30
+ codeLabel: string;
31
+ nameLabel: string;
32
+ namePlaceholder: string;
33
+ descriptionLabel: string;
34
+ statusLabel: string;
35
+ statusOptions: SelectOptionType[];
36
+ timeZoneLabel: string;
37
+ timeZoneOptions?: SelectOptionType[];
38
+ workCalendarLabel?: string;
39
+ workCalendarOptions?: SelectOptionType[];
40
+ plannedStartLabel: string;
41
+ mustFinishByLabel: string;
42
+ dataDateLabel: string;
43
+ saveText: string;
44
+ savingText?: string;
45
+ cancelText: string;
46
+ deleteText?: string;
47
+ errorText?: string | null;
48
+ saving?: boolean;
49
+ onChangeValue: (field: ProjectFormFieldEnum, value: string) => void;
50
+ onSave: () => void;
51
+ onCancel: () => void;
52
+ onDelete?: () => void;
53
+ }
54
+
55
+ export const ProjectFormUI = memo((p: ProjectFormUIProps) => {
56
+ const {
57
+ className,
58
+ values,
59
+ isNew,
60
+ headingText,
61
+ codeLabel,
62
+ nameLabel,
63
+ namePlaceholder,
64
+ descriptionLabel,
65
+ statusLabel,
66
+ statusOptions,
67
+ timeZoneLabel,
68
+ plannedStartLabel,
69
+ mustFinishByLabel,
70
+ dataDateLabel,
71
+ saveText,
72
+ savingText,
73
+ cancelText,
74
+ deleteText,
75
+ errorText,
76
+ saving,
77
+ onChangeValue,
78
+ onSave,
79
+ onCancel,
80
+ onDelete,
81
+ } = p;
82
+
83
+ const saveDisabled = !!saving || !values.name.trim() || !values.plannedStartDate || !values.timeZone;
84
+
85
+ return (
86
+ <div className={cn('v_stretch h_f of', className)}>
87
+ <div
88
+ className="f h_0 of auto_y app_scr"
89
+ style={{ paddingLeft: 12, paddingRight: 12, paddingBottom: 12 }}
90
+ >
91
+ <div
92
+ className="ft_sm ft_semibold"
93
+ style={{ paddingTop: 12, paddingBottom: 8 }}
94
+ >
95
+ {headingText}
96
+ </div>
97
+
98
+ <div className="h_item gap_sm">
99
+ <Input
100
+ className="no_shrink"
101
+ preset="fill"
102
+ name="code"
103
+ label={codeLabel}
104
+ disabled={saving}
105
+ value={values.code}
106
+ onChange={(e) => onChangeValue('code', e.currentTarget.value)}
107
+ />
108
+ <Input
109
+ fullWidth
110
+ autoFocus={isNew}
111
+ className="f"
112
+ preset="fill"
113
+ name="name"
114
+ label={nameLabel}
115
+ placeholder={namePlaceholder}
116
+ disabled={saving}
117
+ value={values.name}
118
+ onChange={(e) => onChangeValue('name', e.currentTarget.value)}
119
+ />
120
+ </div>
121
+
122
+ {!isNew ? (
123
+ <Select
124
+ fullWidth
125
+ className="mt_xs"
126
+ preset="fill"
127
+ name="status"
128
+ label={statusLabel}
129
+ disabled={saving}
130
+ options={statusOptions}
131
+ value={values.status}
132
+ onChange={(value) => onChangeValue('status', String(value ?? ''))}
133
+ />
134
+ ) : null}
135
+
136
+ <Select
137
+ fullWidth
138
+ preset="fill"
139
+ name="timeZone"
140
+ label={timeZoneLabel}
141
+ disabled={saving}
142
+ options={p.timeZoneOptions || [{ value: values.timeZone, text: values.timeZone }]}
143
+ value={values.timeZone}
144
+ onChange={(value) => onChangeValue('timeZone', String(value || 'UTC'))}
145
+ />
146
+ {p.workCalendarOptions ? (
147
+ <Select
148
+ fullWidth
149
+ preset="fill"
150
+ name="workCalendarId"
151
+ label={p.workCalendarLabel}
152
+ disabled={saving}
153
+ options={p.workCalendarOptions}
154
+ value={values.workCalendarId}
155
+ onChange={(value) => onChangeValue('workCalendarId', String(value || ''))}
156
+ />
157
+ ) : null}
158
+
159
+ <div className="h_item gap_sm mt_xs">
160
+ <Input
161
+ fullWidth
162
+ className="f"
163
+ preset="fill"
164
+ type="date"
165
+ name="plannedStartDate"
166
+ label={plannedStartLabel}
167
+ disabled={saving}
168
+ value={values.plannedStartDate}
169
+ onChange={(e) => onChangeValue('plannedStartDate', e.currentTarget.value)}
170
+ />
171
+ <Input
172
+ fullWidth
173
+ className="f"
174
+ preset="fill"
175
+ type="date"
176
+ name="mustFinishByDate"
177
+ label={mustFinishByLabel}
178
+ disabled={saving}
179
+ value={values.mustFinishByDate}
180
+ onChange={(e) => onChangeValue('mustFinishByDate', e.currentTarget.value)}
181
+ />
182
+ </div>
183
+
184
+ <Input
185
+ fullWidth
186
+ className="mt_xs"
187
+ preset="fill"
188
+ type="date"
189
+ name="dataDate"
190
+ label={dataDateLabel}
191
+ disabled={saving}
192
+ value={values.dataDate}
193
+ onChange={(e) => onChangeValue('dataDate', e.currentTarget.value)}
194
+ />
195
+
196
+ <Textarea
197
+ fullWidth
198
+ className="mt_xs"
199
+ preset="fill"
200
+ name="description"
201
+ label={descriptionLabel}
202
+ minHeight={60}
203
+ disabled={saving}
204
+ value={values.description}
205
+ onChange={(e) => onChangeValue('description', e.currentTarget.value)}
206
+ />
207
+
208
+ {errorText ? <div className="ft_xs cl_err mt_xs">{errorText}</div> : null}
209
+ </div>
210
+
211
+ <div
212
+ className="no_shrink h_item gap_sm bd_t_1 bd_t_bd"
213
+ style={{
214
+ paddingLeft: 12,
215
+ paddingRight: 12,
216
+ paddingTop: 8,
217
+ paddingBottom: 8,
218
+ }}
219
+ >
220
+ {!isNew && onDelete && deleteText ? (
221
+ <Button
222
+ preset="cl_err"
223
+ size="sm"
224
+ disabled={saving}
225
+ text={deleteText}
226
+ onClick={onDelete}
227
+ />
228
+ ) : null}
229
+ <div className="f" />
230
+ <Button
231
+ preset="bg"
232
+ size="sm"
233
+ disabled={saving}
234
+ text={cancelText}
235
+ onClick={onCancel}
236
+ />
237
+ <Button
238
+ preset="bg_secondary"
239
+ size="sm"
240
+ disabled={saveDisabled}
241
+ loading={saving}
242
+ text={saving && savingText ? savingText : saveText}
243
+ onClick={onSave}
244
+ />
245
+ </div>
246
+ </div>
247
+ );
248
+ });
249
+
250
+ ProjectFormUI.displayName = 'ProjectFormUI';
@@ -0,0 +1,80 @@
1
+ import { memo, useState } from 'react';
2
+ /* Show a deliberate read-only mobile schedule grouped under collapsible work packages. */
3
+ export const ProjectMobileListUI = memo(
4
+ (p: {
5
+ groups: Array<{
6
+ id: string;
7
+ name: string;
8
+ rows: Array<{
9
+ id: string;
10
+ code: string;
11
+ name: string;
12
+ dates: string;
13
+ status: string;
14
+ critical: boolean;
15
+ }>;
16
+ }>;
17
+ emptyText: string;
18
+ criticalText: string;
19
+ onSelect: (id: string) => void;
20
+ }) => {
21
+ const [collapsed, setCollapsed] = useState(new Set<string>());
22
+ return (
23
+ <div className="hidden phone:bl f auto_y app_scr">
24
+ {!p.groups.some((group) => group.rows.length) ? (
25
+ <p
26
+ className="ft_sm cl_lt"
27
+ style={{ padding: 16 }}
28
+ >
29
+ {p.emptyText}
30
+ </p>
31
+ ) : (
32
+ p.groups.map((group) => (
33
+ <section key={group.id}>
34
+ <button
35
+ className="w_f a_l ft_sm ft_semibold bg_alt"
36
+ style={{ padding: 12 }}
37
+ aria-expanded={!collapsed.has(group.id)}
38
+ onClick={() =>
39
+ setCollapsed((current) => {
40
+ const next = new Set(current);
41
+ if (next.has(group.id)) next.delete(group.id);
42
+ else next.add(group.id);
43
+ return next;
44
+ })
45
+ }
46
+ >
47
+ {group.name}
48
+ </button>
49
+ {collapsed.has(group.id)
50
+ ? null
51
+ : group.rows.map((row) => (
52
+ <button
53
+ type="button"
54
+ key={row.id}
55
+ className="w_f v_stretch a_l gap_xs bd_b_1 bd_b_bd"
56
+ style={{ padding: 12 }}
57
+ onClick={() => p.onSelect(row.id)}
58
+ >
59
+ <span className="ft_sm">
60
+ {row.code} · {row.name}
61
+ </span>
62
+ <span className="ft_xs cl_lt">{row.dates}</span>
63
+ <span className="h_item gap_xs">
64
+ <span className="pill bg_alt ft_xxs">{row.status}</span>
65
+ {row.critical ? (
66
+ <span className="cl_err ft_xxs">
67
+ {p.criticalText}
68
+ </span>
69
+ ) : null}
70
+ </span>
71
+ </button>
72
+ ))}
73
+ </section>
74
+ ))
75
+ )}
76
+ </div>
77
+ );
78
+ },
79
+ );
80
+ ProjectMobileListUI.displayName = 'ProjectMobileListUI';
@@ -0,0 +1,54 @@
1
+ import {
2
+ Button,
3
+ SegmentedControl,
4
+ type SegmentedControlOption,
5
+ } from '@jsb188/react-web/ui/Button';
6
+ import { memo, type ReactNode } from 'react';
7
+ /* Present compact planner controls with translated labels and caller-owned actions. */
8
+ export const ProjectToolbarUI = memo(
9
+ (p: {
10
+ title: string;
11
+ subText?: string | null;
12
+ zoom: string;
13
+ zoomOptions: SegmentedControlOption[];
14
+ actions: Array<{
15
+ key: string;
16
+ text: string;
17
+ disabled?: boolean;
18
+ onClick: () => void;
19
+ }>;
20
+ onSelectZoom: (zoom: string) => void;
21
+ children?: ReactNode;
22
+ }) => (
23
+ <div
24
+ className="no_shrink v_stretch gap_xs bd_b_1 bd_b_bd phone:hidden"
25
+ style={{ padding: '6px 12px' }}
26
+ >
27
+ <div className="h_item gap_sm">
28
+ <span className="f ellip ft_sm ft_semibold">{p.title}</span>
29
+ <SegmentedControl
30
+ options={p.zoomOptions}
31
+ selectedValue={p.zoom}
32
+ onClickItem={(_event, value) => p.onSelectZoom(value)}
33
+ />
34
+ </div>
35
+ {p.subText ? <span className="ft_xxs cl_lt">{p.subText}</span> : null}
36
+ <div className="h_item f_wrap gap_xs">
37
+ {p.actions.map((action) => (
38
+ <Button
39
+ key={action.key}
40
+ size="sm"
41
+ preset="bg_secondary"
42
+ text={action.text}
43
+ disabled={action.disabled}
44
+ onClick={action.onClick}
45
+ />
46
+ ))}
47
+ </div>
48
+ {p.children ? (
49
+ <div className="h_item f_wrap gap_sm">{p.children}</div>
50
+ ) : null}
51
+ </div>
52
+ ),
53
+ );
54
+ ProjectToolbarUI.displayName = 'ProjectToolbarUI';
@@ -0,0 +1,176 @@
1
+ import { memo, useState } from 'react';
2
+
3
+ /* Show one editable relationship while keeping unsaved type and lag local. */
4
+ const RelationshipRowUI = memo(
5
+ (p: {
6
+ row: {
7
+ id: string;
8
+ activityId: string;
9
+ text: string;
10
+ isDriving: boolean;
11
+ type?: string;
12
+ lag?: string;
13
+ };
14
+ editable?: boolean;
15
+ labels: {
16
+ remove: string;
17
+ edit: string;
18
+ type: string;
19
+ lag: string;
20
+ save: string;
21
+ cancel: string;
22
+ };
23
+ onSelectActivity: (id: string) => void;
24
+ onDelete: (id: string) => void;
25
+ onEdit?: (id: string, type: string, lag: string) => Promise<boolean>;
26
+ }) => {
27
+ const [editing, setEditing] = useState(false);
28
+ const [type, setType] = useState(p.row.type || 'FS');
29
+ const [lag, setLag] = useState(p.row.lag || '0');
30
+ const [saving, setSaving] = useState(false);
31
+ /* Close the draft only after the server accepts the relationship change. */
32
+ const save = async () => {
33
+ setSaving(true);
34
+ try {
35
+ if (await p.onEdit?.(p.row.id, type, lag)) setEditing(false);
36
+ } finally {
37
+ setSaving(false);
38
+ }
39
+ };
40
+ return (
41
+ <div className="v_stretch bd_b_1 bd_b_bd">
42
+ <div className="h_item gap_xs">
43
+ <button
44
+ type="button"
45
+ className={`f ft_xs a_l bg_hv${p.row.isDriving ? ' ft_semibold' : ''}`}
46
+ onClick={() => p.onSelectActivity(p.row.activityId)}
47
+ >
48
+ {p.row.text}
49
+ </button>
50
+ {p.editable ? (
51
+ <>
52
+ <button
53
+ type="button"
54
+ className="ft_xxs cl_primary"
55
+ onClick={() => {
56
+ setType(p.row.type || 'FS');
57
+ setLag(p.row.lag || '0');
58
+ setEditing(true);
59
+ }}
60
+ >
61
+ {p.labels.edit}
62
+ </button>
63
+ <button
64
+ type="button"
65
+ className="ft_xxs cl_err"
66
+ onClick={() => p.onDelete(p.row.id)}
67
+ >
68
+ {p.labels.remove}
69
+ </button>
70
+ </>
71
+ ) : null}
72
+ </div>
73
+ {editing && p.editable ? (
74
+ <div className="h_item f_wrap gap_xs mt_xs mb_xs">
75
+ <label className="v_stretch ft_xxs">
76
+ {p.labels.type}
77
+ <select
78
+ className="bg_alt bd_1 bd_bd ft_xs"
79
+ value={type}
80
+ onChange={(event) => setType(event.target.value)}
81
+ >
82
+ {['FS', 'SS', 'FF', 'SF'].map((value) => (
83
+ <option
84
+ key={value}
85
+ value={value}
86
+ >
87
+ {value}
88
+ </option>
89
+ ))}
90
+ </select>
91
+ </label>
92
+ <label className="v_stretch ft_xxs">
93
+ {p.labels.lag}
94
+ <input
95
+ className="bg_alt bd_1 bd_bd ft_xs"
96
+ style={{ width: 70 }}
97
+ type="number"
98
+ step="any"
99
+ value={lag}
100
+ onChange={(event) => setLag(event.target.value)}
101
+ />
102
+ </label>
103
+ <button
104
+ type="button"
105
+ className="ft_xxs cl_primary"
106
+ disabled={saving}
107
+ onClick={() => void save()}
108
+ >
109
+ {p.labels.save}
110
+ </button>
111
+ <button
112
+ type="button"
113
+ className="ft_xxs cl_lt"
114
+ disabled={saving}
115
+ onClick={() => setEditing(false)}
116
+ >
117
+ {p.labels.cancel}
118
+ </button>
119
+ </div>
120
+ ) : null}
121
+ </div>
122
+ );
123
+ },
124
+ );
125
+ /* Render incoming or outgoing links with caller-formatted labels and optional editing. */
126
+ export const RelationshipListUI = memo(
127
+ (p: {
128
+ headingText: string;
129
+ emptyText: string;
130
+ removeText: string;
131
+ editText: string;
132
+ typeLabel: string;
133
+ lagLabel: string;
134
+ saveText: string;
135
+ cancelText: string;
136
+ rows: Array<{
137
+ id: string;
138
+ activityId: string;
139
+ text: string;
140
+ isDriving: boolean;
141
+ type?: string;
142
+ lag?: string;
143
+ }>;
144
+ editable?: boolean;
145
+ onSelectActivity: (id: string) => void;
146
+ onDelete: (id: string) => void;
147
+ onEdit?: (id: string, type: string, lag: string) => Promise<boolean>;
148
+ }) => (
149
+ <div className="v_stretch mt_md">
150
+ <span className="ft_xs ft_semibold">{p.headingText}</span>
151
+ {!p.rows.length ? (
152
+ <span className="ft_xxs cl_lt">{p.emptyText}</span>
153
+ ) : (
154
+ p.rows.map((row) => (
155
+ <RelationshipRowUI
156
+ key={row.id}
157
+ row={row}
158
+ editable={p.editable}
159
+ labels={{
160
+ remove: p.removeText,
161
+ edit: p.editText,
162
+ type: p.typeLabel,
163
+ lag: p.lagLabel,
164
+ save: p.saveText,
165
+ cancel: p.cancelText,
166
+ }}
167
+ onSelectActivity={p.onSelectActivity}
168
+ onDelete={p.onDelete}
169
+ onEdit={p.onEdit}
170
+ />
171
+ ))
172
+ )}
173
+ </div>
174
+ ),
175
+ );
176
+ RelationshipListUI.displayName = 'RelationshipListUI';