@sprucelabs/spruce-people-utils 1.0.18 → 1.0.19
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__/behavioral/searching/SpyPersonSelectInput.d.ts +1 -0
- package/build/__tests__/behavioral/searching/SpyPersonSelectInput.js +3 -0
- package/build/esm/__tests__/behavioral/searching/SpyPersonSelectInput.d.ts +1 -0
- package/build/esm/__tests__/behavioral/searching/SpyPersonSelectInput.js +3 -0
- package/build/esm/viewControllers/PersonSelectInput.vc.d.ts +7 -2
- package/build/esm/viewControllers/PersonSelectInput.vc.js +37 -5
- package/build/esm/viewControllers/searchPeopleToSuggestions.d.ts +8 -1
- package/build/esm/viewControllers/searchPeopleToSuggestions.js +8 -5
- package/build/viewControllers/PersonSelectInput.vc.d.ts +7 -2
- package/build/viewControllers/PersonSelectInput.vc.js +31 -5
- package/build/viewControllers/searchPeopleToSuggestions.d.ts +8 -1
- package/build/viewControllers/searchPeopleToSuggestions.js +10 -6
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import PersonSelectInputViewController from '../../../viewControllers/PersonSelectInput.vc';
|
|
2
2
|
import SpyPersonInviteViewController from '../inviting/SpyPersonInviteViewController';
|
|
3
3
|
export default class SpyPersonSelectInput extends PersonSelectInputViewController {
|
|
4
|
+
getLastLoadedPersonId(): string | undefined;
|
|
4
5
|
getOrganizationId(): string | undefined;
|
|
5
6
|
getLocationId(): string | undefined;
|
|
6
7
|
getAutocompleteVc(): import("@sprucelabs/heartwood-view-controllers").AutocompleteInputViewController;
|
|
@@ -5,6 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const PersonSelectInput_vc_1 = __importDefault(require("../../../viewControllers/PersonSelectInput.vc"));
|
|
7
7
|
class SpyPersonSelectInput extends PersonSelectInput_vc_1.default {
|
|
8
|
+
getLastLoadedPersonId() {
|
|
9
|
+
return this.lastLoadedPersonId;
|
|
10
|
+
}
|
|
8
11
|
getOrganizationId() {
|
|
9
12
|
return this.organizationId;
|
|
10
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import PersonSelectInputViewController from '../../../viewControllers/PersonSelectInput.vc';
|
|
2
2
|
import SpyPersonInviteViewController from '../inviting/SpyPersonInviteViewController';
|
|
3
3
|
export default class SpyPersonSelectInput extends PersonSelectInputViewController {
|
|
4
|
+
getLastLoadedPersonId(): string | undefined;
|
|
4
5
|
getOrganizationId(): string | undefined;
|
|
5
6
|
getLocationId(): string | undefined;
|
|
6
7
|
getAutocompleteVc(): import("@sprucelabs/heartwood-view-controllers").AutocompleteInputViewController;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import PersonSelectInputViewController from '../../../viewControllers/PersonSelectInput.vc.js';
|
|
2
2
|
export default class SpyPersonSelectInput extends PersonSelectInputViewController {
|
|
3
|
+
getLastLoadedPersonId() {
|
|
4
|
+
return this.lastLoadedPersonId;
|
|
5
|
+
}
|
|
3
6
|
getOrganizationId() {
|
|
4
7
|
return this.organizationId;
|
|
5
8
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { AbstractViewController, AutocompleteInputViewController, FormInputViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
1
|
+
import { AbstractViewController, AutocompleteInputViewController, FormInputOptions, FormInputViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
export default class PersonSelectInputViewController extends AbstractViewController<AutocompleteInput> implements FormInputViewController<AutocompleteInput> {
|
|
3
3
|
static id: string;
|
|
4
4
|
protected autoCompleteVc: AutocompleteInputViewController;
|
|
5
5
|
protected organizationId?: string;
|
|
6
6
|
protected locationId?: string;
|
|
7
7
|
protected shouldIgnoreNextChange: boolean;
|
|
8
|
+
protected lastLoadedPersonId?: string;
|
|
9
|
+
private loadingPromise?;
|
|
8
10
|
constructor(options: ViewControllerOptions & PersonSelectInputOptions);
|
|
9
11
|
private handleFocusInput;
|
|
10
12
|
private renderAnonSuggestion;
|
|
@@ -17,14 +19,17 @@ export default class PersonSelectInputViewController extends AbstractViewControl
|
|
|
17
19
|
private handleClickSuggestion;
|
|
18
20
|
setOrganizationId(orgId: string): void;
|
|
19
21
|
setLocationId(locationId: string): void;
|
|
22
|
+
waitForLoading(): Promise<void | undefined>;
|
|
20
23
|
getValue(): any;
|
|
21
24
|
setValue(value: string, renderedValue?: string | null | undefined): Promise<void>;
|
|
22
25
|
setRenderedValue(renderedValue: string): Promise<void>;
|
|
23
26
|
getRenderedValue(): any;
|
|
27
|
+
private loadCurrentPerson;
|
|
28
|
+
private _loadCurrentPerson;
|
|
24
29
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.AutocompleteInput;
|
|
25
30
|
}
|
|
26
31
|
declare type AutocompleteInput = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.AutocompleteInput;
|
|
27
|
-
export interface PersonSelectInputOptions {
|
|
32
|
+
export interface PersonSelectInputOptions extends Pick<FormInputOptions, 'value'> {
|
|
28
33
|
organizationId?: string;
|
|
29
34
|
locationId?: string;
|
|
30
35
|
}
|
|
@@ -16,11 +16,7 @@ export default class PersonSelectInputViewController extends AbstractViewControl
|
|
|
16
16
|
this.shouldIgnoreNextChange = false;
|
|
17
17
|
this.organizationId = options.organizationId;
|
|
18
18
|
this.locationId = options.locationId;
|
|
19
|
-
this.autoCompleteVc = this.Controller('autocompleteInput', {
|
|
20
|
-
onChangeRenderedValue: this.handleOnChangeRenderedValue.bind(this),
|
|
21
|
-
renderedValue: '',
|
|
22
|
-
onFocus: this.handleFocusInput.bind(this),
|
|
23
|
-
});
|
|
19
|
+
this.autoCompleteVc = this.Controller('autocompleteInput', Object.assign(Object.assign({}, options), { onChangeRenderedValue: this.handleOnChangeRenderedValue.bind(this), renderedValue: '', onFocus: this.handleFocusInput.bind(this) }));
|
|
24
20
|
}
|
|
25
21
|
handleFocusInput() {
|
|
26
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -120,6 +116,7 @@ export default class PersonSelectInputViewController extends AbstractViewControl
|
|
|
120
116
|
handleClickSuggestion(person) {
|
|
121
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
118
|
this.shouldIgnoreNextChange = true;
|
|
119
|
+
this.lastLoadedPersonId = person.id;
|
|
123
120
|
yield this.autoCompleteVc.setRenderedValue(renderLabel(person));
|
|
124
121
|
yield this.autoCompleteVc.setValue(person.id);
|
|
125
122
|
this.autoCompleteVc.hideSuggestions();
|
|
@@ -131,6 +128,11 @@ export default class PersonSelectInputViewController extends AbstractViewControl
|
|
|
131
128
|
setLocationId(locationId) {
|
|
132
129
|
this.locationId = locationId;
|
|
133
130
|
}
|
|
131
|
+
waitForLoading() {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
return this.loadingPromise;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
134
136
|
getValue() {
|
|
135
137
|
return this.autoCompleteVc.getValue();
|
|
136
138
|
}
|
|
@@ -143,7 +145,37 @@ export default class PersonSelectInputViewController extends AbstractViewControl
|
|
|
143
145
|
getRenderedValue() {
|
|
144
146
|
return this.autoCompleteVc.getRenderedValue();
|
|
145
147
|
}
|
|
148
|
+
loadCurrentPerson() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
this.loadingPromise = this._loadCurrentPerson();
|
|
151
|
+
return this.loadingPromise;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
_loadCurrentPerson() {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
const id = this.getValue();
|
|
157
|
+
if (id && this.lastLoadedPersonId !== id) {
|
|
158
|
+
this.lastLoadedPersonId = id;
|
|
159
|
+
yield this.setRenderedValue('Loading...');
|
|
160
|
+
try {
|
|
161
|
+
const client = yield this.connectToApi();
|
|
162
|
+
const [{ person }] = yield client.emitAndFlattenResponses('people.get::v2022_05_29', {
|
|
163
|
+
target: {
|
|
164
|
+
organizationId: this.organizationId,
|
|
165
|
+
searchPersonId: id,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
yield this.setRenderedValue(renderLabel(person));
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
console.error(err);
|
|
172
|
+
yield this.setRenderedValue('*** Failed loading person ***');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
146
177
|
render() {
|
|
178
|
+
void this.loadCurrentPerson();
|
|
147
179
|
return this.autoCompleteVc.render();
|
|
148
180
|
}
|
|
149
181
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { AutocompleteSuggestion } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { SearchPerson } from '../types/people-module.types';
|
|
3
|
-
|
|
3
|
+
declare type SuggestionClickHandler = (person: SearchPerson) => Promise<void> | void;
|
|
4
|
+
export default function searchPeopleToSuggestions(people: SearchPerson[], cb?: SuggestionClickHandler): AutocompleteSuggestion[];
|
|
5
|
+
export declare function searchPersonToSuggestion(person: SearchPerson, cb?: SuggestionClickHandler): {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
onClick: () => void | Promise<void> | undefined;
|
|
9
|
+
};
|
|
4
10
|
export declare function renderLabel(p: SearchPerson): string;
|
|
11
|
+
export {};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export default function searchPeopleToSuggestions(people, cb) {
|
|
2
|
-
return people.map((
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
return people.map((person) => searchPersonToSuggestion(person, cb));
|
|
3
|
+
}
|
|
4
|
+
export function searchPersonToSuggestion(person, cb) {
|
|
5
|
+
return {
|
|
6
|
+
id: person.id,
|
|
7
|
+
label: renderLabel(person),
|
|
8
|
+
onClick: () => cb === null || cb === void 0 ? void 0 : cb(person),
|
|
9
|
+
};
|
|
7
10
|
}
|
|
8
11
|
export function renderLabel(p) {
|
|
9
12
|
return `${p.fullName} (${p.phone})`;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { AbstractViewController, AutocompleteInputViewController, FormInputViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
1
|
+
import { AbstractViewController, AutocompleteInputViewController, FormInputOptions, FormInputViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
export default class PersonSelectInputViewController extends AbstractViewController<AutocompleteInput> implements FormInputViewController<AutocompleteInput> {
|
|
3
3
|
static id: string;
|
|
4
4
|
protected autoCompleteVc: AutocompleteInputViewController;
|
|
5
5
|
protected organizationId?: string;
|
|
6
6
|
protected locationId?: string;
|
|
7
7
|
protected shouldIgnoreNextChange: boolean;
|
|
8
|
+
protected lastLoadedPersonId?: string;
|
|
9
|
+
private loadingPromise?;
|
|
8
10
|
constructor(options: ViewControllerOptions & PersonSelectInputOptions);
|
|
9
11
|
private handleFocusInput;
|
|
10
12
|
private renderAnonSuggestion;
|
|
@@ -17,14 +19,17 @@ export default class PersonSelectInputViewController extends AbstractViewControl
|
|
|
17
19
|
private handleClickSuggestion;
|
|
18
20
|
setOrganizationId(orgId: string): void;
|
|
19
21
|
setLocationId(locationId: string): void;
|
|
22
|
+
waitForLoading(): Promise<void | undefined>;
|
|
20
23
|
getValue(): any;
|
|
21
24
|
setValue(value: string, renderedValue?: string | null | undefined): Promise<void>;
|
|
22
25
|
setRenderedValue(renderedValue: string): Promise<void>;
|
|
23
26
|
getRenderedValue(): any;
|
|
27
|
+
private loadCurrentPerson;
|
|
28
|
+
private _loadCurrentPerson;
|
|
24
29
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.AutocompleteInput;
|
|
25
30
|
}
|
|
26
31
|
declare type AutocompleteInput = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.AutocompleteInput;
|
|
27
|
-
export interface PersonSelectInputOptions {
|
|
32
|
+
export interface PersonSelectInputOptions extends Pick<FormInputOptions, 'value'> {
|
|
28
33
|
organizationId?: string;
|
|
29
34
|
locationId?: string;
|
|
30
35
|
}
|
|
@@ -32,11 +32,7 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
|
|
|
32
32
|
this.shouldIgnoreNextChange = false;
|
|
33
33
|
this.organizationId = options.organizationId;
|
|
34
34
|
this.locationId = options.locationId;
|
|
35
|
-
this.autoCompleteVc = this.Controller('autocompleteInput', {
|
|
36
|
-
onChangeRenderedValue: this.handleOnChangeRenderedValue.bind(this),
|
|
37
|
-
renderedValue: '',
|
|
38
|
-
onFocus: this.handleFocusInput.bind(this),
|
|
39
|
-
});
|
|
35
|
+
this.autoCompleteVc = this.Controller('autocompleteInput', Object.assign(Object.assign({}, options), { onChangeRenderedValue: this.handleOnChangeRenderedValue.bind(this), renderedValue: '', onFocus: this.handleFocusInput.bind(this) }));
|
|
40
36
|
}
|
|
41
37
|
async handleFocusInput() {
|
|
42
38
|
if (this.autoCompleteVc.getRenderedValue() === '') {
|
|
@@ -123,6 +119,7 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
|
|
|
123
119
|
}
|
|
124
120
|
async handleClickSuggestion(person) {
|
|
125
121
|
this.shouldIgnoreNextChange = true;
|
|
122
|
+
this.lastLoadedPersonId = person.id;
|
|
126
123
|
await this.autoCompleteVc.setRenderedValue((0, searchPeopleToSuggestions_1.renderLabel)(person));
|
|
127
124
|
await this.autoCompleteVc.setValue(person.id);
|
|
128
125
|
this.autoCompleteVc.hideSuggestions();
|
|
@@ -133,6 +130,9 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
|
|
|
133
130
|
setLocationId(locationId) {
|
|
134
131
|
this.locationId = locationId;
|
|
135
132
|
}
|
|
133
|
+
async waitForLoading() {
|
|
134
|
+
return this.loadingPromise;
|
|
135
|
+
}
|
|
136
136
|
getValue() {
|
|
137
137
|
return this.autoCompleteVc.getValue();
|
|
138
138
|
}
|
|
@@ -145,7 +145,33 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
|
|
|
145
145
|
getRenderedValue() {
|
|
146
146
|
return this.autoCompleteVc.getRenderedValue();
|
|
147
147
|
}
|
|
148
|
+
async loadCurrentPerson() {
|
|
149
|
+
this.loadingPromise = this._loadCurrentPerson();
|
|
150
|
+
return this.loadingPromise;
|
|
151
|
+
}
|
|
152
|
+
async _loadCurrentPerson() {
|
|
153
|
+
const id = this.getValue();
|
|
154
|
+
if (id && this.lastLoadedPersonId !== id) {
|
|
155
|
+
this.lastLoadedPersonId = id;
|
|
156
|
+
await this.setRenderedValue('Loading...');
|
|
157
|
+
try {
|
|
158
|
+
const client = await this.connectToApi();
|
|
159
|
+
const [{ person }] = await client.emitAndFlattenResponses('people.get::v2022_05_29', {
|
|
160
|
+
target: {
|
|
161
|
+
organizationId: this.organizationId,
|
|
162
|
+
searchPersonId: id,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
await this.setRenderedValue((0, searchPeopleToSuggestions_1.renderLabel)(person));
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
console.error(err);
|
|
169
|
+
await this.setRenderedValue('*** Failed loading person ***');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
148
173
|
render() {
|
|
174
|
+
void this.loadCurrentPerson();
|
|
149
175
|
return this.autoCompleteVc.render();
|
|
150
176
|
}
|
|
151
177
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { AutocompleteSuggestion } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { SearchPerson } from '../types/people-module.types';
|
|
3
|
-
|
|
3
|
+
declare type SuggestionClickHandler = (person: SearchPerson) => Promise<void> | void;
|
|
4
|
+
export default function searchPeopleToSuggestions(people: SearchPerson[], cb?: SuggestionClickHandler): AutocompleteSuggestion[];
|
|
5
|
+
export declare function searchPersonToSuggestion(person: SearchPerson, cb?: SuggestionClickHandler): {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
onClick: () => void | Promise<void> | undefined;
|
|
9
|
+
};
|
|
4
10
|
export declare function renderLabel(p: SearchPerson): string;
|
|
11
|
+
export {};
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renderLabel = void 0;
|
|
3
|
+
exports.renderLabel = exports.searchPersonToSuggestion = void 0;
|
|
4
4
|
function searchPeopleToSuggestions(people, cb) {
|
|
5
|
-
return people.map((
|
|
6
|
-
id: p.id,
|
|
7
|
-
label: renderLabel(p),
|
|
8
|
-
onClick: () => cb === null || cb === void 0 ? void 0 : cb(p),
|
|
9
|
-
}));
|
|
5
|
+
return people.map((person) => searchPersonToSuggestion(person, cb));
|
|
10
6
|
}
|
|
11
7
|
exports.default = searchPeopleToSuggestions;
|
|
8
|
+
function searchPersonToSuggestion(person, cb) {
|
|
9
|
+
return {
|
|
10
|
+
id: person.id,
|
|
11
|
+
label: renderLabel(person),
|
|
12
|
+
onClick: () => cb === null || cb === void 0 ? void 0 : cb(person),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.searchPersonToSuggestion = searchPersonToSuggestion;
|
|
12
16
|
function renderLabel(p) {
|
|
13
17
|
return `${p.fullName} (${p.phone})`;
|
|
14
18
|
}
|