@sprucelabs/spruce-profile-utils 0.10.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/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # [Your Skill Name]
2
+
3
+ ## Useful links
4
+ * [Spruce Developer Documentation: https://developer.spruce.ai](https://developer.spruce.ai)
@@ -0,0 +1,2 @@
1
+ export { default as RoleSelectCardViewController } from './viewControllers/RoleSelectCard.vc';
2
+ export * from './types-module';
@@ -0,0 +1,2 @@
1
+ export { default as RoleSelectCardViewController } from './viewControllers/RoleSelectCard.vc.js';
2
+ export * from './types-module.js';
@@ -0,0 +1,9 @@
1
+ import RoleSelectCardViewController, { RoleSelectCardViewControllerOptions } from './viewControllers/RoleSelectCard.vc';
2
+ declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
3
+ interface ViewControllerMap {
4
+ roleSelectCard: RoleSelectCardViewController;
5
+ }
6
+ interface ViewControllerOptionsMap {
7
+ roleSelectCard: RoleSelectCardViewControllerOptions;
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ import { AbstractViewController, ActiveRecordCardViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
3
+ declare type OnChangeHandler = (roleId: string, value: string) => Promise<void> | void;
4
+ declare type ProfileRole = SpruceSchemas.Profile.v2021_11_24.ProfileRole;
5
+ declare type Roles = ProfileRole[];
6
+ export declare type RoleSelectCardViewControllerOptions = ViewControllerOptions & {
7
+ onChange?: OnChangeHandler;
8
+ };
9
+ export default class RoleSelectCardViewController extends AbstractViewController<Card> {
10
+ static id: string;
11
+ private activeRecordCardVc;
12
+ private isLoaded;
13
+ private onChangeHandler?;
14
+ private roles;
15
+ constructor(options: RoleSelectCardViewControllerOptions);
16
+ private ActiveRecordVc;
17
+ getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
18
+ getActiveRecordCardVc(): ActiveRecordCardViewController;
19
+ getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
20
+ getRoles(): SpruceSchemas.Profile.v2021_11_24.ProfileRole[];
21
+ setRoles(roles: Roles): Promise<void>;
22
+ getIsLoaded(): boolean;
23
+ private buildRoleRow;
24
+ private getRequirementsForRole;
25
+ load(options: {
26
+ organizationId: string;
27
+ }): Promise<void>;
28
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
29
+ }
30
+ export {};
@@ -0,0 +1,130 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { AbstractViewController, buildActiveRecordCard, } from '@sprucelabs/heartwood-view-controllers';
11
+ export default class RoleSelectCardViewController extends AbstractViewController {
12
+ constructor(options) {
13
+ super(options);
14
+ this.isLoaded = false;
15
+ this.roles = [];
16
+ this.onChangeHandler = options.onChange;
17
+ this.activeRecordCardVc = this.ActiveRecordVc();
18
+ }
19
+ ActiveRecordVc() {
20
+ return this.Controller('activeRecordCard', buildActiveRecordCard({
21
+ id: 'roles',
22
+ columnWidths: ['fill'],
23
+ shouldRenderRowDividers: true,
24
+ header: {
25
+ title: 'Roles',
26
+ subtitle: 'Select the roles you want to have fill out this profile.',
27
+ },
28
+ payload: {
29
+ shouldIncludePrivateRoles: true,
30
+ shouldIncludeMetaRoles: false,
31
+ },
32
+ eventName: 'list-roles::v2020_12_25',
33
+ responseKey: 'roles',
34
+ rowTransformer: this.buildRoleRow.bind(this),
35
+ }));
36
+ }
37
+ getCardVc() {
38
+ return this.activeRecordCardVc.getCardVc();
39
+ }
40
+ getActiveRecordCardVc() {
41
+ return this.activeRecordCardVc;
42
+ }
43
+ getListVc() {
44
+ return this.activeRecordCardVc.getListVc();
45
+ }
46
+ getRoles() {
47
+ var _a;
48
+ return (_a = this.roles) !== null && _a !== void 0 ? _a : [];
49
+ }
50
+ setRoles(roles) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ this.roles = roles;
53
+ const records = this.activeRecordCardVc.getRecords();
54
+ for (const profileRole of roles) {
55
+ const match = records.find((r) => r.id === profileRole.roleId);
56
+ if (match) {
57
+ const listVc = this.activeRecordCardVc.getListVc();
58
+ const rowVc = listVc.getRowVc(match.id);
59
+ yield rowVc.setValue('requirements', this.getRequirementsForRole(match.id));
60
+ }
61
+ }
62
+ this.activeRecordCardVc.triggerRender();
63
+ });
64
+ }
65
+ getIsLoaded() {
66
+ return this.isLoaded;
67
+ }
68
+ buildRoleRow(role) {
69
+ return {
70
+ id: role.id,
71
+ cells: [
72
+ {
73
+ text: {
74
+ content: role.name,
75
+ },
76
+ subText: {
77
+ content: role.description,
78
+ },
79
+ },
80
+ {
81
+ selectInput: {
82
+ name: 'requirements',
83
+ isRequired: true,
84
+ value: this.getRequirementsForRole(role.id),
85
+ onChange: (value) => {
86
+ var _a;
87
+ (_a = this.onChangeHandler) === null || _a === void 0 ? void 0 : _a.call(this, role.id, value !== null && value !== void 0 ? value : 'skip');
88
+ this.roles = this.roles.filter((r) => r.roleId !== role.id);
89
+ if (value !== 'skip') {
90
+ this.roles.push({
91
+ roleId: role.id,
92
+ requirements: value,
93
+ });
94
+ }
95
+ },
96
+ choices: [
97
+ {
98
+ value: 'skip',
99
+ label: 'Skip',
100
+ },
101
+ {
102
+ value: 'optional',
103
+ label: 'Optional',
104
+ },
105
+ {
106
+ value: 'required',
107
+ label: 'Required',
108
+ },
109
+ ],
110
+ },
111
+ },
112
+ ],
113
+ };
114
+ }
115
+ getRequirementsForRole(roleId) {
116
+ var _a;
117
+ return (_a = this.roles.find((r) => r.roleId === roleId)) === null || _a === void 0 ? void 0 : _a.requirements;
118
+ }
119
+ load(options) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ this.activeRecordCardVc.setTarget(options);
122
+ yield this.activeRecordCardVc.load();
123
+ this.isLoaded = true;
124
+ });
125
+ }
126
+ render() {
127
+ return this.activeRecordCardVc.render();
128
+ }
129
+ }
130
+ RoleSelectCardViewController.id = 'role-select-card';
@@ -0,0 +1,2 @@
1
+ export { default as RoleSelectCardViewController } from './viewControllers/RoleSelectCard.vc';
2
+ export * from './types-module';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.RoleSelectCardViewController = void 0;
21
+ var RoleSelectCard_vc_1 = require("./viewControllers/RoleSelectCard.vc");
22
+ Object.defineProperty(exports, "RoleSelectCardViewController", { enumerable: true, get: function () { return __importDefault(RoleSelectCard_vc_1).default; } });
23
+ __exportStar(require("./types-module"), exports);
@@ -0,0 +1,9 @@
1
+ import RoleSelectCardViewController, { RoleSelectCardViewControllerOptions } from './viewControllers/RoleSelectCard.vc';
2
+ declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
3
+ interface ViewControllerMap {
4
+ roleSelectCard: RoleSelectCardViewController;
5
+ }
6
+ interface ViewControllerOptionsMap {
7
+ roleSelectCard: RoleSelectCardViewControllerOptions;
8
+ }
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,30 @@
1
+ import { AbstractViewController, ActiveRecordCardViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
3
+ declare type OnChangeHandler = (roleId: string, value: string) => Promise<void> | void;
4
+ declare type ProfileRole = SpruceSchemas.Profile.v2021_11_24.ProfileRole;
5
+ declare type Roles = ProfileRole[];
6
+ export declare type RoleSelectCardViewControllerOptions = ViewControllerOptions & {
7
+ onChange?: OnChangeHandler;
8
+ };
9
+ export default class RoleSelectCardViewController extends AbstractViewController<Card> {
10
+ static id: string;
11
+ private activeRecordCardVc;
12
+ private isLoaded;
13
+ private onChangeHandler?;
14
+ private roles;
15
+ constructor(options: RoleSelectCardViewControllerOptions);
16
+ private ActiveRecordVc;
17
+ getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
18
+ getActiveRecordCardVc(): ActiveRecordCardViewController;
19
+ getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
20
+ getRoles(): SpruceSchemas.Profile.v2021_11_24.ProfileRole[];
21
+ setRoles(roles: Roles): Promise<void>;
22
+ getIsLoaded(): boolean;
23
+ private buildRoleRow;
24
+ private getRequirementsForRole;
25
+ load(options: {
26
+ organizationId: string;
27
+ }): Promise<void>;
28
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
29
+ }
30
+ export {};
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
4
+ class RoleSelectCardViewController extends heartwood_view_controllers_1.AbstractViewController {
5
+ constructor(options) {
6
+ super(options);
7
+ this.isLoaded = false;
8
+ this.roles = [];
9
+ this.onChangeHandler = options.onChange;
10
+ this.activeRecordCardVc = this.ActiveRecordVc();
11
+ }
12
+ ActiveRecordVc() {
13
+ return this.Controller('activeRecordCard', (0, heartwood_view_controllers_1.buildActiveRecordCard)({
14
+ id: 'roles',
15
+ columnWidths: ['fill'],
16
+ shouldRenderRowDividers: true,
17
+ header: {
18
+ title: 'Roles',
19
+ subtitle: 'Select the roles you want to have fill out this profile.',
20
+ },
21
+ payload: {
22
+ shouldIncludePrivateRoles: true,
23
+ shouldIncludeMetaRoles: false,
24
+ },
25
+ eventName: 'list-roles::v2020_12_25',
26
+ responseKey: 'roles',
27
+ rowTransformer: this.buildRoleRow.bind(this),
28
+ }));
29
+ }
30
+ getCardVc() {
31
+ return this.activeRecordCardVc.getCardVc();
32
+ }
33
+ getActiveRecordCardVc() {
34
+ return this.activeRecordCardVc;
35
+ }
36
+ getListVc() {
37
+ return this.activeRecordCardVc.getListVc();
38
+ }
39
+ getRoles() {
40
+ var _a;
41
+ return (_a = this.roles) !== null && _a !== void 0 ? _a : [];
42
+ }
43
+ async setRoles(roles) {
44
+ this.roles = roles;
45
+ const records = this.activeRecordCardVc.getRecords();
46
+ for (const profileRole of roles) {
47
+ const match = records.find((r) => r.id === profileRole.roleId);
48
+ if (match) {
49
+ const listVc = this.activeRecordCardVc.getListVc();
50
+ const rowVc = listVc.getRowVc(match.id);
51
+ await rowVc.setValue('requirements', this.getRequirementsForRole(match.id));
52
+ }
53
+ }
54
+ this.activeRecordCardVc.triggerRender();
55
+ }
56
+ getIsLoaded() {
57
+ return this.isLoaded;
58
+ }
59
+ buildRoleRow(role) {
60
+ return {
61
+ id: role.id,
62
+ cells: [
63
+ {
64
+ text: {
65
+ content: role.name,
66
+ },
67
+ subText: {
68
+ content: role.description,
69
+ },
70
+ },
71
+ {
72
+ selectInput: {
73
+ name: 'requirements',
74
+ isRequired: true,
75
+ value: this.getRequirementsForRole(role.id),
76
+ onChange: (value) => {
77
+ var _a;
78
+ (_a = this.onChangeHandler) === null || _a === void 0 ? void 0 : _a.call(this, role.id, value !== null && value !== void 0 ? value : 'skip');
79
+ this.roles = this.roles.filter((r) => r.roleId !== role.id);
80
+ if (value !== 'skip') {
81
+ this.roles.push({
82
+ roleId: role.id,
83
+ requirements: value,
84
+ });
85
+ }
86
+ },
87
+ choices: [
88
+ {
89
+ value: 'skip',
90
+ label: 'Skip',
91
+ },
92
+ {
93
+ value: 'optional',
94
+ label: 'Optional',
95
+ },
96
+ {
97
+ value: 'required',
98
+ label: 'Required',
99
+ },
100
+ ],
101
+ },
102
+ },
103
+ ],
104
+ };
105
+ }
106
+ getRequirementsForRole(roleId) {
107
+ var _a;
108
+ return (_a = this.roles.find((r) => r.roleId === roleId)) === null || _a === void 0 ? void 0 : _a.requirements;
109
+ }
110
+ async load(options) {
111
+ this.activeRecordCardVc.setTarget(options);
112
+ await this.activeRecordCardVc.load();
113
+ this.isLoaded = true;
114
+ }
115
+ render() {
116
+ return this.activeRecordCardVc.render();
117
+ }
118
+ }
119
+ exports.default = RoleSelectCardViewController;
120
+ RoleSelectCardViewController.id = 'role-select-card';
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@sprucelabs/spruce-profile-utils",
3
+ "description": "Useeful utilities",
4
+ "version": "0.10.0",
5
+ "skill": {
6
+ "namespace": "profile"
7
+ },
8
+ "homepage": "https://github.com/sprucelabsai/spruce-profile-skill",
9
+ "bugs": {
10
+ "url": "https://github.com/sprucelabsai/spruce-profile-skill/issues"
11
+ },
12
+ "main": "./build/index-module.js",
13
+ "types": "./build/index-module.d.ts",
14
+ "module": "./build/esm/index-module.js",
15
+ "sideEffects": false,
16
+ "files": [
17
+ "build/index-module.js",
18
+ "build/index-module.d.ts",
19
+ "build/viewControllers/RoleSelectCard.vc.js",
20
+ "build/viewControllers/RoleSelectCard.vc.d.ts",
21
+ "build/esm/index-module.js",
22
+ "build/esm/index-module.d.ts",
23
+ "build/esm/viewControllers/RoleSelectCard.vc.js",
24
+ "build/esm/viewControllers/RoleSelectCard.vc.d.ts",
25
+ "build/types-module.js",
26
+ "build/types-module.d.ts",
27
+ "build/esm/types-module.js",
28
+ "build/esm/types-module.d.ts"
29
+ ],
30
+ "keywords": [],
31
+ "scripts": {
32
+ "release": "npm publish"
33
+ },
34
+ "dependencies": {
35
+ "@sprucelabs/heartwood-view-controllers": "latest"
36
+ },
37
+ "engines": {
38
+ "node": "16.x",
39
+ "yarn": "1.x"
40
+ }
41
+ }