@nyaruka/temba-components 0.114.1 → 0.116.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/CHANGELOG.md +6 -0
- package/dist/temba-components.js +293 -293
- package/dist/temba-components.js.map +1 -1
- package/out-tsc/src/contacts/ContactChat.js +27 -16
- package/out-tsc/src/contacts/ContactChat.js.map +1 -1
- package/out-tsc/src/list/TembaList.js +3 -2
- package/out-tsc/src/list/TembaList.js.map +1 -1
- package/out-tsc/src/options/Options.js +4 -1
- package/out-tsc/src/options/Options.js.map +1 -1
- package/out-tsc/src/store/Store.js +3 -1
- package/out-tsc/src/store/Store.js.map +1 -1
- package/out-tsc/src/user/TembaUser.js +25 -10
- package/out-tsc/src/user/TembaUser.js.map +1 -1
- package/out-tsc/test/temba-contact-chat.test.js +1 -0
- package/out-tsc/test/temba-contact-chat.test.js.map +1 -1
- package/package.json +1 -1
- package/src/contacts/ContactChat.ts +30 -20
- package/src/list/TembaList.ts +3 -6
- package/src/options/Options.ts +5 -1
- package/src/store/Store.ts +3 -1
- package/src/user/TembaUser.ts +21 -9
- package/test/temba-contact-chat.test.ts +5 -0
|
@@ -519,6 +519,12 @@ export class ContactChat extends ContactStoreElement {
|
|
|
519
519
|
changedProperties.has('data') ||
|
|
520
520
|
changedProperties.has('currentContact')
|
|
521
521
|
) {
|
|
522
|
+
// unschedule any previous refreshes
|
|
523
|
+
if (this.refreshId) {
|
|
524
|
+
clearTimeout(this.refreshId);
|
|
525
|
+
this.refreshId = null;
|
|
526
|
+
}
|
|
527
|
+
|
|
522
528
|
this.currentContact = this.data;
|
|
523
529
|
}
|
|
524
530
|
|
|
@@ -527,17 +533,6 @@ export class ContactChat extends ContactStoreElement {
|
|
|
527
533
|
this.reset();
|
|
528
534
|
this.fetchPreviousMessages();
|
|
529
535
|
}
|
|
530
|
-
|
|
531
|
-
if (changedProperties.has('currentTicket')) {
|
|
532
|
-
const users = this.shadowRoot.querySelector(
|
|
533
|
-
'temba-user-select'
|
|
534
|
-
) as UserSelect;
|
|
535
|
-
if (users) {
|
|
536
|
-
users.setValues(
|
|
537
|
-
this.currentTicket?.assignee ? [this.currentTicket?.assignee] : []
|
|
538
|
-
);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
536
|
}
|
|
542
537
|
|
|
543
538
|
private reset() {
|
|
@@ -609,7 +604,10 @@ export class ContactChat extends ContactStoreElement {
|
|
|
609
604
|
}
|
|
610
605
|
|
|
611
606
|
private getEndpoint() {
|
|
612
|
-
|
|
607
|
+
if (this.contact) {
|
|
608
|
+
return `/contact/history/${this.contact}/?_format=json`;
|
|
609
|
+
}
|
|
610
|
+
return null;
|
|
613
611
|
}
|
|
614
612
|
|
|
615
613
|
private scheduleRefresh() {
|
|
@@ -894,6 +892,9 @@ export class ContactChat extends ContactStoreElement {
|
|
|
894
892
|
if (this.currentContact && this.newestEventTime) {
|
|
895
893
|
this.polling = true;
|
|
896
894
|
const endpoint = this.getEndpoint();
|
|
895
|
+
if (!endpoint) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
897
898
|
|
|
898
899
|
const fetchContact = this.currentContact.uuid;
|
|
899
900
|
|
|
@@ -929,6 +930,10 @@ export class ContactChat extends ContactStoreElement {
|
|
|
929
930
|
chat.fetching = true;
|
|
930
931
|
if (this.currentContact) {
|
|
931
932
|
const endpoint = this.getEndpoint();
|
|
933
|
+
if (!endpoint) {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
|
|
932
937
|
fetchContactHistory(
|
|
933
938
|
false,
|
|
934
939
|
endpoint,
|
|
@@ -949,7 +954,9 @@ export class ContactChat extends ContactStoreElement {
|
|
|
949
954
|
}
|
|
950
955
|
|
|
951
956
|
private fetchComplete() {
|
|
952
|
-
this.chat
|
|
957
|
+
if (this.chat) {
|
|
958
|
+
this.chat.fetching = false;
|
|
959
|
+
}
|
|
953
960
|
}
|
|
954
961
|
|
|
955
962
|
private getTembaCompose(): TemplateResult {
|
|
@@ -1003,6 +1010,7 @@ export class ContactChat extends ContactStoreElement {
|
|
|
1003
1010
|
private handleAssignmentChanged(evt: CustomEvent) {
|
|
1004
1011
|
const users = evt.currentTarget as UserSelect;
|
|
1005
1012
|
const assignee = users.values[0];
|
|
1013
|
+
|
|
1006
1014
|
this.assignTicket(assignee ? assignee.email : null);
|
|
1007
1015
|
users.blur();
|
|
1008
1016
|
}
|
|
@@ -1054,13 +1062,15 @@ export class ContactChat extends ContactStoreElement {
|
|
|
1054
1062
|
if (this.currentTicket) {
|
|
1055
1063
|
fetchResults(`/api/v2/tickets.json?uuid=${this.currentTicket.uuid}`).then(
|
|
1056
1064
|
(values) => {
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1065
|
+
this.store.resolveUsers(values, ['assignee']).then(() => {
|
|
1066
|
+
if (values.length > 0) {
|
|
1067
|
+
this.fireCustomEvent(CustomEventType.TicketUpdated, {
|
|
1068
|
+
ticket: values[0],
|
|
1069
|
+
previous: this.currentTicket
|
|
1070
|
+
});
|
|
1071
|
+
this.currentTicket = values[0];
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1064
1074
|
}
|
|
1065
1075
|
);
|
|
1066
1076
|
}
|
package/src/list/TembaList.ts
CHANGED
|
@@ -195,12 +195,9 @@ export class TembaList extends RapidElement {
|
|
|
195
195
|
const index = this.getItemIndex(value);
|
|
196
196
|
this.items.splice(index, 1);
|
|
197
197
|
this.items = [...this.items];
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
0,
|
|
202
|
-
Math.min(this.items.length - 1, this.cursorIndex - 1)
|
|
203
|
-
);
|
|
198
|
+
if (this.cursorIndex === index) {
|
|
199
|
+
this.cursorIndex = -1;
|
|
200
|
+
}
|
|
204
201
|
|
|
205
202
|
// request a change even if it is the same, the item is different
|
|
206
203
|
this.requestUpdate('cursorIndex');
|
package/src/options/Options.ts
CHANGED
|
@@ -372,7 +372,7 @@ export class Options extends RapidElement {
|
|
|
372
372
|
(previousCount === 0 && newCount > 0 && !changed.has('cursorIndex'))
|
|
373
373
|
) {
|
|
374
374
|
if (!this.internalFocusDisabled) {
|
|
375
|
-
if (!this.block
|
|
375
|
+
if (!this.block) {
|
|
376
376
|
this.cursorIndex = 0;
|
|
377
377
|
} else {
|
|
378
378
|
if (this.cursorIndex >= newCount) {
|
|
@@ -444,6 +444,10 @@ export class Options extends RapidElement {
|
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
446
|
|
|
447
|
+
if (index === -1) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
447
451
|
const selected = this.options[index];
|
|
448
452
|
this.fireCustomEvent(CustomEventType.Selection, {
|
|
449
453
|
selected,
|
package/src/store/Store.ts
CHANGED
|
@@ -519,7 +519,9 @@ export class Store extends RapidElement {
|
|
|
519
519
|
// we don't want to fetch all users at once so we can benefit from caching
|
|
520
520
|
emails.forEach((email) => {
|
|
521
521
|
promises.push(
|
|
522
|
-
this.getUrl(`/api/v2/users.json?email=${encodeURIComponent(email)}
|
|
522
|
+
this.getUrl(`/api/v2/users.json?email=${encodeURIComponent(email)}`, {
|
|
523
|
+
force: true
|
|
524
|
+
})
|
|
523
525
|
);
|
|
524
526
|
});
|
|
525
527
|
|
package/src/user/TembaUser.ts
CHANGED
|
@@ -48,7 +48,10 @@ export class TembaUser extends RapidElement {
|
|
|
48
48
|
system: boolean;
|
|
49
49
|
|
|
50
50
|
@property({ type: String, attribute: false })
|
|
51
|
-
|
|
51
|
+
bgimage: string = null;
|
|
52
|
+
|
|
53
|
+
@property({ type: String, attribute: false })
|
|
54
|
+
bgcolor: string = '#e6e6e6';
|
|
52
55
|
|
|
53
56
|
@property({ type: String, attribute: false })
|
|
54
57
|
initials: string = '';
|
|
@@ -68,16 +71,25 @@ export class TembaUser extends RapidElement {
|
|
|
68
71
|
super.updated(changed);
|
|
69
72
|
|
|
70
73
|
if (changed.has('system') && this.system) {
|
|
71
|
-
this.
|
|
74
|
+
this.bgimage = `url('${DEFAULT_AVATAR}') center / contain no-repeat`;
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
if (changed.has('name')
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
if (changed.has('name')) {
|
|
78
|
+
if (this.name) {
|
|
79
|
+
this.bgcolor = colorHash.hex(this.name);
|
|
80
|
+
this.initials = extractInitials(this.name);
|
|
81
|
+
} else {
|
|
82
|
+
this.bgcolor = '#e6e6e6';
|
|
83
|
+
this.initials = '';
|
|
84
|
+
}
|
|
77
85
|
}
|
|
78
86
|
|
|
79
|
-
if (changed.has('avatar')
|
|
80
|
-
|
|
87
|
+
if (changed.has('avatar')) {
|
|
88
|
+
if (this.avatar) {
|
|
89
|
+
this.bgimage = `url('${this.avatar}') center / contain no-repeat`;
|
|
90
|
+
} else if (!this.system) {
|
|
91
|
+
this.bgimage = null;
|
|
92
|
+
}
|
|
81
93
|
}
|
|
82
94
|
}
|
|
83
95
|
|
|
@@ -98,9 +110,9 @@ export class TembaUser extends RapidElement {
|
|
|
98
110
|
overflow: hidden;
|
|
99
111
|
font-size: 12px;
|
|
100
112
|
box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.1);
|
|
101
|
-
background:${this.
|
|
113
|
+
background:${this.bgimage || this.bgcolor};"
|
|
102
114
|
>
|
|
103
|
-
${this.initials && !this.
|
|
115
|
+
${this.initials && !this.bgimage
|
|
104
116
|
? html` <div
|
|
105
117
|
style="border: 0px solid red; display:flex; flex-direction: column; align-items:center;flex-grow:1"
|
|
106
118
|
>
|
|
@@ -60,6 +60,11 @@ describe('temba-contact-chat', () => {
|
|
|
60
60
|
'/test-assets/contacts/history.json'
|
|
61
61
|
);
|
|
62
62
|
|
|
63
|
+
mockGET(
|
|
64
|
+
/\/api\/v2\/users\.json\?email=admin1%40nyaruka\.com/,
|
|
65
|
+
'/test-assets/api/users/admin1.json'
|
|
66
|
+
);
|
|
67
|
+
|
|
63
68
|
mockAPI();
|
|
64
69
|
clock = useFakeTimers();
|
|
65
70
|
});
|