@nyaruka/temba-components 0.107.1 → 0.108.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/temba-modules.ts CHANGED
@@ -60,7 +60,7 @@ import { MediaPicker } from './src/mediapicker/MediaPicker';
60
60
  import { ContactNotepad } from './src/contacts/ContactNotepad';
61
61
  import { OutboxMonitor } from './src/outboxmonitor/OutboxMonitor';
62
62
  import { ProgressBar } from './src/progress/ProgressBar';
63
- import { FlowStartProgress } from './src/progress/FlowStartProgress';
63
+ import { StartProgress } from './src/progress/StartProgress';
64
64
 
65
65
  export function addCustomElement(name: string, comp: any) {
66
66
  if (!window.customElements.get(name)) {
@@ -131,4 +131,4 @@ addCustomElement('temba-media-picker', MediaPicker);
131
131
  addCustomElement('temba-contact-notepad', ContactNotepad);
132
132
  addCustomElement('temba-outbox-monitor', OutboxMonitor);
133
133
  addCustomElement('temba-progress', ProgressBar);
134
- addCustomElement('temba-flowstart-progress', FlowStartProgress);
134
+ addCustomElement('temba-start-progress', StartProgress);
@@ -1,69 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { html } from 'lit';
3
- import { RapidElement } from '../RapidElement';
4
- import { property } from 'lit/decorators.js';
5
- import { fetchResults } from '../utils';
6
- export class FlowStartProgress extends RapidElement {
7
- constructor() {
8
- super(...arguments);
9
- this.refreshes = 0;
10
- }
11
- updated(changes) {
12
- super.updated(changes);
13
- if (changes.has('uuid')) {
14
- this.refresh();
15
- }
16
- }
17
- refresh() {
18
- fetchResults(`/api/v2/flow_starts.json?uuid=${this.uuid}`).then((data) => {
19
- if (data.length > 0) {
20
- this.refreshes++;
21
- const start = data[0];
22
- this.started = start.progress.started;
23
- this.total = start.progress.total;
24
- const elapsed = new Date().getTime() - new Date(start.created_on).getTime();
25
- const rate = this.started / elapsed;
26
- // calculate the estimated time of arrival
27
- const eta = new Date(new Date().getTime() + (this.total - this.started) / rate);
28
- // Don't bother with estimates months out
29
- const nextMonth = new Date();
30
- nextMonth.setMonth(nextMonth.getMonth() + 2);
31
- if (eta > nextMonth) {
32
- this.eta = null;
33
- }
34
- else {
35
- this.eta = eta.toISOString();
36
- }
37
- if (this.started < this.total) {
38
- // refresh with a backoff up to 1 minute
39
- setTimeout(() => {
40
- this.refresh();
41
- }, Math.min(1000 * this.refreshes, 60000));
42
- }
43
- }
44
- });
45
- }
46
- render() {
47
- return html `<temba-progress
48
- total=${this.total}
49
- current=${this.started}
50
- eta=${this.eta}
51
- ></temba-progress>`;
52
- }
53
- }
54
- __decorate([
55
- property({ type: String })
56
- ], FlowStartProgress.prototype, "uuid", void 0);
57
- __decorate([
58
- property({ type: Number })
59
- ], FlowStartProgress.prototype, "started", void 0);
60
- __decorate([
61
- property({ type: Number })
62
- ], FlowStartProgress.prototype, "total", void 0);
63
- __decorate([
64
- property({ type: Number })
65
- ], FlowStartProgress.prototype, "refreshes", void 0);
66
- __decorate([
67
- property({ type: String })
68
- ], FlowStartProgress.prototype, "eta", void 0);
69
- //# sourceMappingURL=FlowStartProgress.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FlowStartProgress.js","sourceRoot":"","sources":["../../../src/progress/FlowStartProgress.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAoC,MAAM,KAAK,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IAAnD;;QAWE,cAAS,GAAW,CAAC,CAAC;IA2DxB,CAAC;IAtDQ,OAAO,CACZ,OAA0D;QAE1D,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC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AAE;wBACd,IAAI,CAAC,OAAO,EAAE,CAAC;oBACjB,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAA;cACD,IAAI,CAAC,KAAK;gBACR,IAAI,CAAC,OAAO;YAChB,IAAI,CAAC,GAAG;uBACG,CAAC;IACtB,CAAC;CACF;AApEC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CACd;AAGb;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDACX;AAGhB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDACb;AAGd;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDACL;AAGtB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CACf","sourcesContent":["import { html, PropertyValueMap, TemplateResult } from 'lit';\nimport { RapidElement } from '../RapidElement';\nimport { property } from 'lit/decorators.js';\nimport { fetchResults } from '../utils';\n\nexport class FlowStartProgress extends RapidElement {\n @property({ type: String })\n uuid: string;\n\n @property({ type: Number })\n started: number;\n\n @property({ type: Number })\n total: number;\n\n @property({ type: Number })\n refreshes: number = 0;\n\n @property({ type: String })\n eta: string;\n\n public updated(\n changes: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.updated(changes);\n if (changes.has('uuid')) {\n this.refresh();\n }\n }\n\n public refresh(): void {\n fetchResults(`/api/v2/flow_starts.json?uuid=${this.uuid}`).then(\n (data: any) => {\n if (data.length > 0) {\n this.refreshes++;\n const start = data[0];\n this.started = start.progress.started;\n this.total = start.progress.total;\n\n const elapsed =\n new Date().getTime() - new Date(start.created_on).getTime();\n const rate = this.started / elapsed;\n\n // calculate the estimated time of arrival\n const eta = new Date(\n new Date().getTime() + (this.total - this.started) / rate\n );\n\n // Don't bother with estimates months out\n const nextMonth = new Date();\n nextMonth.setMonth(nextMonth.getMonth() + 2);\n if (eta > nextMonth) {\n this.eta = null;\n } else {\n this.eta = eta.toISOString();\n }\n\n if (this.started < this.total) {\n // refresh with a backoff up to 1 minute\n setTimeout(() => {\n this.refresh();\n }, Math.min(1000 * this.refreshes, 60000));\n }\n }\n }\n );\n }\n\n public render(): TemplateResult {\n return html`<temba-progress\n total=${this.total}\n current=${this.started}\n eta=${this.eta}\n ></temba-progress>`;\n }\n}\n"]}
@@ -1,76 +0,0 @@
1
- import { html, PropertyValueMap, TemplateResult } from 'lit';
2
- import { RapidElement } from '../RapidElement';
3
- import { property } from 'lit/decorators.js';
4
- import { fetchResults } from '../utils';
5
-
6
- export class FlowStartProgress extends RapidElement {
7
- @property({ type: String })
8
- uuid: string;
9
-
10
- @property({ type: Number })
11
- started: number;
12
-
13
- @property({ type: Number })
14
- total: number;
15
-
16
- @property({ type: Number })
17
- refreshes: number = 0;
18
-
19
- @property({ type: String })
20
- eta: string;
21
-
22
- public updated(
23
- changes: PropertyValueMap<any> | Map<PropertyKey, unknown>
24
- ): void {
25
- super.updated(changes);
26
- if (changes.has('uuid')) {
27
- this.refresh();
28
- }
29
- }
30
-
31
- public refresh(): void {
32
- fetchResults(`/api/v2/flow_starts.json?uuid=${this.uuid}`).then(
33
- (data: any) => {
34
- if (data.length > 0) {
35
- this.refreshes++;
36
- const start = data[0];
37
- this.started = start.progress.started;
38
- this.total = start.progress.total;
39
-
40
- const elapsed =
41
- new Date().getTime() - new Date(start.created_on).getTime();
42
- const rate = this.started / elapsed;
43
-
44
- // calculate the estimated time of arrival
45
- const eta = new Date(
46
- new Date().getTime() + (this.total - this.started) / rate
47
- );
48
-
49
- // Don't bother with estimates months out
50
- const nextMonth = new Date();
51
- nextMonth.setMonth(nextMonth.getMonth() + 2);
52
- if (eta > nextMonth) {
53
- this.eta = null;
54
- } else {
55
- this.eta = eta.toISOString();
56
- }
57
-
58
- if (this.started < this.total) {
59
- // refresh with a backoff up to 1 minute
60
- setTimeout(() => {
61
- this.refresh();
62
- }, Math.min(1000 * this.refreshes, 60000));
63
- }
64
- }
65
- }
66
- );
67
- }
68
-
69
- public render(): TemplateResult {
70
- return html`<temba-progress
71
- total=${this.total}
72
- current=${this.started}
73
- eta=${this.eta}
74
- ></temba-progress>`;
75
- }
76
- }