@nyaruka/temba-components 0.164.0 → 0.166.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/DEV_DATA.md +11 -11
  3. package/README.md +4 -4
  4. package/TEST_OPTIMIZATION.md +8 -11
  5. package/dist/locales/es.js +4 -0
  6. package/dist/locales/es.js.map +1 -1
  7. package/dist/locales/fr.js +4 -0
  8. package/dist/locales/fr.js.map +1 -1
  9. package/dist/locales/pt.js +4 -0
  10. package/dist/locales/pt.js.map +1 -1
  11. package/dist/static/svg/index.svg +1 -1
  12. package/dist/temba-components.js +1983 -865
  13. package/dist/temba-components.js.map +1 -1
  14. package/orca/setup.sh +2 -2
  15. package/package.json +13 -18
  16. package/scripts/dev-data-sync.mjs +4 -4
  17. package/src/Icons.ts +3 -2
  18. package/src/display/Chat.ts +232 -18
  19. package/src/display/ProgressBar.ts +15 -2
  20. package/src/form/Compose.ts +31 -1
  21. package/src/form/ContactSearch.ts +229 -126
  22. package/src/interfaces.ts +73 -0
  23. package/src/layout/Card.ts +25 -0
  24. package/src/layout/CardLayout.ts +3 -3
  25. package/src/layout/HeaderBar.ts +4 -1
  26. package/src/list/BroadcastList.ts +912 -0
  27. package/src/list/ContentList.ts +46 -10
  28. package/src/list/FieldList.ts +1057 -0
  29. package/src/list/NotificationList.ts +131 -21
  30. package/src/list/SortableList.ts +7 -2
  31. package/src/list/TembaList.ts +19 -5
  32. package/src/list/TembaMenu.ts +47 -46
  33. package/src/live/CampaignEvents.ts +33 -19
  34. package/src/live/ContactChat.ts +190 -18
  35. package/src/live/ContactDetails.ts +20 -13
  36. package/src/live/ContactFieldEditor.ts +7 -3
  37. package/src/live/ContactStoreElement.ts +3 -1
  38. package/src/live/ContactTimeline.ts +28 -7
  39. package/src/live/Realtime.ts +133 -0
  40. package/src/live/SocketService.ts +24 -0
  41. package/src/locales/es.ts +4 -0
  42. package/src/locales/fr.ts +4 -0
  43. package/src/locales/pt.ts +4 -0
  44. package/src/store/Store.ts +12 -0
  45. package/src/utils.ts +4 -0
  46. package/static/svg/index.svg +1 -1
  47. package/static/svg/packs/2-temba/star-filled.svg +3 -0
  48. package/static/svg/work/traced/star-filled.svg +1 -0
  49. package/static/svg/work/used/star-filled.svg +3 -0
  50. package/stress-test.js +3 -3
  51. package/temba-modules.ts +4 -0
  52. package/web-test-runner.config.mjs +1 -1
  53. package/xliff/es.xlf +12 -0
  54. package/xliff/fr.xlf +12 -0
  55. package/xliff/pt.xlf +12 -0
@@ -226,12 +226,33 @@ export class ContactSearch extends FieldElement {
226
226
  border: 1px solid var(--color-borders);
227
227
  border-radius: var(--curvature);
228
228
  }
