@servicetitan/titan-chatbot-api 7.1.2 → 8.0.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 (109) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/api-client/__mocks__/chatbot-api-client.mock.js +21 -47
  3. package/dist/api-client/__mocks__/chatbot-api-client.mock.js.map +1 -1
  4. package/dist/api-client/base/chatbot-api-client.js +3 -4
  5. package/dist/api-client/base/chatbot-api-client.js.map +1 -1
  6. package/dist/api-client/help-center/__tests__/converter-from-models.test.js +48 -15
  7. package/dist/api-client/help-center/__tests__/converter-from-models.test.js.map +1 -1
  8. package/dist/api-client/help-center/__tests__/converter-to-models.test.js +23 -22
  9. package/dist/api-client/help-center/__tests__/converter-to-models.test.js.map +1 -1
  10. package/dist/api-client/help-center/chatbot-api-client.js +51 -52
  11. package/dist/api-client/help-center/chatbot-api-client.js.map +1 -1
  12. package/dist/api-client/help-center/converter-from-models.js +15 -12
  13. package/dist/api-client/help-center/converter-from-models.js.map +1 -1
  14. package/dist/api-client/help-center/converter-to-models.js +29 -26
  15. package/dist/api-client/help-center/converter-to-models.js.map +1 -1
  16. package/dist/api-client/help-center/index.d.ts +2 -1
  17. package/dist/api-client/help-center/index.d.ts.map +1 -1
  18. package/dist/api-client/help-center/index.js +1 -0
  19. package/dist/api-client/help-center/index.js.map +1 -1
  20. package/dist/api-client/help-center/native-client.js +1192 -2884
  21. package/dist/api-client/help-center/native-client.js.map +1 -1
  22. package/dist/api-client/index.d.ts +2 -1
  23. package/dist/api-client/index.d.ts.map +1 -1
  24. package/dist/api-client/index.js +14 -7
  25. package/dist/api-client/index.js.map +1 -1
  26. package/dist/api-client/models/__mocks__/models.mock.js +154 -124
  27. package/dist/api-client/models/__mocks__/models.mock.js.map +1 -1
  28. package/dist/api-client/models/index.d.ts +2 -1
  29. package/dist/api-client/models/index.d.ts.map +1 -1
  30. package/dist/api-client/models/index.js +8 -7
  31. package/dist/api-client/models/index.js.map +1 -1
  32. package/dist/api-client/titan-chat/__tests__/native-client.test.js +6 -6
  33. package/dist/api-client/titan-chat/__tests__/native-client.test.js.map +1 -1
  34. package/dist/api-client/titan-chat/chatbot-api-client.js +40 -35
  35. package/dist/api-client/titan-chat/chatbot-api-client.js.map +1 -1
  36. package/dist/api-client/titan-chat/index.d.ts +2 -1
  37. package/dist/api-client/titan-chat/index.d.ts.map +1 -1
  38. package/dist/api-client/titan-chat/index.js +1 -0
  39. package/dist/api-client/titan-chat/index.js.map +1 -1
  40. package/dist/api-client/titan-chat/native-client.js +359 -812
  41. package/dist/api-client/titan-chat/native-client.js.map +1 -1
  42. package/dist/api-client/utils/__tests__/model-utils.test.js +454 -191
  43. package/dist/api-client/utils/__tests__/model-utils.test.js.map +1 -1
  44. package/dist/api-client/utils/model-utils.d.ts.map +1 -1
  45. package/dist/api-client/utils/model-utils.js +28 -25
  46. package/dist/api-client/utils/model-utils.js.map +1 -1
  47. package/dist/hooks/use-customization-chatbot.js +2 -1
  48. package/dist/hooks/use-customization-chatbot.js.map +1 -1
  49. package/dist/index.d.ts +1 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +6 -5
  52. package/dist/index.js.map +1 -1
  53. package/dist/models/chatbot-customizations.js +2 -1
  54. package/dist/models/chatbot-customizations.js.map +1 -1
  55. package/dist/models/index.d.ts +1 -1
  56. package/dist/models/index.d.ts.map +1 -1
  57. package/dist/models/index.js +2 -1
  58. package/dist/models/index.js.map +1 -1
  59. package/dist/stores/__tests__/chatbot-ui-backend.store.test.js +267 -172
  60. package/dist/stores/__tests__/chatbot-ui-backend.store.test.js.map +1 -1
  61. package/dist/stores/__tests__/chatbot-ui.store.test.js +61 -64
  62. package/dist/stores/__tests__/chatbot-ui.store.test.js.map +1 -1
  63. package/dist/stores/__tests__/filter.store.test.js +243 -116
  64. package/dist/stores/__tests__/filter.store.test.js.map +1 -1
  65. package/dist/stores/__tests__/initialize.store.test.js +9 -8
  66. package/dist/stores/__tests__/initialize.store.test.js.map +1 -1
  67. package/dist/stores/__tests__/message-feedback-guardrail.store.test.js +8 -7
  68. package/dist/stores/__tests__/message-feedback-guardrail.store.test.js.map +1 -1
  69. package/dist/stores/__tests__/message-feedback.store.test.js +34 -27
  70. package/dist/stores/__tests__/message-feedback.store.test.js.map +1 -1
  71. package/dist/stores/__tests__/session-feedback.store.test.js +9 -8
  72. package/dist/stores/__tests__/session-feedback.store.test.js.map +1 -1
  73. package/dist/stores/chatbot-ui-backend.store.js +171 -240
  74. package/dist/stores/chatbot-ui-backend.store.js.map +1 -1
  75. package/dist/stores/chatbot-ui.store.js +73 -46
  76. package/dist/stores/chatbot-ui.store.js.map +1 -1
  77. package/dist/stores/filter.store.js +298 -378
  78. package/dist/stores/filter.store.js.map +1 -1
  79. package/dist/stores/index.d.ts +5 -3
  80. package/dist/stores/index.d.ts.map +1 -1
  81. package/dist/stores/index.js +3 -2
  82. package/dist/stores/index.js.map +1 -1
  83. package/dist/stores/initialize.store.js +55 -51
  84. package/dist/stores/initialize.store.js.map +1 -1
  85. package/dist/stores/message-feedback-base.store.js +2 -1
  86. package/dist/stores/message-feedback-base.store.js.map +1 -1
  87. package/dist/stores/message-feedback-guardrail.store.js +50 -47
  88. package/dist/stores/message-feedback-guardrail.store.js.map +1 -1
  89. package/dist/stores/message-feedback.store.js +84 -89
  90. package/dist/stores/message-feedback.store.js.map +1 -1
  91. package/dist/stores/session-feedback.store.js +46 -39
  92. package/dist/stores/session-feedback.store.js.map +1 -1
  93. package/dist/utils/__tests__/axios-utils.test.js +8 -7
  94. package/dist/utils/__tests__/axios-utils.test.js.map +1 -1
  95. package/dist/utils/axios-utils.js +9 -7
  96. package/dist/utils/axios-utils.js.map +1 -1
  97. package/dist/utils/test-utils.js +5 -5
  98. package/dist/utils/test-utils.js.map +1 -1
  99. package/package.json +3 -3
  100. package/src/api-client/help-center/index.ts +2 -1
  101. package/src/api-client/help-center/native-client.ts +4 -4
  102. package/src/api-client/index.ts +2 -6
  103. package/src/api-client/models/index.ts +15 -13
  104. package/src/api-client/titan-chat/index.ts +2 -1
  105. package/src/api-client/utils/model-utils.ts +4 -8
  106. package/src/index.ts +1 -1
  107. package/src/models/index.ts +1 -1
  108. package/src/stores/index.ts +5 -12
  109. package/tsconfig.tsbuildinfo +1 -1
