@nyaruka/temba-components 0.130.4 → 0.131.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 (104) hide show
  1. package/CHANGELOG.md +10 -13
  2. package/demo/sortable-rules-demo.html +155 -0
  3. package/dist/temba-components.js +150 -159
  4. package/dist/temba-components.js.map +1 -1
  5. package/out-tsc/src/events.js.map +1 -1
  6. package/out-tsc/src/flow/CanvasNode.js +13 -7
  7. package/out-tsc/src/flow/CanvasNode.js.map +1 -1
  8. package/out-tsc/src/flow/actions/send_msg.js +1 -0
  9. package/out-tsc/src/flow/actions/send_msg.js.map +1 -1
  10. package/out-tsc/src/flow/nodes/split_by_groups.js +149 -1
  11. package/out-tsc/src/flow/nodes/split_by_groups.js.map +1 -1
  12. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js +1 -0
  13. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js.map +1 -1
  14. package/out-tsc/src/flow/nodes/split_by_random.js +1 -0
  15. package/out-tsc/src/flow/nodes/split_by_random.js.map +1 -1
  16. package/out-tsc/src/flow/nodes/wait_for_response.js +332 -137
  17. package/out-tsc/src/flow/nodes/wait_for_response.js.map +1 -1
  18. package/out-tsc/src/form/ArrayEditor.js +301 -30
  19. package/out-tsc/src/form/ArrayEditor.js.map +1 -1
  20. package/out-tsc/src/form/select/Omnibox.js +4 -0
  21. package/out-tsc/src/form/select/Omnibox.js.map +1 -1
  22. package/out-tsc/src/form/select/Select.js +21 -25
  23. package/out-tsc/src/form/select/Select.js.map +1 -1
  24. package/out-tsc/src/list/SortableList.js +214 -140
  25. package/out-tsc/src/list/SortableList.js.map +1 -1
  26. package/out-tsc/src/live/ContactChat.js +9 -5
  27. package/out-tsc/src/live/ContactChat.js.map +1 -1
  28. package/out-tsc/test/nodes/split_by_groups.test.js +130 -0
  29. package/out-tsc/test/nodes/split_by_groups.test.js.map +1 -0
  30. package/out-tsc/test/nodes/wait_for_response.test.js +522 -8
  31. package/out-tsc/test/nodes/wait_for_response.test.js.map +1 -1
  32. package/out-tsc/test/temba-field-config.test.js +56 -0
  33. package/out-tsc/test/temba-field-config.test.js.map +1 -1
  34. package/package.json +1 -1
  35. package/screenshots/truth/actions/add_contact_groups/render/descriptive-group-names.png +0 -0
  36. package/screenshots/truth/actions/add_contact_groups/render/long-group-names.png +0 -0
  37. package/screenshots/truth/actions/add_contact_groups/render/many-groups.png +0 -0
  38. package/screenshots/truth/actions/add_contact_groups/render/multiple-groups.png +0 -0
  39. package/screenshots/truth/actions/add_contact_groups/render/single-group.png +0 -0
  40. package/screenshots/truth/actions/remove_contact_groups/render/cleanup-groups.png +0 -0
  41. package/screenshots/truth/actions/remove_contact_groups/render/long-descriptive-group-names.png +0 -0
  42. package/screenshots/truth/actions/remove_contact_groups/render/many-groups.png +0 -0
  43. package/screenshots/truth/actions/remove_contact_groups/render/multiple-groups.png +0 -0
  44. package/screenshots/truth/actions/remove_contact_groups/render/remove-from-all-groups.png +0 -0
  45. package/screenshots/truth/actions/remove_contact_groups/render/single-group.png +0 -0
  46. package/screenshots/truth/actions/send_email/render/complex-business-email.png +0 -0
  47. package/screenshots/truth/actions/send_email/render/empty-body.png +0 -0
  48. package/screenshots/truth/actions/send_email/render/empty-subject.png +0 -0
  49. package/screenshots/truth/actions/send_email/render/multiline-body.png +0 -0
  50. package/screenshots/truth/actions/send_email/render/multiple-recipients.png +0 -0
  51. package/screenshots/truth/actions/send_email/render/simple-email.png +0 -0
  52. package/screenshots/truth/actions/send_email/render/with-expressions.png +0 -0
  53. package/screenshots/truth/actions/send_msg/render/long-quick-replies.png +0 -0
  54. package/screenshots/truth/actions/send_msg/render/multiline-text-with-replies.png +0 -0
  55. package/screenshots/truth/actions/send_msg/render/simple-text.png +0 -0
  56. package/screenshots/truth/actions/send_msg/render/text-with-linebreaks.png +0 -0
  57. package/screenshots/truth/actions/send_msg/render/text-with-many-quick-replies.png +0 -0
  58. package/screenshots/truth/actions/send_msg/render/text-with-quick-replies.png +0 -0
  59. package/screenshots/truth/actions/send_msg/render/text-without-quick-replies.png +0 -0
  60. package/screenshots/truth/editor/wait.png +0 -0
  61. package/screenshots/truth/field-renderer/select-with-label.png +0 -0
  62. package/screenshots/truth/list/fields-dragging.png +0 -0
  63. package/screenshots/truth/list/sortable-dragging.png +0 -0
  64. package/screenshots/truth/nodes/split_by_llm/editor/information-extraction.png +0 -0
  65. package/screenshots/truth/nodes/split_by_llm/editor/sentiment-analysis.png +0 -0
  66. package/screenshots/truth/nodes/split_by_llm/editor/summarization.png +0 -0
  67. package/screenshots/truth/nodes/split_by_llm/editor/translation-task.png +0 -0
  68. package/screenshots/truth/nodes/split_by_llm_categorize/editor/basic-categorization.png +0 -0
  69. package/screenshots/truth/nodes/split_by_llm_categorize/editor/custom-input-and-result-name.png +0 -0
  70. package/screenshots/truth/nodes/split_by_llm_categorize/editor/feedback-categorization.png +0 -0
  71. package/screenshots/truth/nodes/split_by_llm_categorize/editor/many-categories.png +0 -0
  72. package/screenshots/truth/nodes/split_by_llm_categorize/editor/minimal-categories.png +0 -0
  73. package/screenshots/truth/nodes/split_by_random/editor/ab-test-multiple-variants.png +0 -0
  74. package/screenshots/truth/nodes/split_by_random/editor/sampling-split.png +0 -0
  75. package/screenshots/truth/nodes/split_by_random/editor/three-way-split.png +0 -0
  76. package/screenshots/truth/nodes/split_by_random/editor/two-bucket-split.png +0 -0
  77. package/screenshots/truth/nodes/wait_for_response/editor/basic-wait.png +0 -0
  78. package/screenshots/truth/nodes/wait_for_response/editor/custom-result-name.png +0 -0
  79. package/screenshots/truth/nodes/wait_for_response/editor/no-timeout.png +0 -0
  80. package/screenshots/truth/nodes/wait_for_response/editor/short-timeout.png +0 -0
  81. package/screenshots/truth/nodes/wait_for_response/render/basic-wait.png +0 -0
  82. package/screenshots/truth/nodes/wait_for_response/render/custom-result-name.png +0 -0
  83. package/screenshots/truth/nodes/wait_for_response/render/no-timeout.png +0 -0
  84. package/screenshots/truth/nodes/wait_for_response/render/short-timeout.png +0 -0
  85. package/screenshots/truth/select/search-enabled.png +0 -0
  86. package/screenshots/truth/select/search-selected-focus.png +0 -0
  87. package/screenshots/truth/select/search-selected.png +0 -0
  88. package/screenshots/truth/templates/default.png +0 -0
  89. package/screenshots/truth/templates/unapproved.png +0 -0
  90. package/src/events.ts +6 -6
  91. package/src/flow/CanvasNode.ts +15 -13
  92. package/src/flow/actions/send_msg.ts +1 -0
  93. package/src/flow/nodes/split_by_groups.ts +190 -1
  94. package/src/flow/nodes/split_by_llm_categorize.ts +1 -0
  95. package/src/flow/nodes/split_by_random.ts +1 -0
  96. package/src/flow/nodes/wait_for_response.ts +424 -145
  97. package/src/form/ArrayEditor.ts +372 -30
  98. package/src/form/select/Omnibox.ts +3 -0
  99. package/src/form/select/Select.ts +24 -25
  100. package/src/list/SortableList.ts +250 -149
  101. package/src/live/ContactChat.ts +11 -5
  102. package/test/nodes/split_by_groups.test.ts +165 -0
  103. package/test/nodes/wait_for_response.test.ts +608 -8
  104. package/test/temba-field-config.test.ts +69 -0
