@servicetitan/titan-chatbot-api 7.1.1 → 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.
- package/CHANGELOG.md +25 -0
- package/dist/api-client/__mocks__/chatbot-api-client.mock.js +21 -47
- package/dist/api-client/__mocks__/chatbot-api-client.mock.js.map +1 -1
- package/dist/api-client/base/chatbot-api-client.js +3 -4
- package/dist/api-client/base/chatbot-api-client.js.map +1 -1
- package/dist/api-client/help-center/__tests__/converter-from-models.test.js +48 -15
- package/dist/api-client/help-center/__tests__/converter-from-models.test.js.map +1 -1
- package/dist/api-client/help-center/__tests__/converter-to-models.test.js +23 -22
- package/dist/api-client/help-center/__tests__/converter-to-models.test.js.map +1 -1
- package/dist/api-client/help-center/chatbot-api-client.js +51 -52
- package/dist/api-client/help-center/chatbot-api-client.js.map +1 -1
- package/dist/api-client/help-center/converter-from-models.js +15 -12
- package/dist/api-client/help-center/converter-from-models.js.map +1 -1
- package/dist/api-client/help-center/converter-to-models.js +29 -26
- package/dist/api-client/help-center/converter-to-models.js.map +1 -1
- package/dist/api-client/help-center/index.d.ts +2 -1
- package/dist/api-client/help-center/index.d.ts.map +1 -1
- package/dist/api-client/help-center/index.js +1 -0
- package/dist/api-client/help-center/index.js.map +1 -1
- package/dist/api-client/help-center/native-client.js +1192 -2884
- package/dist/api-client/help-center/native-client.js.map +1 -1
- package/dist/api-client/index.d.ts +2 -1
- package/dist/api-client/index.d.ts.map +1 -1
- package/dist/api-client/index.js +14 -7
- package/dist/api-client/index.js.map +1 -1
- package/dist/api-client/models/__mocks__/models.mock.js +154 -124
- package/dist/api-client/models/__mocks__/models.mock.js.map +1 -1
- package/dist/api-client/models/index.d.ts +2 -1
- package/dist/api-client/models/index.d.ts.map +1 -1
- package/dist/api-client/models/index.js +8 -7
- package/dist/api-client/models/index.js.map +1 -1
- package/dist/api-client/titan-chat/__tests__/native-client.test.js +6 -6
- package/dist/api-client/titan-chat/__tests__/native-client.test.js.map +1 -1
- package/dist/api-client/titan-chat/chatbot-api-client.js +40 -35
- package/dist/api-client/titan-chat/chatbot-api-client.js.map +1 -1
- package/dist/api-client/titan-chat/index.d.ts +2 -1
- package/dist/api-client/titan-chat/index.d.ts.map +1 -1
- package/dist/api-client/titan-chat/index.js +1 -0
- package/dist/api-client/titan-chat/index.js.map +1 -1
- package/dist/api-client/titan-chat/native-client.d.ts +14 -14
- package/dist/api-client/titan-chat/native-client.d.ts.map +1 -1
- package/dist/api-client/titan-chat/native-client.js +359 -809
- package/dist/api-client/titan-chat/native-client.js.map +1 -1
- package/dist/api-client/utils/__tests__/model-utils.test.js +454 -191
- package/dist/api-client/utils/__tests__/model-utils.test.js.map +1 -1
- package/dist/api-client/utils/model-utils.d.ts.map +1 -1
- package/dist/api-client/utils/model-utils.js +28 -25
- package/dist/api-client/utils/model-utils.js.map +1 -1
- package/dist/hooks/use-customization-chatbot.js +2 -1
- package/dist/hooks/use-customization-chatbot.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/models/chatbot-customizations.js +2 -1
- package/dist/models/chatbot-customizations.js.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +2 -1
- package/dist/models/index.js.map +1 -1
- package/dist/stores/__tests__/chatbot-ui-backend.store.test.js +267 -172
- package/dist/stores/__tests__/chatbot-ui-backend.store.test.js.map +1 -1
- package/dist/stores/__tests__/chatbot-ui.store.test.js +61 -64
- package/dist/stores/__tests__/chatbot-ui.store.test.js.map +1 -1
- package/dist/stores/__tests__/filter.store.test.js +243 -116
- package/dist/stores/__tests__/filter.store.test.js.map +1 -1
- package/dist/stores/__tests__/initialize.store.test.js +9 -8
- package/dist/stores/__tests__/initialize.store.test.js.map +1 -1
- package/dist/stores/__tests__/message-feedback-guardrail.store.test.js +8 -7
- package/dist/stores/__tests__/message-feedback-guardrail.store.test.js.map +1 -1
- package/dist/stores/__tests__/message-feedback.store.test.js +34 -27
- package/dist/stores/__tests__/message-feedback.store.test.js.map +1 -1
- package/dist/stores/__tests__/session-feedback.store.test.js +9 -8
- package/dist/stores/__tests__/session-feedback.store.test.js.map +1 -1
- package/dist/stores/chatbot-ui-backend.store.js +171 -240
- package/dist/stores/chatbot-ui-backend.store.js.map +1 -1
- package/dist/stores/chatbot-ui.store.js +73 -46
- package/dist/stores/chatbot-ui.store.js.map +1 -1
- package/dist/stores/filter.store.js +298 -378
- package/dist/stores/filter.store.js.map +1 -1
- package/dist/stores/index.d.ts +5 -3
- package/dist/stores/index.d.ts.map +1 -1
- package/dist/stores/index.js +3 -2
- package/dist/stores/index.js.map +1 -1
- package/dist/stores/initialize.store.js +55 -51
- package/dist/stores/initialize.store.js.map +1 -1
- package/dist/stores/message-feedback-base.store.js +2 -1
- package/dist/stores/message-feedback-base.store.js.map +1 -1
- package/dist/stores/message-feedback-guardrail.store.js +50 -47
- package/dist/stores/message-feedback-guardrail.store.js.map +1 -1
- package/dist/stores/message-feedback.store.js +84 -89
- package/dist/stores/message-feedback.store.js.map +1 -1
- package/dist/stores/session-feedback.store.js +46 -39
- package/dist/stores/session-feedback.store.js.map +1 -1
- package/dist/utils/__tests__/axios-utils.test.js +8 -7
- package/dist/utils/__tests__/axios-utils.test.js.map +1 -1
- package/dist/utils/axios-utils.js +9 -7
- package/dist/utils/axios-utils.js.map +1 -1
- package/dist/utils/test-utils.js +5 -5
- package/dist/utils/test-utils.js.map +1 -1
- package/package.json +3 -3
- package/src/api-client/help-center/index.ts +2 -1
- package/src/api-client/help-center/native-client.ts +4 -4
- package/src/api-client/index.ts +2 -6
- package/src/api-client/models/index.ts +15 -13
- package/src/api-client/titan-chat/index.ts +2 -1
- package/src/api-client/titan-chat/native-client.ts +17 -14
- package/src/api-client/utils/model-utils.ts +4 -8
- package/src/index.ts +1 -1
- package/src/models/index.ts +1 -1
- package/src/stores/index.ts +5 -12
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,443 +1,363 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
//
|
|
82
|
-
for (const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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
|
-
|
|
360
|
-
|
|
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
|
-
|
|
364
|
-
|
|
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
|
-
|
|
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
|
-
|
|
400
|
-
observable
|
|
401
|
-
__metadata("design:type", Object)
|
|
320
|
+
_ts_decorate([
|
|
321
|
+
observable
|
|
402
322
|
], FilterStore.prototype, "selected", void 0);
|
|
403
|
-
|
|
323
|
+
_ts_decorate([
|
|
404
324
|
observable,
|
|
405
|
-
|
|
325
|
+
_ts_metadata("design:type", Array)
|
|
406
326
|
], FilterStore.prototype, "filters", void 0);
|
|
407
|
-
|
|
327
|
+
_ts_decorate([
|
|
408
328
|
action,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
|
|
414
|
-
action
|
|
415
|
-
__metadata("design:type", Object)
|
|
336
|
+
_ts_decorate([
|
|
337
|
+
action
|
|
416
338
|
], FilterStore.prototype, "selectOption", void 0);
|
|
417
|
-
|
|
418
|
-
action
|
|
419
|
-
__metadata("design:type", Object)
|
|
339
|
+
_ts_decorate([
|
|
340
|
+
action
|
|
420
341
|
], FilterStore.prototype, "selectAll", void 0);
|
|
421
|
-
|
|
422
|
-
action
|
|
423
|
-
__metadata("design:type", Object)
|
|
342
|
+
_ts_decorate([
|
|
343
|
+
action
|
|
424
344
|
], FilterStore.prototype, "deselectOption", void 0);
|
|
425
|
-
|
|
426
|
-
action
|
|
427
|
-
__metadata("design:type", Object)
|
|
345
|
+
_ts_decorate([
|
|
346
|
+
action
|
|
428
347
|
], FilterStore.prototype, "deselectAll", void 0);
|
|
429
|
-
|
|
348
|
+
_ts_decorate([
|
|
430
349
|
action,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
-
|
|
436
|
-
action
|
|
437
|
-
__metadata("design:type", Object)
|
|
356
|
+
_ts_decorate([
|
|
357
|
+
action
|
|
438
358
|
], FilterStore.prototype, "uncheckDisabledOptions", void 0);
|
|
439
|
-
|
|
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
|