@sprucelabs/spruce-calendar-components 25.5.5 → 25.5.7
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/__tests__/support/utilities/calendarSkillAssert.js +2 -0
- package/build/esm/__tests__/support/utilities/calendarSkillAssert.js +2 -0
- package/build/esm/toolBelt/CalendarToolRegistrar.d.ts +4 -2
- package/build/esm/toolBelt/CalendarToolRegistrar.js +15 -10
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +0 -1
- package/build/toolBelt/CalendarToolRegistrar.d.ts +4 -2
- package/build/toolBelt/CalendarToolRegistrar.js +13 -9
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +0 -1
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
|
10
10
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
11
11
|
const test_utils_2 = require("@sprucelabs/test-utils");
|
|
12
12
|
const Calendar_vc_1 = __importDefault(require("../../../calendar/Calendar.vc"));
|
|
13
|
+
const CalendarToolRegistrar_1 = __importDefault(require("../../../toolBelt/CalendarToolRegistrar"));
|
|
13
14
|
const AbstractCalendarEventToolBeltState_1 = __importDefault(require("../../../toolBelt/states/AbstractCalendarEventToolBeltState"));
|
|
14
15
|
const EventDateTimeTool_vc_1 = __importDefault(require("../../../tools/EventDateTimeTool.vc"));
|
|
15
16
|
const EventDurationTool_vc_1 = __importDefault(require("../../../tools/EventDurationTool.vc"));
|
|
@@ -50,6 +51,7 @@ const calendarSkillAssert = {
|
|
|
50
51
|
this.createdCalendars = [];
|
|
51
52
|
const factory = views.getFactory();
|
|
52
53
|
factory.mixinControllers(vcs);
|
|
54
|
+
CalendarToolRegistrar_1.default.reset();
|
|
53
55
|
await spruce_test_fixtures_1.eventFaker.on('calendar.register-event-tools::v2021_05_19', () => ({
|
|
54
56
|
vcIds: [],
|
|
55
57
|
}));
|
|
@@ -14,6 +14,7 @@ import { eventFaker } from '@sprucelabs/spruce-test-fixtures';
|
|
|
14
14
|
import { assert } from '@sprucelabs/test-utils';
|
|
15
15
|
import { generateId } from '@sprucelabs/test-utils';
|
|
16
16
|
import CalendarViewController from '../../../calendar/Calendar.vc.js';
|
|
17
|
+
import CalendarToolRegistrar from '../../../toolBelt/CalendarToolRegistrar.js';
|
|
17
18
|
import AbstractCalendarEventToolBeltState from '../../../toolBelt/states/AbstractCalendarEventToolBeltState.js';
|
|
18
19
|
import EventDateTimeToolViewController from '../../../tools/EventDateTimeTool.vc.js';
|
|
19
20
|
import EventDurationToolViewController from '../../../tools/EventDurationTool.vc.js';
|
|
@@ -57,6 +58,7 @@ const calendarSkillAssert = {
|
|
|
57
58
|
this.createdCalendars = [];
|
|
58
59
|
const factory = views.getFactory();
|
|
59
60
|
factory.mixinControllers(vcs);
|
|
61
|
+
CalendarToolRegistrar.reset();
|
|
60
62
|
yield eventFaker.on('calendar.register-event-tools::v2021_05_19', () => ({
|
|
61
63
|
vcIds: [],
|
|
62
64
|
}));
|
|
@@ -2,9 +2,10 @@ import { RemoteCalendarTool, CalendarToolBeltStateMachine } from '../types/calen
|
|
|
2
2
|
export default class CalendarToolRegistrar {
|
|
3
3
|
private sm;
|
|
4
4
|
private addToolHandler?;
|
|
5
|
-
private fetchedRecord;
|
|
5
|
+
private static fetchedRecord;
|
|
6
6
|
constructor(sm: CalendarToolBeltStateMachine, addToolHandler?: AddToolHandler);
|
|
7
|
-
|
|
7
|
+
static reset(): void;
|
|
8
|
+
fetchAndAddCards(getControllerOptions?: GetControllerOptions): Promise<RemoteCalendarTool[]>;
|
|
8
9
|
private get views();
|
|
9
10
|
private fetchUncached;
|
|
10
11
|
private addTool;
|
|
@@ -12,3 +13,4 @@ export default class CalendarToolRegistrar {
|
|
|
12
13
|
export type AddToolHandler = (vc: RemoteCalendarTool & {
|
|
13
14
|
id: string;
|
|
14
15
|
}) => Promise<void> | void;
|
|
16
|
+
export type GetControllerOptions = (vcId: string) => Record<string, any>;
|
|
@@ -8,35 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { CardRegistrar } from '@sprucelabs/spruce-heartwood-utils';
|
|
11
|
-
|
|
11
|
+
class CalendarToolRegistrar {
|
|
12
12
|
constructor(sm, addToolHandler) {
|
|
13
|
-
this.fetchedRecord = {};
|
|
14
13
|
this.sm = sm;
|
|
15
14
|
this.addToolHandler = addToolHandler;
|
|
16
15
|
}
|
|
17
|
-
|
|
16
|
+
static reset() {
|
|
17
|
+
CalendarToolRegistrar.fetchedRecord = {};
|
|
18
|
+
}
|
|
19
|
+
fetchAndAddCards(getControllerOptions) {
|
|
18
20
|
var _a;
|
|
19
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
22
|
const { event } = this.sm.getContext();
|
|
21
23
|
let cards = [];
|
|
22
|
-
const cacheKey = (_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : '';
|
|
23
|
-
if (!
|
|
24
|
-
const { cards: fetchedCards, vcIds } = yield this.fetchUncached(
|
|
25
|
-
|
|
24
|
+
const cacheKey = (_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'none';
|
|
25
|
+
if (!CalendarToolRegistrar.fetchedRecord[cacheKey]) {
|
|
26
|
+
const { cards: fetchedCards, vcIds } = yield this.fetchUncached(getControllerOptions);
|
|
27
|
+
CalendarToolRegistrar.fetchedRecord[cacheKey] = vcIds;
|
|
26
28
|
cards = fetchedCards;
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
|
-
cards =
|
|
31
|
+
cards = CalendarToolRegistrar.fetchedRecord[cacheKey].map((vcId) => { var _a; return this.views.Controller(vcId, (_a = getControllerOptions === null || getControllerOptions === void 0 ? void 0 : getControllerOptions(vcId)) !== null && _a !== void 0 ? _a : {}); });
|
|
30
32
|
}
|
|
31
33
|
for (const card of cards) {
|
|
32
34
|
yield this.addTool(card);
|
|
33
35
|
}
|
|
36
|
+
return cards;
|
|
34
37
|
});
|
|
35
38
|
}
|
|
36
39
|
get views() {
|
|
37
40
|
return this.sm.getVcFactory();
|
|
38
41
|
}
|
|
39
|
-
fetchUncached(
|
|
42
|
+
fetchUncached(getControllerOptions) {
|
|
40
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
44
|
const { scope, event } = this.sm.getContext();
|
|
42
45
|
const [org, location] = yield Promise.all([
|
|
@@ -59,7 +62,7 @@ export default class CalendarToolRegistrar {
|
|
|
59
62
|
controllerOptionsHandler: (vcId) => {
|
|
60
63
|
var _a;
|
|
61
64
|
vcIds.push(vcId);
|
|
62
|
-
return (_a =
|
|
65
|
+
return (_a = getControllerOptions === null || getControllerOptions === void 0 ? void 0 : getControllerOptions(vcId)) !== null && _a !== void 0 ? _a : {};
|
|
63
66
|
},
|
|
64
67
|
target: {
|
|
65
68
|
organizationId: org.id,
|
|
@@ -92,3 +95,5 @@ export default class CalendarToolRegistrar {
|
|
|
92
95
|
});
|
|
93
96
|
}
|
|
94
97
|
}
|
|
98
|
+
CalendarToolRegistrar.fetchedRecord = {};
|
|
99
|
+
export default CalendarToolRegistrar;
|
|
@@ -43,7 +43,6 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
43
43
|
}
|
|
44
44
|
loadRemoteCards() {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
//TODO TODAY Rewrite to only load remote tools once
|
|
47
46
|
const registrar = new CalendarToolRegistrar(this.sm, (vc) => {
|
|
48
47
|
//@ts-ignore
|
|
49
48
|
return this.addVc(vc.id, vc.getLineIcon(), vc);
|
|
@@ -2,9 +2,10 @@ import { RemoteCalendarTool, CalendarToolBeltStateMachine } from '../types/calen
|
|
|
2
2
|
export default class CalendarToolRegistrar {
|
|
3
3
|
private sm;
|
|
4
4
|
private addToolHandler?;
|
|
5
|
-
private fetchedRecord;
|
|
5
|
+
private static fetchedRecord;
|
|
6
6
|
constructor(sm: CalendarToolBeltStateMachine, addToolHandler?: AddToolHandler);
|
|
7
|
-
|
|
7
|
+
static reset(): void;
|
|
8
|
+
fetchAndAddCards(getControllerOptions?: GetControllerOptions): Promise<RemoteCalendarTool[]>;
|
|
8
9
|
private get views();
|
|
9
10
|
private fetchUncached;
|
|
10
11
|
private addTool;
|
|
@@ -12,3 +13,4 @@ export default class CalendarToolRegistrar {
|
|
|
12
13
|
export type AddToolHandler = (vc: RemoteCalendarTool & {
|
|
13
14
|
id: string;
|
|
14
15
|
}) => Promise<void> | void;
|
|
16
|
+
export type GetControllerOptions = (vcId: string) => Record<string, any>;
|
|
@@ -3,31 +3,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const spruce_heartwood_utils_1 = require("@sprucelabs/spruce-heartwood-utils");
|
|
4
4
|
class CalendarToolRegistrar {
|
|
5
5
|
constructor(sm, addToolHandler) {
|
|
6
|
-
this.fetchedRecord = {};
|
|
7
6
|
this.sm = sm;
|
|
8
7
|
this.addToolHandler = addToolHandler;
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
static reset() {
|
|
10
|
+
CalendarToolRegistrar.fetchedRecord = {};
|
|
11
|
+
}
|
|
12
|
+
async fetchAndAddCards(getControllerOptions) {
|
|
11
13
|
var _a;
|
|
12
14
|
const { event } = this.sm.getContext();
|
|
13
15
|
let cards = [];
|
|
14
|
-
const cacheKey = (_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : '';
|
|
15
|
-
if (!
|
|
16
|
-
const { cards: fetchedCards, vcIds } = await this.fetchUncached(
|
|
17
|
-
|
|
16
|
+
const cacheKey = (_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'none';
|
|
17
|
+
if (!CalendarToolRegistrar.fetchedRecord[cacheKey]) {
|
|
18
|
+
const { cards: fetchedCards, vcIds } = await this.fetchUncached(getControllerOptions);
|
|
19
|
+
CalendarToolRegistrar.fetchedRecord[cacheKey] = vcIds;
|
|
18
20
|
cards = fetchedCards;
|
|
19
21
|
}
|
|
20
22
|
else {
|
|
21
|
-
cards =
|
|
23
|
+
cards = CalendarToolRegistrar.fetchedRecord[cacheKey].map((vcId) => { var _a; return this.views.Controller(vcId, (_a = getControllerOptions === null || getControllerOptions === void 0 ? void 0 : getControllerOptions(vcId)) !== null && _a !== void 0 ? _a : {}); });
|
|
22
24
|
}
|
|
23
25
|
for (const card of cards) {
|
|
24
26
|
await this.addTool(card);
|
|
25
27
|
}
|
|
28
|
+
return cards;
|
|
26
29
|
}
|
|
27
30
|
get views() {
|
|
28
31
|
return this.sm.getVcFactory();
|
|
29
32
|
}
|
|
30
|
-
async fetchUncached(
|
|
33
|
+
async fetchUncached(getControllerOptions) {
|
|
31
34
|
const { scope, event } = this.sm.getContext();
|
|
32
35
|
const [org, location] = await Promise.all([
|
|
33
36
|
scope.getCurrentOrganization(),
|
|
@@ -49,7 +52,7 @@ class CalendarToolRegistrar {
|
|
|
49
52
|
controllerOptionsHandler: (vcId) => {
|
|
50
53
|
var _a;
|
|
51
54
|
vcIds.push(vcId);
|
|
52
|
-
return (_a =
|
|
55
|
+
return (_a = getControllerOptions === null || getControllerOptions === void 0 ? void 0 : getControllerOptions(vcId)) !== null && _a !== void 0 ? _a : {};
|
|
53
56
|
},
|
|
54
57
|
target: {
|
|
55
58
|
organizationId: org.id,
|
|
@@ -79,4 +82,5 @@ class CalendarToolRegistrar {
|
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
}
|
|
85
|
+
CalendarToolRegistrar.fetchedRecord = {};
|
|
82
86
|
exports.default = CalendarToolRegistrar;
|
|
@@ -36,7 +36,6 @@ class AbstractCalendarEventToolBeltState {
|
|
|
36
36
|
return this.isLoaded;
|
|
37
37
|
}
|
|
38
38
|
async loadRemoteCards() {
|
|
39
|
-
//TODO TODAY Rewrite to only load remote tools once
|
|
40
39
|
const registrar = new CalendarToolRegistrar_1.default(this.sm, (vc) => {
|
|
41
40
|
//@ts-ignore
|
|
42
41
|
return this.addVc(vc.id, vc.getLineIcon(), vc);
|