@@ -0,0 +1,165 @@
1
+ import { expect } from '@open-wc/testing';
2
+ import { split_by_groups } from '../../src/flow/nodes/split_by_groups';
3
+ import { Node } from '../../src/store/flow-definition.d';
4
+
5
+ describe('temba-split-by-groups', () => {
6
+ it('should transform from flow definition to form data correctly', () => {
7
+ const node: Node = {
8
+ uuid: 'test-node-uuid',
9
+ actions: [],
10
+ router: {
11
+ type: 'switch',
12
+ cases: [
13
+ {
14
+ uuid: 'case-1',
15
+ type: 'has_group',
16
+ arguments: ['group-uuid-1', 'Group 1'],
17
+ category_uuid: 'cat-1'
18
+ },
19
+ {
20
+ uuid: 'case-2',
21
+ type: 'has_group',
22
+ arguments: ['group-uuid-2', 'Group 2'],
23
+ category_uuid: 'cat-2'
24
+ }
25
+ ],
26
+ categories: [
27
+ { uuid: 'cat-1', name: 'Group 1', exit_uuid: 'exit-1' },
28
+ { uuid: 'cat-2', name: 'Group 2', exit_uuid: 'exit-2' },
29
+ { uuid: 'cat-other', name: 'Other', exit_uuid: 'exit-other' }
30
+ ],
31
+ default_category_uuid: 'cat-other',
32
+ operand: '@contact.groups',
33
+ result_name: ''
34
+ },
35
+ exits: [
36
+ { uuid: 'exit-1', destination_uuid: null },
37
+ { uuid: 'exit-2', destination_uuid: null },
38
+ { uuid: 'exit-other', destination_uuid: null }
39
+ ]
40
+ };
41
+
42
+ const formData = split_by_groups.toFormData!(node);
43
+
44
+ expect(formData.uuid).to.equal('test-node-uuid');
45
+ expect(formData.groups).to.have.lengthOf(2);
46
+ expect(formData.groups[0]).to.deep.equal({
47
+ uuid: 'group-uuid-1',
48
+ name: 'Group 1'
49
+ });
50
+ expect(formData.groups[1]).to.deep.equal({
51
+ uuid: 'group-uuid-2',
52
+ name: 'Group 2'
53
+ });
54
+ });
55
+
56
+ it('should transform from form data to flow definition correctly', () => {
57
+ const originalNode: Node = {
58
+ uuid: 'test-node-uuid',
59
+ actions: [],
60
+ exits: []
61
+ };
62
+
63
+ const formData = {
64
+ uuid: 'test-node-uuid',
65
+ groups: [
66
+ { uuid: 'group-uuid-1', name: 'Group 1' },
67
+ { uuid: 'group-uuid-2', name: 'Group 2' }
68
+ ]
69
+ };
70
+
71
+ const resultNode = split_by_groups.fromFormData!(formData, originalNode);
72
+
73
+ expect(resultNode.uuid).to.equal('test-node-uuid');
74
+ expect(resultNode.router!.type).to.equal('switch');
75
+ expect(resultNode.router!.operand).to.equal('@contact.groups');
76
+ expect(resultNode.router!.cases).to.have.lengthOf(2);
77
+ expect(resultNode.router!.categories).to.have.lengthOf(3); // 2 groups + Other
78
+ expect(resultNode.exits).to.have.lengthOf(3); // 2 groups + Other
79
+
80
+ // Check first group case
81
+ const case1 = resultNode.router!.cases![0];
82
+ expect(case1.type).to.equal('has_group');
83
+ expect(case1.arguments).to.deep.equal(['group-uuid-1', 'Group 1']);
84
+
85
+ // Check that "Other" category exists
86
+ const otherCategory = resultNode.router!.categories!.find(
87
+ (cat) => cat.name === 'Other'
88
+ );
89
+ expect(otherCategory).to.exist;
90
+ expect(resultNode.router!.default_category_uuid).to.equal(
91
+ otherCategory!.uuid
92
+ );
93
+ });
94
+
95
+ it('should validate form data correctly', () => {
96
+ // Valid form data
97
+ const validData = {
98
+ groups: [{ uuid: 'group-uuid-1', name: 'Group 1' }]
99
+ };
100
+
101
+ const validResult = split_by_groups.validate!(validData);
102
+ expect(validResult.valid).to.be.true;
103
+ expect(Object.keys(validResult.errors)).to.have.lengthOf(0);
104
+
105
+ // Invalid form data - no groups
106
+ const invalidData = {
107
+ groups: []
108
+ };
109
+
110
+ const invalidResult = split_by_groups.validate!(invalidData);
111
+ expect(invalidResult.valid).to.be.false;
112
+ expect(invalidResult.errors.groups).to.equal(
113
+ 'At least one group is required'
114
+ );
115
+
116
+ // Invalid form data - missing groups
117
+ const missingGroupsData = {};
118
+
119
+ const missingResult = split_by_groups.validate!(missingGroupsData);
120
+ expect(missingResult.valid).to.be.false;
121
+ expect(missingResult.errors.groups).to.equal(
122
+ 'At least one group is required'
123
+ );
124
+ });
125
+
126
+ it('should handle arbitrary groups correctly', () => {
127
+ const originalNode: Node = {
128
+ uuid: 'test-node-uuid',
129
+ actions: [],
130
+ exits: []
131
+ };
132
+
133
+ const formData = {
134
+ uuid: 'test-node-uuid',
135
+ groups: [
136
+ { uuid: 'group-uuid-1', name: 'Existing Group' },
137
+ { name: 'New Group', arbitrary: true }
138
+ ]
139
+ };
140
+
141
+ const resultNode = split_by_groups.fromFormData!(formData, originalNode);
142
+
143
+ expect(resultNode.router!.cases).to.have.lengthOf(2);
144
+
145
+ // Check existing group
146
+ const existingGroupCase = resultNode.router!.cases!.find(
147
+ (c) => c.arguments![0] === 'group-uuid-1'
148
+ );
149
+ expect(existingGroupCase).to.exist;
150
+ expect(existingGroupCase!.arguments).to.deep.equal([
151
+ 'group-uuid-1',
152
+ 'Existing Group'
153
+ ]);
154
+
155
+ // Check arbitrary group (should have generated UUID)
156
+ const arbitraryGroupCase = resultNode.router!.cases!.find(
157
+ (c) => c.arguments![1] === 'New Group'
158
+ );
159
+ expect(arbitraryGroupCase).to.exist;
160
+ expect(arbitraryGroupCase!.arguments![0]).to.match(
161
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
162
+ );
163
+ expect(arbitraryGroupCase!.arguments![1]).to.equal('New Group');
164
+ });
165
+ });