@sprucelabs/spruce-calendar-components 28.3.102 → 29.0.0
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/errors.types.js +0 -2
- package/build/.spruce/errors/options.types.d.ts +2 -2
- package/build/.spruce/schemas/schemas.types.d.ts +3287 -2737
- package/build/.spruce/schemas/schemas.types.js +1 -2
- package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +24 -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 -4
- package/build/__tests__/support/utilities/calendarSkillAssert.js +25 -10
- package/build/__tests__/support/utilities/calendarToolBeltInteractor.js +3 -1
- package/build/calendar/Calendar.vc.js +52 -43
- package/build/calendar/CalendarEventManager.js +86 -66
- package/build/calendar/CalendarPeopleManager.js +17 -16
- package/build/calendar/CalendarPersister.d.ts +2 -2
- package/build/calendar/CalendarPersister.js +13 -8
- package/build/calendar/calculateCalendarEventDifferences.js +6 -3
- package/build/constants.js +1 -2
- package/build/errors/SpruceError.d.ts +1 -1
- package/build/errors/SpruceError.js +1 -1
- package/build/esm/.spruce/errors/errors.types.d.ts +12 -12
- package/build/esm/.spruce/errors/errors.types.js +0 -2
- package/build/esm/.spruce/errors/options.types.d.ts +2 -2
- package/build/esm/.spruce/schemas/schemas.types.d.ts +3287 -2737
- package/build/esm/.spruce/schemas/schemas.types.js +1 -2
- package/build/esm/__tests__/support/utilities/calendarAssert.js +0 -1
- package/build/esm/__tests__/support/utilities/calendarSkillAssert.js +2 -2
- package/build/esm/calendar/Calendar.vc.js +0 -3
- package/build/esm/calendar/CalendarEventManager.js +3 -2
- package/build/esm/calendar/CalendarPeopleManager.js +0 -2
- package/build/esm/calendar/CalendarPersister.d.ts +2 -2
- package/build/esm/errors/SpruceError.d.ts +1 -1
- package/build/esm/noSchedules/peopleToPeopleWithoutSchedules.d.ts +1 -1
- package/build/esm/root/Root.svc.d.ts +2 -2
- package/build/esm/root/Root.svc.js +4 -2
- package/build/esm/stores/RemoteEventStore.js +7 -4
- package/build/esm/toolBelt/CalendarToolRegistrar.js +4 -1
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +5 -2
- package/build/esm/toolBelt/states/RootToolBeltState.js +2 -1
- package/build/esm/tools/CalendarSelectTool.vc.js +5 -2
- package/build/esm/tools/EventRepeatingTool.vc.js +3 -1
- package/build/esm/tools/PersonSelectTool.vc.js +8 -3
- package/build/esm/viewControllers/DateSelectCard.vc.js +1 -4
- package/build/esm/viewControllers/RepeatingControlsList.vc.js +2 -1
- package/build/noSchedules/peopleToPeopleWithoutSchedules.d.ts +1 -1
- package/build/root/Root.svc.d.ts +2 -2
- package/build/root/Root.svc.js +73 -48
- package/build/stores/RemoteEventStore.js +60 -38
- package/build/stores/RemotePreferencesStore.js +10 -4
- package/build/toolBelt/CalendarToolRegistrar.js +8 -9
- package/build/toolBelt/CalendarToolTestFactory.js +10 -4
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +37 -27
- package/build/toolBelt/states/PrerequisitesToolBeltState.js +31 -22
- package/build/toolBelt/states/RootToolBeltState.js +23 -19
- package/build/toolBelt/states/UniversalEventToolBeltState.js +1 -4
- package/build/toolBelt/states/makeEventTyped.js +1 -2
- package/build/tools/CalendarSelectTool.vc.js +12 -6
- package/build/tools/EventDateTimeTool.vc.js +10 -6
- package/build/tools/EventDurationTool.vc.js +8 -5
- package/build/tools/EventRepeatingTool.vc.js +23 -7
- package/build/tools/EventTitleTool.vc.js +8 -5
- package/build/tools/PersonSelectTool.vc.js +17 -9
- package/build/utilities/draftGenerator.js +1 -1
- package/build/viewControllers/DateSelectCard.vc.js +12 -7
- package/build/viewControllers/EventControlsCard.vc.js +9 -5
- package/build/viewControllers/RepeatingControlsList.vc.js +52 -58
- package/build/viewControllers/SelectUpdateRepeatingStrategyCard.vc.js +7 -4
- package/build/viewControllers/UniversalCalendarEvent.vc.js +1 -1
- package/package.json +1 -1
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -19,13 +8,21 @@ const schema_1 = require("@sprucelabs/schema");
|
|
|
19
8
|
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
20
9
|
const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"));
|
|
21
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;
|
|
22
25
|
constructor(options) {
|
|
23
|
-
this.pendingEvents = {};
|
|
24
|
-
this.draftIdMap = {};
|
|
25
|
-
this.promises = [];
|
|
26
|
-
this.queueByEventId = {};
|
|
27
|
-
this.busyByEvent = {};
|
|
28
|
-
this.lastSavedById = {};
|
|
29
26
|
const { connectToApi, calendarId } = (0, schema_1.assertOptions)(options, [
|
|
30
27
|
'connectToApi',
|
|
31
28
|
]);
|
|
@@ -41,8 +38,7 @@ class RemoteEventStoreImpl {
|
|
|
41
38
|
this.organizationId = organizationId;
|
|
42
39
|
this.client = await this.connectToApi();
|
|
43
40
|
await this.client.on('calendar.stream-schedules::v2021_05_19', ({ payload }) => {
|
|
44
|
-
|
|
45
|
-
(_a = this.streamHandler) === null || _a === void 0 ? void 0 : _a.call(this, payload);
|
|
41
|
+
this.streamHandler?.(payload);
|
|
46
42
|
});
|
|
47
43
|
}
|
|
48
44
|
async setStreamHandler(cb) {
|
|
@@ -70,17 +66,17 @@ class RemoteEventStoreImpl {
|
|
|
70
66
|
return promise;
|
|
71
67
|
}
|
|
72
68
|
async startQueueForEvent(id) {
|
|
73
|
-
var _a, _b;
|
|
74
69
|
if (!this.queueByEventId[id][0] || this.busyByEvent[id]) {
|
|
75
70
|
return;
|
|
76
71
|
}
|
|
77
|
-
const { event, resolve, reject, promiseIdx } =
|
|
72
|
+
const { event, resolve, reject, promiseIdx } = this.queueByEventId[id].shift() ?? {};
|
|
78
73
|
if (!event || !resolve || !reject || typeof promiseIdx !== 'number') {
|
|
79
74
|
return;
|
|
80
75
|
}
|
|
81
76
|
delete event.isBusy;
|
|
82
|
-
const lastSaved =
|
|
83
|
-
if ((0, spruce_skill_utils_1.isEqual)(lastSaved.before, event) ||
|
|
77
|
+
const lastSaved = this.lastSavedById[this.getId(id)] ?? {};
|
|
78
|
+
if ((0, spruce_skill_utils_1.isEqual)(lastSaved.before, event) ||
|
|
79
|
+
(0, spruce_skill_utils_1.isEqual)(lastSaved.after, event)) {
|
|
84
80
|
resolve(lastSaved.after);
|
|
85
81
|
}
|
|
86
82
|
else {
|
|
@@ -91,7 +87,8 @@ class RemoteEventStoreImpl {
|
|
|
91
87
|
if (draftGenerator_1.default.isDraftId(event.id)) {
|
|
92
88
|
saved = await this.createEvent(event);
|
|
93
89
|
this.draftIdMap[event.id] = saved.id;
|
|
94
|
-
this.queueByEventId[saved.id] =
|
|
90
|
+
this.queueByEventId[saved.id] =
|
|
91
|
+
this.queueByEventId[event.id];
|
|
95
92
|
delete this.queueByEventId[event.id];
|
|
96
93
|
}
|
|
97
94
|
else {
|
|
@@ -103,7 +100,7 @@ class RemoteEventStoreImpl {
|
|
|
103
100
|
after: saved,
|
|
104
101
|
};
|
|
105
102
|
this.busyByEvent[event.id] = false;
|
|
106
|
-
resolve(
|
|
103
|
+
resolve({ ...saved });
|
|
107
104
|
}
|
|
108
105
|
catch (err) {
|
|
109
106
|
console.error('Error saving draft', err);
|
|
@@ -114,15 +111,20 @@ class RemoteEventStoreImpl {
|
|
|
114
111
|
void this.startQueueForEvent(this.getId(event.id));
|
|
115
112
|
}
|
|
116
113
|
getId(eventId) {
|
|
117
|
-
|
|
118
|
-
return (_a = this.draftIdMap[eventId]) !== null && _a !== void 0 ? _a : eventId;
|
|
114
|
+
return this.draftIdMap[eventId] ?? eventId;
|
|
119
115
|
}
|
|
120
116
|
async updateEvent(event) {
|
|
121
117
|
const { target, payload } = this.splitPayloadAndTarget(event);
|
|
122
118
|
const client = await this.connectToApi();
|
|
123
119
|
const results = await client.emitAndFlattenResponses('calendar.update-calendar-event::v2021_05_19', {
|
|
124
|
-
target:
|
|
125
|
-
|
|
120
|
+
target: {
|
|
121
|
+
calendarEventId: event.id,
|
|
122
|
+
...target,
|
|
123
|
+
},
|
|
124
|
+
payload: {
|
|
125
|
+
...payload,
|
|
126
|
+
isBusy: false,
|
|
127
|
+
},
|
|
126
128
|
});
|
|
127
129
|
const [{ calendarEvent }] = results;
|
|
128
130
|
return calendarEvent;
|
|
@@ -135,23 +137,34 @@ class RemoteEventStoreImpl {
|
|
|
135
137
|
async emitCreate(event) {
|
|
136
138
|
const { target, payload } = this.splitPayloadAndTarget(event);
|
|
137
139
|
const [{ calendarEvent }] = await this.client.emitAndFlattenResponses('calendar.create-calendar-event::v2021_05_19', {
|
|
138
|
-
target:
|
|
139
|
-
|
|
140
|
+
target: {
|
|
141
|
+
...target,
|
|
142
|
+
calendarId: this.resolveCalendarId(event),
|
|
143
|
+
},
|
|
144
|
+
payload: {
|
|
145
|
+
...payload,
|
|
146
|
+
isBusy: false,
|
|
147
|
+
},
|
|
140
148
|
});
|
|
141
149
|
return calendarEvent;
|
|
142
150
|
}
|
|
143
151
|
resolveCalendarId(event) {
|
|
144
|
-
return event.calendarId &&
|
|
152
|
+
return event.calendarId &&
|
|
153
|
+
!draftGenerator_1.default.isDraftId(event.calendarId)
|
|
145
154
|
? event.calendarId
|
|
146
155
|
: this.calendarId;
|
|
147
156
|
}
|
|
148
157
|
splitPayloadAndTarget(event) {
|
|
149
|
-
let
|
|
158
|
+
let { target: { personId, ...target }, ...payload } = event;
|
|
150
159
|
target = this.cleanTarget(target);
|
|
151
160
|
payload = this.cleanPayload(payload);
|
|
152
161
|
return {
|
|
153
162
|
payload,
|
|
154
|
-
target:
|
|
163
|
+
target: {
|
|
164
|
+
...target,
|
|
165
|
+
calendarEventPersonId: personId,
|
|
166
|
+
locationId: this.locationId,
|
|
167
|
+
},
|
|
155
168
|
};
|
|
156
169
|
}
|
|
157
170
|
cleanTarget(target) {
|
|
@@ -216,14 +229,23 @@ class RemoteEventStoreImpl {
|
|
|
216
229
|
locationId: this.locationId,
|
|
217
230
|
calendarEventId: id,
|
|
218
231
|
},
|
|
219
|
-
payload:
|
|
232
|
+
payload: {
|
|
233
|
+
...options,
|
|
234
|
+
},
|
|
220
235
|
});
|
|
221
236
|
}
|
|
222
237
|
}
|
|
223
238
|
async sendSchedules(options) {
|
|
224
|
-
const { chunkingId
|
|
239
|
+
const { chunkingId, ...rest } = options;
|
|
225
240
|
const getSchedulesTargetAndPayload = this.buildTargetAndPayload(rest);
|
|
226
|
-
await this.client.emitAndFlattenResponses('calendar.send-schedules::v2021_05_19',
|
|
241
|
+
await this.client.emitAndFlattenResponses('calendar.send-schedules::v2021_05_19', {
|
|
242
|
+
...getSchedulesTargetAndPayload,
|
|
243
|
+
payload: {
|
|
244
|
+
...getSchedulesTargetAndPayload.payload,
|
|
245
|
+
chunkingId,
|
|
246
|
+
sendToFqen: 'calendar.stream-schedules::v2021_05_19',
|
|
247
|
+
},
|
|
248
|
+
});
|
|
227
249
|
}
|
|
228
250
|
async getSchedules(options) {
|
|
229
251
|
const targetAndPayload = this.buildTargetAndPayload(options);
|
|
@@ -231,7 +253,7 @@ class RemoteEventStoreImpl {
|
|
|
231
253
|
return events;
|
|
232
254
|
}
|
|
233
255
|
buildTargetAndPayload(options) {
|
|
234
|
-
const { calendarIds, peopleIds: personIds, startDate, endDate } = options;
|
|
256
|
+
const { calendarIds, peopleIds: personIds, startDate, endDate, } = options;
|
|
235
257
|
const targetAndPayload = {
|
|
236
258
|
target: {
|
|
237
259
|
calendarIds,
|
|
@@ -2,8 +2,14 @@
|
|
|
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;
|
|
5
12
|
constructor(options) {
|
|
6
|
-
this.isLoaded = false;
|
|
7
13
|
const { connectToApi } = (0, schema_1.assertOptions)(options, ['connectToApi']);
|
|
8
14
|
this.connectToApi = connectToApi;
|
|
9
15
|
}
|
|
@@ -20,9 +26,9 @@ class RemotePreferencesStore {
|
|
|
20
26
|
organizationId: this.organizationId,
|
|
21
27
|
},
|
|
22
28
|
});
|
|
23
|
-
this.visibleCalendarIds = selectedCalendarIds
|
|
24
|
-
this.visiblePeopleMode = visiblePeopleMode
|
|
25
|
-
this.visiblePeopleIds = visiblePeopleIds
|
|
29
|
+
this.visibleCalendarIds = selectedCalendarIds ?? undefined;
|
|
30
|
+
this.visiblePeopleMode = visiblePeopleMode ?? undefined;
|
|
31
|
+
this.visiblePeopleIds = visiblePeopleIds ?? undefined;
|
|
26
32
|
}
|
|
27
33
|
async setVisibleCalendarIds(ids) {
|
|
28
34
|
this.visibleCalendarIds = ids;
|
|
@@ -2,6 +2,9 @@
|
|
|
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 = {};
|
|
5
8
|
constructor(sm, addToolHandler) {
|
|
6
9
|
this.sm = sm;
|
|
7
10
|
this.addToolHandler = addToolHandler;
|
|
@@ -10,17 +13,16 @@ class CalendarToolRegistrar {
|
|
|
10
13
|
CalendarToolRegistrar.fetchedRecord = {};
|
|
11
14
|
}
|
|
12
15
|
async fetchAndAddCards(getControllerOptions) {
|
|
13
|
-
var _a;
|
|
14
16
|
const { event } = this.sm.getContext();
|
|
15
17
|
let cards = [];
|
|
16
|
-
const cacheKey =
|
|
18
|
+
const cacheKey = event.eventTypeSlug ?? 'none';
|
|
17
19
|
if (!CalendarToolRegistrar.fetchedRecord[cacheKey]) {
|
|
18
20
|
const { cards: fetchedCards, vcIds } = await this.fetchUncached(getControllerOptions);
|
|
19
21
|
CalendarToolRegistrar.fetchedRecord[cacheKey] = vcIds;
|
|
20
22
|
cards = fetchedCards;
|
|
21
23
|
}
|
|
22
24
|
else {
|
|
23
|
-
cards = CalendarToolRegistrar.fetchedRecord[cacheKey].map((vcId) =>
|
|
25
|
+
cards = CalendarToolRegistrar.fetchedRecord[cacheKey].map((vcId) => this.views.Controller(vcId, getControllerOptions?.(vcId) ?? {}));
|
|
24
26
|
}
|
|
25
27
|
await Promise.all(cards.map((card) => this.addTool(card)));
|
|
26
28
|
return cards;
|
|
@@ -48,14 +50,13 @@ class CalendarToolRegistrar {
|
|
|
48
50
|
const cards = (await registrar.fetch({
|
|
49
51
|
each: async () => { },
|
|
50
52
|
controllerOptionsHandler: (vcId) => {
|
|
51
|
-
var _a;
|
|
52
53
|
vcIds.push(vcId);
|
|
53
|
-
return
|
|
54
|
+
return getControllerOptions?.(vcId) ?? {};
|
|
54
55
|
},
|
|
55
56
|
target: {
|
|
56
57
|
organizationId: org.id,
|
|
57
58
|
calendarEventId: event.id,
|
|
58
|
-
locationId: location
|
|
59
|
+
locationId: location?.id,
|
|
59
60
|
},
|
|
60
61
|
payload: {
|
|
61
62
|
eventTypeSlug: event.eventTypeSlug,
|
|
@@ -64,7 +65,6 @@ class CalendarToolRegistrar {
|
|
|
64
65
|
return { cards, vcIds };
|
|
65
66
|
}
|
|
66
67
|
async addTool(card) {
|
|
67
|
-
var _a;
|
|
68
68
|
const toolBeltVc = this.sm.getToolBeltVc();
|
|
69
69
|
if (this.addToolHandler) {
|
|
70
70
|
await this.addToolHandler(card);
|
|
@@ -76,9 +76,8 @@ class CalendarToolRegistrar {
|
|
|
76
76
|
lineIcon: card.getLineIcon(),
|
|
77
77
|
card: card.render(),
|
|
78
78
|
});
|
|
79
|
-
await
|
|
79
|
+
await card.load?.();
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
CalendarToolRegistrar.fetchedRecord = {};
|
|
84
83
|
exports.default = CalendarToolRegistrar;
|
|
@@ -9,21 +9,27 @@ const just_clone_1 = __importDefault(require("just-clone"));
|
|
|
9
9
|
class CalendarToolTestFactory {
|
|
10
10
|
static Tool(stateMachine, vcId, options) {
|
|
11
11
|
(0, schema_1.assertOptions)({ stateMachine, vcId }, ['stateMachine', 'vcId']);
|
|
12
|
-
const vc = stateMachine.Controller(vcId,
|
|
12
|
+
const vc = stateMachine.Controller(vcId, {
|
|
13
|
+
getContext: () => stateMachine.getContext(),
|
|
14
|
+
updateContext: (context) => {
|
|
13
15
|
return stateMachine.updateContext(context);
|
|
14
|
-
},
|
|
16
|
+
},
|
|
17
|
+
getPersonFromEvent: () => {
|
|
15
18
|
throw new schema_1.SchemaError({
|
|
16
19
|
code: 'MISSING_PARAMETERS',
|
|
17
20
|
parameters: ['getPersonFromEvent'],
|
|
18
21
|
friendlyMessage: `You need to pass 'getPersonFromEvent: () => login.getPerson()' or similar to CalendarToolTestFactory.Tool(....)`,
|
|
19
22
|
});
|
|
20
|
-
},
|
|
23
|
+
},
|
|
24
|
+
getHasPendingContextChanges: () => {
|
|
21
25
|
throw new schema_1.SchemaError({
|
|
22
26
|
code: 'MISSING_PARAMETERS',
|
|
23
27
|
parameters: ['getHasPendingContextChanges'],
|
|
24
28
|
friendlyMessage: `You need to pass 'getHasPendingContextChanges: () => boolean' or similar to CalendarToolTestFactory.Tool(....)`,
|
|
25
29
|
});
|
|
26
|
-
}
|
|
30
|
+
},
|
|
31
|
+
...(0, just_clone_1.default)(options ?? {}),
|
|
32
|
+
});
|
|
27
33
|
void stateMachine.on('did-update-context', () => {
|
|
28
34
|
return vc.handleUpdateContext(stateMachine.getContext());
|
|
29
35
|
});
|
|
@@ -8,20 +8,30 @@ 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;
|
|
11
21
|
constructor() {
|
|
12
|
-
this.vcs = [];
|
|
13
|
-
this.pendingContextUpdates = {};
|
|
14
|
-
this.isLoaded = false;
|
|
15
|
-
this.shouldLoadToolsRightAway = true;
|
|
16
22
|
this._handleDidUpdateContext = this._handleDidUpdateContext.bind(this);
|
|
17
23
|
this._handleWillUpdateContext = this._handleWillUpdateContext.bind(this);
|
|
18
24
|
}
|
|
19
25
|
async load(sm) {
|
|
20
|
-
var _a;
|
|
21
26
|
this.sm = sm;
|
|
22
27
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
23
28
|
this.isLoaded = true;
|
|
24
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card',
|
|
29
|
+
this.controlsVc = sm.Controller('calendar.event-controls-card', {
|
|
30
|
+
onCancel: this.clearPendingContextChanges.bind(this),
|
|
31
|
+
onSave: this.handleClickSave.bind(this),
|
|
32
|
+
...this.buildVcConstructorOptions('controls'),
|
|
33
|
+
onCancelEvent: this.handleClickCancel.bind(this),
|
|
34
|
+
});
|
|
25
35
|
this.events = this.context.events;
|
|
26
36
|
this.events.setUpdateContextHandler(async (updates) => {
|
|
27
37
|
return this.handleUpdateContextFromTool(updates, 'eventManager', {
|
|
@@ -36,7 +46,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
36
46
|
});
|
|
37
47
|
void this.sm.on('will-update-context', this._handleWillUpdateContext);
|
|
38
48
|
void this.sm.on('did-update-context', this._handleDidUpdateContext);
|
|
39
|
-
this.lastEventId =
|
|
49
|
+
this.lastEventId = this.event?.id;
|
|
40
50
|
}
|
|
41
51
|
getIsLoaded() {
|
|
42
52
|
return this.isLoaded;
|
|
@@ -51,7 +61,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
51
61
|
async handleClickSave() {
|
|
52
62
|
const updates = this.pendingContextUpdates;
|
|
53
63
|
await this.clearPendingContextChanges(false);
|
|
54
|
-
await this.sm.updateContext(
|
|
64
|
+
await this.sm.updateContext({ ...updates });
|
|
55
65
|
await this.deselectEvent();
|
|
56
66
|
}
|
|
57
67
|
async handleClickCancel() {
|
|
@@ -84,10 +94,12 @@ class AbstractCalendarEventToolBeltState {
|
|
|
84
94
|
}
|
|
85
95
|
}));
|
|
86
96
|
this.controlsVc.handleUpdateContext();
|
|
87
|
-
this.lastEventId = event
|
|
97
|
+
this.lastEventId = event?.id;
|
|
88
98
|
}
|
|
89
99
|
getContextWithPendingChanges() {
|
|
90
|
-
return
|
|
100
|
+
return {
|
|
101
|
+
...this.sm.getContext(this.pendingContextUpdates),
|
|
102
|
+
};
|
|
91
103
|
}
|
|
92
104
|
async clearPendingContextChanges(shouldEmitDidUpdate = true) {
|
|
93
105
|
this.pendingContextUpdates = {};
|
|
@@ -96,7 +108,6 @@ class AbstractCalendarEventToolBeltState {
|
|
|
96
108
|
}
|
|
97
109
|
}
|
|
98
110
|
async addTool(options) {
|
|
99
|
-
var _a;
|
|
100
111
|
(0, schema_1.assertOptions)(options, ['id', 'lineIcon', 'cardVcId']);
|
|
101
112
|
if (!this.sm) {
|
|
102
113
|
throw new Error("You can't add a tool until after load. Make sure you're calling 'await super.load()' inside your 'load()'.");
|
|
@@ -108,7 +119,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
108
119
|
return vc;
|
|
109
120
|
}
|
|
110
121
|
catch (err) {
|
|
111
|
-
if (
|
|
122
|
+
if (err.options?.code === 'CALENDAR_TOOL_INTERFACE') {
|
|
112
123
|
throw err;
|
|
113
124
|
}
|
|
114
125
|
console.error(err);
|
|
@@ -128,8 +139,11 @@ class AbstractCalendarEventToolBeltState {
|
|
|
128
139
|
async addVc(toolId, lineIcon, vc) {
|
|
129
140
|
this.vcs.push({ vc, toolId });
|
|
130
141
|
if (typeof vc.handleUpdateContext !== 'function') {
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
throw new SpruceError_1.default({
|
|
143
|
+
code: 'CALENDAR_TOOL_INTERFACE',
|
|
144
|
+
//@ts-ignore
|
|
145
|
+
vcId: vc.id,
|
|
146
|
+
});
|
|
133
147
|
}
|
|
134
148
|
this.toolBeltVc.addTool({
|
|
135
149
|
id: toolId,
|
|
@@ -141,27 +155,24 @@ class AbstractCalendarEventToolBeltState {
|
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
157
|
async loadVc(vc) {
|
|
144
|
-
var _a, _b;
|
|
145
158
|
try {
|
|
146
|
-
await
|
|
159
|
+
await vc.load?.();
|
|
147
160
|
}
|
|
148
161
|
catch (err) {
|
|
149
|
-
|
|
162
|
+
vc.setCriticalError?.(err);
|
|
150
163
|
}
|
|
151
164
|
}
|
|
152
165
|
async loadTools() {
|
|
153
166
|
await Promise.all(this.vcs.map(({ vc }) => this.loadVc(vc)));
|
|
154
167
|
}
|
|
155
168
|
async getPersonFromEvent() {
|
|
156
|
-
var _a;
|
|
157
169
|
if (this.getPersonPromise) {
|
|
158
170
|
return this.getPersonPromise;
|
|
159
171
|
}
|
|
160
172
|
this.getPersonPromise = this._getPersonFromEvent();
|
|
161
|
-
return
|
|
173
|
+
return this.getPersonPromise ?? null;
|
|
162
174
|
}
|
|
163
175
|
async _getPersonFromEvent() {
|
|
164
|
-
var _a;
|
|
165
176
|
try {
|
|
166
177
|
const id = this.event.target.personId;
|
|
167
178
|
const client = await this.sm.connectToApi();
|
|
@@ -173,21 +184,21 @@ class AbstractCalendarEventToolBeltState {
|
|
|
173
184
|
return person;
|
|
174
185
|
}
|
|
175
186
|
catch (err) {
|
|
176
|
-
console.error(
|
|
187
|
+
console.error(err.stack ?? err.message);
|
|
177
188
|
return null;
|
|
178
189
|
}
|
|
179
190
|
}
|
|
180
191
|
async handleUpdateContextFromTool(updates, fromToolId, options) {
|
|
181
|
-
const pendingUpdates =
|
|
192
|
+
const pendingUpdates = { ...this.pendingContextUpdates, ...updates };
|
|
182
193
|
if ((0, just_compare_1.default)(this.pendingContextUpdates, pendingUpdates)) {
|
|
183
194
|
return false;
|
|
184
195
|
}
|
|
185
196
|
this.pendingContextUpdates = pendingUpdates;
|
|
186
197
|
const vc = this.getVcForTool(fromToolId);
|
|
187
|
-
const shouldPersistChanges =
|
|
188
|
-
|
|
198
|
+
const shouldPersistChanges = vc?.shouldPersistContextChangesImmediately ||
|
|
199
|
+
options?.shouldPersistContextChangesImmediately;
|
|
189
200
|
if (shouldPersistChanges) {
|
|
190
|
-
return this.sm.updateContext(
|
|
201
|
+
return this.sm.updateContext({ ...updates });
|
|
191
202
|
}
|
|
192
203
|
else {
|
|
193
204
|
await this._handleDidUpdateContext(fromToolId);
|
|
@@ -207,8 +218,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
207
218
|
return this.pendingContextUpdates;
|
|
208
219
|
}
|
|
209
220
|
getVcForTool(toolId) {
|
|
210
|
-
|
|
211
|
-
return (_a = this.vcs.find((v) => v.toolId === toolId)) === null || _a === void 0 ? void 0 : _a.vc;
|
|
221
|
+
return this.vcs.find((v) => v.toolId === toolId)?.vc;
|
|
212
222
|
}
|
|
213
223
|
getControlsVc() {
|
|
214
224
|
return this.controlsVc;
|
|
@@ -6,13 +6,20 @@ 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;
|
|
9
17
|
get calendars() {
|
|
10
18
|
return this.sm.getContext().events.getCalendars();
|
|
11
19
|
}
|
|
12
20
|
constructor(options) {
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.selectEventTypeHandler = options === null || options === void 0 ? void 0 : options.onSelectEventType;
|
|
21
|
+
this.selectCalendarHandler = options?.onSelectCalendar;
|
|
22
|
+
this.selectEventTypeHandler = options?.onSelectEventType;
|
|
16
23
|
}
|
|
17
24
|
async load(stateMachine) {
|
|
18
25
|
const toolBeltVc = stateMachine.getToolBeltVc();
|
|
@@ -28,7 +35,10 @@ class PrerequisitesToolBeltState {
|
|
|
28
35
|
}
|
|
29
36
|
this.setupCalendarSelectCard(this.calendars);
|
|
30
37
|
await this.sm.updateContext({
|
|
31
|
-
event:
|
|
38
|
+
event: {
|
|
39
|
+
...this.sm.getContext().event,
|
|
40
|
+
isBusy: false,
|
|
41
|
+
},
|
|
32
42
|
});
|
|
33
43
|
}
|
|
34
44
|
destroy() { }
|
|
@@ -58,13 +68,12 @@ class PrerequisitesToolBeltState {
|
|
|
58
68
|
this.calendarSelectCardVc.setIsBusy(false);
|
|
59
69
|
}
|
|
60
70
|
async handleSelectCalendar(calendar) {
|
|
61
|
-
|
|
62
|
-
(_a = this.calendarSelectCardVc) === null || _a === void 0 ? void 0 : _a.setIsBusy(true);
|
|
71
|
+
this.calendarSelectCardVc?.setIsBusy(true);
|
|
63
72
|
this.calendar = calendar;
|
|
64
|
-
await
|
|
73
|
+
await this.selectCalendarHandler?.(calendar);
|
|
65
74
|
const client = await this.connectToApi();
|
|
66
75
|
let [{ calendarEventTypes }] = await client.emitAndFlattenResponses('calendar.list-calendar-event-types::v2021_05_19');
|
|
67
|
-
const types =
|
|
76
|
+
const types = calendar.eventTypes ?? [];
|
|
68
77
|
if (types.length > 0) {
|
|
69
78
|
calendarEventTypes = calendarEventTypes.filter((t) => types.indexOf(t.slug) > -1);
|
|
70
79
|
}
|
|
@@ -75,10 +84,9 @@ class PrerequisitesToolBeltState {
|
|
|
75
84
|
await this.updateEvent();
|
|
76
85
|
await this.setupTypeSelectCard(calendarEventTypes);
|
|
77
86
|
}
|
|
78
|
-
|
|
87
|
+
this.calendarSelectCardVc?.setIsBusy(false);
|
|
79
88
|
}
|
|
80
89
|
async setupTypeSelectCard(types) {
|
|
81
|
-
var _a, _b, _c, _d, _e, _f;
|
|
82
90
|
if (!this.toolBeltVc.getTool('types')) {
|
|
83
91
|
this.typeSelectCardVc = this.TypeSelectCardVc();
|
|
84
92
|
this.toolBeltVc.addTool({
|
|
@@ -87,16 +95,16 @@ class PrerequisitesToolBeltState {
|
|
|
87
95
|
card: this.typeSelectCardVc.render(),
|
|
88
96
|
});
|
|
89
97
|
}
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
this.typeSelectCardVc?.setIsBusy(true);
|
|
99
|
+
this.toolBeltVc?.focusTool('types');
|
|
92
100
|
const section = await this.renderTypeButtonsSection(types);
|
|
93
|
-
if (
|
|
94
|
-
|
|
101
|
+
if (this.typeSelectCardVc?.getTotalSections() === 0) {
|
|
102
|
+
this.typeSelectCardVc?.addSection(section);
|
|
95
103
|
}
|
|
96
104
|
else {
|
|
97
|
-
|
|
105
|
+
this.typeSelectCardVc?.setSection(0, section);
|
|
98
106
|
}
|
|
99
|
-
|
|
107
|
+
this.typeSelectCardVc?.setIsBusy(false);
|
|
100
108
|
}
|
|
101
109
|
async renderTypeButtonsSection(calendarEventTypes) {
|
|
102
110
|
const section = {
|
|
@@ -109,22 +117,23 @@ class PrerequisitesToolBeltState {
|
|
|
109
117
|
return section;
|
|
110
118
|
}
|
|
111
119
|
async handleSelectType(type) {
|
|
112
|
-
|
|
113
|
-
(_a = this.typeSelectCardVc) === null || _a === void 0 ? void 0 : _a.setIsBusy(true);
|
|
120
|
+
this.typeSelectCardVc?.setIsBusy(true);
|
|
114
121
|
const { event } = this.sm.getContext();
|
|
115
122
|
const updated = (0, makeEventTyped_1.default)(event, type);
|
|
116
123
|
await this.updateEvent({
|
|
117
124
|
eventTypeSlug: type.slug,
|
|
118
125
|
timeBlocks: updated.timeBlocks,
|
|
119
126
|
});
|
|
120
|
-
await
|
|
121
|
-
|
|
127
|
+
await this.selectEventTypeHandler?.(type);
|
|
128
|
+
this.typeSelectCardVc?.setIsBusy(false);
|
|
122
129
|
}
|
|
123
130
|
async updateEvent(updates) {
|
|
124
|
-
var _a;
|
|
125
131
|
const { event, events } = this.sm.getContext();
|
|
126
132
|
if (event) {
|
|
127
|
-
events.updateEvent(event.id,
|
|
133
|
+
events.updateEvent(event.id, {
|
|
134
|
+
calendarId: this.calendar?.id,
|
|
135
|
+
...updates,
|
|
136
|
+
});
|
|
128
137
|
await events.waitForPendingOperations();
|
|
129
138
|
}
|
|
130
139
|
}
|