229
+
230
+ .interrupt-confirm {
231
+ display: flex;
232
+ align-items: center;
233
+ margin-top: 0.5em;
234
+ margin-left: 0.6em;
235
+ cursor: pointer;
236
+ }
229
237
  `;
230
238
  }
231
239
 
232
240
  @property({ type: Boolean })
233
241
  in_a_flow: boolean;
234
242
 
243
+ // recipients are locked, e.g. starting a specific contact from their read page -
244
+ // no recipient editing, filters or query editing
245
+ @property({ type: Boolean })
246
+ fixed: boolean;
247
+
248
+ // name of the flow the fixed contact is currently in, if any
249
+ @property({ type: String, attribute: 'current_flow' })
250
+ currentFlow: string;
251
+
252
+ // whether the user has explicitly confirmed interrupting the current flow
253
+ @property({ type: Boolean })
254
+ interruptConfirmed = false;
255
+
235
256
  @property({ type: Boolean })
236
257
  started_previously: boolean;
237
258
 
@@ -310,6 +331,30 @@ export class ContactSearch extends FieldElement {
310
331
  }
311
332
  }
312
333
 
334
+ protected willUpdate(changedProperties: Map<string, any>) {
335
+ super.willUpdate(changedProperties);
336
+
337
+ // reconcile the in_a_flow exclusion; outside of fixed mode it is user-controlled
338
+ // via the filter checkbox, so we only ever clear it when the option goes away
339
+ if (
340
+ changedProperties.has('in_a_flow') ||
341
+ changedProperties.has('interruptConfirmed') ||
342
+ changedProperties.has('fixed') ||
343
+ changedProperties.has('currentFlow')
344
+ ) {
345
+ if (!this.in_a_flow) {
346
+ delete this.exclusions['in_a_flow'];
347
+ } else if (this.fixed && this.currentFlow) {
348
+ // a fixed contact already in a flow stays excluded until interruption is confirmed
349
+ if (this.interruptConfirmed) {
350
+ delete this.exclusions['in_a_flow'];
351
+ } else {
352
+ this.exclusions['in_a_flow'] = true;
353
+ }
354
+ }
355
+ }
356
+ }
357
+
313
358
  public updated(changedProperties: Map<string, any>) {
314
359
  super.updated(changedProperties);
315
360
 
@@ -317,12 +362,6 @@ export class ContactSearch extends FieldElement {
317
362
  this.handleRecipientsChanged();
318
363
  }
319
364
 
320
- // if we remove the in_a_flow option, make sure it's not part of our exclusions
321
- if (changedProperties.has('in_a_flow') && !this.in_a_flow) {
322
- delete this.exclusions['in_a_flow'];
323
- this.requestUpdate('exclusions');
324
- }
325
-
326
365
  if (
327
366
  (changedProperties.has('query') && this.advanced) ||
328
367
  (changedProperties.has('refreshKey') && this.refreshKey !== '0')
@@ -455,6 +494,32 @@ export class ContactSearch extends FieldElement {
455
494
  }
456
495
  }
457
496
 
497
+ private async handleInterruptChanged(evt: any) {
498
+ const checkbox = evt.target as Checkbox;
499
+ this.interruptConfirmed = checkbox.checked;
500
+
501
+ // wait for willUpdate() to reconcile our exclusions
502
+ await this.updateComplete;
503
+
504
+ this.setValue({
505
+ advanced: this.advanced,
506
+ query: this.query,
507
+ exclusions: this.exclusions,
508
+ recipients: this.recipients
509
+ });
510
+
511
+ // we already know whether our fixed contacts will be included so no need to re-run
512
+ // the search - just let the modal know, counting contacts only since a group entry
513
+ // doesn't tell us its membership size
514
+ const contactCount = this.recipients.filter(
515
+ (value: OmniOption) => value.type === 'contact'
516
+ ).length;
517
+ this.fireCustomEvent(CustomEventType.ContentChanged, {
518
+ ...(this.summary || {}),
519
+ total: this.interruptConfirmed ? contactCount : 0
520
+ });
521
+ }
522
+
458
523
  private handleExclusionChanged(evt: any) {
459
524
  if (evt.target.tagName === 'TEMBA-CHECKBOX') {
460
525
  const ex = JSON.stringify(this.exclusions);
@@ -487,7 +552,7 @@ export class ContactSearch extends FieldElement {
487
552
 
488
553
  public renderWidget(): TemplateResult {
489
554
  let summary: TemplateResult;
490
- if (this.summary) {
555
+ if (this.summary && !this.fixed) {
491
556
  if (!this.summary.error) {
492
557
  const count = this.summary.total || 0;
493
558
 
@@ -544,132 +609,170 @@ export class ContactSearch extends FieldElement {
544
609
  )}`;
545
610
  }
546
611
 