@@ -1,443 +1,363 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _ts_decorate(decorators, target, key, desc) {
2
15
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
16
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
18
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
19
+ }
20
+ function _ts_metadata(k, v) {
8
21
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
22
+ }
10
23
  import cloneDeep from 'lodash/cloneDeep';
11
24
  import { action, makeObservable, observable } from 'mobx';
12
25
  import { nanoid } from 'nanoid';
13
26
  import { Models, ModelsUtils } from '../api-client';
27
+ import { FilterDefaultSelectionFn } from '../models/chatbot-customizations';
14
28
  export class FilterStore {
15
- constructor() {
29
+ initFilters(model, options) {
30
+ var _ref;
31
+ var _model_options_subOptions;
32
+ this.originalFilters = cloneDeep((_ref = model === null || model === void 0 ? void 0 : (_model_options_subOptions = model.options.subOptions) === null || _model_options_subOptions === void 0 ? void 0 : _model_options_subOptions.filter((x)=>x.type === Models.OptionType.Group)) !== null && _ref !== void 0 ? _ref : []);
33
+ this.initLocalFilters(this.originalFilters);
34
+ this.applyDefaultSelections(options === null || options === void 0 ? void 0 : options.isDefaultSelected);
35
+ }
36
+ export() {
37
+ return ModelsUtils.createSelectionsModel(this.originalFilters, this.selected);
38
+ }
39
+ /**
40
+ * Applies default selections based on the provided customization function.
41
+ * Iterates through all filters and their options, selecting those where
42
+ * isDefaultSelected returns true.
43
+ */ applyDefaultSelections(isDefaultSelected) {
44
+ if (!isDefaultSelected) {
45
+ return;
46
+ }
47
+ for (const filter of this.filters){
48
+ const filterOptions = this.getFilterOptions(filter.key);
49
+ for (const option of filterOptions){
50
+ if (isDefaultSelected(filter.key, option.key)) {
51
+ this.selectOption(filter.key, option.key);
52
+ }
53
+ }
54
+ }
55
+ }
56
+ constructor(){
16
57
  /**
17
- * Selected items map: filter key -> selectable keys
18
- */
19
- Object.defineProperty(this, "selected", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: new Map()
24
- });
58
+ * Selected items map: filter key -> selectable keys
59
+ */ _define_property(this, "selected", new Map());
25
60
  /**
26
- * Available filters with their selectable options (flattened and merged)
27
- */
28
- Object.defineProperty(this, "filters", {
29
- enumerable: true,
30
- configurable: true,
31
- writable: true,
32
- value: []
33
- });
34
- Object.defineProperty(this, "localFilters", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: []
39
- });
40
- Object.defineProperty(this, "originalFilters", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: []
45
- });
46
- Object.defineProperty(this, "mapUidToOption", {
47
- enumerable: true,
48
- configurable: true,
49
- writable: true,
50
- value: new Map()
51
- });
52
- Object.defineProperty(this, "mapUidToParentUid", {
53
- enumerable: true,
54
- configurable: true,
55
- writable: true,
56
- value: new Map()
57
- });
58
- Object.defineProperty(this, "isOptionChecked", {
59
- enumerable: true,
60
- configurable: true,
61
- writable: true,
62
- value: (filterKey, optionKey) => {
63
- const selectedOptions = this.selected.get(filterKey);
64
- if (!selectedOptions) {
65
- return false;
66
- }
67
- return selectedOptions.includes(optionKey);
61
+ * Available filters with their selectable options (flattened and merged)
62
+ */ _define_property(this, "filters", []);
63
+ _define_property(this, "localFilters", []);
64
+ _define_property(this, "originalFilters", []);
65
+ _define_property(this, "mapUidToOption", new Map());
66
+ _define_property(this, "mapUidToParentUid", new Map());
67
+ _define_property(this, "isOptionChecked", (filterKey, optionKey)=>{
68
+ const selectedOptions = this.selected.get(filterKey);
69
+ if (!selectedOptions) {
70
+ return false;
68
71
  }
72
+ return selectedOptions.includes(optionKey);
69
73
  });
70
- Object.defineProperty(this, "isOptionDisabled", {
71
- enumerable: true,
72
- configurable: true,
73
- writable: true,
74
- value: (filterKey, optionKey) => {
75
- var _a, _b;
76
- const filter = this.getFilterByKey(filterKey);
77
- const option = (_a = filter === null || filter === void 0 ? void 0 : filter.subOptions) === null || _a === void 0 ? void 0 : _a.find(o => o.key === optionKey);
78
- if (!option) {
74
+ _define_property(this, "isOptionDisabled", (filterKey, optionKey)=>{
75
+ var _filter_subOptions;
76
+ const filter = this.getFilterByKey(filterKey);
77
+ const option = filter === null || filter === void 0 ? void 0 : (_filter_subOptions = filter.subOptions) === null || _filter_subOptions === void 0 ? void 0 : _filter_subOptions.find((o)=>o.key === optionKey);
78
+ if (!option) {
79
+ return false;
80
+ }
81
+ // check any parent selectable is selected
82
+ for (const optionFilter of option.parentUids.map((uid)=>this.mapUidToOption.get(uid)).filter(Boolean)){
83
+ var _optionFilter_parentUids;
84
+ if (!(optionFilter === null || optionFilter === void 0 ? void 0 : (_optionFilter_parentUids = optionFilter.parentUids) === null || _optionFilter_parentUids === void 0 ? void 0 : _optionFilter_parentUids.length)) {
85
+ // no parent -> root filter -> so not disabled
79
86
  return false;
80
87
  }
81
- // check any parent selectable is selected
82
- for (const optionFilter of option.parentUids
83
- .map(uid => this.mapUidToOption.get(uid))
84
- .filter(Boolean)) {
85
- if (!((_b = optionFilter === null || optionFilter === void 0 ? void 0 : optionFilter.parentUids) === null || _b === void 0 ? void 0 : _b.length)) {
86
- // no parent -> root filter -> so not disabled
87
- return false;
88
+ // Check all parent filters
89
+ for (const parentUid of optionFilter.parentUids){
90
+ const parentOption = this.mapUidToOption.get(parentUid);
91
+ if (!parentOption) {
92
+ continue;
88
93
  }
89
- // Check all parent filters
90
- for (const parentUid of optionFilter.parentUids) {
91
- const parentOption = this.mapUidToOption.get(parentUid);
92
- if (!parentOption) {
93
- continue;
94
- }
95
- const parentFilter = this.getOptionFilter(parentOption);
96
- if (!parentFilter) {
97
- continue;
98
- }
99
- const isParentSelected = this.isOptionChecked(parentFilter.key, parentOption.key);
100
- if (isParentSelected) {
101
- return false;
102
- }
94
+ const parentFilter = this.getOptionFilter(parentOption);
95
+ if (!parentFilter) {
96
+ continue;
97
+ }
98
+ const isParentSelected = this.isOptionChecked(parentFilter.key, parentOption.key);
99
+ if (isParentSelected) {
100
+ return false;
103
101
  }
104
102
  }
105
- return true;
106
103
  }
104
+ return true;
107
105
  });
108
- Object.defineProperty(this, "getFilterOptions", {
109
- enumerable: true,
110
- configurable: true,
111
- writable: true,
112
- value: (filterKey) => {
113
- const filter = this.getFilterByKey(filterKey);
114
- if (!(filter === null || filter === void 0 ? void 0 : filter.subOptions)) {
115
- return [];
116
- }
117
- return filter.subOptions.filter(x => x.type === Models.OptionType.Selectable);
106
+ _define_property(this, "getFilterOptions", (filterKey)=>{
107
+ const filter = this.getFilterByKey(filterKey);
108
+ if (!(filter === null || filter === void 0 ? void 0 : filter.subOptions)) {
109
+ return [];
118
110
  }
111
+ return filter.subOptions.filter((x)=>x.type === Models.OptionType.Selectable);
119
112
  });
120
- Object.defineProperty(this, "selectOption", {
121
- enumerable: true,
122
- configurable: true,
123
- writable: true,
124
- value: (filterKey, optionKey) => {
125
- this.assertFilterKeyExists(filterKey);
126
- this.assertOptionKeyExists(filterKey, optionKey);
127
- if (!this.selected.has(filterKey)) {
128
- this.selected.set(filterKey, []);
129
- }
130
- const selectedOptions = this.selected.get(filterKey);
131
- if (selectedOptions.includes(optionKey)) {
132
- return;
133
- }
134
- this.selected.set(filterKey, [...selectedOptions, optionKey]);
113
+ _define_property(this, "selectOption", (filterKey, optionKey)=>{
114
+ this.assertFilterKeyExists(filterKey);
115
+ this.assertOptionKeyExists(filterKey, optionKey);
116
+ if (!this.selected.has(filterKey)) {
117
+ this.selected.set(filterKey, []);
135
118
  }
136
- });
137
- Object.defineProperty(this, "selectAll", {
138
- enumerable: true,
139
- configurable: true,
140
- writable: true,
141
- value: (filterKey) => {
142
- this.assertFilterKeyExists(filterKey);
143
- const filter = this.getFilterByKey(filterKey);
144
- if (!(filter === null || filter === void 0 ? void 0 : filter.subOptions)) {
145
- return;
146
- }
147
- const selectableOptions = filter.subOptions.filter(x => x.type === Models.OptionType.Selectable);
148
- this.selected.set(filterKey, selectableOptions.map(o => o.key));
119
+ const selectedOptions = this.selected.get(filterKey);
120
+ if (selectedOptions.includes(optionKey)) {
121
+ return;
149
122
  }
123
+ this.selected.set(filterKey, [
124
+ ...selectedOptions,
125
+ optionKey
126
+ ]);
150
127
  });
151
- Object.defineProperty(this, "deselectOption", {
152
- enumerable: true,
153
- configurable: true,
154
- writable: true,
155
- value: (filterKey, optionKey) => {
156
- var _a;
157
- this.assertFilterKeyExists(filterKey);
158
- this.assertOptionKeyExists(filterKey, optionKey);
159
- const selectedOptions = (_a = this.selected.get(filterKey)) !== null && _a !== void 0 ? _a : [];
160
- this.selected.set(filterKey, selectedOptions.filter(o => o !== optionKey));
161
- this.uncheckDisabledOptions();
128
+ _define_property(this, "selectAll", (filterKey)=>{
129
+ this.assertFilterKeyExists(filterKey);
130
+ const filter = this.getFilterByKey(filterKey);
131
+ if (!(filter === null || filter === void 0 ? void 0 : filter.subOptions)) {
132
+ return;
162
133
  }
134
+ const selectableOptions = filter.subOptions.filter((x)=>x.type === Models.OptionType.Selectable);
135
+ this.selected.set(filterKey, selectableOptions.map((o)=>o.key));
163
136
  });
164
- Object.defineProperty(this, "deselectAll", {
165
- enumerable: true,
166
- configurable: true,
167
- writable: true,
168
- value: (filterKey) => {
169
- this.assertFilterKeyExists(filterKey);
170
- this.selected.set(filterKey, []);
171
- this.uncheckDisabledOptions();
172
- }
137
+ _define_property(this, "deselectOption", (filterKey, optionKey)=>{
138
+ var _this_selected_get;
139
+ this.assertFilterKeyExists(filterKey);
140
+ this.assertOptionKeyExists(filterKey, optionKey);
141
+ const selectedOptions = (_this_selected_get = this.selected.get(filterKey)) !== null && _this_selected_get !== void 0 ? _this_selected_get : [];
142
+ this.selected.set(filterKey, selectedOptions.filter((o)=>o !== optionKey));
143
+ this.uncheckDisabledOptions();
173
144
  });
174
- Object.defineProperty(this, "getFilterLabel", {
175
- enumerable: true,
176
- configurable: true,
177
- writable: true,
178
- value: (key) => {
179
- // transform camel case key to human-readable label
180
- const normalizedKey = key.trim().replace(/\s+/g, ' ');
181
- // Now transform camel case to human-readable label
182
- return normalizedKey.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/^./, function (str) {
183
- return str.toUpperCase();
184
- });
185
- }
145
+ _define_property(this, "deselectAll", (filterKey)=>{
146
+ this.assertFilterKeyExists(filterKey);
147
+ this.selected.set(filterKey, []);
148
+ this.uncheckDisabledOptions();
186
149
  });
187
- Object.defineProperty(this, "assertFilterKeyExists", {
188
- enumerable: true,
189
- configurable: true,
190
- writable: true,
191
- value: (filterKey) => {
192
- const filter = this.getFilterByKey(filterKey);
193
- if (!filter) {
194
- throw new Error(`Filter with key "${filterKey}" does not exist.`);
195
- }
196
- }
150
+ _define_property(this, "getFilterLabel", (key)=>{
151
+ // transform camel case key to human-readable label
152
+ const normalizedKey = key.trim().replace(/\s+/g, ' ');
153
+ // Now transform camel case to human-readable label
154
+ return normalizedKey.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/^./, function(str) {
155
+ return str.toUpperCase();
156
+ });
197
157
  });
198
- Object.defineProperty(this, "assertOptionKeyExists", {
199
- enumerable: true,
200
- configurable: true,
201
- writable: true,
202
- value: (filterKey, optionKey) => {
203
- var _a;
204
- this.assertFilterKeyExists(filterKey);
205
- const filter = this.getFilterByKey(filterKey);
206
- const option = (_a = filter.subOptions) === null || _a === void 0 ? void 0 : _a.find(o => o.key === optionKey);
207
- if (!option) {
208
- throw new Error(`Option with key "${optionKey}" does not exist in filter "${filterKey}".`);
209
- }
158
+ _define_property(this, "assertFilterKeyExists", (filterKey)=>{
159
+ const filter = this.getFilterByKey(filterKey);
160
+ if (!filter) {
161
+ throw new Error(`Filter with key "${filterKey}" does not exist.`);
210
162
  }
211
163
  });
212
- Object.defineProperty(this, "getFilterByKey", {
213
- enumerable: true,
214
- configurable: true,
215
- writable: true,
216
- value: (filterKey) => {
217
- return this.filters.find(f => f.key === filterKey);
164
+ _define_property(this, "assertOptionKeyExists", (filterKey, optionKey)=>{
165
+ var _filter_subOptions;
166
+ this.assertFilterKeyExists(filterKey);
167
+ const filter = this.getFilterByKey(filterKey);
168
+ const option = (_filter_subOptions = filter.subOptions) === null || _filter_subOptions === void 0 ? void 0 : _filter_subOptions.find((o)=>o.key === optionKey);
169
+ if (!option) {
170
+ throw new Error(`Option with key "${optionKey}" does not exist in filter "${filterKey}".`);
218
171
  }
219
172
  });
220
- Object.defineProperty(this, "getOptionFilter", {
221
- enumerable: true,
222
- configurable: true,
223
- writable: true,
224
- value: (option) => {
225
- const parentUid = this.mapUidToParentUid.get(option.uid);
226
- if (!parentUid) {
227
- return undefined;
228
- }
229
- return this.mapUidToOption.get(parentUid);
173
+ _define_property(this, "getFilterByKey", (filterKey)=>{
174
+ return this.filters.find((f)=>f.key === filterKey);
175
+ });
176
+ _define_property(this, "getOptionFilter", (option)=>{
177
+ const parentUid = this.mapUidToParentUid.get(option.uid);
178
+ if (!parentUid) {
179
+ return undefined;
230
180
  }
181
+ return this.mapUidToOption.get(parentUid);
231
182
  });
232
- Object.defineProperty(this, "uncheckDisabledOptions", {
233
- enumerable: true,
234
- configurable: true,
235
- writable: true,
236
- value: () => {
237
- for (const [filterKey, selectedOptions] of this.selected.entries()) {
238
- const filter = this.getFilterByKey(filterKey);
239
- if (!filter) {
240
- continue;
241
- }
242
- const validSelectedOptions = selectedOptions.filter(optionKey => {
243
- var _a;
244
- const option = (_a = filter.subOptions) === null || _a === void 0 ? void 0 : _a.find(o => o.key === optionKey);
245
- if (!option) {
246
- return false;
247
- }
248
- return !this.isOptionDisabled(filterKey, optionKey);
249
- });
250
- this.selected.set(filterKey, validSelectedOptions);
183
+ _define_property(this, "uncheckDisabledOptions", ()=>{
184
+ for (const [filterKey, selectedOptions] of this.selected.entries()){
185
+ const filter = this.getFilterByKey(filterKey);
186
+ if (!filter) {
187
+ continue;
251
188
  }
189
+ const validSelectedOptions = selectedOptions.filter((optionKey)=>{
190
+ var _filter_subOptions;
191
+ const option = (_filter_subOptions = filter.subOptions) === null || _filter_subOptions === void 0 ? void 0 : _filter_subOptions.find((o)=>o.key === optionKey);
192
+ if (!option) {
193
+ return false;
194
+ }
195
+ return !this.isOptionDisabled(filterKey, optionKey);
196
+ });
197
+ this.selected.set(filterKey, validSelectedOptions);
252
198
  }
253
199
  });
254
200
  /**
255
- * Sets unique IDs (uids) for each option and builds a parent options map that tracks parent-child relationships.
256
- * @param options The list of options to process (recursive).
257
- */
258
- Object.defineProperty(this, "initLocalFilters", {
259
- enumerable: true,
260
- configurable: true,
261
- writable: true,
262
- value: (options) => {
263
- // Set up local filters uids
264
- this.localFilters = cloneDeep(options);
265
- const setUids = (o, parentUid) => {
266
- if (!o) {
267
- return;
268
- }
269
- o.forEach(x => {
270
- x.uid = nanoid();
271
- x.parentUids = parentUid ? [parentUid] : [];
272
- setUids(x.subOptions, x.uid);
273
- });
274
- };
275
- setUids(this.localFilters);
276
- this.initLocalUiFilters(this.localFilters);
277
- }
201
+ * Sets unique IDs (uids) for each option and builds a parent options map that tracks parent-child relationships.
202
+ * @param options The list of options to process (recursive).
203
+ */ _define_property(this, "initLocalFilters", (options)=>{
204
+ // Set up local filters uids
205
+ this.localFilters = cloneDeep(options);
206
+ const setUids = (o, parentUid)=>{
207
+ if (!o) {
208
+ return;
209
+ }
210
+ o.forEach((x)=>{
211
+ x.uid = nanoid();
212
+ x.parentUids = parentUid ? [
213
+ parentUid
214
+ ] : [];
215
+ setUids(x.subOptions, x.uid);
216
+ });
217
+ };
218
+ setUids(this.localFilters);
219
+ this.initLocalUiFilters(this.localFilters);
278
220
  });
279
221
  /**
280
- * Go through local filters and set up UI objects that will be rendered: filters and filter selectables
281
- */
282
- Object.defineProperty(this, "initLocalUiFilters", {
283
- enumerable: true,
284
- configurable: true,
285
- writable: true,
286
- value: (options) => {
287
- this.mapUidToOption = new Map();
288
- this.mapUidToParentUid = new Map();
289
- const filtersKeyToFilter = new Map();
290
- // Function to merge duplicate selectable options by key
291
- const mergeDuplicates = (options) => {
292
- // Merge selectables with the same keys. Original uids will be stored in "parentUids"
293
- const keyToOption = new Map();
294
- for (const option of options) {
295
- if (option.type !== Models.OptionType.Selectable) {
296
- continue;
297
- }
298
- if (!keyToOption.has(option.key)) {
299
- keyToOption.set(option.key, {
300
- uid: option.uid,
301
- parentUids: [],
302
- key: option.key,
303
- displayName: option.displayName,
304
- type: option.type,
305
- subOptions: [],
306
- });
307
- }
308
- const existingOption = keyToOption.get(option.key);
309
- existingOption.parentUids = [...existingOption.parentUids, ...option.parentUids];
310
- }
311
- return Array.from(keyToOption.values());
312
- };
313
- // Recursive flattening function
314
- const flatten = (curr, parent) => {
315
- var _a, _b, _c, _d;
316
- // Skip empty objects and none types
317
- if (!curr || curr.type === Models.OptionType.None) {
318
- return;
319
- }
320
- // Map uid to parent uid
321
- if (parent) {
322
- this.mapUidToParentUid.set(curr.uid, parent.uid);
323
- }
324
- // Process selectable
325
- if (curr.type === Models.OptionType.Selectable) {
326
- const newOption = {
327
- uid: curr.uid,
328
- parentUids: parent ? [parent.uid] : [],
329
- key: curr.key,
330
- displayName: curr.displayName,
331
- type: curr.type,
332
- };
333
- this.mapUidToOption.set(newOption.uid, newOption);
334
- const optionFilter = filtersKeyToFilter.get(parent.key);
335
- optionFilter.subOptions = [...((_a = optionFilter.subOptions) !== null && _a !== void 0 ? _a : []), newOption];
336
- // Go into subfilters
337
- for (const subOption of (_b = curr.subOptions) !== null && _b !== void 0 ? _b : []) {
338
- flatten(subOption, newOption);
339
- }
340
- return;
341
- }
342
- // Process filter
343
- if (!filtersKeyToFilter.has(curr.key)) {
344
- const newFilter = {
345
- uid: curr.uid,
346
- parentUids: parent ? [parent.uid] : [],
347
- key: curr.key,
348
- type: curr.type,
349
- displayName: curr.displayName,
350
- subOptions: [],
351
- };
352
- filtersKeyToFilter.set(curr.key, newFilter);
222
+ * Go through local filters and set up UI objects that will be rendered: filters and filter selectables
223
+ */ _define_property(this, "initLocalUiFilters", (options)=>{
224
+ this.mapUidToOption = new Map();
225
+ this.mapUidToParentUid = new Map();
226
+ const filtersKeyToFilter = new Map();
227
+ // Function to merge duplicate selectable options by key
228
+ const mergeDuplicates = (options)=>{
229
+ // Merge selectables with the same keys. Original uids will be stored in "parentUids"
230
+ const keyToOption = new Map();
231
+ for (const option of options){
232
+ if (option.type !== Models.OptionType.Selectable) {
233
+ continue;
353
234
  }
354
- const filter = filtersKeyToFilter.get(curr.key);
355
- this.mapUidToOption.set(curr.uid, curr);
356
- for (const subOption of (_c = curr.subOptions) !== null && _c !== void 0 ? _c : []) {
357
- flatten(subOption, curr);
235
+ if (!keyToOption.has(option.key)) {
236
+ keyToOption.set(option.key, {
237
+ uid: option.uid,
238
+ parentUids: [],
239
+ key: option.key,
240
+ displayName: option.displayName,
241
+ type: option.type,
242
+ subOptions: []
243
+ });
358
244
  }
359
- if ((_d = filter.subOptions) === null || _d === void 0 ? void 0 : _d.length) {
360
- filter.subOptions = mergeDuplicates(filter.subOptions);
245
+ const existingOption = keyToOption.get(option.key);
246
+ existingOption.parentUids = [
247
+ ...existingOption.parentUids,
248
+ ...option.parentUids
249
+ ];
250
+ }
251
+ return Array.from(keyToOption.values());
252
+ };
253
+ // Recursive flattening function
254
+ const flatten = (curr, parent)=>{
255
+ var _curr_subOptions;
256
+ var _filter_subOptions;
257
+ // Skip empty objects and none types
258
+ if (!curr || curr.type === Models.OptionType.None) {
259
+ return;
260
+ }
261
+ // Map uid to parent uid
262
+ if (parent) {
263
+ this.mapUidToParentUid.set(curr.uid, parent.uid);
264
+ }
265
+ // Process selectable
266
+ if (curr.type === Models.OptionType.Selectable) {
267
+ var _optionFilter_subOptions, _curr_subOptions1;
268
+ const newOption = {
269
+ uid: curr.uid,
270
+ parentUids: parent ? [
271
+ parent.uid
272
+ ] : [],
273
+ key: curr.key,
274
+ displayName: curr.displayName,
275
+ type: curr.type
276
+ };
277
+ this.mapUidToOption.set(newOption.uid, newOption);
278
+ const optionFilter = filtersKeyToFilter.get(parent.key);
279
+ optionFilter.subOptions = [
280
+ ...(_optionFilter_subOptions = optionFilter.subOptions) !== null && _optionFilter_subOptions !== void 0 ? _optionFilter_subOptions : [],
281
+ newOption
282
+ ];
283
+ // Go into subfilters
284
+ for (const subOption of (_curr_subOptions1 = curr.subOptions) !== null && _curr_subOptions1 !== void 0 ? _curr_subOptions1 : []){
285
+ flatten(subOption, newOption);
361
286
  }
362
- };
363
- for (const option of options) {
364
- flatten(option);
287
+ return;
288
+ }
289
+ // Process filter
290
+ if (!filtersKeyToFilter.has(curr.key)) {
291
+ const newFilter = {
292
+ uid: curr.uid,
293
+ parentUids: parent ? [
294
+ parent.uid
295
+ ] : [],
296
+ key: curr.key,
297
+ type: curr.type,
298
+ displayName: curr.displayName,
299
+ subOptions: []
300
+ };
301
+ filtersKeyToFilter.set(curr.key, newFilter);
365
302
  }
366
- this.filters = Array.from(filtersKeyToFilter.values());
303
+ const filter = filtersKeyToFilter.get(curr.key);
304
+ this.mapUidToOption.set(curr.uid, curr);
305
+ for (const subOption of (_curr_subOptions = curr.subOptions) !== null && _curr_subOptions !== void 0 ? _curr_subOptions : []){
306
+ flatten(subOption, curr);
307
+ }
308
+ if ((_filter_subOptions = filter.subOptions) === null || _filter_subOptions === void 0 ? void 0 : _filter_subOptions.length) {
309
+ filter.subOptions = mergeDuplicates(filter.subOptions);
310
+ }
311
+ };
312
+ for (const option of options){
313
+ flatten(option);
367
314
  }
315
+ this.filters = Array.from(filtersKeyToFilter.values());
368
316
  });
369
317
  makeObservable(this);
370
318
  }
371
- initFilters(model, options) {
372
- var _a, _b;
373
- this.originalFilters = cloneDeep((_b = (_a = model === null || model === void 0 ? void 0 : model.options.subOptions) === null || _a === void 0 ? void 0 : _a.filter(x => x.type === Models.OptionType.Group)) !== null && _b !== void 0 ? _b : []);
374
- this.initLocalFilters(this.originalFilters);
375
- this.applyDefaultSelections(options === null || options === void 0 ? void 0 : options.isDefaultSelected);
376
- }
377
- export() {
378
- return ModelsUtils.createSelectionsModel(this.originalFilters, this.selected);
379
- }
380
- /**
381
- * Applies default selections based on the provided customization function.
382
- * Iterates through all filters and their options, selecting those where
383
- * isDefaultSelected returns true.
384
- */
385
- applyDefaultSelections(isDefaultSelected) {
386
- if (!isDefaultSelected) {
387
- return;
388
- }
389
- for (const filter of this.filters) {
390
- const filterOptions = this.getFilterOptions(filter.key);
391
- for (const option of filterOptions) {
392
- if (isDefaultSelected(filter.key, option.key)) {
393
- this.selectOption(filter.key, option.key);
394
- }
395
- }
396
- }
397
- }
398
319
  }
399
- __decorate([
400
- observable,
401
- __metadata("design:type", Object)
320
+ _ts_decorate([
321
+ observable
402
322
  ], FilterStore.prototype, "selected", void 0);
403
- __decorate([
323
+ _ts_decorate([
404
324
  observable,
405
- __metadata("design:type", Array)
325
+ _ts_metadata("design:type", Array)
406
326
  ], FilterStore.prototype, "filters", void 0);
407
- __decorate([
327
+ _ts_decorate([
408
328
  action,
409
- __metadata("design:type", Function),
410
- __metadata("design:paramtypes", [Object, Object]),
411
- __metadata("design:returntype", void 0)
329
+ _ts_metadata("design:type", Function),
330
+ _ts_metadata("design:paramtypes", [
331
+ typeof Models === "undefined" || typeof Models.IFrontendModel === "undefined" ? Object : Models.IFrontendModel,
332
+ typeof IFilterStoreInitOptions === "undefined" ? Object : IFilterStoreInitOptions
333
+ ]),
334
+ _ts_metadata("design:returntype", void 0)
412
335
  ], FilterStore.prototype, "initFilters", null);
413
- __decorate([
414
- action,
415
- __metadata("design:type", Object)
336
+ _ts_decorate([
337
+ action
416
338
  ], FilterStore.prototype, "selectOption", void 0);
417
- __decorate([
418
- action,
419
- __metadata("design:type", Object)
339
+ _ts_decorate([
340
+ action
420
341
  ], FilterStore.prototype, "selectAll", void 0);
421
- __decorate([
422
- action,
423
- __metadata("design:type", Object)
342
+ _ts_decorate([
343
+ action
424
344
  ], FilterStore.prototype, "deselectOption", void 0);
425
- __decorate([
426
- action,
427
- __metadata("design:type", Object)
345
+ _ts_decorate([
346
+ action
428
347
  ], FilterStore.prototype, "deselectAll", void 0);
429
- __decorate([
348
+ _ts_decorate([
430
349
  action,
431
- __metadata("design:type", Function),
432
- __metadata("design:paramtypes", [Function]),
433
- __metadata("design:returntype", void 0)
350
+ _ts_metadata("design:type", Function),
351
+ _ts_metadata("design:paramtypes", [
352
+ typeof FilterDefaultSelectionFn === "undefined" ? Object : FilterDefaultSelectionFn
353
+ ]),
354
+ _ts_metadata("design:returntype", void 0)
434
355
  ], FilterStore.prototype, "applyDefaultSelections", null);
435
- __decorate([
436
- action,
437
- __metadata("design:type", Object)
356
+ _ts_decorate([
357
+ action
438
358
  ], FilterStore.prototype, "uncheckDisabledOptions", void 0);
439
- __decorate([
440
- action,
441
- __metadata("design:type", Object)
359
+ _ts_decorate([
360
+ action
442
361
  ], FilterStore.prototype, "initLocalUiFilters", void 0);
362
+
443
363
  //# sourceMappingURL=filter.store.js.map