@sprucelabs/spruce-calendar-components 29.0.4 → 29.0.6
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/build/.spruce/errors/errors.types.d.ts +12 -12
- package/build/.spruce/errors/options.types.d.ts +2 -2
- package/build/.spruce/schemas/schemas.types.d.ts +2602 -3152
- package/build/.spruce/schemas/schemas.types.js +3 -0
- package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +11 -13
- package/build/__tests__/support/SpyEventManager.js +1 -1
- package/build/__tests__/support/SpyPeopleManager.js +4 -4
- package/build/__tests__/support/SpyRemoteEventStore.js +4 -4
- package/build/__tests__/support/utilities/calendarAssert.js +2 -1
- package/build/__tests__/support/utilities/calendarSkillAssert.js +5 -4
- package/build/calendar/Calendar.vc.js +17 -18
- package/build/calendar/CalendarEventManager.js +42 -49
- package/build/calendar/CalendarPeopleManager.js +12 -15
- package/build/calendar/CalendarPersister.js +9 -12
- package/build/constants.js +2 -1
- package/build/errors/SpruceError.js +1 -1
- package/build/esm/.spruce/errors/errors.types.d.ts +12 -12
- package/build/esm/.spruce/errors/options.types.d.ts +2 -2
- package/build/esm/.spruce/schemas/schemas.types.d.ts +2602 -3152
- package/build/esm/.spruce/schemas/schemas.types.js +3 -0
- package/build/root/Root.svc.js +36 -49
- package/build/stores/RemoteEventStore.js +13 -18
- package/build/stores/RemotePreferencesStore.js +4 -10
- package/build/toolBelt/CalendarToolRegistrar.js +12 -8
- package/build/toolBelt/CalendarToolTestFactory.js +1 -1
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +20 -20
- package/build/toolBelt/states/PrerequisitesToolBeltState.js +21 -24
- package/build/toolBelt/states/RootToolBeltState.js +19 -22
- package/build/toolBelt/states/UniversalEventToolBeltState.js +4 -1
- package/build/toolBelt/states/makeEventTyped.js +2 -1
- package/build/tools/CalendarSelectTool.vc.js +4 -7
- package/build/tools/EventDateTimeTool.vc.js +6 -10
- package/build/tools/EventDurationTool.vc.js +4 -7
- package/build/tools/EventRepeatingTool.vc.js +3 -7
- package/build/tools/EventTitleTool.vc.js +5 -8
- package/build/tools/PersonSelectTool.vc.js +8 -11
- package/build/utilities/draftGenerator.js +1 -1
- package/build/viewControllers/DateSelectCard.vc.js +2 -5
- package/build/viewControllers/EventControlsCard.vc.js +5 -9
- package/build/viewControllers/RepeatingControlsList.vc.js +54 -44
- package/build/viewControllers/SelectUpdateRepeatingStrategyCard.vc.js +4 -7
- package/build/viewControllers/UniversalCalendarEvent.vc.js +1 -1
- package/package.json +1 -1
package/build/root/Root.svc.js
CHANGED
|
@@ -12,35 +12,10 @@ const RemotePreferencesStore_1 = __importDefault(require("../stores/RemotePrefer
|
|
|
12
12
|
const PrerequisitesToolBeltState_1 = require("../toolBelt/states/PrerequisitesToolBeltState");
|
|
13
13
|
const RootToolBeltState_1 = require("../toolBelt/states/RootToolBeltState");
|
|
14
14
|
class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkillViewController {
|
|
15
|
-
static id = 'root';
|
|
16
|
-
static shouldConfirmDrops = false;
|
|
17
|
-
static shouldUpdateOnInterval = true;
|
|
18
|
-
static refreshInterval = 1000 * 60;
|
|
19
|
-
static shouldCacheEvents = false;
|
|
20
|
-
calendarVc;
|
|
21
|
-
toolBeltVc;
|
|
22
|
-
person;
|
|
23
|
-
sm;
|
|
24
|
-
toolBeltStates;
|
|
25
|
-
remoteEventStore;
|
|
26
|
-
selectingTypePromise;
|
|
27
|
-
selectingTypeResolve;
|
|
28
|
-
client;
|
|
29
|
-
organizationId;
|
|
30
|
-
locationId;
|
|
31
|
-
transitionPromise;
|
|
32
|
-
loadEventsPromise;
|
|
33
|
-
events;
|
|
34
|
-
preferences;
|
|
35
|
-
people;
|
|
36
|
-
remoteVc;
|
|
37
|
-
draftEvent;
|
|
38
|
-
loadEventInterval;
|
|
39
|
-
shouldIgnoreNextDeselectEvent = false;
|
|
40
|
-
lastStartDate;
|
|
41
|
-
locale;
|
|
42
15
|
constructor(options) {
|
|
43
16
|
super(options);
|
|
17
|
+
this.shouldIgnoreNextDeselectEvent = false;
|
|
18
|
+
this.getScope = () => ['employed', 'location'];
|
|
44
19
|
this.toolBeltVc = this.ToolBeltVc();
|
|
45
20
|
this.calendarVc = this.CalendarVc();
|
|
46
21
|
this.sm = this.ToolBeltStateMachine();
|
|
@@ -77,7 +52,6 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
77
52
|
this.handleDidCreateOrUpdateRemoteEvent.bind(this);
|
|
78
53
|
this.handleDidCancelEvent = this.handleDidCancelEvent.bind(this);
|
|
79
54
|
}
|
|
80
|
-
getScope = () => ['employed', 'location'];
|
|
81
55
|
createToolBeltStates() {
|
|
82
56
|
this.toolBeltStates = {
|
|
83
57
|
root: new RootToolBeltState_1.RootToolBeltState({
|
|
@@ -104,8 +78,9 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
104
78
|
return sm;
|
|
105
79
|
}
|
|
106
80
|
async handleCancelEvent(eventId) {
|
|
81
|
+
var _a;
|
|
107
82
|
const event = this.events.getEvent(eventId);
|
|
108
|
-
const confirm = (event.totalInRepeating
|
|
83
|
+
const confirm = ((_a = event.totalInRepeating) !== null && _a !== void 0 ? _a : 0) > 0 ||
|
|
109
84
|
(await this.confirm({
|
|
110
85
|
title: 'Cancel?',
|
|
111
86
|
message: `You wanna cancel this?`,
|
|
@@ -132,6 +107,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
132
107
|
return strategy;
|
|
133
108
|
}
|
|
134
109
|
async handleSelectEventType(type) {
|
|
110
|
+
var _a, _b;
|
|
135
111
|
this.selectingTypePromise = new Promise((resolve) => {
|
|
136
112
|
this.selectingTypeResolve = resolve;
|
|
137
113
|
});
|
|
@@ -141,7 +117,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
141
117
|
await this.transitionToStateFromDraftEvent();
|
|
142
118
|
}
|
|
143
119
|
catch (err) {
|
|
144
|
-
this.selectingTypeResolve
|
|
120
|
+
(_a = this.selectingTypeResolve) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
145
121
|
console.error(err);
|
|
146
122
|
await this.alert({
|
|
147
123
|
message: `I could not load what I need to add your ${type.name}! I've let the humans know and they are on the case!`,
|
|
@@ -150,7 +126,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
150
126
|
return;
|
|
151
127
|
}
|
|
152
128
|
}
|
|
153
|
-
this.selectingTypeResolve
|
|
129
|
+
(_b = this.selectingTypeResolve) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
154
130
|
}
|
|
155
131
|
async restoreDraftAfterStateLoadError() {
|
|
156
132
|
await this.waitUntilDoneSaving();
|
|
@@ -163,8 +139,9 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
163
139
|
await this.transitionToolBeltForEvent(event.id);
|
|
164
140
|
}
|
|
165
141
|
async transitionToolBeltForEvent(eventId) {
|
|
142
|
+
var _a;
|
|
166
143
|
const vc = this.calendarVc.getEventVc(eventId);
|
|
167
|
-
const state = vc.getToolBeltState
|
|
144
|
+
const state = (_a = vc.getToolBeltState) === null || _a === void 0 ? void 0 : _a.call(vc);
|
|
168
145
|
if (state) {
|
|
169
146
|
await this.transitionTo(state);
|
|
170
147
|
}
|
|
@@ -173,8 +150,9 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
173
150
|
await this.sm.transitionTo(state);
|
|
174
151
|
}
|
|
175
152
|
async waitUntilDoneSaving() {
|
|
153
|
+
var _a;
|
|
176
154
|
await Promise.all([
|
|
177
|
-
this.remoteEventStore
|
|
155
|
+
(_a = this.remoteEventStore) === null || _a === void 0 ? void 0 : _a.waitForPendingSaves(),
|
|
178
156
|
this.selectingTypePromise,
|
|
179
157
|
this.transitionPromise,
|
|
180
158
|
this.loadEventsPromise,
|
|
@@ -184,7 +162,8 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
184
162
|
]);
|
|
185
163
|
}
|
|
186
164
|
async handleSelectCalendar(calendar) {
|
|
187
|
-
|
|
165
|
+
var _a;
|
|
166
|
+
(_a = this.remoteEventStore) === null || _a === void 0 ? void 0 : _a.setCalendarId(calendar.id);
|
|
188
167
|
await this.events.makeCalendarVisible(calendar.id);
|
|
189
168
|
}
|
|
190
169
|
getToolBeltStateMachine() {
|
|
@@ -236,7 +215,8 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
236
215
|
this.rootToolBeltState.setSelectedDate(year, month, day);
|
|
237
216
|
}
|
|
238
217
|
getStartDate() {
|
|
239
|
-
|
|
218
|
+
var _a;
|
|
219
|
+
return (_a = this.calendarVc.getStartDate()) !== null && _a !== void 0 ? _a : this.dates.date();
|
|
240
220
|
}
|
|
241
221
|
async handleDeselectEvent() {
|
|
242
222
|
if (this.shouldIgnoreNextDeselectEvent ||
|
|
@@ -276,6 +256,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
276
256
|
}
|
|
277
257
|
}
|
|
278
258
|
async handleClickEvent(options) {
|
|
259
|
+
var _a, _b;
|
|
279
260
|
const { event } = options;
|
|
280
261
|
const selected = this.events.getSelectedEvent();
|
|
281
262
|
if (selected) {
|
|
@@ -283,7 +264,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
283
264
|
}
|
|
284
265
|
await this.events.selectEvent(event.id);
|
|
285
266
|
this.toolBeltVc.open({ shouldStayOpen: true });
|
|
286
|
-
const isSameEventTypeSlug = selected
|
|
267
|
+
const isSameEventTypeSlug = (selected === null || selected === void 0 ? void 0 : selected.eventTypeSlug) === event.eventTypeSlug;
|
|
287
268
|
const shouldNotTransition = selected && isSameEventTypeSlug;
|
|
288
269
|
if (shouldNotTransition) {
|
|
289
270
|
return;
|
|
@@ -297,11 +278,10 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
297
278
|
}
|
|
298
279
|
}
|
|
299
280
|
catch (err) {
|
|
300
|
-
console.error(err.stack
|
|
281
|
+
console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
301
282
|
await this.events.deselectEvent();
|
|
302
283
|
await this.alert({
|
|
303
|
-
message: err.message
|
|
304
|
-
'Shoot! I could not load that for you! Refresh and try again!!',
|
|
284
|
+
message: (_b = err.message) !== null && _b !== void 0 ? _b : 'Shoot! I could not load that for you! Refresh and try again!!',
|
|
305
285
|
});
|
|
306
286
|
}
|
|
307
287
|
}
|
|
@@ -352,6 +332,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
352
332
|
return this.calendarVc;
|
|
353
333
|
}
|
|
354
334
|
async load(options) {
|
|
335
|
+
var _a;
|
|
355
336
|
await this.sm.updateContext({
|
|
356
337
|
...options,
|
|
357
338
|
people: this.people,
|
|
@@ -373,8 +354,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
373
354
|
}
|
|
374
355
|
catch (err) {
|
|
375
356
|
await this.alert({
|
|
376
|
-
message: err.message
|
|
377
|
-
'Something catastrophic happened! We gotta get out of there!',
|
|
357
|
+
message: (_a = err.message) !== null && _a !== void 0 ? _a : 'Something catastrophic happened! We gotta get out of there!',
|
|
378
358
|
});
|
|
379
359
|
await router.redirect('heartwood.root');
|
|
380
360
|
return;
|
|
@@ -414,11 +394,12 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
414
394
|
}
|
|
415
395
|
}
|
|
416
396
|
async destroy() {
|
|
397
|
+
var _a, _b, _c, _d;
|
|
417
398
|
clearInterval(this.loadEventInterval);
|
|
418
|
-
await this.client
|
|
419
|
-
await this.client
|
|
420
|
-
await this.client
|
|
421
|
-
await this.client
|
|
399
|
+
await ((_a = this.client) === null || _a === void 0 ? void 0 : _a.off('connection-status-change', this.handleStateChange));
|
|
400
|
+
await ((_b = this.client) === null || _b === void 0 ? void 0 : _b.off('calendar.did-create-calendar-event::v2021_05_19', this.handleDidCreateOrUpdateRemoteEvent));
|
|
401
|
+
await ((_c = this.client) === null || _c === void 0 ? void 0 : _c.off('calendar.did-update-calendar-event::v2021_05_19', this.handleDidCreateOrUpdateRemoteEvent));
|
|
402
|
+
await ((_d = this.client) === null || _d === void 0 ? void 0 : _d.off('calendar.did-cancel-calendar-event::v2021_05_19', this.handleDidCancelEvent));
|
|
422
403
|
}
|
|
423
404
|
async setupCalendarEventListeners() {
|
|
424
405
|
await Promise.all([
|
|
@@ -472,8 +453,8 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
472
453
|
scope.getCurrentLocation(),
|
|
473
454
|
this.loadLoggedInPerson(),
|
|
474
455
|
]);
|
|
475
|
-
this.organizationId = location
|
|
476
|
-
this.locationId = location
|
|
456
|
+
this.organizationId = location === null || location === void 0 ? void 0 : location.organizationId;
|
|
457
|
+
this.locationId = location === null || location === void 0 ? void 0 : location.id;
|
|
477
458
|
}
|
|
478
459
|
syncPeopleOnCalendar() {
|
|
479
460
|
const visiblePeople = this.people.getVisiblePeople();
|
|
@@ -488,6 +469,7 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
488
469
|
await this.loadEventsPromise;
|
|
489
470
|
}
|
|
490
471
|
async _loadEvents(options) {
|
|
472
|
+
var _a;
|
|
491
473
|
try {
|
|
492
474
|
if (this.events.getCalendars().length > 0) {
|
|
493
475
|
const date = this.getStartDate();
|
|
@@ -499,13 +481,13 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
499
481
|
}
|
|
500
482
|
}
|
|
501
483
|
catch (err) {
|
|
502
|
-
if (options
|
|
484
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldRenderAlertOnFail) === false) {
|
|
503
485
|
this.toast({
|
|
504
486
|
message: 'Updating your calendar failed! Trying to connect...',
|
|
505
487
|
});
|
|
506
488
|
return;
|
|
507
489
|
}
|
|
508
|
-
console.error(err.stack
|
|
490
|
+
console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
509
491
|
void this.alert({
|
|
510
492
|
message: err.message,
|
|
511
493
|
});
|
|
@@ -556,4 +538,9 @@ class RootSkillViewController extends heartwood_view_controllers_1.AbstractSkill
|
|
|
556
538
|
};
|
|
557
539
|
}
|
|
558
540
|
}
|
|
541
|
+
RootSkillViewController.id = 'root';
|
|
542
|
+
RootSkillViewController.shouldConfirmDrops = false;
|
|
543
|
+
RootSkillViewController.shouldUpdateOnInterval = true;
|
|
544
|
+
RootSkillViewController.refreshInterval = 1000 * 60;
|
|
545
|
+
RootSkillViewController.shouldCacheEvents = false;
|
|
559
546
|
exports.default = RootSkillViewController;
|
|
@@ -8,21 +8,13 @@ const schema_1 = require("@sprucelabs/schema");
|
|
|
8
8
|
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
9
9
|
const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"));
|
|
10
10
|
class RemoteEventStoreImpl {
|
|
11
|
-
connectToApi;
|
|
12
|
-
calendarId;
|
|
13
|
-
locationId;
|
|
14
|
-
organizationId;
|
|
15
|
-
client;
|
|
16
|
-
pendingEvents = {};
|
|
17
|
-
draftIdMap = {};
|
|
18
|
-
promises = [];
|
|
19
|
-
queueByEventId = {};
|
|
20
|
-
busyByEvent = {};
|
|
21
|
-
lastSavedById = {};
|
|
22
|
-
calendarEventTypes;
|
|
23
|
-
calendars;
|
|
24
|
-
streamHandler;
|
|
25
11
|
constructor(options) {
|
|
12
|
+
this.pendingEvents = {};
|
|
13
|
+
this.draftIdMap = {};
|
|
14
|
+
this.promises = [];
|
|
15
|
+
this.queueByEventId = {};
|
|
16
|
+
this.busyByEvent = {};
|
|
17
|
+
this.lastSavedById = {};
|
|
26
18
|
const { connectToApi, calendarId } = (0, schema_1.assertOptions)(options, [
|
|
27
19
|
'connectToApi',
|
|
28
20
|
]);
|
|
@@ -38,7 +30,8 @@ class RemoteEventStoreImpl {
|
|
|
38
30
|
this.organizationId = organizationId;
|
|
39
31
|
this.client = await this.connectToApi();
|
|
40
32
|
await this.client.on('calendar.stream-schedules::v2021_05_19', ({ payload }) => {
|
|
41
|
-
|
|
33
|
+
var _a;
|
|
34
|
+
(_a = this.streamHandler) === null || _a === void 0 ? void 0 : _a.call(this, payload);
|
|
42
35
|
});
|
|
43
36
|
}
|
|
44
37
|
async setStreamHandler(cb) {
|
|
@@ -66,15 +59,16 @@ class RemoteEventStoreImpl {
|
|
|
66
59
|
return promise;
|
|
67
60
|
}
|
|
68
61
|
async startQueueForEvent(id) {
|
|
62
|
+
var _a, _b;
|
|
69
63
|
if (!this.queueByEventId[id][0] || this.busyByEvent[id]) {
|
|
70
64
|
return;
|
|
71
65
|
}
|
|
72
|
-
const { event, resolve, reject, promiseIdx } = this.queueByEventId[id].shift()
|
|
66
|
+
const { event, resolve, reject, promiseIdx } = (_a = this.queueByEventId[id].shift()) !== null && _a !== void 0 ? _a : {};
|
|
73
67
|
if (!event || !resolve || !reject || typeof promiseIdx !== 'number') {
|
|
74
68
|
return;
|
|
75
69
|
}
|
|
76
70
|
delete event.isBusy;
|
|
77
|
-
const lastSaved = this.lastSavedById[this.getId(id)]
|
|
71
|
+
const lastSaved = (_b = this.lastSavedById[this.getId(id)]) !== null && _b !== void 0 ? _b : {};
|
|
78
72
|
if ((0, spruce_skill_utils_1.isEqual)(lastSaved.before, event) ||
|
|
79
73
|
(0, spruce_skill_utils_1.isEqual)(lastSaved.after, event)) {
|
|
80
74
|
resolve(lastSaved.after);
|
|
@@ -111,7 +105,8 @@ class RemoteEventStoreImpl {
|
|
|
111
105
|
void this.startQueueForEvent(this.getId(event.id));
|
|
112
106
|
}
|
|
113
107
|
getId(eventId) {
|
|
114
|
-
|
|
108
|
+
var _a;
|
|
109
|
+
return (_a = this.draftIdMap[eventId]) !== null && _a !== void 0 ? _a : eventId;
|
|
115
110
|
}
|
|
116
111
|
async updateEvent(event) {
|
|
117
112
|
const { target, payload } = this.splitPayloadAndTarget(event);
|
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const schema_1 = require("@sprucelabs/schema");
|
|
4
4
|
class RemotePreferencesStore {
|
|
5
|
-
isLoaded = false;
|
|
6
|
-
client;
|
|
7
|
-
organizationId;
|
|
8
|
-
visiblePeopleMode;
|
|
9
|
-
visibleCalendarIds;
|
|
10
|
-
visiblePeopleIds;
|
|
11
|
-
connectToApi;
|
|
12
5
|
constructor(options) {
|
|
6
|
+
this.isLoaded = false;
|
|
13
7
|
const { connectToApi } = (0, schema_1.assertOptions)(options, ['connectToApi']);
|
|
14
8
|
this.connectToApi = connectToApi;
|
|
15
9
|
}
|
|
@@ -26,9 +20,9 @@ class RemotePreferencesStore {
|
|
|
26
20
|
organizationId: this.organizationId,
|
|
27
21
|
},
|
|
28
22
|
});
|
|
29
|
-
this.visibleCalendarIds = selectedCalendarIds
|
|
30
|
-
this.visiblePeopleMode = visiblePeopleMode
|
|
31
|
-
this.visiblePeopleIds = visiblePeopleIds
|
|
23
|
+
this.visibleCalendarIds = selectedCalendarIds !== null && selectedCalendarIds !== void 0 ? selectedCalendarIds : undefined;
|
|
24
|
+
this.visiblePeopleMode = visiblePeopleMode !== null && visiblePeopleMode !== void 0 ? visiblePeopleMode : undefined;
|
|
25
|
+
this.visiblePeopleIds = visiblePeopleIds !== null && visiblePeopleIds !== void 0 ? visiblePeopleIds : undefined;
|
|
32
26
|
}
|
|
33
27
|
async setVisibleCalendarIds(ids) {
|
|
34
28
|
this.visibleCalendarIds = ids;
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const spruce_heartwood_utils_1 = require("@sprucelabs/spruce-heartwood-utils");
|
|
4
4
|
class CalendarToolRegistrar {
|
|
5
|
-
sm;
|
|
6
|
-
addToolHandler;
|
|
7
|
-
static fetchedRecord = {};
|
|
8
5
|
constructor(sm, addToolHandler) {
|
|
9
6
|
this.sm = sm;
|
|
10
7
|
this.addToolHandler = addToolHandler;
|
|
@@ -13,16 +10,20 @@ class CalendarToolRegistrar {
|
|
|
13
10
|
CalendarToolRegistrar.fetchedRecord = {};
|
|
14
11
|
}
|
|
15
12
|
async fetchAndAddCards(getControllerOptions) {
|
|
13
|
+
var _a;
|
|
16
14
|
const { event } = this.sm.getContext();
|
|
17
15
|
let cards = [];
|
|
18
|
-
const cacheKey = event.eventTypeSlug
|
|
16
|
+
const cacheKey = (_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'none';
|
|
19
17
|
if (!CalendarToolRegistrar.fetchedRecord[cacheKey]) {
|
|
20
18
|
const { cards: fetchedCards, vcIds } = await this.fetchUncached(getControllerOptions);
|
|
21
19
|
CalendarToolRegistrar.fetchedRecord[cacheKey] = vcIds;
|
|
22
20
|
cards = fetchedCards;
|
|
23
21
|
}
|
|
24
22
|
else {
|
|
25
|
-
cards = CalendarToolRegistrar.fetchedRecord[cacheKey].map((vcId) =>
|
|
23
|
+
cards = CalendarToolRegistrar.fetchedRecord[cacheKey].map((vcId) => {
|
|
24
|
+
var _a;
|
|
25
|
+
return this.views.Controller(vcId, (_a = getControllerOptions === null || getControllerOptions === void 0 ? void 0 : getControllerOptions(vcId)) !== null && _a !== void 0 ? _a : {});
|
|
26
|
+
});
|
|
26
27
|
}
|
|
27
28
|
await Promise.all(cards.map((card) => this.addTool(card)));
|
|
28
29
|
return cards;
|
|
@@ -50,13 +51,14 @@ class CalendarToolRegistrar {
|
|
|
50
51
|
const cards = (await registrar.fetch({
|
|
51
52
|
each: async () => { },
|
|
52
53
|
controllerOptionsHandler: (vcId) => {
|
|
54
|
+
var _a;
|
|
53
55
|
vcIds.push(vcId);
|
|
54
|
-
return getControllerOptions
|
|
56
|
+
return (_a = getControllerOptions === null || getControllerOptions === void 0 ? void 0 : getControllerOptions(vcId)) !== null && _a !== void 0 ? _a : {};
|
|
55
57
|
},
|
|
56
58
|
target: {
|
|
57
59
|
organizationId: org.id,
|
|
58
60
|
calendarEventId: event.id,
|
|
59
|
-
locationId: location
|
|
61
|
+
locationId: location === null || location === void 0 ? void 0 : location.id,
|
|
60
62
|
},
|
|
61
63
|
payload: {
|
|
62
64
|
eventTypeSlug: event.eventTypeSlug,
|
|
@@ -65,6 +67,7 @@ class CalendarToolRegistrar {
|
|
|
65
67
|
return { cards, vcIds };
|
|
66
68
|
}
|
|
67
69
|
async addTool(card) {
|
|
70
|
+
var _a;
|
|
68
71
|
const toolBeltVc = this.sm.getToolBeltVc();
|
|
69
72
|
if (this.addToolHandler) {
|
|
70
73
|
await this.addToolHandler(card);
|
|
@@ -76,8 +79,9 @@ class CalendarToolRegistrar {
|
|
|
76
79
|
lineIcon: card.getLineIcon(),
|
|
77
80
|
card: card.render(),
|
|
78
81
|
});
|
|
79
|
-
await card.load
|
|
82
|
+
await ((_a = card.load) === null || _a === void 0 ? void 0 : _a.call(card));
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
}
|
|
86
|
+
CalendarToolRegistrar.fetchedRecord = {};
|
|
83
87
|
exports.default = CalendarToolRegistrar;
|
|
@@ -28,7 +28,7 @@ class CalendarToolTestFactory {
|
|
|
28
28
|
friendlyMessage: `You need to pass 'getHasPendingContextChanges: () => boolean' or similar to CalendarToolTestFactory.Tool(....)`,
|
|
29
29
|
});
|
|
30
30
|
},
|
|
31
|
-
...(0, just_clone_1.default)(options
|
|
31
|
+
...(0, just_clone_1.default)(options !== null && options !== void 0 ? options : {}),
|
|
32
32
|
});
|
|
33
33
|
void stateMachine.on('did-update-context', () => {
|
|
34
34
|
return vc.handleUpdateContext(stateMachine.getContext());
|
|
@@ -8,21 +8,16 @@ const just_compare_1 = __importDefault(require("just-compare"));
|
|
|
8
8
|
const SpruceError_1 = __importDefault(require("../../errors/SpruceError"));
|
|
9
9
|
const CalendarToolRegistrar_1 = __importDefault(require("../CalendarToolRegistrar"));
|
|
10
10
|
class AbstractCalendarEventToolBeltState {
|
|
11
|
-
sm;
|
|
12
|
-
toolBeltVc;
|
|
13
|
-
vcs = [];
|
|
14
|
-
pendingContextUpdates = {};
|
|
15
|
-
controlsVc;
|
|
16
|
-
isLoaded = false;
|
|
17
|
-
events;
|
|
18
|
-
shouldLoadToolsRightAway = true;
|
|
19
|
-
getPersonPromise;
|
|
20
|
-
lastEventId;
|
|
21
11
|
constructor() {
|
|
12
|
+
this.vcs = [];
|
|
13
|
+
this.pendingContextUpdates = {};
|
|
14
|
+
this.isLoaded = false;
|
|
15
|
+
this.shouldLoadToolsRightAway = true;
|
|
22
16
|
this._handleDidUpdateContext = this._handleDidUpdateContext.bind(this);
|
|
23
17
|
this._handleWillUpdateContext = this._handleWillUpdateContext.bind(this);
|
|
24
18
|
}
|
|
25
19
|
async load(sm) {
|
|
20
|
+
var _a;
|
|
26
21
|
this.sm = sm;
|
|
27
22
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
28
23
|
this.isLoaded = true;
|
|
@@ -46,7 +41,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
46
41
|
});
|
|
47
42
|
void this.sm.on('will-update-context', this._handleWillUpdateContext);
|
|
48
43
|
void this.sm.on('did-update-context', this._handleDidUpdateContext);
|
|
49
|
-
this.lastEventId = this.event
|
|
44
|
+
this.lastEventId = (_a = this.event) === null || _a === void 0 ? void 0 : _a.id;
|
|
50
45
|
}
|
|
51
46
|
getIsLoaded() {
|
|
52
47
|
return this.isLoaded;
|
|
@@ -94,7 +89,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
94
89
|
}
|
|
95
90
|
}));
|
|
96
91
|
this.controlsVc.handleUpdateContext();
|
|
97
|
-
this.lastEventId = event
|
|
92
|
+
this.lastEventId = event === null || event === void 0 ? void 0 : event.id;
|
|
98
93
|
}
|
|
99
94
|
getContextWithPendingChanges() {
|
|
100
95
|
return {
|
|
@@ -108,6 +103,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
108
103
|
}
|
|
109
104
|
}
|
|
110
105
|
async addTool(options) {
|
|
106
|
+
var _a;
|
|
111
107
|
(0, schema_1.assertOptions)(options, ['id', 'lineIcon', 'cardVcId']);
|
|
112
108
|
if (!this.sm) {
|
|
113
109
|
throw new Error("You can't add a tool until after load. Make sure you're calling 'await super.load()' inside your 'load()'.");
|
|
@@ -119,7 +115,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
119
115
|
return vc;
|
|
120
116
|
}
|
|
121
117
|
catch (err) {
|
|
122
|
-
if (err.options
|
|
118
|
+
if (((_a = err.options) === null || _a === void 0 ? void 0 : _a.code) === 'CALENDAR_TOOL_INTERFACE') {
|
|
123
119
|
throw err;
|
|
124
120
|
}
|
|
125
121
|
console.error(err);
|
|
@@ -155,24 +151,27 @@ class AbstractCalendarEventToolBeltState {
|
|
|
155
151
|
}
|
|
156
152
|
}
|
|
157
153
|
async loadVc(vc) {
|
|
154
|
+
var _a, _b;
|
|
158
155
|
try {
|
|
159
|
-
await vc.load
|
|
156
|
+
await ((_a = vc.load) === null || _a === void 0 ? void 0 : _a.call(vc));
|
|
160
157
|
}
|
|
161
158
|
catch (err) {
|
|
162
|
-
vc.setCriticalError
|
|
159
|
+
(_b = vc.setCriticalError) === null || _b === void 0 ? void 0 : _b.call(vc, err);
|
|
163
160
|
}
|
|
164
161
|
}
|
|
165
162
|
async loadTools() {
|
|
166
163
|
await Promise.all(this.vcs.map(({ vc }) => this.loadVc(vc)));
|
|
167
164
|
}
|
|
168
165
|
async getPersonFromEvent() {
|
|
166
|
+
var _a;
|
|
169
167
|
if (this.getPersonPromise) {
|
|
170
168
|
return this.getPersonPromise;
|
|
171
169
|
}
|
|
172
170
|
this.getPersonPromise = this._getPersonFromEvent();
|
|
173
|
-
return this.getPersonPromise
|
|
171
|
+
return (_a = this.getPersonPromise) !== null && _a !== void 0 ? _a : null;
|
|
174
172
|
}
|
|
175
173
|
async _getPersonFromEvent() {
|
|
174
|
+
var _a;
|
|
176
175
|
try {
|
|
177
176
|
const id = this.event.target.personId;
|
|
178
177
|
const client = await this.sm.connectToApi();
|
|
@@ -184,7 +183,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
184
183
|
return person;
|
|
185
184
|
}
|
|
186
185
|
catch (err) {
|
|
187
|
-
console.error(err.stack
|
|
186
|
+
console.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
188
187
|
return null;
|
|
189
188
|
}
|
|
190
189
|
}
|
|
@@ -195,8 +194,8 @@ class AbstractCalendarEventToolBeltState {
|
|
|
195
194
|
}
|
|
196
195
|
this.pendingContextUpdates = pendingUpdates;
|
|
197
196
|
const vc = this.getVcForTool(fromToolId);
|
|
198
|
-
const shouldPersistChanges = vc
|
|
199
|
-
options
|
|
197
|
+
const shouldPersistChanges = (vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately) ||
|
|
198
|
+
(options === null || options === void 0 ? void 0 : options.shouldPersistContextChangesImmediately);
|
|
200
199
|
if (shouldPersistChanges) {
|
|
201
200
|
return this.sm.updateContext({ ...updates });
|
|
202
201
|
}
|
|
@@ -218,7 +217,8 @@ class AbstractCalendarEventToolBeltState {
|
|
|
218
217
|
return this.pendingContextUpdates;
|
|
219
218
|
}
|
|
220
219
|
getVcForTool(toolId) {
|
|
221
|
-
|
|
220
|
+
var _a;
|
|
221
|
+
return (_a = this.vcs.find((v) => v.toolId === toolId)) === null || _a === void 0 ? void 0 : _a.vc;
|
|
222
222
|
}
|
|
223
223
|
getControlsVc() {
|
|
224
224
|
return this.controlsVc;
|
|
@@ -6,20 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.PrerequisitesToolBeltState = void 0;
|
|
7
7
|
const makeEventTyped_1 = __importDefault(require("./makeEventTyped"));
|
|
8
8
|
class PrerequisitesToolBeltState {
|
|
9
|
-
id = 'prerequisites';
|
|
10
|
-
calendarSelectCardVc;
|
|
11
|
-
typeSelectCardVc;
|
|
12
|
-
toolBeltVc;
|
|
13
|
-
sm;
|
|
14
|
-
selectCalendarHandler;
|
|
15
|
-
selectEventTypeHandler;
|
|
16
|
-
calendar;
|
|
17
9
|
get calendars() {
|
|
18
10
|
return this.sm.getContext().events.getCalendars();
|
|
19
11
|
}
|
|
20
12
|
constructor(options) {
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
13
|
+
this.id = 'prerequisites';
|
|
14
|
+
this.selectCalendarHandler = options === null || options === void 0 ? void 0 : options.onSelectCalendar;
|
|
15
|
+
this.selectEventTypeHandler = options === null || options === void 0 ? void 0 : options.onSelectEventType;
|
|
23
16
|
}
|
|
24
17
|
async load(stateMachine) {
|
|
25
18
|
const toolBeltVc = stateMachine.getToolBeltVc();
|
|
@@ -68,12 +61,13 @@ class PrerequisitesToolBeltState {
|
|
|
68
61
|
this.calendarSelectCardVc.setIsBusy(false);
|
|
69
62
|
}
|
|
70
63
|
async handleSelectCalendar(calendar) {
|
|
71
|
-
|
|
64
|
+
var _a, _b, _c, _d;
|
|
65
|
+
(_a = this.calendarSelectCardVc) === null || _a === void 0 ? void 0 : _a.setIsBusy(true);
|
|
72
66
|
this.calendar = calendar;
|
|
73
|
-
await this.selectCalendarHandler
|
|
67
|
+
await ((_b = this.selectCalendarHandler) === null || _b === void 0 ? void 0 : _b.call(this, calendar));
|
|
74
68
|
const client = await this.connectToApi();
|
|
75
69
|
let [{ calendarEventTypes }] = await client.emitAndFlattenResponses('calendar.list-calendar-event-types::v2021_05_19');
|
|
76
|
-
const types = calendar.eventTypes
|
|
70
|
+
const types = (_c = calendar.eventTypes) !== null && _c !== void 0 ? _c : [];
|
|
77
71
|
if (types.length > 0) {
|
|
78
72
|
calendarEventTypes = calendarEventTypes.filter((t) => types.indexOf(t.slug) > -1);
|
|
79
73
|
}
|
|
@@ -84,9 +78,10 @@ class PrerequisitesToolBeltState {
|
|
|
84
78
|
await this.updateEvent();
|
|
85
79
|
await this.setupTypeSelectCard(calendarEventTypes);
|
|
86
80
|
}
|
|
87
|
-
this.calendarSelectCardVc
|
|
81
|
+
(_d = this.calendarSelectCardVc) === null || _d === void 0 ? void 0 : _d.setIsBusy(false);
|
|
88
82
|
}
|
|
89
83
|
async setupTypeSelectCard(types) {
|
|
84
|
+
var _a, _b, _c, _d, _e, _f;
|
|
90
85
|
if (!this.toolBeltVc.getTool('types')) {
|
|
91
86
|
this.typeSelectCardVc = this.TypeSelectCardVc();
|
|
92
87
|
this.toolBeltVc.addTool({
|
|
@@ -95,16 +90,16 @@ class PrerequisitesToolBeltState {
|
|
|
95
90
|
card: this.typeSelectCardVc.render(),
|
|
96
91
|
});
|
|
97
92
|
}
|
|
98
|
-
this.typeSelectCardVc
|
|
99
|
-
this.toolBeltVc
|
|
93
|
+
(_a = this.typeSelectCardVc) === null || _a === void 0 ? void 0 : _a.setIsBusy(true);
|
|
94
|
+
(_b = this.toolBeltVc) === null || _b === void 0 ? void 0 : _b.focusTool('types');
|
|
100
95
|
const section = await this.renderTypeButtonsSection(types);
|
|
101
|
-
if (this.typeSelectCardVc
|
|
102
|
-
this.typeSelectCardVc
|
|
96
|
+
if (((_c = this.typeSelectCardVc) === null || _c === void 0 ? void 0 : _c.getTotalSections()) === 0) {
|
|
97
|
+
(_d = this.typeSelectCardVc) === null || _d === void 0 ? void 0 : _d.addSection(section);
|
|
103
98
|
}
|
|
104
99
|
else {
|
|
105
|
-
this.typeSelectCardVc
|
|
100
|
+
(_e = this.typeSelectCardVc) === null || _e === void 0 ? void 0 : _e.setSection(0, section);
|
|
106
101
|
}
|
|
107
|
-
this.typeSelectCardVc
|
|
102
|
+
(_f = this.typeSelectCardVc) === null || _f === void 0 ? void 0 : _f.setIsBusy(false);
|
|
108
103
|
}
|
|
109
104
|
async renderTypeButtonsSection(calendarEventTypes) {
|
|
110
105
|
const section = {
|
|
@@ -117,21 +112,23 @@ class PrerequisitesToolBeltState {
|
|
|
117
112
|
return section;
|
|
118
113
|
}
|
|
119
114
|
async handleSelectType(type) {
|
|
120
|
-
|
|
115
|
+
var _a, _b, _c;
|
|
116
|
+
(_a = this.typeSelectCardVc) === null || _a === void 0 ? void 0 : _a.setIsBusy(true);
|
|
121
117
|
const { event } = this.sm.getContext();
|
|
122
118
|
const updated = (0, makeEventTyped_1.default)(event, type);
|
|
123
119
|
await this.updateEvent({
|
|
124
120
|
eventTypeSlug: type.slug,
|
|
125
121
|
timeBlocks: updated.timeBlocks,
|
|
126
122
|
});
|
|
127
|
-
await this.selectEventTypeHandler
|
|
128
|
-
this.typeSelectCardVc
|
|
123
|
+
await ((_b = this.selectEventTypeHandler) === null || _b === void 0 ? void 0 : _b.call(this, type));
|
|
124
|
+
(_c = this.typeSelectCardVc) === null || _c === void 0 ? void 0 : _c.setIsBusy(false);
|
|
129
125
|
}
|
|
130
126
|
async updateEvent(updates) {
|
|
127
|
+
var _a;
|
|
131
128
|
const { event, events } = this.sm.getContext();
|
|
132
129
|
if (event) {
|
|
133
130
|
events.updateEvent(event.id, {
|
|
134
|
-
calendarId: this.calendar
|
|
131
|
+
calendarId: (_a = this.calendar) === null || _a === void 0 ? void 0 : _a.id,
|
|
135
132
|
...updates,
|
|
136
133
|
});
|
|
137
134
|
await events.waitForPendingOperations();
|