@sprucelabs/spruce-calendar-components 19.2.0 → 20.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/esm/stores/RemoteEventStore.d.ts +2 -2
- package/build/esm/stores/RemoteEventStore.js +4 -4
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.d.ts +1 -1
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +3 -4
- package/build/esm/types/calendar.types.d.ts +2 -0
- package/build/esm/viewControllers/EventControlsCard.vc.d.ts +4 -2
- package/build/esm/viewControllers/EventControlsCard.vc.js +32 -2
- package/build/stores/RemoteEventStore.d.ts +2 -2
- package/build/stores/RemoteEventStore.js +4 -4
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.d.ts +1 -1
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +3 -4
- package/build/types/calendar.types.d.ts +2 -0
- package/build/viewControllers/EventControlsCard.vc.d.ts +4 -2
- package/build/viewControllers/EventControlsCard.vc.js +35 -2
- package/package.json +1 -1
|
@@ -4,13 +4,13 @@ import { UpdateEvent } from '../types/calendar.types';
|
|
|
4
4
|
export interface RemoteEventStoreOptions {
|
|
5
5
|
client: MercuryClient;
|
|
6
6
|
calendarId?: string;
|
|
7
|
-
|
|
7
|
+
locationId: string;
|
|
8
8
|
}
|
|
9
9
|
declare type FullEvent = SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
10
10
|
export default class RemoteEventStore {
|
|
11
11
|
private client;
|
|
12
12
|
private calendarId?;
|
|
13
|
-
private
|
|
13
|
+
private locationId;
|
|
14
14
|
private pendingEvent?;
|
|
15
15
|
private draftIdMap;
|
|
16
16
|
private promises;
|
|
@@ -28,10 +28,10 @@ export default class RemoteEventStore {
|
|
|
28
28
|
this.queueByEventId = {};
|
|
29
29
|
this.busyByEvent = {};
|
|
30
30
|
this.lastSavedById = {};
|
|
31
|
-
assertOptions(options, ['client', '
|
|
31
|
+
assertOptions(options, ['client', 'locationId']);
|
|
32
32
|
this.client = options.client;
|
|
33
33
|
this.calendarId = options.calendarId;
|
|
34
|
-
this.
|
|
34
|
+
this.locationId = options.locationId;
|
|
35
35
|
}
|
|
36
36
|
persist(event) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -141,7 +141,7 @@ export default class RemoteEventStore {
|
|
|
141
141
|
payload = this.cleanPayload(payload);
|
|
142
142
|
return {
|
|
143
143
|
payload,
|
|
144
|
-
target: Object.assign(Object.assign({}, target), { calendarEventPersonId: personId,
|
|
144
|
+
target: Object.assign(Object.assign({}, target), { calendarEventPersonId: personId, locationId: this.locationId }),
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
147
|
cleanTarget(target) {
|
|
@@ -195,7 +195,7 @@ export default class RemoteEventStore {
|
|
|
195
195
|
else {
|
|
196
196
|
yield this.client.emitAndFlattenResponses('calendar.delete-calendar-event::v2021_05_19', {
|
|
197
197
|
target: {
|
|
198
|
-
|
|
198
|
+
locationId: this.locationId,
|
|
199
199
|
calendarEventId: id,
|
|
200
200
|
},
|
|
201
201
|
});
|
|
@@ -18,7 +18,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
18
18
|
private handleDidUpdateContext;
|
|
19
19
|
private getContext;
|
|
20
20
|
clearPendingContextChanges(): Promise<void>;
|
|
21
|
-
addTool(options: AddToolOptions): Promise<
|
|
21
|
+
addTool(options: AddToolOptions): Promise<CalendarTool>;
|
|
22
22
|
private buildVcConstructorOptions;
|
|
23
23
|
private addVc;
|
|
24
24
|
protected getPersonFromEvent(): ReturnType<GetPersonFromEventHandler>;
|
|
@@ -22,10 +22,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
22
22
|
this.sm = sm;
|
|
23
23
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
24
24
|
this._isLoaded = true;
|
|
25
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card', {
|
|
26
|
-
onCancel: this.clearPendingContextChanges.bind(this),
|
|
27
|
-
onSave: this.handleClickSave.bind(this),
|
|
28
|
-
});
|
|
25
|
+
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')));
|
|
29
26
|
this.toolBeltVc.clearTools();
|
|
30
27
|
this.toolBeltVc.setStickyTool({
|
|
31
28
|
card: this.controlsVc.render(),
|
|
@@ -79,6 +76,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
79
76
|
const { cardVcId, lineIcon, id } = options;
|
|
80
77
|
const vc = this.sm.Controller(cardVcId, this.buildVcConstructorOptions(id));
|
|
81
78
|
yield this.addVc(id, lineIcon, vc);
|
|
79
|
+
return vc;
|
|
82
80
|
});
|
|
83
81
|
}
|
|
84
82
|
buildVcConstructorOptions(id) {
|
|
@@ -86,6 +84,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
86
84
|
updateContext: (updates, options) => this.handleUpdateContextFromTool(updates, id, options),
|
|
87
85
|
getContext: () => this.getContext(),
|
|
88
86
|
getPersonFromEvent: () => this.getPersonFromEvent(),
|
|
87
|
+
getHasPendingContextChanges: () => Object.keys(this.pendingContextUpdates).length > 0,
|
|
89
88
|
};
|
|
90
89
|
}
|
|
91
90
|
addVc(toolId, lineIcon, vc) {
|
|
@@ -34,10 +34,12 @@ export interface UpdateCalendarContextOptions {
|
|
|
34
34
|
export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<CalendarToolBeltContext>, options?: UpdateCalendarContextOptions) => Promise<void>;
|
|
35
35
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
36
36
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
37
|
+
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
37
38
|
export interface CalendarToolOptions {
|
|
38
39
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
39
40
|
getContext: GetCalendarToolBeltContextHandler;
|
|
40
41
|
getPersonFromEvent: GetPersonFromEventHandler;
|
|
42
|
+
getHasPendingContextChanges: GetHasPendingContextChangesHandler;
|
|
41
43
|
}
|
|
42
44
|
export interface EventWithToolBeltState {
|
|
43
45
|
getToolBeltState(): ToolBeltState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
-
export interface EventControlsCardOptions {
|
|
4
|
+
export interface EventControlsCardOptions extends CalendarToolOptions {
|
|
5
5
|
onCancel: () => Promise<void | boolean> | void | boolean;
|
|
6
6
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
7
|
}
|
|
@@ -10,6 +10,8 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
10
10
|
private cardVc;
|
|
11
11
|
private saveHandler;
|
|
12
12
|
private cancelHandler;
|
|
13
|
+
private getHasPendingContextChangesHandler;
|
|
14
|
+
private getContext;
|
|
13
15
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
14
16
|
private handleClickCancel;
|
|
15
17
|
private handleClickSave;
|
|
@@ -9,12 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { AbstractViewController, } from '@sprucelabs/heartwood-view-controllers';
|
|
11
11
|
import { assertOptions } from '@sprucelabs/schema';
|
|
12
|
+
import draftEventGenerator from '../utilities/draftGenerator.js';
|
|
12
13
|
export default class EventControlsCardViewController extends AbstractViewController {
|
|
13
14
|
constructor(options) {
|
|
14
15
|
super(options);
|
|
15
|
-
const { onSave, onCancel } = assertOptions(options, [
|
|
16
|
+
const { onSave, onCancel, getHasPendingContextChanges, getContext } = assertOptions(options, [
|
|
17
|
+
'onCancel',
|
|
18
|
+
'onSave',
|
|
19
|
+
'getHasPendingContextChanges',
|
|
20
|
+
'getContext',
|
|
21
|
+
]);
|
|
16
22
|
this.saveHandler = onSave;
|
|
17
23
|
this.cancelHandler = onCancel;
|
|
24
|
+
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
25
|
+
this.getContext = getContext;
|
|
18
26
|
this.cardVc = this.Controller('card', {
|
|
19
27
|
footer: {
|
|
20
28
|
isEnabled: false,
|
|
@@ -50,7 +58,29 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
50
58
|
});
|
|
51
59
|
}
|
|
52
60
|
handleUpdateContext() {
|
|
53
|
-
|
|
61
|
+
var _a;
|
|
62
|
+
if (this.getHasPendingContextChangesHandler()) {
|
|
63
|
+
this.cardVc.enableFooter();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.cardVc.disableFooter();
|
|
67
|
+
}
|
|
68
|
+
const { event } = this.getContext();
|
|
69
|
+
if ((event === null || event === void 0 ? void 0 : event.id) && !draftEventGenerator.isDraftId(event.id)) {
|
|
70
|
+
this.cardVc.setBody({
|
|
71
|
+
sections: [
|
|
72
|
+
{
|
|
73
|
+
buttons: [
|
|
74
|
+
{
|
|
75
|
+
id: 'cancel-event',
|
|
76
|
+
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
77
|
+
type: 'destructive',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
54
84
|
}
|
|
55
85
|
render() {
|
|
56
86
|
return this.cardVc.render();
|
|
@@ -4,13 +4,13 @@ import { UpdateEvent } from '../types/calendar.types';
|
|
|
4
4
|
export interface RemoteEventStoreOptions {
|
|
5
5
|
client: MercuryClient;
|
|
6
6
|
calendarId?: string;
|
|
7
|
-
|
|
7
|
+
locationId: string;
|
|
8
8
|
}
|
|
9
9
|
declare type FullEvent = SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
10
10
|
export default class RemoteEventStore {
|
|
11
11
|
private client;
|
|
12
12
|
private calendarId?;
|
|
13
|
-
private
|
|
13
|
+
private locationId;
|
|
14
14
|
private pendingEvent?;
|
|
15
15
|
private draftIdMap;
|
|
16
16
|
private promises;
|
|
@@ -24,10 +24,10 @@ class RemoteEventStore {
|
|
|
24
24
|
this.queueByEventId = {};
|
|
25
25
|
this.busyByEvent = {};
|
|
26
26
|
this.lastSavedById = {};
|
|
27
|
-
(0, schema_1.assertOptions)(options, ['client', '
|
|
27
|
+
(0, schema_1.assertOptions)(options, ['client', 'locationId']);
|
|
28
28
|
this.client = options.client;
|
|
29
29
|
this.calendarId = options.calendarId;
|
|
30
|
-
this.
|
|
30
|
+
this.locationId = options.locationId;
|
|
31
31
|
}
|
|
32
32
|
async persist(event) {
|
|
33
33
|
if (!this.resolveCalendarId(event)) {
|
|
@@ -127,7 +127,7 @@ class RemoteEventStore {
|
|
|
127
127
|
payload = this.cleanPayload(payload);
|
|
128
128
|
return {
|
|
129
129
|
payload,
|
|
130
|
-
target: Object.assign(Object.assign({}, target), { calendarEventPersonId: personId,
|
|
130
|
+
target: Object.assign(Object.assign({}, target), { calendarEventPersonId: personId, locationId: this.locationId }),
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
cleanTarget(target) {
|
|
@@ -178,7 +178,7 @@ class RemoteEventStore {
|
|
|
178
178
|
else {
|
|
179
179
|
await this.client.emitAndFlattenResponses('calendar.delete-calendar-event::v2021_05_19', {
|
|
180
180
|
target: {
|
|
181
|
-
|
|
181
|
+
locationId: this.locationId,
|
|
182
182
|
calendarEventId: id,
|
|
183
183
|
},
|
|
184
184
|
});
|
|
@@ -18,7 +18,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
18
18
|
private handleDidUpdateContext;
|
|
19
19
|
private getContext;
|
|
20
20
|
clearPendingContextChanges(): Promise<void>;
|
|
21
|
-
addTool(options: AddToolOptions): Promise<
|
|
21
|
+
addTool(options: AddToolOptions): Promise<CalendarTool>;
|
|
22
22
|
private buildVcConstructorOptions;
|
|
23
23
|
private addVc;
|
|
24
24
|
protected getPersonFromEvent(): ReturnType<GetPersonFromEventHandler>;
|
|
@@ -17,10 +17,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
17
17
|
this.sm = sm;
|
|
18
18
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
19
19
|
this._isLoaded = true;
|
|
20
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card', {
|
|
21
|
-
onCancel: this.clearPendingContextChanges.bind(this),
|
|
22
|
-
onSave: this.handleClickSave.bind(this),
|
|
23
|
-
});
|
|
20
|
+
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')));
|
|
24
21
|
this.toolBeltVc.clearTools();
|
|
25
22
|
this.toolBeltVc.setStickyTool({
|
|
26
23
|
card: this.controlsVc.render(),
|
|
@@ -64,12 +61,14 @@ class AbstractCalendarEventToolBeltState {
|
|
|
64
61
|
const { cardVcId, lineIcon, id } = options;
|
|
65
62
|
const vc = this.sm.Controller(cardVcId, this.buildVcConstructorOptions(id));
|
|
66
63
|
await this.addVc(id, lineIcon, vc);
|
|
64
|
+
return vc;
|
|
67
65
|
}
|
|
68
66
|
buildVcConstructorOptions(id) {
|
|
69
67
|
return {
|
|
70
68
|
updateContext: (updates, options) => this.handleUpdateContextFromTool(updates, id, options),
|
|
71
69
|
getContext: () => this.getContext(),
|
|
72
70
|
getPersonFromEvent: () => this.getPersonFromEvent(),
|
|
71
|
+
getHasPendingContextChanges: () => Object.keys(this.pendingContextUpdates).length > 0,
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
74
|
async addVc(toolId, lineIcon, vc) {
|
|
@@ -34,10 +34,12 @@ export interface UpdateCalendarContextOptions {
|
|
|
34
34
|
export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<CalendarToolBeltContext>, options?: UpdateCalendarContextOptions) => Promise<void>;
|
|
35
35
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
36
36
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
37
|
+
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
37
38
|
export interface CalendarToolOptions {
|
|
38
39
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
39
40
|
getContext: GetCalendarToolBeltContextHandler;
|
|
40
41
|
getPersonFromEvent: GetPersonFromEventHandler;
|
|
42
|
+
getHasPendingContextChanges: GetHasPendingContextChangesHandler;
|
|
41
43
|
}
|
|
42
44
|
export interface EventWithToolBeltState {
|
|
43
45
|
getToolBeltState(): ToolBeltState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
-
export interface EventControlsCardOptions {
|
|
4
|
+
export interface EventControlsCardOptions extends CalendarToolOptions {
|
|
5
5
|
onCancel: () => Promise<void | boolean> | void | boolean;
|
|
6
6
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
7
|
}
|
|
@@ -10,6 +10,8 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
10
10
|
private cardVc;
|
|
11
11
|
private saveHandler;
|
|
12
12
|
private cancelHandler;
|
|
13
|
+
private getHasPendingContextChangesHandler;
|
|
14
|
+
private getContext;
|
|
13
15
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
14
16
|
private handleClickCancel;
|
|
15
17
|
private handleClickSave;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
7
|
const schema_1 = require("@sprucelabs/schema");
|
|
8
|
+
const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"));
|
|
5
9
|
class EventControlsCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
6
10
|
constructor(options) {
|
|
7
11
|
super(options);
|
|
8
|
-
const { onSave, onCancel } = (0, schema_1.assertOptions)(options, [
|
|
12
|
+
const { onSave, onCancel, getHasPendingContextChanges, getContext } = (0, schema_1.assertOptions)(options, [
|
|
13
|
+
'onCancel',
|
|
14
|
+
'onSave',
|
|
15
|
+
'getHasPendingContextChanges',
|
|
16
|
+
'getContext',
|
|
17
|
+
]);
|
|
9
18
|
this.saveHandler = onSave;
|
|
10
19
|
this.cancelHandler = onCancel;
|
|
20
|
+
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
21
|
+
this.getContext = getContext;
|
|
11
22
|
this.cardVc = this.Controller('card', {
|
|
12
23
|
footer: {
|
|
13
24
|
isEnabled: false,
|
|
@@ -39,7 +50,29 @@ class EventControlsCardViewController extends heartwood_view_controllers_1.Abstr
|
|
|
39
50
|
this.cardVc.disableFooter();
|
|
40
51
|
}
|
|
41
52
|
handleUpdateContext() {
|
|
42
|
-
|
|
53
|
+
var _a;
|
|
54
|
+
if (this.getHasPendingContextChangesHandler()) {
|
|
55
|
+
this.cardVc.enableFooter();
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.cardVc.disableFooter();
|
|
59
|
+
}
|
|
60
|
+
const { event } = this.getContext();
|
|
61
|
+
if ((event === null || event === void 0 ? void 0 : event.id) && !draftGenerator_1.default.isDraftId(event.id)) {
|
|
62
|
+
this.cardVc.setBody({
|
|
63
|
+
sections: [
|
|
64
|
+
{
|
|
65
|
+
buttons: [
|
|
66
|
+
{
|
|
67
|
+
id: 'cancel-event',
|
|
68
|
+
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
69
|
+
type: 'destructive',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
43
76
|
}
|
|
44
77
|
render() {
|
|
45
78
|
return this.cardVc.render();
|