612
+ const interruptConfirm =
613
+ this.fixed && this.currentFlow && this.in_a_flow && !this.fetching
614
+ ? html`<div
615
+ class="interrupt-confirm"
616
+ @click=${this.handleActivityLabelClicked}
617
+ >
618
+ <temba-checkbox
619
+ name="interrupt"
620
+ ?checked=${this.interruptConfirmed}
621
+ @change=${this.handleInterruptChanged}
622
+ ></temba-checkbox>
623
+ <div>
624
+ ${this.flow && this.flow.name === this.currentFlow
625
+ ? html`${msg("It's okay to restart")}
626
+ <b>${this.currentFlow}</b> ${msg('from the beginning')}`
627
+ : html`${msg("It's okay to interrupt")}
628
+ <b>${this.currentFlow}</b> ${msg('and start this one')}`}
629
+ </div>
630
+ </div>`
631
+ : null;
632
+
547
633
  return html`
548
634
  ${
549
- this.advanced
550
- ? html`<div class="query">
551
- <temba-textinput
552
- .helpText=${this.helpText}
553
- .widgetOnly=${this.widgetOnly}
554
- .errors=${this.errors}
555
- name=${this.name}
556
- .inputRoot=${this}
557
- @input=${this.handleQueryChange}
558
- placeholder=${this.placeholder}
559
- .value=${this.query}
560
- textarea
561
- autogrow
562
- >
563
- </temba-textinput>
564
- </div>`
565
- : html`<temba-omnibox
566
- placeholder="Search for contacts or groups"
567
- widget_only=""
568
- groups=""
569
- contacts=""
570
- label="Recipients"
571
- help_text="The contacts to send the message to."
572
- .errors=${this.errors}
573
- id="recipients"
574
- name="recipients"
575
- .values=${this.recipients}
576
- endpoint="/contact/omnibox/?"
577
- @change=${this.handleRecipientsChanged}
578
- >
579
- </temba-omnibox>
580
-
581
- ${this.not_seen_since_days ||
582
- this.in_a_flow ||
583
- this.started_previously
584
- ? html`
585
- <div class="filters">
586
- <div
587
- style="display:flex;font-size:1em;margin-bottom:0.5em"
588
- >
589
- <temba-icon size="1" name="filter"></temba-icon>
590
- <div style="margin-left:0.5em">
591
- Only include contacts who...
635
+ this.fixed
636
+ ? null
637
+ : this.advanced
638
+ ? html`<div class="query">
639
+ <temba-textinput
640
+ .helpText=${this.helpText}
641
+ .widgetOnly=${this.widgetOnly}
642
+ .errors=${this.errors}
643
+ name=${this.name}
644
+ .inputRoot=${this}
645
+ @input=${this.handleQueryChange}
646
+ placeholder=${this.placeholder}
647
+ .value=${this.query}
648
+ textarea
649
+ autogrow
650
+ >
651
+ </temba-textinput>
652
+ </div>`
653
+ : html`<temba-omnibox
654
+ placeholder="Search for contacts or groups"
655
+ widget_only=""
656
+ groups=""
657
+ contacts=""
658
+ label="Recipients"
659
+ help_text="The contacts to send the message to."
660
+ .errors=${this.errors}
661
+ id="recipients"
662
+ name="recipients"
663
+ .values=${this.recipients}
664
+ endpoint="/contact/omnibox/?"
665
+ @change=${this.handleRecipientsChanged}
666
+ >
667
+ </temba-omnibox>
668
+
669
+ ${this.not_seen_since_days ||
670
+ this.in_a_flow ||
671
+ this.started_previously
672
+ ? html`
673
+ <div class="filters">
674
+ <div
675
+ style="display:flex;font-size:1em;margin-bottom:0.5em"
676
+ >
677
+ <temba-icon size="1" name="filter"></temba-icon>
678
+ <div style="margin-left:0.5em">
679
+ Only include contacts who...
680
+ </div>
592
681
  </div>
593
- </div>
594
- ${this.in_a_flow
595
- ? html`<temba-checkbox
596
- name="in_a_flow"
597
- label="${msg('Are not currently in a flow')}"
598
- ?checked=${this.exclusions['in_a_flow']}
599
- @change=${this.handleExclusionChanged}
600
- ></temba-checkbox>`
601
- : null}
602
- ${this.not_seen_since_days
603
- ? html`
604
- <div
605
- class="activity-select"
606
- @click=${this.handleActivityLabelClicked}
607
- >
608
- <temba-checkbox
609
- style="display:inline;"
610
- name="not_seen_since_days"
611
- ?checked=${notSeenSinceDays}
612
- @change=${this.handleExclusionChanged}
682
+ ${this.in_a_flow
683
+ ? html`<temba-checkbox
684
+ name="in_a_flow"
685
+ label="${msg('Are not currently in a flow')}"
686
+ ?checked=${this.exclusions['in_a_flow']}
687
+ @change=${this.handleExclusionChanged}
688
+ ></temba-checkbox>`
689
+ : null}
690
+ ${this.not_seen_since_days
691
+ ? html`
692
+ <div
693
+ class="activity-select"
694
+ @click=${this.handleActivityLabelClicked}
613
695
  >
614
- </temba-checkbox>
615
-
616
- <div>
617
- ${msg('Have sent a message in the last')}
696
+ <temba-checkbox
697
+ style="display:inline;"
698
+ name="not_seen_since_days"
699
+ ?checked=${notSeenSinceDays}
700
+ @change=${this.handleExclusionChanged}
701
+ >
702
+ </temba-checkbox>
703
+
704
+ <div>
705
+ ${msg('Have sent a message in the last')}
706
+ </div>
707
+
708
+ <temba-select
709
+ style="margin-left:0.5em"
710
+ class="small-select"
711
+ @change=${this.handleActivityLevelChanged}
712
+ ?disabled=${!notSeenSinceDays}
713
+ >
714
+ <temba-option
715
+ name="90 days"
716
+ value="90"
717
+ ?selected=${notSeenSinceDays === 90}
718
+ ></temba-option>
719
+ <temba-option
720
+ name="180 days"
721
+ value="180"
722
+ ?selected=${notSeenSinceDays === 180}
723
+ ></temba-option>
724
+ <temba-option
725
+ name="Year"
726
+ value="365"
727
+ ?selected=${notSeenSinceDays === 365}
728
+ ></temba-option>
729
+ </temba-select>
730
+ <div></div>
618
731
  </div>
619
-
620
- <temba-select
621
- style="margin-left:0.5em"
622
- class="small-select"
623
- @change=${this.handleActivityLevelChanged}
624
- ?disabled=${!notSeenSinceDays}
625
- >
626
- <temba-option
627
- name="90 days"
628
- value="90"
629
- ?selected=${notSeenSinceDays === 90}
630
- ></temba-option>
631
- <temba-option
632
- name="180 days"
633
- value="180"
634
- ?selected=${notSeenSinceDays === 180}
635
- ></temba-option>
636
- <temba-option
637
- name="Year"
638
- value="365"
639
- ?selected=${notSeenSinceDays === 365}
640
- ></temba-option>
641
- </temba-select>
642
- <div></div>
643
- </div>
644
- `
645
- : null}
646
- ${this.started_previously
647
- ? html`<temba-checkbox
648
- name="started_previously"
649
- label="${msg(
650
- 'Have not started this flow in the last 90 days'
651
- )}"
652
- ?checked=${this.exclusions['started_previously']}
653
- @change=${this.handleExclusionChanged}
654
- ></temba-checkbox>`
655
- : null}
656
- </div>
657
- `
658
- : null} `
732
+ `
733
+ : null}
734
+ ${this.started_previously
735
+ ? html`<temba-checkbox
736
+ name="started_previously"
737
+ label="${msg(
738
+ 'Have not started this flow in the last 90 days'
739
+ )}"
740
+ ?checked=${this.exclusions['started_previously']}
741
+ @change=${this.handleExclusionChanged}
742
+ ></temba-checkbox>`
743
+ : null}
744
+ </div>
745
+ `
746
+ : null} `
659
747
  }
660
748
  </div>
661
- <div
662
- class="results ${getClasses({
663
- fetching: this.fetching,
664
- initialized: this.initialized || this.fetching,
665
- empty:
666
- ((this.summary && this.summary.error) || !this.summary) &&
667
- !this.fetching
668
- })}"
669
- >
670
- <temba-loading units="6" size="8"></temba-loading>
671
- <div class="summary ${this.expanded ? 'expanded' : ''}">${summary}</div>
672
- </div>
749
+ ${interruptConfirm}
750
+ ${
751
+ this.fixed
752
+ ? html`<div
753
+ class="results ${getClasses({
754
+ fetching: this.fetching,
755
+ initialized: this.fetching,
756
+ empty: !this.fetching
757
+ })}"
758
+ >
759
+ <temba-loading units="6" size="8"></temba-loading>
760
+ </div>`
761
+ : html`<div
762
+ class="results ${getClasses({
763
+ fetching: this.fetching,
764
+ initialized: this.initialized || this.fetching,
765
+ empty:
766
+ ((this.summary && this.summary.error) || !this.summary) &&
767
+ !this.fetching
768
+ })}"
769
+ >
770
+ <temba-loading units="6" size="8"></temba-loading>
771
+ <div class="summary ${this.expanded ? 'expanded' : ''}">
772
+ ${summary}
773
+ </div>
774
+ </div>`
775
+ }
673
776
  ${blockers}
674
777
  ${
675
778
  !blockers && this.summary && this.summary.warnings
package/src/interfaces.ts CHANGED
@@ -18,6 +18,26 @@ export interface Language {
18
18
  name: string;
19
19
  }
20
20
 
21
+ export interface Notification {
22
+ created_on: string;
23
+ type: string;
24
+ url: string;
25
+ is_seen: boolean;
26
+ export?: {
27
+ type: string;
28
+ num_records: number;
29
+ };
30
+ import?: {
31
+ type: string;
32
+ num_records: number;
33
+ };
34
+ incident?: {
35
+ type: string;
36
+ started_on: string;
37
+ ended_on?: string;
38
+ };
39
+ }
40
+
21
41
  export interface Attachment {
22
42
  uuid: string;
23
43
  content_type: string;
@@ -192,6 +212,58 @@ export interface Trigger {
192
212
  created_on?: string;
193
213
  }
194
214
 
215
+ /** A single row in the broadcast CRUDL lists — both the scheduled
216
+ * list (`msgs/broadcast_scheduled.html`) and the sent list
217
+ * (`msgs/broadcast_list.html`). Broadcasts key off the numeric id;
218
+ * content fields carry the base-language translation. */
219
+ export interface Broadcast {
220
+ id: number;
221
+ /** Server status slug — `pending`, `queued`, `started`,
222
+ * `completed`, `failed` or `interrupted`. Scheduled broadcasts
223
+ * that haven't fired yet sit at `pending`. */
224
+ status?: string;
225
+ /** Send progress for an in-flight broadcast — total recipients
226
+ * (-1 until the org's contact count resolves) and messages
227
+ * created so far. */
228
+ progress?: { total: number; started: number };
229
+ /** Base-language message text. */
230
+ text?: string;
231
+ /** Base-language attachments (`{content_type, url}` objects or
232
+ * `contentType:url` strings). */
233
+ attachments?: (string | Attachment)[];
234
+ /** Base-language quick replies. */
235
+ quick_replies?: string[];
236
+ /** The opt-in the broadcast requests, when it is one. */
237
+ optin?: ObjectReference | null;
238
+ /** The WhatsApp template the broadcast sends, when it uses one. */
239
+ template?: ObjectReference | null;
240
+ /** Recipient groups. */
241
+ groups?: ObjectReference[];
242
+ /** Recipient contacts. */
243
+ contacts?: ObjectReference[];
244
+ /** Raw recipient URNs (editors/admins only). */
245
+ urns?: string[];
246
+ /** Recipient contact query, for query-addressed broadcasts. */
247
+ query?: string | null;
248
+ /** Human-readable exclusion descriptions ("Skip inactive
249
+ * contacts", ...) rendered in the detail view. */
250
+ exclusions?: string[];
251
+ /** Scheduled broadcasts only — `display` is the server-rendered
252
+ * human repeat ("each week on Monday, Wednesday"); `next_fire` is
253
+ * null once the schedule is exhausted or paused. */
254
+ schedule?: {
255
+ repeat_period?: string;
256
+ display?: string;
257
+ next_fire?: string | null;
258
+ } | null;
259
+ /** Messages created by a sent broadcast. */
260
+ msg_count?: number;
261
+ created_on?: string;
262
+ /** Email of the user who created the broadcast. */
263
+ created_by?: string | null;
264
+ modified_on?: string;
265
+ }
266
+
195
267
  export interface Msg {
196
268
  /** Numeric id — present on persisted messages (the CRUDL list
197
269
  * keys rows off it); absent on outbound drafts. */
@@ -416,6 +488,7 @@ export enum CustomEventType {
416
488
  Error = 'temba-error',
417
489
  Interrupt = 'temba-interrupt',
418
490
  Opened = 'temba-opened',
491
+ NotificationReceived = 'temba-notification',
419
492
  TicketUpdated = 'temba-ticket-updated',
420
493
  Moved = 'temba-moved',
421
494
  DateRangeChanged = 'temba-date-range-changed',
@@ -20,6 +20,12 @@ export class Card extends RapidElement {
20
20
  display: block;
21
21
  }
22
22
 
23
+ /* an empty panel drops its card entirely — in tab (plain) mode the
24
+ pane still renders so the tab keeps working */
25
+ :host([empty]:not([plain])) {
26
+ display: none;
27
+ }
28
+
23
29
  /* The chrome lives on an inner frame rather than the host so
24
30
  document-level universal rules (e.g. tailwind's preflight
25
31
  border-color) can't override it. */
@@ -130,6 +136,16 @@ export class Card extends RapidElement {
130
136
  padding: 0 10px 10px;
131
137
  }
132
138
 
139
+ /* card chrome bounds the panel tightly — slotted panels scale their
140
+ empty-state treatment down from the roomy tab-pane default to a
141
+ single quiet line */
142
+ :host(:not([plain])) .content ::slotted(*) {
143
+ --empty-padding: 1em;
144
+ --empty-extras-display: none;
145
+ --empty-title-size: 0.9em;
146
+ --empty-title-color: var(--text-3);
147
+ }
148
+
133
149
  /* bleed mode: the body content runs edge-to-edge so a panel with its
134
150
  own surface (e.g. the notepad) fills the card, clipped to the card
135
151
  radius. The footer of such content sits on the card's bottom edge. */
@@ -210,6 +226,12 @@ export class Card extends RapidElement {
210
226
  @property({ type: Boolean, reflect: true })
211
227
  bleed = false;
212
228
 
229
+ // the slotted panel reported (via temba-details-changed) that it has
230
+ // nothing to show — the card hides entirely in card mode, though its
231
+ // tab remains available in narrow mode
232
+ @property({ type: Boolean, reflect: true })
233
+ empty = false;
234
+
213
235
  // named surface treatments, e.g. "note" for the sticky-note look
214
236
  @property({ type: String, reflect: true })
215
237
  variant = '';
@@ -252,6 +274,9 @@ export class Card extends RapidElement {
252
274
  if ('count' in event.detail) {
253
275
  this.count = event.detail.count;
254
276
  }
277
+ if ('empty' in event.detail) {
278
+ this.empty = event.detail.empty;
279
+ }
255
280
  }
256
281
 
257
282
  public render(): TemplateResult {
@@ -88,13 +88,13 @@ export class CardLayout extends RapidElement {
88
88
  /* the column soaks up whatever the main view doesn't take. Its
89
89
  scrollport runs the full height (the host supplies no vertical
90
90
  padding) so the scrollbar bleeds top to bottom, while the inner
91
- padding aligns the first card with the main view and doubles as
92
- room for card shadows. */
91
+ padding aligns the cards with the main view including below,
92
+ so the last card scrolls to rest level with the bottom of the
93
+ main view — and doubles as room for card shadows. */
93
94
  flex: 1 0 var(--card-column-width, 360px);
94
95
  min-height: 0;
95
96
  overflow-y: auto;
96
97
  padding: var(--layout-spacing, 8px);
97
- padding-bottom: 0;
98
98
  }
99
99
 
100
100
  temba-tabs {
@@ -22,7 +22,10 @@ export class HeaderBar extends RapidElement {
22
22
  box-sizing: border-box;
23
23
  padding: 0 8px;
24
24
  background: var(--surface);
25
- border-bottom: 1px solid var(--border);
25
+ /* the rule is a box-shadow, not a border — host pages (tailwind
26
+ preflight) reset border-width on every element, and outer-scope
27
+ element styles beat :host */
28
+ box-shadow: inset 0 -1px 0 0 var(--border);
26
29
  }
27
30
 
28
31
  ::slotted(*) {