@activecollab/components 2.0.577 → 2.0.579
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.
- package/dist/cjs/components/ViewSwitcher/useApplyToAllOffer.js +3 -1
- package/dist/cjs/components/ViewSwitcher/useApplyToAllOffer.js.map +1 -1
- package/dist/cjs/presentation/myWork/MyWorkTasks.js +83 -30
- package/dist/cjs/presentation/myWork/MyWorkTasks.js.map +1 -1
- package/dist/cjs/presentation/myWork/agendaGrid.js +1095 -0
- package/dist/cjs/presentation/myWork/agendaGrid.js.map +1 -0
- package/dist/cjs/presentation/shared/settings.js +6 -2
- package/dist/cjs/presentation/shared/settings.js.map +1 -1
- package/dist/cjs/presentation/shared/tokens.js +8 -1
- package/dist/cjs/presentation/shared/tokens.js.map +1 -1
- package/dist/cjs/presentation/timeboxes/AdjustmentList.js +31 -0
- package/dist/cjs/presentation/timeboxes/AdjustmentList.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/AgendaDayView.js +1722 -0
- package/dist/cjs/presentation/timeboxes/AgendaDayView.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/CapacityBar.js +54 -0
- package/dist/cjs/presentation/timeboxes/CapacityBar.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/SimulationCard.js +47 -0
- package/dist/cjs/presentation/timeboxes/SimulationCard.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/SimulationPanel.js +319 -0
- package/dist/cjs/presentation/timeboxes/SimulationPanel.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/TimeRecordsSection.js +206 -0
- package/dist/cjs/presentation/timeboxes/TimeRecordsSection.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/WorkloadView.js +887 -0
- package/dist/cjs/presentation/timeboxes/WorkloadView.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/__tests__/timeboxes.test.js +699 -0
- package/dist/cjs/presentation/timeboxes/__tests__/timeboxes.test.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/changes.js +293 -0
- package/dist/cjs/presentation/timeboxes/changes.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/mockData.js +320 -0
- package/dist/cjs/presentation/timeboxes/mockData.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/model.js +186 -0
- package/dist/cjs/presentation/timeboxes/model.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/pillLook.js +72 -0
- package/dist/cjs/presentation/timeboxes/pillLook.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/plan.js +181 -0
- package/dist/cjs/presentation/timeboxes/plan.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/reducer.js +763 -0
- package/dist/cjs/presentation/timeboxes/reducer.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/scheduler.js +147 -0
- package/dist/cjs/presentation/timeboxes/scheduler.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/store.js +65 -0
- package/dist/cjs/presentation/timeboxes/store.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/timeBlocks.js +1931 -0
- package/dist/cjs/presentation/timeboxes/timeBlocks.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/timeboxSettings.js +369 -0
- package/dist/cjs/presentation/timeboxes/timeboxSettings.js.map +1 -0
- package/dist/cjs/presentation/timeboxes/tracked.js +189 -0
- package/dist/cjs/presentation/timeboxes/tracked.js.map +1 -0
- package/dist/esm/components/ViewSwitcher/useApplyToAllOffer.d.ts.map +1 -1
- package/dist/esm/components/ViewSwitcher/useApplyToAllOffer.js +4 -2
- package/dist/esm/components/ViewSwitcher/useApplyToAllOffer.js.map +1 -1
- package/dist/esm/presentation/myWork/MyWorkTasks.d.ts +81 -1
- package/dist/esm/presentation/myWork/MyWorkTasks.d.ts.map +1 -1
- package/dist/esm/presentation/myWork/MyWorkTasks.js +76 -23
- package/dist/esm/presentation/myWork/MyWorkTasks.js.map +1 -1
- package/dist/esm/presentation/myWork/agendaGrid.d.ts +341 -0
- package/dist/esm/presentation/myWork/agendaGrid.d.ts.map +1 -0
- package/dist/esm/presentation/myWork/agendaGrid.js +1001 -0
- package/dist/esm/presentation/myWork/agendaGrid.js.map +1 -0
- package/dist/esm/presentation/shared/settings.d.ts +2 -0
- package/dist/esm/presentation/shared/settings.d.ts.map +1 -1
- package/dist/esm/presentation/shared/settings.js +5 -1
- package/dist/esm/presentation/shared/settings.js.map +1 -1
- package/dist/esm/presentation/shared/tokens.d.ts +6 -0
- package/dist/esm/presentation/shared/tokens.d.ts.map +1 -1
- package/dist/esm/presentation/shared/tokens.js +7 -0
- package/dist/esm/presentation/shared/tokens.js.map +1 -1
- package/dist/esm/presentation/timeboxes/AdjustmentList.d.ts +11 -0
- package/dist/esm/presentation/timeboxes/AdjustmentList.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/AdjustmentList.js +22 -0
- package/dist/esm/presentation/timeboxes/AdjustmentList.js.map +1 -0
- package/dist/esm/presentation/timeboxes/AgendaDayView.d.ts +15 -0
- package/dist/esm/presentation/timeboxes/AgendaDayView.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/AgendaDayView.js +1524 -0
- package/dist/esm/presentation/timeboxes/AgendaDayView.js.map +1 -0
- package/dist/esm/presentation/timeboxes/CapacityBar.d.ts +15 -0
- package/dist/esm/presentation/timeboxes/CapacityBar.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/CapacityBar.js +48 -0
- package/dist/esm/presentation/timeboxes/CapacityBar.js.map +1 -0
- package/dist/esm/presentation/timeboxes/SimulationCard.d.ts +13 -0
- package/dist/esm/presentation/timeboxes/SimulationCard.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/SimulationCard.js +41 -0
- package/dist/esm/presentation/timeboxes/SimulationCard.js.map +1 -0
- package/dist/esm/presentation/timeboxes/SimulationPanel.d.ts +18 -0
- package/dist/esm/presentation/timeboxes/SimulationPanel.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/SimulationPanel.js +267 -0
- package/dist/esm/presentation/timeboxes/SimulationPanel.js.map +1 -0
- package/dist/esm/presentation/timeboxes/TimeRecordsSection.d.ts +14 -0
- package/dist/esm/presentation/timeboxes/TimeRecordsSection.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/TimeRecordsSection.js +159 -0
- package/dist/esm/presentation/timeboxes/TimeRecordsSection.js.map +1 -0
- package/dist/esm/presentation/timeboxes/WorkloadView.d.ts +9 -0
- package/dist/esm/presentation/timeboxes/WorkloadView.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/WorkloadView.js +761 -0
- package/dist/esm/presentation/timeboxes/WorkloadView.js.map +1 -0
- package/dist/esm/presentation/timeboxes/__tests__/timeboxes.test.d.ts +2 -0
- package/dist/esm/presentation/timeboxes/__tests__/timeboxes.test.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/__tests__/timeboxes.test.js +640 -0
- package/dist/esm/presentation/timeboxes/__tests__/timeboxes.test.js.map +1 -0
- package/dist/esm/presentation/timeboxes/changes.d.ts +72 -0
- package/dist/esm/presentation/timeboxes/changes.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/changes.js +224 -0
- package/dist/esm/presentation/timeboxes/changes.js.map +1 -0
- package/dist/esm/presentation/timeboxes/mockData.d.ts +16 -0
- package/dist/esm/presentation/timeboxes/mockData.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/mockData.js +297 -0
- package/dist/esm/presentation/timeboxes/mockData.js.map +1 -0
- package/dist/esm/presentation/timeboxes/model.d.ts +136 -0
- package/dist/esm/presentation/timeboxes/model.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/model.js +129 -0
- package/dist/esm/presentation/timeboxes/model.js.map +1 -0
- package/dist/esm/presentation/timeboxes/pillLook.d.ts +40 -0
- package/dist/esm/presentation/timeboxes/pillLook.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/pillLook.js +65 -0
- package/dist/esm/presentation/timeboxes/pillLook.js.map +1 -0
- package/dist/esm/presentation/timeboxes/plan.d.ts +62 -0
- package/dist/esm/presentation/timeboxes/plan.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/plan.js +116 -0
- package/dist/esm/presentation/timeboxes/plan.js.map +1 -0
- package/dist/esm/presentation/timeboxes/reducer.d.ts +203 -0
- package/dist/esm/presentation/timeboxes/reducer.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/reducer.js +616 -0
- package/dist/esm/presentation/timeboxes/reducer.js.map +1 -0
- package/dist/esm/presentation/timeboxes/scheduler.d.ts +63 -0
- package/dist/esm/presentation/timeboxes/scheduler.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/scheduler.js +120 -0
- package/dist/esm/presentation/timeboxes/scheduler.js.map +1 -0
- package/dist/esm/presentation/timeboxes/store.d.ts +23 -0
- package/dist/esm/presentation/timeboxes/store.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/store.js +46 -0
- package/dist/esm/presentation/timeboxes/store.js.map +1 -0
- package/dist/esm/presentation/timeboxes/timeBlocks.d.ts +10 -0
- package/dist/esm/presentation/timeboxes/timeBlocks.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/timeBlocks.js +1767 -0
- package/dist/esm/presentation/timeboxes/timeBlocks.js.map +1 -0
- package/dist/esm/presentation/timeboxes/timeboxSettings.d.ts +71 -0
- package/dist/esm/presentation/timeboxes/timeboxSettings.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/timeboxSettings.js +302 -0
- package/dist/esm/presentation/timeboxes/timeboxSettings.js.map +1 -0
- package/dist/esm/presentation/timeboxes/tracked.d.ts +51 -0
- package/dist/esm/presentation/timeboxes/tracked.d.ts.map +1 -0
- package/dist/esm/presentation/timeboxes/tracked.js +136 -0
- package/dist/esm/presentation/timeboxes/tracked.js.map +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { describeChange } from "./changes";
|
|
3
|
+
import { MINUTES_PER_DAY, SNAP_MINUTES, allocationOn, availableDays, clockToMinutes, evenSpread, formatMinutes, isSplit, isTimebox, minutesToClock, partsOf, pinnedOn, rangeOf, snap, snapDown, timeboxesOn, untimedOn, untimedPartOn } from "./model";
|
|
4
|
+
import { lastAvailableDay, taskById, userOf } from "./plan";
|
|
5
|
+
|
|
6
|
+
/** The new state, and a message when the action was refused (state
|
|
7
|
+
unchanged) or stopped short (a resize that stops at its edge). */
|
|
8
|
+
|
|
9
|
+
const ok = state => ({
|
|
10
|
+
state
|
|
11
|
+
});
|
|
12
|
+
const validMinutes = minutes => Number.isInteger(minutes) && minutes > 0;
|
|
13
|
+
const MINUTES_ERROR = "Tracked time is whole minutes above 0";
|
|
14
|
+
const fail = (state, error) => ({
|
|
15
|
+
state,
|
|
16
|
+
error
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/* ------------------------------------------------------------------ */
|
|
20
|
+
/* Part helpers */
|
|
21
|
+
/* ------------------------------------------------------------------ */
|
|
22
|
+
|
|
23
|
+
const newPartId = state => ["p" + state.nextId, _extends({}, state, {
|
|
24
|
+
nextId: state.nextId + 1
|
|
25
|
+
})];
|
|
26
|
+
|
|
27
|
+
/** Sets the day's untimed part; 0 removes it. */
|
|
28
|
+
const setUntimed = (state, taskId, date, minutes) => {
|
|
29
|
+
const existing = untimedPartOn(state, taskId, date);
|
|
30
|
+
if (minutes <= 0) {
|
|
31
|
+
return existing ? _extends({}, state, {
|
|
32
|
+
parts: state.parts.filter(part => part !== existing)
|
|
33
|
+
}) : state;
|
|
34
|
+
}
|
|
35
|
+
if (existing) {
|
|
36
|
+
return _extends({}, state, {
|
|
37
|
+
parts: state.parts.map(part => part === existing ? _extends({}, part, {
|
|
38
|
+
durationMinutes: minutes
|
|
39
|
+
}) : part)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const _newPartId = newPartId(state),
|
|
43
|
+
id = _newPartId[0],
|
|
44
|
+
next = _newPartId[1];
|
|
45
|
+
return _extends({}, next, {
|
|
46
|
+
parts: [...next.parts, {
|
|
47
|
+
id,
|
|
48
|
+
taskId,
|
|
49
|
+
date,
|
|
50
|
+
startsOnTime: null,
|
|
51
|
+
durationMinutes: minutes
|
|
52
|
+
}]
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const addTimebox = (state, taskId, date, start, minutes) => {
|
|
56
|
+
const _newPartId2 = newPartId(state),
|
|
57
|
+
id = _newPartId2[0],
|
|
58
|
+
next = _newPartId2[1];
|
|
59
|
+
return _extends({}, next, {
|
|
60
|
+
parts: [...next.parts, {
|
|
61
|
+
id,
|
|
62
|
+
taskId,
|
|
63
|
+
date,
|
|
64
|
+
startsOnTime: minutesToClock(start),
|
|
65
|
+
durationMinutes: minutes
|
|
66
|
+
}]
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const updateTask = (state, taskId, patch) => _extends({}, state, {
|
|
70
|
+
tasks: state.tasks.map(task => task.id === taskId ? _extends({}, task, patch) : task)
|
|
71
|
+
});
|
|
72
|
+
const partById = (state, partId) => state.parts.find(part => part.id === partId);
|
|
73
|
+
|
|
74
|
+
/** Splits a task as the app's add(): its estimate spread evenly over the
|
|
75
|
+
assignee's available days, as untimed parts. */
|
|
76
|
+
export const ensureSplit = (state, context, taskId) => {
|
|
77
|
+
if (isSplit(state, taskId)) return state;
|
|
78
|
+
const task = taskById(state, taskId);
|
|
79
|
+
if (task.estimate === null) return state;
|
|
80
|
+
const spread = evenSpread(task.estimate, availableDays(task, userOf(context, task)));
|
|
81
|
+
let next = state;
|
|
82
|
+
spread.forEach((minutes, date) => {
|
|
83
|
+
next = setUntimed(next, taskId, date, minutes);
|
|
84
|
+
});
|
|
85
|
+
return next;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** The timeboxes that block a task on a day: the same assignee's
|
|
89
|
+
timeboxes of other tasks. Only these stop moves, resizes and drops. */
|
|
90
|
+
const blockingTimeboxes = (state, task, date) => state.parts.filter(part => {
|
|
91
|
+
var _state$tasks$find;
|
|
92
|
+
return part.date === date && isTimebox(part) && part.taskId !== task.id && ((_state$tasks$find = state.tasks.find(item => item.id === part.taskId)) == null ? void 0 : _state$tasks$find.assigneeId) === task.assigneeId;
|
|
93
|
+
}).map(rangeOf);
|
|
94
|
+
|
|
95
|
+
/** The task's own timeboxes on a day, except one. */
|
|
96
|
+
const sameTaskTimeboxes = (state, taskId, date, exceptPartId) => timeboxesOn(state, taskId, date).filter(part => part.id !== exceptPartId);
|
|
97
|
+
|
|
98
|
+
/** Two ranges that touch (one ends where the other starts) or overlap. */
|
|
99
|
+
const touches = (a, b) => a.start <= b.end && b.start <= a.end;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The task's own timeboxes on a day a range would join, and the union with
|
|
103
|
+
* them; a timebox the union reaches joins too.
|
|
104
|
+
*/
|
|
105
|
+
export const mergeTargets = (state, taskId, date, range, exceptPartId) => {
|
|
106
|
+
const parts = [];
|
|
107
|
+
let union = _extends({}, range);
|
|
108
|
+
let rest = sameTaskTimeboxes(state, taskId, date, exceptPartId);
|
|
109
|
+
let joined = true;
|
|
110
|
+
while (joined) {
|
|
111
|
+
joined = false;
|
|
112
|
+
const reached = rest.filter(part => touches(union, rangeOf(part)));
|
|
113
|
+
if (reached.length > 0) {
|
|
114
|
+
joined = true;
|
|
115
|
+
parts.push(...reached);
|
|
116
|
+
rest = rest.filter(part => !reached.includes(part));
|
|
117
|
+
union = reached.reduce((all, part) => ({
|
|
118
|
+
start: Math.min(all.start, rangeOf(part).start),
|
|
119
|
+
end: Math.max(all.end, rangeOf(part).end)
|
|
120
|
+
}), union);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
parts,
|
|
125
|
+
union
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Joins the task's touching or overlapping timeboxes on a day into one, the
|
|
131
|
+
* union of their ranges. The run keeps keepPartId when it is in it, else its
|
|
132
|
+
* earliest timebox. The day's total does not change: the untimed part is
|
|
133
|
+
* derived again (minutes an overlap loses go back to it).
|
|
134
|
+
*/
|
|
135
|
+
export const mergeTimeboxes = (state, taskId, date, keepPartId) => {
|
|
136
|
+
const total = partsOf(state, taskId).filter(part => part.date === date).reduce((sum, part) => sum + part.durationMinutes, 0);
|
|
137
|
+
const runs = [];
|
|
138
|
+
let runEnd = -1;
|
|
139
|
+
timeboxesOn(state, taskId, date).forEach(part => {
|
|
140
|
+
const range = rangeOf(part);
|
|
141
|
+
const run = runs[runs.length - 1];
|
|
142
|
+
if (run && range.start <= runEnd) {
|
|
143
|
+
run.push(part);
|
|
144
|
+
runEnd = Math.max(runEnd, range.end);
|
|
145
|
+
} else {
|
|
146
|
+
runs.push([part]);
|
|
147
|
+
runEnd = range.end;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
if (runs.every(run => run.length === 1)) return state;
|
|
151
|
+
let next = state;
|
|
152
|
+
runs.filter(run => run.length > 1).forEach(run => {
|
|
153
|
+
var _run$find;
|
|
154
|
+
const keep = (_run$find = run.find(part => part.id === keepPartId)) != null ? _run$find : run[0];
|
|
155
|
+
const start = Math.min(...run.map(part => rangeOf(part).start));
|
|
156
|
+
const end = Math.max(...run.map(part => rangeOf(part).end));
|
|
157
|
+
next = _extends({}, next, {
|
|
158
|
+
parts: next.parts.filter(part => part === keep || !run.includes(part)).map(part => part === keep ? _extends({}, part, {
|
|
159
|
+
startsOnTime: minutesToClock(start),
|
|
160
|
+
durationMinutes: end - start
|
|
161
|
+
}) : part)
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
return setUntimed(next, taskId, date, total - pinnedOn(next, taskId, date));
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/* ------------------------------------------------------------------ */
|
|
168
|
+
/* Edit day value */
|
|
169
|
+
/* ------------------------------------------------------------------ */
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The bounds of a day's total (EstimationsSplitsDialog's maxEstimate):
|
|
173
|
+
* anything from 0 to the estimate less the days before. Timeboxes do not
|
|
174
|
+
* bound it; they are fitted to the new totals (fitTimeboxes).
|
|
175
|
+
*/
|
|
176
|
+
export const dayValueRange = (state, context, taskId, date) => {
|
|
177
|
+
var _task$estimate, _lastAvailableDay;
|
|
178
|
+
const task = taskById(state, taskId);
|
|
179
|
+
const user = userOf(context, task);
|
|
180
|
+
const days = availableDays(task, user);
|
|
181
|
+
const estimate = (_task$estimate = task.estimate) != null ? _task$estimate : 0;
|
|
182
|
+
const before = days.filter(day => day < date).reduce((total, day) => total + allocationOn(state, task, user, day), 0);
|
|
183
|
+
return {
|
|
184
|
+
min: 0,
|
|
185
|
+
max: estimate - before,
|
|
186
|
+
locked: date >= ((_lastAvailableDay = lastAvailableDay(task, user)) != null ? _lastAvailableDay : date)
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/** The inline error for a day value, or null when it can be saved. */
|
|
191
|
+
export const dayValueError = (state, context, taskId, date, minutes) => {
|
|
192
|
+
const range = dayValueRange(state, context, taskId, date);
|
|
193
|
+
if (range.locked) return "The last workday takes what the other days leave";
|
|
194
|
+
if (minutes < range.min) return "Enter 0 or more";
|
|
195
|
+
if (minutes > range.max) {
|
|
196
|
+
return "At most " + formatMinutes(range.max) + ": the estimate has no more left";
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Fits a day's timeboxes into a new total. When the total still holds what
|
|
203
|
+
* is pinned, the timeboxes stay and the untimed part takes the rest.
|
|
204
|
+
* Otherwise the untimed part goes first, then the timeboxes from the latest
|
|
205
|
+
* start back: those no longer needed are deleted, the last one kept is
|
|
206
|
+
* shortened at its end (rounded down to 5 minutes, the leftover minutes
|
|
207
|
+
* untimed), and deleted too when that leaves it under the min gap.
|
|
208
|
+
*/
|
|
209
|
+
export const fitTimeboxes = (state, taskId, date, total) => {
|
|
210
|
+
let excess = pinnedOn(state, taskId, date) - total;
|
|
211
|
+
let next = state;
|
|
212
|
+
const latestFirst = [...timeboxesOn(state, taskId, date)].reverse();
|
|
213
|
+
for (const part of latestFirst) {
|
|
214
|
+
if (excess <= 0) break;
|
|
215
|
+
if (excess >= part.durationMinutes) {
|
|
216
|
+
next = _extends({}, next, {
|
|
217
|
+
parts: next.parts.filter(item => item.id !== part.id)
|
|
218
|
+
});
|
|
219
|
+
excess -= part.durationMinutes;
|
|
220
|
+
} else {
|
|
221
|
+
const length = snapDown(part.durationMinutes - excess);
|
|
222
|
+
next = _extends({}, next, {
|
|
223
|
+
parts: length < next.settings.minGapMinutes ? next.parts.filter(item => item.id !== part.id) : next.parts.map(item => item.id === part.id ? _extends({}, item, {
|
|
224
|
+
durationMinutes: length
|
|
225
|
+
}) : item)
|
|
226
|
+
});
|
|
227
|
+
excess = 0;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return setUntimed(next, taskId, date, total - pinnedOn(next, taskId, date));
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* A new total for one day, as the app's edit(): earlier days stay, the day
|
|
235
|
+
* takes the total, later days share the rest of the estimate evenly. Then
|
|
236
|
+
* the timeboxes of every day whose total was set are fitted into it.
|
|
237
|
+
*/
|
|
238
|
+
const editDayValue = (state, context, taskId, date, minutes) => {
|
|
239
|
+
var _task$estimate2;
|
|
240
|
+
const error = dayValueError(state, context, taskId, date, minutes);
|
|
241
|
+
if (error) return fail(state, error);
|
|
242
|
+
const task = taskById(state, taskId);
|
|
243
|
+
const user = userOf(context, task);
|
|
244
|
+
let next = ensureSplit(state, context, taskId);
|
|
245
|
+
const days = availableDays(task, user);
|
|
246
|
+
const before = days.filter(day => day < date).reduce((total, day) => total + allocationOn(next, task, user, day), 0);
|
|
247
|
+
const totals = evenSpread(((_task$estimate2 = task.estimate) != null ? _task$estimate2 : 0) - before - minutes, days.filter(day => day > date));
|
|
248
|
+
totals.set(date, minutes);
|
|
249
|
+
totals.forEach((total, day) => {
|
|
250
|
+
next = fitTimeboxes(next, taskId, day, total);
|
|
251
|
+
});
|
|
252
|
+
return ok(next);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/** The timeboxes an edit of a day's total would shorten or delete,
|
|
256
|
+
without saving it. */
|
|
257
|
+
export const previewDayValue = (state, context, taskId, date, minutes) => {
|
|
258
|
+
const result = reduce(state, context, {
|
|
259
|
+
type: "editDayValue",
|
|
260
|
+
taskId,
|
|
261
|
+
date,
|
|
262
|
+
minutes
|
|
263
|
+
});
|
|
264
|
+
if (result.error) return [];
|
|
265
|
+
return describeChange(state, result.state, context).timeboxes.filter(item => item.kind === "resized" || item.kind === "deleted");
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/* ------------------------------------------------------------------ */
|
|
269
|
+
/* Drop, move, resize */
|
|
270
|
+
/* ------------------------------------------------------------------ */
|
|
271
|
+
|
|
272
|
+
/** How many of the day's minutes a dragged row can still pin. */
|
|
273
|
+
export const draggableMinutes = (state, context, taskId, date) => {
|
|
274
|
+
const task = taskById(state, taskId);
|
|
275
|
+
if (task.estimate === null) return 60;
|
|
276
|
+
return Math.max(0, untimedOn(state, task, userOf(context, task), date));
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Where a dropped task lands: at the snapped drop time, as long as its
|
|
281
|
+
* untimed minutes for the day, cut at the next pinned timebox (the rest
|
|
282
|
+
* stays a suggestion) and at midnight. A task without an estimate gets an
|
|
283
|
+
* hour.
|
|
284
|
+
*/
|
|
285
|
+
export const planDrop = (state, context, taskId, date, dropAt) => {
|
|
286
|
+
const task = taskById(state, taskId);
|
|
287
|
+
const start = Math.min(snap(dropAt), MINUTES_PER_DAY - SNAP_MINUTES);
|
|
288
|
+
const others = blockingTimeboxes(state, task, date);
|
|
289
|
+
const own = sameTaskTimeboxes(state, taskId, date).map(rangeOf);
|
|
290
|
+
if ([...others, ...own].some(range => range.start <= start && range.end > start)) {
|
|
291
|
+
return {
|
|
292
|
+
error: "That time is already pinned"
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
const nextPinned = others.filter(range => range.start > start).reduce((first, range) => Math.min(first, range.start), MINUTES_PER_DAY);
|
|
296
|
+
const available = draggableMinutes(state, context, taskId, date);
|
|
297
|
+
const minutes = snapDown(Math.min(available, nextPinned - start));
|
|
298
|
+
if (minutes < SNAP_MINUTES) {
|
|
299
|
+
return available < SNAP_MINUTES ? {
|
|
300
|
+
error: "All of today's allocation is scheduled"
|
|
301
|
+
} : {
|
|
302
|
+
error: "No room before the next pinned timebox"
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
start,
|
|
307
|
+
minutes
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/** A timebox's new start: snapped, kept between its pinned neighbours and
|
|
312
|
+
inside the day. Events may overlap it. */
|
|
313
|
+
export const planMove = (state, partId, start) => {
|
|
314
|
+
const part = partById(state, partId);
|
|
315
|
+
if (!part) return start;
|
|
316
|
+
const task = taskById(state, part.taskId);
|
|
317
|
+
const own = rangeOf(part);
|
|
318
|
+
const others = blockingTimeboxes(state, task, part.date);
|
|
319
|
+
const previousEnd = others.filter(range => range.end <= own.start).reduce((last, range) => Math.max(last, range.end), 0);
|
|
320
|
+
const nextStart = others.filter(range => range.start >= own.end).reduce((first, range) => Math.min(first, range.start), MINUTES_PER_DAY);
|
|
321
|
+
return Math.min(Math.max(snap(start), previousEnd), nextStart - part.durationMinutes);
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* A resize: snapped, kept between pinned neighbours and inside the day, at
|
|
325
|
+
* least the min gap long. An edge that reaches one of the task's own
|
|
326
|
+
* timeboxes joins it: the plan is the union, and its growth is the union
|
|
327
|
+
* less both lengths. Growing past the day's allocation takes minutes
|
|
328
|
+
* from the following days, which a one-day task or the task's last day
|
|
329
|
+
* cannot.
|
|
330
|
+
*/
|
|
331
|
+
export const planResize = (state, context, partId, start, end) => {
|
|
332
|
+
var _days;
|
|
333
|
+
const part = partById(state, partId);
|
|
334
|
+
if (!part) return {
|
|
335
|
+
kind: "blocked",
|
|
336
|
+
start,
|
|
337
|
+
end,
|
|
338
|
+
reason: ""
|
|
339
|
+
};
|
|
340
|
+
const task = taskById(state, part.taskId);
|
|
341
|
+
const user = userOf(context, task);
|
|
342
|
+
const own = rangeOf(part);
|
|
343
|
+
const minLength = state.settings.minGapMinutes;
|
|
344
|
+
const others = blockingTimeboxes(state, task, part.date);
|
|
345
|
+
const previousEnd = others.filter(range => range.end <= own.start).reduce((last, range) => Math.max(last, range.end), 0);
|
|
346
|
+
const nextStart = others.filter(range => range.start >= own.end).reduce((first, range) => Math.min(first, range.start), MINUTES_PER_DAY);
|
|
347
|
+
let newStart = Math.max(snap(start), previousEnd);
|
|
348
|
+
let newEnd = Math.min(snap(end), nextStart);
|
|
349
|
+
if (newEnd - newStart < minLength) {
|
|
350
|
+
if (start !== own.start) newStart = newEnd - minLength;else newEnd = newStart + minLength;
|
|
351
|
+
}
|
|
352
|
+
const _mergeTargets = mergeTargets(state, task.id, part.date, {
|
|
353
|
+
start: newStart,
|
|
354
|
+
end: newEnd
|
|
355
|
+
}, partId),
|
|
356
|
+
merges = _mergeTargets.parts,
|
|
357
|
+
union = _mergeTargets.union;
|
|
358
|
+
const growth = union.end - union.start - part.durationMinutes - merges.reduce((sum, item) => sum + item.durationMinutes, 0);
|
|
359
|
+
const untimed = Math.max(0, untimedOn(state, task, user, part.date));
|
|
360
|
+
if (growth <= untimed) {
|
|
361
|
+
return {
|
|
362
|
+
kind: "free",
|
|
363
|
+
start: union.start,
|
|
364
|
+
end: union.end,
|
|
365
|
+
merges
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
const allocation = allocationOn(state, task, user, part.date);
|
|
369
|
+
const days = availableDays(task, user);
|
|
370
|
+
const stopAt = (limit, reason) => {
|
|
371
|
+
const allowed = part.durationMinutes + limit;
|
|
372
|
+
return start !== own.start ? {
|
|
373
|
+
kind: "blocked",
|
|
374
|
+
start: newEnd - allowed,
|
|
375
|
+
end: newEnd,
|
|
376
|
+
reason
|
|
377
|
+
} : {
|
|
378
|
+
kind: "blocked",
|
|
379
|
+
start: newStart,
|
|
380
|
+
end: newStart + allowed,
|
|
381
|
+
reason
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
if (days.length <= 1 || part.date >= ((_days = days[days.length - 1]) != null ? _days : part.date)) {
|
|
385
|
+
return stopAt(untimed, "Today's allocation is " + formatMinutes(allocation));
|
|
386
|
+
}
|
|
387
|
+
const to = allocation + growth - untimed;
|
|
388
|
+
const _dayValueRange = dayValueRange(state, context, task.id, part.date),
|
|
389
|
+
max = _dayValueRange.max;
|
|
390
|
+
if (to > max) {
|
|
391
|
+
return stopAt(untimed + max - allocation, "At most " + formatMinutes(max) + " fits on this day");
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
kind: "increase",
|
|
395
|
+
start: union.start,
|
|
396
|
+
end: union.end,
|
|
397
|
+
from: allocation,
|
|
398
|
+
to,
|
|
399
|
+
merges
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/** The confirm dialog's text for growing a day's allocation. */
|
|
404
|
+
export const increaseConfirmText = (task, from, to) => "Increase today's allocation for " + task.name + " from " + formatMinutes(from) + " to " + formatMinutes(to) + "? The difference is taken from the following days.";
|
|
405
|
+
|
|
406
|
+
/** The confirm dialog's text for unsplitting a task. */
|
|
407
|
+
export const unsplitConfirmText = (state, task) => {
|
|
408
|
+
const pinned = partsOf(state, task.id).filter(isTimebox).length;
|
|
409
|
+
return pinned > 0 ? "Unsplit " + task.name + " and remove " + pinned + " pinned " + (pinned === 1 ? "timebox" : "timeboxes") + "?" : "Unsplit " + task.name + "?";
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
/* ------------------------------------------------------------------ */
|
|
413
|
+
/* The reducer */
|
|
414
|
+
/* ------------------------------------------------------------------ */
|
|
415
|
+
|
|
416
|
+
const pin = (state, context, taskId, date, start, minutes) => {
|
|
417
|
+
var _untimedPartOn$durati, _untimedPartOn;
|
|
418
|
+
const next = ensureSplit(state, context, taskId);
|
|
419
|
+
const untimed = (_untimedPartOn$durati = (_untimedPartOn = untimedPartOn(next, taskId, date)) == null ? void 0 : _untimedPartOn.durationMinutes) != null ? _untimedPartOn$durati : 0;
|
|
420
|
+
const pinned = Math.min(minutes, untimed);
|
|
421
|
+
if (pinned <= 0) return fail(state, "All of today's allocation is scheduled");
|
|
422
|
+
/* Pinned next to (or over) one of its own timeboxes, the new one joins
|
|
423
|
+
that one, which keeps its id. */
|
|
424
|
+
const joins = mergeTargets(next, taskId, date, {
|
|
425
|
+
start,
|
|
426
|
+
end: start + pinned
|
|
427
|
+
}).parts[0];
|
|
428
|
+
return ok(mergeTimeboxes(addTimebox(setUntimed(next, taskId, date, untimed - pinned), taskId, date, start, pinned), taskId, date, joins == null ? void 0 : joins.id));
|
|
429
|
+
};
|
|
430
|
+
export const reduce = (state, context, action) => {
|
|
431
|
+
switch (action.type) {
|
|
432
|
+
case "pin":
|
|
433
|
+
return pin(state, context, action.taskId, action.date, action.start, action.minutes);
|
|
434
|
+
case "pinAll":
|
|
435
|
+
return ok(action.suggestions.reduce((next, item) => pin(next, context, item.taskId, action.date, item.start, item.minutes).state, state));
|
|
436
|
+
case "dropTask":
|
|
437
|
+
{
|
|
438
|
+
const task = taskById(state, action.taskId);
|
|
439
|
+
const plan = planDrop(state, context, action.taskId, action.date, action.start);
|
|
440
|
+
if ("error" in plan) return fail(state, plan.error);
|
|
441
|
+
let next = state;
|
|
442
|
+
if (task.estimate === null) {
|
|
443
|
+
/* An hour a day over the task's range: the drop pins today's. */
|
|
444
|
+
next = updateTask(next, task.id, {
|
|
445
|
+
estimate: 60 * availableDays(task, userOf(context, task)).length
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
const result = pin(next, context, task.id, action.date, plan.start, plan.minutes);
|
|
449
|
+
return result.error ? fail(state, result.error) : result;
|
|
450
|
+
}
|
|
451
|
+
case "moveTimebox":
|
|
452
|
+
{
|
|
453
|
+
const part = partById(state, action.partId);
|
|
454
|
+
if (!part) return fail(state, "No such timebox");
|
|
455
|
+
const start = planMove(state, action.partId, action.start);
|
|
456
|
+
return ok(mergeTimeboxes(_extends({}, state, {
|
|
457
|
+
parts: state.parts.map(item => item === part ? _extends({}, item, {
|
|
458
|
+
startsOnTime: minutesToClock(start)
|
|
459
|
+
}) : item)
|
|
460
|
+
}), part.taskId, part.date, part.id));
|
|
461
|
+
}
|
|
462
|
+
case "resizeTimebox":
|
|
463
|
+
{
|
|
464
|
+
const part = partById(state, action.partId);
|
|
465
|
+
if (!part) return fail(state, "No such timebox");
|
|
466
|
+
const task = taskById(state, part.taskId);
|
|
467
|
+
const user = userOf(context, task);
|
|
468
|
+
const plan = planResize(state, context, action.partId, action.start, action.end);
|
|
469
|
+
if (plan.kind === "increase" && !action.allowIncrease) {
|
|
470
|
+
return fail(state, increaseConfirmText(task, plan.from, plan.to));
|
|
471
|
+
}
|
|
472
|
+
const allocation = allocationOn(state, task, user, part.date);
|
|
473
|
+
let next = _extends({}, state, {
|
|
474
|
+
parts: state.parts.map(item => item === part ? _extends({}, item, {
|
|
475
|
+
startsOnTime: minutesToClock(plan.start),
|
|
476
|
+
durationMinutes: plan.end - plan.start
|
|
477
|
+
}) : item)
|
|
478
|
+
});
|
|
479
|
+
/* The plan is the union with any timebox it reaches: those join this
|
|
480
|
+
one; the untimed part follows below. */
|
|
481
|
+
next = mergeTimeboxes(next, task.id, part.date, part.id);
|
|
482
|
+
if (plan.kind === "increase") {
|
|
483
|
+
const result = editDayValue(next, context, task.id, part.date, plan.to);
|
|
484
|
+
if (result.error) return fail(state, result.error);
|
|
485
|
+
next = result.state;
|
|
486
|
+
} else {
|
|
487
|
+
next = setUntimed(next, task.id, part.date, allocation - pinnedOn(next, task.id, part.date));
|
|
488
|
+
}
|
|
489
|
+
return plan.kind === "blocked" ? fail(next, plan.reason) : ok(next);
|
|
490
|
+
}
|
|
491
|
+
case "unpin":
|
|
492
|
+
{
|
|
493
|
+
var _untimedPartOn$durati2, _untimedPartOn2;
|
|
494
|
+
const part = partById(state, action.partId);
|
|
495
|
+
if (!part) return fail(state, "No such timebox");
|
|
496
|
+
const untimed = (_untimedPartOn$durati2 = (_untimedPartOn2 = untimedPartOn(state, part.taskId, part.date)) == null ? void 0 : _untimedPartOn2.durationMinutes) != null ? _untimedPartOn$durati2 : 0;
|
|
497
|
+
const next = _extends({}, state, {
|
|
498
|
+
parts: state.parts.filter(item => item !== part)
|
|
499
|
+
});
|
|
500
|
+
return ok(setUntimed(next, part.taskId, part.date, untimed + part.durationMinutes));
|
|
501
|
+
}
|
|
502
|
+
case "editDayValue":
|
|
503
|
+
return editDayValue(state, context, action.taskId, action.date, action.minutes);
|
|
504
|
+
case "split":
|
|
505
|
+
{
|
|
506
|
+
const task = taskById(state, action.taskId);
|
|
507
|
+
if (task.estimate === null) return fail(state, "Set an estimate first");
|
|
508
|
+
return ok(ensureSplit(state, context, action.taskId));
|
|
509
|
+
}
|
|
510
|
+
case "unsplit":
|
|
511
|
+
return ok(_extends({}, state, {
|
|
512
|
+
parts: state.parts.filter(part => part.taskId !== action.taskId)
|
|
513
|
+
}));
|
|
514
|
+
case "setEstimate":
|
|
515
|
+
{
|
|
516
|
+
const task = taskById(state, action.taskId);
|
|
517
|
+
if (!isSplit(state, task.id) || action.minutes === null) {
|
|
518
|
+
const next = updateTask(state, task.id, {
|
|
519
|
+
estimate: action.minutes
|
|
520
|
+
});
|
|
521
|
+
return ok(action.minutes === null ? _extends({}, next, {
|
|
522
|
+
parts: next.parts.filter(part => part.taskId !== task.id)
|
|
523
|
+
}) : next);
|
|
524
|
+
}
|
|
525
|
+
/* A split task keeps its timeboxes; the rest of the new estimate is
|
|
526
|
+
spread evenly over its untimed parts. */
|
|
527
|
+
const pinned = partsOf(state, task.id).filter(isTimebox).reduce((total, part) => total + part.durationMinutes, 0);
|
|
528
|
+
if (action.minutes < pinned) {
|
|
529
|
+
return fail(state, formatMinutes(pinned) + " is pinned on this task");
|
|
530
|
+
}
|
|
531
|
+
let next = updateTask(state, task.id, {
|
|
532
|
+
estimate: action.minutes
|
|
533
|
+
});
|
|
534
|
+
const days = availableDays(task, userOf(context, task));
|
|
535
|
+
const spread = evenSpread(action.minutes - pinned, days);
|
|
536
|
+
days.forEach(day => {
|
|
537
|
+
var _spread$get;
|
|
538
|
+
next = setUntimed(next, task.id, day, (_spread$get = spread.get(day)) != null ? _spread$get : 0);
|
|
539
|
+
});
|
|
540
|
+
return ok(next);
|
|
541
|
+
}
|
|
542
|
+
case "setCompleted":
|
|
543
|
+
return ok(updateTask(state, action.taskId, {
|
|
544
|
+
isCompleted: action.completed
|
|
545
|
+
}));
|
|
546
|
+
case "setSubtaskCompleted":
|
|
547
|
+
return ok(_extends({}, state, {
|
|
548
|
+
subtasks: state.subtasks.map(subtask => subtask.id === action.subtaskId ? _extends({}, subtask, {
|
|
549
|
+
isCompleted: action.completed
|
|
550
|
+
}) : subtask)
|
|
551
|
+
}));
|
|
552
|
+
case "upsertEvent":
|
|
553
|
+
{
|
|
554
|
+
const event = action.event;
|
|
555
|
+
if (clockToMinutes(event.endsOnTime) <= clockToMinutes(event.startsOnTime)) {
|
|
556
|
+
return fail(state, "An event ends after it starts");
|
|
557
|
+
}
|
|
558
|
+
if (event.id !== undefined) {
|
|
559
|
+
return ok(_extends({}, state, {
|
|
560
|
+
events: state.events.map(item => item.id === event.id ? _extends({}, item, event, {
|
|
561
|
+
id: item.id
|
|
562
|
+
}) : item)
|
|
563
|
+
}));
|
|
564
|
+
}
|
|
565
|
+
return ok(_extends({}, state, {
|
|
566
|
+
nextId: state.nextId + 1,
|
|
567
|
+
events: [...state.events, _extends({}, event, {
|
|
568
|
+
id: state.nextId
|
|
569
|
+
})]
|
|
570
|
+
}));
|
|
571
|
+
}
|
|
572
|
+
case "removeEvent":
|
|
573
|
+
return ok(_extends({}, state, {
|
|
574
|
+
events: state.events.filter(event => event.id !== action.id)
|
|
575
|
+
}));
|
|
576
|
+
case "updateSettings":
|
|
577
|
+
return ok(_extends({}, state, {
|
|
578
|
+
settings: _extends({}, state.settings, action.settings)
|
|
579
|
+
}));
|
|
580
|
+
case "addTimeRecord":
|
|
581
|
+
{
|
|
582
|
+
var _action$userId;
|
|
583
|
+
if (!validMinutes(action.minutes)) return fail(state, MINUTES_ERROR);
|
|
584
|
+
const task = taskById(state, action.taskId);
|
|
585
|
+
return ok(_extends({}, state, {
|
|
586
|
+
nextId: state.nextId + 1,
|
|
587
|
+
timeRecords: [...state.timeRecords, {
|
|
588
|
+
id: "t" + state.nextId,
|
|
589
|
+
taskId: task.id,
|
|
590
|
+
userId: (_action$userId = action.userId) != null ? _action$userId : task.assigneeId,
|
|
591
|
+
recordDate: action.recordDate,
|
|
592
|
+
minutes: action.minutes
|
|
593
|
+
}]
|
|
594
|
+
}));
|
|
595
|
+
}
|
|
596
|
+
case "updateTimeRecord":
|
|
597
|
+
{
|
|
598
|
+
if (!validMinutes(action.minutes)) return fail(state, MINUTES_ERROR);
|
|
599
|
+
if (!state.timeRecords.some(record => record.id === action.id)) {
|
|
600
|
+
return fail(state, "No such time record");
|
|
601
|
+
}
|
|
602
|
+
return ok(_extends({}, state, {
|
|
603
|
+
timeRecords: state.timeRecords.map(record => record.id === action.id ? _extends({}, record, {
|
|
604
|
+
minutes: action.minutes
|
|
605
|
+
}) : record)
|
|
606
|
+
}));
|
|
607
|
+
}
|
|
608
|
+
case "removeTimeRecord":
|
|
609
|
+
return ok(_extends({}, state, {
|
|
610
|
+
timeRecords: state.timeRecords.filter(record => record.id !== action.id)
|
|
611
|
+
}));
|
|
612
|
+
default:
|
|
613
|
+
return ok(state);
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
//# sourceMappingURL=reducer.js.map
|