@sprucelabs/spruce-people-utils 1.0.15 → 1.0.18

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.
@@ -7,6 +7,7 @@ export default class PersonSelectInputViewController extends AbstractViewControl
7
7
  protected shouldIgnoreNextChange: boolean;
8
8
  constructor(options: ViewControllerOptions & PersonSelectInputOptions);
9
9
  private handleFocusInput;
10
+ private renderAnonSuggestion;
10
11
  private handleOnChangeRenderedValue;
11
12
  private populateSuggestions;
12
13
  private handleClickInviteAnonymous;
@@ -25,16 +25,17 @@ export default class PersonSelectInputViewController extends AbstractViewControl
25
25
  handleFocusInput() {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
27
  if (this.autoCompleteVc.getRenderedValue() === '') {
28
- this.autoCompleteVc.showSuggestions([
29
- {
30
- id: 'anonymous',
31
- label: 'Add anonymous',
32
- onClick: this.handleClickInviteAnonymous.bind(this),
33
- },
34
- ]);
28
+ this.autoCompleteVc.showSuggestions([this.renderAnonSuggestion()]);
35
29
  }
36
30
  });
37
31
  }
32
+ renderAnonSuggestion() {
33
+ return {
34
+ id: 'anonymous',
35
+ label: 'Add anonymous',
36
+ onClick: this.handleClickInviteAnonymous.bind(this),
37
+ };
38
+ }
38
39
  handleOnChangeRenderedValue(value) {
39
40
  return __awaiter(this, void 0, void 0, function* () {
40
41
  if (!this.shouldIgnoreNextChange && value.length > 2) {
@@ -45,21 +46,26 @@ export default class PersonSelectInputViewController extends AbstractViewControl
45
46
  }
46
47
  populateSuggestions(value) {
47
48
  return __awaiter(this, void 0, void 0, function* () {
48
- const people = yield this.search(value);
49
- const suggestions = searchPeopleToSuggestions(people, (person) => __awaiter(this, void 0, void 0, function* () { return this.handleClickSuggestion(person); }));
50
- this.autoCompleteVc.showSuggestions([
51
- ...suggestions,
52
- {
53
- id: 'invite',
54
- label: 'Invite person',
55
- onClick: this.handleClickInvitePerson.bind(this),
56
- },
57
- {
58
- id: 'anonymous',
59
- label: 'Add anonymously',
60
- onClick: this.handleClickInviteAnonymous.bind(this),
61
- },
62
- ]);
49
+ assertOptions({ organizationId: this.organizationId }, ['organizationId'], `You gotta set an organizationId to your person select input for it to function. Try using 'this.vc.setOrganizationId(...)'!`);
50
+ try {
51
+ const people = yield this.search(value);
52
+ const suggestions = searchPeopleToSuggestions(people, (person) => __awaiter(this, void 0, void 0, function* () { return this.handleClickSuggestion(person); }));
53
+ this.autoCompleteVc.showSuggestions([
54
+ ...suggestions,
55
+ {
56
+ id: 'invite',
57
+ label: 'Invite person',
58
+ onClick: this.handleClickInvitePerson.bind(this),
59
+ },
60
+ this.renderAnonSuggestion(),
61
+ ]);
62
+ }
63
+ catch (err) {
64
+ console.error(err);
65
+ yield this.alert({
66
+ message: `I could not complete your search!! I've let the humans know and they are on it!`,
67
+ });
68
+ }
63
69
  });
64
70
  }
65
71
  handleClickInviteAnonymous() {
@@ -99,11 +105,10 @@ export default class PersonSelectInputViewController extends AbstractViewControl
99
105
  }
100
106
  search(value) {
101
107
  return __awaiter(this, void 0, void 0, function* () {
102
- const { organizationId } = assertOptions({ organizationId: this.organizationId }, ['organizationId'], `You gotta set an organizationId to your person select input for it to function. Try using 'this.vc.setOrganizationId(...)'!`);
103
108
  const client = yield this.connectToApi();
104
109
  const [{ people }] = yield client.emitAndFlattenResponses('people.search::v2022_05_29', {
105
110
  target: {
106
- organizationId,
111
+ organizationId: this.organizationId,
107
112
  },
108
113
  payload: {
109
114
  query: value,
@@ -7,6 +7,7 @@ export default class PersonSelectInputViewController extends AbstractViewControl
7
7
  protected shouldIgnoreNextChange: boolean;
8
8
  constructor(options: ViewControllerOptions & PersonSelectInputOptions);
9
9
  private handleFocusInput;
10
+ private renderAnonSuggestion;
10
11
  private handleOnChangeRenderedValue;
11
12
  private populateSuggestions;
12
13
  private handleClickInviteAnonymous;
@@ -40,15 +40,16 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
40
40
  }
41
41
  async handleFocusInput() {
42
42
  if (this.autoCompleteVc.getRenderedValue() === '') {
43
- this.autoCompleteVc.showSuggestions([
44
- {
45
- id: 'anonymous',
46
- label: 'Add anonymous',
47
- onClick: this.handleClickInviteAnonymous.bind(this),
48
- },
49
- ]);
43
+ this.autoCompleteVc.showSuggestions([this.renderAnonSuggestion()]);
50
44
  }
51
45
  }
46
+ renderAnonSuggestion() {
47
+ return {
48
+ id: 'anonymous',
49
+ label: 'Add anonymous',
50
+ onClick: this.handleClickInviteAnonymous.bind(this),
51
+ };
52
+ }
52
53
  async handleOnChangeRenderedValue(value) {
53
54
  if (!this.shouldIgnoreNextChange && value.length > 2) {
54
55
  await this.populateSuggestions(value);
@@ -56,21 +57,26 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
56
57
  this.shouldIgnoreNextChange = false;
57
58
  }
58
59
  async populateSuggestions(value) {
59
- const people = await this.search(value);
60
- const suggestions = (0, searchPeopleToSuggestions_1.default)(people, async (person) => this.handleClickSuggestion(person));
61
- this.autoCompleteVc.showSuggestions([
62
- ...suggestions,
63
- {
64
- id: 'invite',
65
- label: 'Invite person',
66
- onClick: this.handleClickInvitePerson.bind(this),
67
- },
68
- {
69
- id: 'anonymous',
70
- label: 'Add anonymously',
71
- onClick: this.handleClickInviteAnonymous.bind(this),
72
- },
73
- ]);
60
+ (0, schema_1.assertOptions)({ organizationId: this.organizationId }, ['organizationId'], `You gotta set an organizationId to your person select input for it to function. Try using 'this.vc.setOrganizationId(...)'!`);
61
+ try {
62
+ const people = await this.search(value);
63
+ const suggestions = (0, searchPeopleToSuggestions_1.default)(people, async (person) => this.handleClickSuggestion(person));
64
+ this.autoCompleteVc.showSuggestions([
65
+ ...suggestions,
66
+ {
67
+ id: 'invite',
68
+ label: 'Invite person',
69
+ onClick: this.handleClickInvitePerson.bind(this),
70
+ },
71
+ this.renderAnonSuggestion(),
72
+ ]);
73
+ }
74
+ catch (err) {
75
+ console.error(err);
76
+ await this.alert({
77
+ message: `I could not complete your search!! I've let the humans know and they are on it!`,
78
+ });
79
+ }
74
80
  }
75
81
  async handleClickInviteAnonymous() {
76
82
  this.autoCompleteVc.hideSuggestions();
@@ -104,11 +110,10 @@ class PersonSelectInputViewController extends heartwood_view_controllers_1.Abstr
104
110
  return vc;
105
111
  }
106
112
  async search(value) {
107
- const { organizationId } = (0, schema_1.assertOptions)({ organizationId: this.organizationId }, ['organizationId'], `You gotta set an organizationId to your person select input for it to function. Try using 'this.vc.setOrganizationId(...)'!`);
108
113
  const client = await this.connectToApi();
109
114
  const [{ people }] = await client.emitAndFlattenResponses('people.search::v2022_05_29', {
110
115
  target: {
111
- organizationId,
116
+ organizationId: this.organizationId,
112
117
  },
113
118
  payload: {
114
119
  query: value,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-people-utils",
3
3
  "description": "People Utilities",
4
- "version": "1.0.15",
4
+ "version": "1.0.18",
5
5
  "skill": {
6
6
  "namespace": "invite"
7
7
  },