@nyaruka/temba-components 0.166.0 → 0.167.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nyaruka/temba-components",
3
- "version": "0.166.0",
3
+ "version": "0.167.0",
4
4
  "description": "Web components to support rapidpro and related projects",
5
5
  "author": "Nyaruka <code@nyaruka.coim>",
6
6
  "main": "dist/index.js",
@@ -49,6 +49,12 @@ export class ContactList extends ContentList<Contact> {
49
49
  @property({ type: String, attribute: 'fields-endpoint' })
50
50
  fieldsEndpoint = '/api/v2/fields.json';
51
51
 
52
+ /** Anonymous workspaces mask URN values, so instead of the URN
53
+ * column the list shows each contact's ref (served as its own
54
+ * anon-only key by the endpoint). */
55
+ @property({ type: Boolean })
56
+ anon = false;
57
+
52
58
  @state()
53
59
  private featuredFields: any[] = [];
54
60
 
@@ -91,6 +97,16 @@ export class ContactList extends ContentList<Contact> {
91
97
  super.disconnectedCallback();
92
98
  }
93
99
 
100
+ protected willUpdate(changes: PropertyValues): void {
101
+ super.willUpdate(changes);
102
+ // Rebuilding here (rather than in updated()) means a mounted
103
+ // anon attribute is reflected in the first paint instead of
104
+ // flashing the URN header for a frame.
105
+ if (changes.has('anon')) {
106
+ this.columns = this.buildColumns();
107
+ }
108
+ }
109
+
94
110
  protected updated(changes: PropertyValues): void {
95
111
  super.updated(changes);
96
112
  if (changes.has('fieldsEndpoint') && this.fieldsEndpoint) {
@@ -168,12 +184,19 @@ export class ContactList extends ContentList<Contact> {
168
184
  maxWidth: '260px',
169
185
  pinned: true
170
186
  },
171
- {
172
- key: 'urn',
173
- label: 'URN',
174
- minWidth: '120px',
175
- maxWidth: '190px'
176
- },
187
+ this.anon
188
+ ? {
189
+ key: 'ref',
190
+ label: 'Ref',
191
+ minWidth: '120px',
192
+ maxWidth: '190px'
193
+ }
194
+ : {
195
+ key: 'urn',
196
+ label: 'URN',
197
+ minWidth: '120px',
198
+ maxWidth: '190px'
199
+ },
177
200
  ...fieldColumns,
178
201
  {
179
202
  key: 'last_seen_on',
@@ -232,6 +255,10 @@ export class ContactList extends ContentList<Contact> {
232
255
  return html`<span class="contact-urn"
233
256
  >${this.primaryUrn(item) || EMPTY}</span
234
257
  >`;
258
+ case 'ref':
259
+ return html`<span class="contact-urn"
260
+ >${(item as any).ref || EMPTY}</span
261
+ >`;
235
262
  case 'last_seen_on':
236
263
  return item.last_seen_on
237
264
  ? html`<temba-date
@@ -281,7 +308,11 @@ export class ContactList extends ContentList<Contact> {
281
308
 
282
309
  private primaryUrn(item: Contact): string {
283
310
  const i = item as any;
284
- if (i.urn) return i.urn;
311
+ if (i.urn) {
312
+ // served as {scheme, display} by the list endpoint, but tolerate
313
+ // a plain string (e.g. the public API's urn field)
314
+ return typeof i.urn === 'string' ? i.urn : i.urn.display || '';
315
+ }
285
316
  if (Array.isArray(i.urns) && i.urns.length > 0) {
286
317
  const u = i.urns[0];
287
318
  return typeof u === 'string'