@miso.ai/client-sdk-ui 1.11.0-beta.9 → 1.11.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/dist/cjs/actor/feedback.js +6 -39
- package/dist/cjs/actor/fields.js +14 -6
- package/dist/cjs/actor/index.js +0 -7
- package/dist/cjs/actor/interactions.js +4 -15
- package/dist/cjs/actor/sessions.js +2 -32
- package/dist/cjs/actor/tracker.js +25 -26
- package/dist/cjs/actor/utils.js +0 -49
- package/dist/cjs/actor/view.js +40 -40
- package/dist/cjs/actor/views.js +29 -8
- package/dist/cjs/constants.js +18 -19
- package/dist/cjs/defaults/hybrid-search/phrases.js +3 -3
- package/dist/cjs/defaults/hybrid-search/templates.js +22 -7
- package/dist/cjs/element/role/index.js +12 -5
- package/dist/cjs/element/role/{miso-hits.js → miso-more.js} +4 -4
- package/dist/cjs/element/role/miso-total.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +0 -3
- package/dist/cjs/layout/banner/banner.js +0 -4
- package/dist/cjs/layout/button/more-button.js +73 -0
- package/dist/cjs/layout/container/container.js +0 -3
- package/dist/cjs/layout/error/error.js +0 -4
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/facets.js +0 -4
- package/dist/cjs/layout/input/option-list.js +0 -4
- package/dist/cjs/layout/input/search-box.js +13 -12
- package/dist/cjs/layout/list/cards.js +0 -3
- package/dist/cjs/layout/list/carousel.js +0 -3
- package/dist/cjs/layout/list/collection.js +22 -7
- package/dist/cjs/layout/list/list.js +0 -3
- package/dist/cjs/layout/radio/feedback.js +0 -3
- package/dist/cjs/layout/radio/radio.js +0 -4
- package/dist/cjs/layout/raf.js +4 -2
- package/dist/cjs/layout/text/text.js +0 -4
- package/dist/cjs/layout/text/typewriter/index.js +0 -3
- package/dist/cjs/layout/triggerable.js +79 -0
- package/dist/cjs/util/states.js +0 -15
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +70 -105
- package/dist/cjs/workflow/ask.js +29 -27
- package/dist/cjs/workflow/asks.js +1 -1
- package/dist/cjs/workflow/autocompletable.js +33 -0
- package/dist/cjs/workflow/autocomplete.js +122 -0
- package/dist/cjs/workflow/base.js +156 -98
- package/dist/cjs/workflow/explore.js +48 -46
- package/dist/cjs/workflow/hybrid-search-answer.js +17 -7
- package/dist/cjs/workflow/hybrid-search-results.js +17 -87
- package/dist/cjs/workflow/hybrid-search-views.js +122 -0
- package/dist/cjs/workflow/hybrid-search.js +47 -168
- package/dist/cjs/workflow/options.js +32 -17
- package/dist/cjs/workflow/processors.js +166 -2
- package/dist/cjs/workflow/recommendation.js +36 -49
- package/dist/cjs/workflow/search-based.js +228 -0
- package/dist/cjs/workflow/search.js +21 -68
- package/dist/cjs/workflow/use-link.js +44 -0
- package/package.json +2 -2
- package/src/actor/feedback.js +6 -23
- package/src/actor/fields.js +14 -6
- package/src/actor/index.js +0 -1
- package/src/actor/interactions.js +4 -10
- package/src/actor/sessions.js +3 -31
- package/src/actor/tracker.js +25 -19
- package/src/actor/utils.js +0 -47
- package/src/actor/view.js +27 -15
- package/src/actor/views.js +32 -8
- package/src/constants.js +25 -16
- package/src/defaults/hybrid-search/phrases.js +2 -2
- package/src/defaults/hybrid-search/templates.js +17 -5
- package/src/element/role/index.js +2 -1
- package/src/element/role/{miso-hits.js → miso-more.js} +3 -3
- package/src/element/role/miso-total.js +16 -0
- package/src/layout/affiliation/affiliation.js +1 -5
- package/src/layout/banner/banner.js +0 -5
- package/src/layout/button/more-button.js +69 -0
- package/src/layout/container/container.js +1 -5
- package/src/layout/error/error.js +0 -5
- package/src/layout/index.js +2 -1
- package/src/layout/input/facets.js +0 -5
- package/src/layout/input/option-list.js +0 -5
- package/src/layout/input/search-box.js +11 -14
- package/src/layout/list/cards.js +0 -4
- package/src/layout/list/carousel.js +0 -4
- package/src/layout/list/collection.js +21 -9
- package/src/layout/list/list.js +0 -4
- package/src/layout/radio/feedback.js +0 -4
- package/src/layout/radio/radio.js +0 -5
- package/src/layout/raf.js +2 -2
- package/src/layout/text/text.js +0 -5
- package/src/layout/text/typewriter/index.js +1 -5
- package/src/layout/triggerable.js +76 -0
- package/src/util/states.js +0 -14
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +61 -72
- package/src/workflow/ask.js +30 -24
- package/src/workflow/asks.js +1 -1
- package/src/workflow/autocompletable.js +29 -0
- package/src/workflow/autocomplete.js +113 -0
- package/src/workflow/base.js +133 -87
- package/src/workflow/explore.js +38 -30
- package/src/workflow/hybrid-search-answer.js +17 -6
- package/src/workflow/hybrid-search-results.js +17 -77
- package/src/workflow/hybrid-search-views.js +124 -0
- package/src/workflow/hybrid-search.js +47 -157
- package/src/workflow/options.js +26 -11
- package/src/workflow/processors.js +151 -3
- package/src/workflow/recommendation.js +32 -33
- package/src/workflow/search-based.js +222 -0
- package/src/workflow/search.js +21 -65
- package/src/workflow/use-link.js +40 -0
- package/dist/cjs/actor/autocomplete.js +0 -160
- package/dist/cjs/workflow/utils.js +0 -42
- package/src/actor/autocomplete.js +0 -133
- package/src/workflow/utils.js +0 -29
|
@@ -3,16 +3,27 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.buildBaseInteraction = buildBaseInteraction;
|
|
7
|
+
exports.concatItemsFromMoreResponse = concatItemsFromMoreResponse;
|
|
8
|
+
exports.getRevision = getRevision;
|
|
9
|
+
exports.mergeInteraction = mergeInteraction;
|
|
10
|
+
exports.retainFacetCountsInData = retainFacetCountsInData;
|
|
11
|
+
exports.writeAffiliationInfoToInteraction = writeAffiliationInfoToInteraction;
|
|
7
12
|
exports.writeAnswerStageToMeta = writeAnswerStageToMeta;
|
|
8
13
|
exports.writeDataStatus = writeDataStatus;
|
|
14
|
+
exports.writeExhaustionToData = writeExhaustionToData;
|
|
15
|
+
exports.writeFiltersToPayload = writeFiltersToPayload;
|
|
9
16
|
exports.writeKeywordsToData = writeKeywordsToData;
|
|
10
17
|
exports.writeMisoIdToMeta = writeMisoIdToMeta;
|
|
11
18
|
var _commons = require("@miso.ai/commons");
|
|
12
19
|
var _constants = require("../constants.js");
|
|
20
|
+
// data //
|
|
21
|
+
function getRevision(data) {
|
|
22
|
+
return data && data.value && data.value.revision;
|
|
23
|
+
}
|
|
13
24
|
function writeDataStatus(data) {
|
|
14
25
|
const status = getStatus(data);
|
|
15
|
-
const ongoing = status === _constants.STATUS.READY ?
|
|
26
|
+
const ongoing = status === _constants.STATUS.READY ? data.ongoing : undefined;
|
|
16
27
|
return (0, _commons.trimObj)(Object.assign({
|
|
17
28
|
status,
|
|
18
29
|
ongoing
|
|
@@ -94,6 +105,11 @@ function writeAnswerStageToMeta(data) {
|
|
|
94
105
|
})
|
|
95
106
|
});
|
|
96
107
|
}
|
|
108
|
+
function writeFiltersToPayload() {
|
|
109
|
+
let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
110
|
+
let filters = arguments.length > 1 ? arguments[1] : undefined;
|
|
111
|
+
return (0, _commons.trimObj)(Object.assign({}, payload, composeFiltersPayload(filters)));
|
|
112
|
+
}
|
|
97
113
|
function composeFiltersPayload(filters) {
|
|
98
114
|
if (!filters) {
|
|
99
115
|
return undefined;
|
|
@@ -120,4 +136,152 @@ function composeFacetFilters(facets) {
|
|
|
120
136
|
};
|
|
121
137
|
}
|
|
122
138
|
return Object.keys(filters).length ? filters : undefined;
|
|
139
|
+
}
|
|
140
|
+
function retainFacetCountsInData(data, currentFacetCounts) {
|
|
141
|
+
if (!currentFacetCounts) {
|
|
142
|
+
return data;
|
|
143
|
+
}
|
|
144
|
+
const {
|
|
145
|
+
status,
|
|
146
|
+
value
|
|
147
|
+
} = data;
|
|
148
|
+
switch (status) {
|
|
149
|
+
case _constants.STATUS.INITIAL:
|
|
150
|
+
case _constants.STATUS.LOADING:
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
return data;
|
|
154
|
+
}
|
|
155
|
+
if (value && value.facet_counts) {
|
|
156
|
+
return data;
|
|
157
|
+
}
|
|
158
|
+
return Object.assign({}, data, {
|
|
159
|
+
value: Object.assign({}, value, {
|
|
160
|
+
facet_counts: currentFacetCounts
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function concatItemsFromMoreResponse(oldData, newData) {
|
|
165
|
+
let {
|
|
166
|
+
role = _constants.ROLE.PRODUCTS
|
|
167
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
168
|
+
if (!newData.value) {
|
|
169
|
+
return oldData;
|
|
170
|
+
}
|
|
171
|
+
const {
|
|
172
|
+
[role]: oldProducts = [],
|
|
173
|
+
facet_counts,
|
|
174
|
+
total
|
|
175
|
+
} = oldData.value;
|
|
176
|
+
const {
|
|
177
|
+
[role]: newProducts = []
|
|
178
|
+
} = newData.value;
|
|
179
|
+
// keep old exhaustion flag, just in case
|
|
180
|
+
// TODO
|
|
181
|
+
|
|
182
|
+
// use old values of facet_counts and total, for they are affected by product_id exclusion
|
|
183
|
+
return Object.assign({}, newData, {
|
|
184
|
+
facet_counts,
|
|
185
|
+
total,
|
|
186
|
+
value: Object.assign({}, newData.value, {
|
|
187
|
+
[role]: [...oldProducts, ...newProducts]
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function writeExhaustionToData(data) {
|
|
192
|
+
let {
|
|
193
|
+
role = _constants.ROLE.PRODUCTS
|
|
194
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
195
|
+
const {
|
|
196
|
+
status,
|
|
197
|
+
request,
|
|
198
|
+
value
|
|
199
|
+
} = data;
|
|
200
|
+
// keep track of the exhaustion state
|
|
201
|
+
if (status !== _constants.STATUS.READY || !request || !value) {
|
|
202
|
+
return data;
|
|
203
|
+
}
|
|
204
|
+
const {
|
|
205
|
+
[role]: items
|
|
206
|
+
} = value;
|
|
207
|
+
if (!items) {
|
|
208
|
+
return data;
|
|
209
|
+
}
|
|
210
|
+
const {
|
|
211
|
+
rows
|
|
212
|
+
} = request.payload;
|
|
213
|
+
const {
|
|
214
|
+
length
|
|
215
|
+
} = items;
|
|
216
|
+
const exhausted = length < rows;
|
|
217
|
+
if (!exhausted) {
|
|
218
|
+
return data;
|
|
219
|
+
}
|
|
220
|
+
return Object.assign({}, data, {
|
|
221
|
+
meta: Object.assign({}, data.meta, {
|
|
222
|
+
exhausted: true
|
|
223
|
+
})
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// interactions //
|
|
228
|
+
function buildBaseInteraction(args) {
|
|
229
|
+
const {
|
|
230
|
+
role,
|
|
231
|
+
type,
|
|
232
|
+
items
|
|
233
|
+
} = args;
|
|
234
|
+
const payload = {
|
|
235
|
+
type: type === 'viewable' ? 'viewable_impression' : type,
|
|
236
|
+
context: {
|
|
237
|
+
custom_context: (0, _commons.trimObj)({
|
|
238
|
+
property: role
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
if ((0, _constants.isPerformanceEventType)(type)) {
|
|
243
|
+
if ((0, _constants.isProductRole)(role)) {
|
|
244
|
+
payload.product_ids = (items || []).map(v => typeof v === 'string' ? v : v.product_id).filter(v => v);
|
|
245
|
+
} else {
|
|
246
|
+
payload.product_ids = [];
|
|
247
|
+
payload.context.custom_context.items = (items || []).map(v => v.text || v.id || v);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
switch (type) {
|
|
251
|
+
case _constants.EVENT_TYPE.SUBMIT:
|
|
252
|
+
payload.context.custom_context.value = args.value;
|
|
253
|
+
break;
|
|
254
|
+
case _constants.EVENT_TYPE.FEEDBACK:
|
|
255
|
+
payload.context.custom_context.value = payload.value = args.value;
|
|
256
|
+
payload.context.custom_context.result_type = payload.result_type = args.result_type;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
return (0, _commons.trimObj)(payload);
|
|
260
|
+
}
|
|
261
|
+
function writeAffiliationInfoToInteraction(payload, args) {
|
|
262
|
+
if (args.role !== _constants.ROLE.AFFILIATION) {
|
|
263
|
+
return payload;
|
|
264
|
+
}
|
|
265
|
+
const {
|
|
266
|
+
items
|
|
267
|
+
} = args;
|
|
268
|
+
const channel = items[0] && items[0].channel || undefined;
|
|
269
|
+
const positions = items.map(v => v.position);
|
|
270
|
+
return mergeInteraction(payload, {
|
|
271
|
+
context: {
|
|
272
|
+
custom_context: {
|
|
273
|
+
channel,
|
|
274
|
+
positions
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function mergeInteraction() {
|
|
280
|
+
let base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
281
|
+
let patch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
282
|
+
return (0, _commons.trimObj)(Object.assign({}, base, patch, {
|
|
283
|
+
context: (0, _commons.trimObj)(Object.assign({}, base.context, patch.context, {
|
|
284
|
+
custom_context: (0, _commons.trimObj)(Object.assign({}, base.context && base.context.custom_context, patch.context && patch.context.custom_context))
|
|
285
|
+
}))
|
|
286
|
+
}));
|
|
123
287
|
}
|
|
@@ -6,35 +6,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
|
-
var
|
|
10
|
-
var _index = require("../actor/index.js");
|
|
11
|
-
var _index2 = require("../layout/index.js");
|
|
9
|
+
var _index = require("../layout/index.js");
|
|
12
10
|
var _constants = require("../constants.js");
|
|
11
|
+
var _options = require("./options.js");
|
|
12
|
+
var _processors = require("./processors.js");
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
14
|
+
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
15
15
|
group: _commons.API.GROUP.RECOMMENDATION,
|
|
16
16
|
name: _commons.API.NAME.USER_TO_PRODUCTS,
|
|
17
|
-
payload: {
|
|
17
|
+
payload: Object.assign({}, _base.default.DEFAULT_API_OPTIONS.payload, {
|
|
18
18
|
fl: ['*']
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
const DEFAULT_LAYOUTS = Object.freeze({
|
|
22
|
-
[_constants.ROLE.PRODUCTS]:
|
|
23
|
-
});
|
|
24
|
-
const DEFAULT_TRACKERS = Object.freeze({
|
|
19
|
+
})
|
|
20
|
+
}));
|
|
21
|
+
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
|
|
22
|
+
[_constants.ROLE.PRODUCTS]: _index.ListLayout.type
|
|
23
|
+
}));
|
|
24
|
+
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
|
|
25
25
|
[_constants.ROLE.PRODUCTS]: {}
|
|
26
|
-
});
|
|
27
|
-
const DEFAULT_OPTIONS = Object.freeze({
|
|
26
|
+
}));
|
|
27
|
+
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
|
|
28
28
|
api: DEFAULT_API_OPTIONS,
|
|
29
29
|
layouts: DEFAULT_LAYOUTS,
|
|
30
30
|
trackers: DEFAULT_TRACKERS
|
|
31
|
+
}));
|
|
32
|
+
const ROLES_OPTIONS = (0, _options.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
33
|
+
main: _constants.ROLE.PRODUCTS,
|
|
34
|
+
members: Object.keys(DEFAULT_LAYOUTS)
|
|
31
35
|
});
|
|
32
36
|
class Recommendation extends _base.default {
|
|
33
37
|
constructor(context, id) {
|
|
34
38
|
super({
|
|
35
39
|
name: 'recommendation',
|
|
36
40
|
context,
|
|
37
|
-
roles:
|
|
41
|
+
roles: ROLES_OPTIONS,
|
|
38
42
|
defaults: DEFAULT_OPTIONS,
|
|
39
43
|
id
|
|
40
44
|
});
|
|
@@ -48,32 +52,15 @@ class Recommendation extends _base.default {
|
|
|
48
52
|
id
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
_initSession(args) {
|
|
52
56
|
this._context._members.set(args.id, this);
|
|
53
|
-
super.
|
|
57
|
+
super._initSession(args);
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
// lifecycle //
|
|
57
61
|
start() {
|
|
58
|
-
this._sessions.start();
|
|
59
62
|
// in recommendation workflow, start() triggers query
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
session
|
|
63
|
-
} = this;
|
|
64
|
-
this._hub.update(_index.fields.request(), (0, _options.mergeApiOptions)(this._options.resolved.api, {
|
|
65
|
-
session
|
|
66
|
-
}));
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// TODO: deprecate this
|
|
71
|
-
startTracker() {
|
|
72
|
-
this.useApi(false);
|
|
73
|
-
this.useLayouts(false);
|
|
74
|
-
this._sessions.start();
|
|
75
|
-
this.notifyViewUpdate(_constants.ROLE.CONTAINER);
|
|
76
|
-
this.notifyViewUpdate(_constants.ROLE.PRODUCTS);
|
|
63
|
+
this._request();
|
|
77
64
|
return this;
|
|
78
65
|
}
|
|
79
66
|
notifyViewUpdate() {
|
|
@@ -86,21 +73,21 @@ class Recommendation extends _base.default {
|
|
|
86
73
|
}
|
|
87
74
|
|
|
88
75
|
// interactions //
|
|
89
|
-
|
|
90
|
-
payload = super.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return
|
|
98
|
-
context:
|
|
99
|
-
custom_context:
|
|
100
|
-
unit_id
|
|
101
|
-
unit_instance_uuid
|
|
102
|
-
}
|
|
103
|
-
}
|
|
76
|
+
_defaultProcessInteraction(payload, args) {
|
|
77
|
+
payload = super._defaultProcessInteraction(payload, args);
|
|
78
|
+
payload = this._writeUnitIdToInteraction(payload, args);
|
|
79
|
+
return payload;
|
|
80
|
+
}
|
|
81
|
+
_writeUnitIdToInteraction(payload) {
|
|
82
|
+
const unit_id = this.id;
|
|
83
|
+
const unit_instance_uuid = this.uuid;
|
|
84
|
+
return (0, _processors.mergeInteraction)(payload, {
|
|
85
|
+
context: {
|
|
86
|
+
custom_context: {
|
|
87
|
+
unit_id,
|
|
88
|
+
unit_instance_uuid
|
|
89
|
+
}
|
|
90
|
+
}
|
|
104
91
|
});
|
|
105
92
|
}
|
|
106
93
|
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _commons = require("@miso.ai/commons");
|
|
8
|
+
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
|
+
var _index = require("../actor/index.js");
|
|
10
|
+
var _constants = require("../constants.js");
|
|
11
|
+
var _index2 = require("../layout/index.js");
|
|
12
|
+
var _processors = require("./processors.js");
|
|
13
|
+
var _options = require("./options.js");
|
|
14
|
+
const _excluded = ["filters"];
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
17
|
+
const DEFAULT_ROWS = 10;
|
|
18
|
+
const DEFAULT_PAGE_LIMIT = 10;
|
|
19
|
+
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
20
|
+
group: _commons.API.GROUP.SEARCH,
|
|
21
|
+
payload: Object.assign({}, _base.default.DEFAULT_API_OPTIONS.payload, {
|
|
22
|
+
fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at', 'title'],
|
|
23
|
+
rows: DEFAULT_ROWS
|
|
24
|
+
})
|
|
25
|
+
}));
|
|
26
|
+
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
|
|
27
|
+
[_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type],
|
|
28
|
+
[_constants.ROLE.PRODUCTS]: [_index2.ListLayout.type, {
|
|
29
|
+
incremental: true,
|
|
30
|
+
infiniteScroll: true
|
|
31
|
+
}],
|
|
32
|
+
[_constants.ROLE.KEYWORDS]: [_index2.TextLayout.type, {
|
|
33
|
+
raw: true
|
|
34
|
+
}],
|
|
35
|
+
[_constants.ROLE.TOTAL]: [_index2.TextLayout.type, {
|
|
36
|
+
raw: true,
|
|
37
|
+
format: 'number'
|
|
38
|
+
}],
|
|
39
|
+
[_constants.ROLE.FACETS]: [_index2.FacetsLayout.type],
|
|
40
|
+
[_constants.ROLE.MORE]: [_index2.MoreButtonLayout.type]
|
|
41
|
+
}));
|
|
42
|
+
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
|
|
43
|
+
[_constants.ROLE.PRODUCTS]: {}
|
|
44
|
+
}));
|
|
45
|
+
const DEFAULT_PAGINATION = Object.freeze({
|
|
46
|
+
active: false,
|
|
47
|
+
mode: 'infiniteScroll',
|
|
48
|
+
pageLimit: 10
|
|
49
|
+
});
|
|
50
|
+
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
|
|
51
|
+
api: DEFAULT_API_OPTIONS,
|
|
52
|
+
layouts: DEFAULT_LAYOUTS,
|
|
53
|
+
trackers: DEFAULT_TRACKERS,
|
|
54
|
+
pagination: DEFAULT_PAGINATION
|
|
55
|
+
}));
|
|
56
|
+
const ROLES_OPTIONS = (0, _options.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
57
|
+
main: _constants.ROLE.PRODUCTS,
|
|
58
|
+
members: Object.keys(DEFAULT_LAYOUTS),
|
|
59
|
+
mappings: {
|
|
60
|
+
[_constants.ROLE.FACETS]: 'facet_counts'
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
class SearchBasedWorkflow extends _base.default {
|
|
64
|
+
_initSubscriptions(args) {
|
|
65
|
+
super._initSubscriptions(args);
|
|
66
|
+
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args)), this._hub.on(_index.fields.filters(), filters => this._refine(filters)), this._hub.on(_index.fields.more(), () => this._more())];
|
|
67
|
+
}
|
|
68
|
+
restart() {
|
|
69
|
+
super.restart();
|
|
70
|
+
this._page = 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// properties //
|
|
74
|
+
get exhausted() {
|
|
75
|
+
const data = this._hub.states[_index.fields.data()];
|
|
76
|
+
return !!(data && data.meta && data.meta.exhausted);
|
|
77
|
+
}
|
|
78
|
+
get page() {
|
|
79
|
+
return this._page;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// query //
|
|
83
|
+
query(args) {
|
|
84
|
+
if (!args.q) {
|
|
85
|
+
throw new Error(`q is required in query() call`);
|
|
86
|
+
}
|
|
87
|
+
this._hub.update(_index.fields.query(), args);
|
|
88
|
+
}
|
|
89
|
+
_query(args) {
|
|
90
|
+
// keep track of the query args for refine and more calls
|
|
91
|
+
this._queryArgs = args;
|
|
92
|
+
|
|
93
|
+
// start a new session
|
|
94
|
+
this.restart();
|
|
95
|
+
|
|
96
|
+
// payload
|
|
97
|
+
const payload = this._buildPayload(args);
|
|
98
|
+
this._request({
|
|
99
|
+
payload
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
_refine(filters) {
|
|
103
|
+
// remember current facet_counts
|
|
104
|
+
const {
|
|
105
|
+
facet_counts
|
|
106
|
+
} = this._hub.states[_index.fields.data()].value || {};
|
|
107
|
+
this._currentFacetCounts = facet_counts;
|
|
108
|
+
|
|
109
|
+
// start a new session
|
|
110
|
+
this.restart();
|
|
111
|
+
|
|
112
|
+
// payload
|
|
113
|
+
const query = this._getQuery();
|
|
114
|
+
const payload = this._buildPayload(Object.assign({}, query, {
|
|
115
|
+
filters
|
|
116
|
+
}));
|
|
117
|
+
this._request({
|
|
118
|
+
payload
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
_more() {
|
|
122
|
+
// if still loading, complain
|
|
123
|
+
if (this.status !== _constants.STATUS.READY) {
|
|
124
|
+
throw new Error(`Can not call more() while loading.`);
|
|
125
|
+
}
|
|
126
|
+
// no more pages, ignore
|
|
127
|
+
if (this.exhausted || this._page >= DEFAULT_PAGE_LIMIT - 1) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
// don't create a new session!
|
|
131
|
+
|
|
132
|
+
this._page++;
|
|
133
|
+
|
|
134
|
+
// payload
|
|
135
|
+
const query = this._getQuery();
|
|
136
|
+
const filters = this._hub.states[_index.fields.filters()]; // get stored filters
|
|
137
|
+
let payload = this._buildPayload(Object.assign({}, query, {
|
|
138
|
+
filters
|
|
139
|
+
}));
|
|
140
|
+
payload = this._processPayloadForMoreRequest(payload);
|
|
141
|
+
this._request({
|
|
142
|
+
payload
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
_getQuery() {
|
|
146
|
+
// TODO: just get from the hub
|
|
147
|
+
return this._queryArgs;
|
|
148
|
+
}
|
|
149
|
+
_getPageSize() {
|
|
150
|
+
return this._options.resolved.api.payload.rows;
|
|
151
|
+
}
|
|
152
|
+
_buildPayload() {
|
|
153
|
+
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
154
|
+
let {
|
|
155
|
+
filters
|
|
156
|
+
} = _ref,
|
|
157
|
+
payload = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
158
|
+
payload = (0, _processors.writeFiltersToPayload)(payload, filters);
|
|
159
|
+
payload = this._writePageInfoToPayload(payload);
|
|
160
|
+
return payload;
|
|
161
|
+
}
|
|
162
|
+
_writePageInfoToPayload(payload) {
|
|
163
|
+
return Object.assign({}, payload, {
|
|
164
|
+
_meta: Object.assign({}, payload._meta, {
|
|
165
|
+
page: this._page
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
_processPayloadForMoreRequest() {
|
|
170
|
+
let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
171
|
+
const data = this._hub.states[_index.fields.data()];
|
|
172
|
+
const {
|
|
173
|
+
[this._roles.main]: items = []
|
|
174
|
+
} = data && data.value || {};
|
|
175
|
+
const productIds = items.map(item => item.product_id).filter(v => v);
|
|
176
|
+
const exclude = [...(payload.exclude || []), ...productIds];
|
|
177
|
+
if (exclude.length === 0) {
|
|
178
|
+
return payload;
|
|
179
|
+
}
|
|
180
|
+
return Object.assign({}, payload, {
|
|
181
|
+
exclude
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// data //
|
|
186
|
+
_defaultProcessData(data) {
|
|
187
|
+
data = super._defaultProcessData(data);
|
|
188
|
+
data = (0, _processors.writeKeywordsToData)(data);
|
|
189
|
+
data = (0, _processors.retainFacetCountsInData)(data, this._currentFacetCounts);
|
|
190
|
+
data = (0, _processors.writeExhaustionToData)(data, {
|
|
191
|
+
role: this._roles.main
|
|
192
|
+
});
|
|
193
|
+
return data;
|
|
194
|
+
}
|
|
195
|
+
_updateDataInHub(data) {
|
|
196
|
+
data = this._appendResultsFromMoreRequest(data);
|
|
197
|
+
super._updateDataInHub(data);
|
|
198
|
+
}
|
|
199
|
+
_appendResultsFromMoreRequest(data) {
|
|
200
|
+
const {
|
|
201
|
+
request
|
|
202
|
+
} = data;
|
|
203
|
+
if (!request) {
|
|
204
|
+
return data; // the initial state
|
|
205
|
+
}
|
|
206
|
+
const {
|
|
207
|
+
_meta
|
|
208
|
+
} = request.payload;
|
|
209
|
+
if (!_meta || !_meta.page) {
|
|
210
|
+
return data; // not from "more" request
|
|
211
|
+
}
|
|
212
|
+
// concat records if it's from "more" request
|
|
213
|
+
const currentData = this._hub.states[_index.fields.data()];
|
|
214
|
+
return (0, _processors.concatItemsFromMoreResponse)(currentData, data, {
|
|
215
|
+
role: this._roles.main
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.default = SearchBasedWorkflow;
|
|
220
|
+
(0, _options.makeConfigurable)(SearchBasedWorkflow.prototype, ['pagination']);
|
|
221
|
+
Object.assign(SearchBasedWorkflow, {
|
|
222
|
+
DEFAULT_API_OPTIONS,
|
|
223
|
+
DEFAULT_LAYOUTS,
|
|
224
|
+
DEFAULT_TRACKERS,
|
|
225
|
+
DEFAULT_PAGINATION,
|
|
226
|
+
DEFAULT_OPTIONS,
|
|
227
|
+
ROLES_OPTIONS
|
|
228
|
+
});
|
|
@@ -5,14 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
|
-
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
|
-
var _options = require("./options.js");
|
|
10
|
-
var sources = _interopRequireWildcard(require("../source.js"));
|
|
11
|
-
var _index = require("../actor/index.js");
|
|
12
8
|
var _constants = require("../constants.js");
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
|
+
var _searchBased = _interopRequireDefault(require("./search-based.js"));
|
|
10
|
+
var _autocompletable = require("./autocompletable.js");
|
|
16
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
12
|
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
18
13
|
group: _commons.API.GROUP.SEARCH,
|
|
@@ -22,7 +17,6 @@ const DEFAULT_API_OPTIONS = Object.freeze({
|
|
|
22
17
|
}
|
|
23
18
|
});
|
|
24
19
|
const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
|
|
25
|
-
actor: false,
|
|
26
20
|
api: {
|
|
27
21
|
group: _commons.API.GROUP.SEARCH,
|
|
28
22
|
name: _commons.API.NAME.AUTOCOMPLETE,
|
|
@@ -30,45 +24,31 @@ const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
|
|
|
30
24
|
completion_fields: ['suggested_queries', 'title'],
|
|
31
25
|
fl: ['title', 'url', 'cover_image']
|
|
32
26
|
}
|
|
33
|
-
}
|
|
34
|
-
throttle: 300
|
|
35
|
-
});
|
|
36
|
-
const DEFAULT_LAYOUTS = Object.freeze({
|
|
37
|
-
[_constants.ROLE.QUERY]: _index2.SearchBoxLayout.type,
|
|
38
|
-
[_constants.ROLE.PRODUCTS]: _index2.ListLayout.type
|
|
39
|
-
});
|
|
40
|
-
const DEFAULT_TRACKERS = Object.freeze({
|
|
41
|
-
[_constants.ROLE.PRODUCTS]: {}
|
|
27
|
+
}
|
|
42
28
|
});
|
|
43
|
-
const
|
|
29
|
+
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _searchBased.default.DEFAULT_LAYOUTS));
|
|
30
|
+
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _searchBased.default.DEFAULT_TRACKERS));
|
|
31
|
+
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _searchBased.default.DEFAULT_OPTIONS, {
|
|
44
32
|
api: DEFAULT_API_OPTIONS,
|
|
45
33
|
autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS,
|
|
46
34
|
layouts: DEFAULT_LAYOUTS,
|
|
47
35
|
trackers: DEFAULT_TRACKERS
|
|
48
|
-
});
|
|
49
|
-
|
|
36
|
+
}));
|
|
37
|
+
const ROLES_OPTIONS = _searchBased.default.ROLES_OPTIONS;
|
|
38
|
+
class Search extends _searchBased.default {
|
|
50
39
|
constructor(plugin, client) {
|
|
51
40
|
super({
|
|
52
41
|
name: 'search',
|
|
53
42
|
plugin,
|
|
54
43
|
client,
|
|
55
|
-
roles:
|
|
44
|
+
roles: ROLES_OPTIONS,
|
|
56
45
|
defaults: DEFAULT_OPTIONS
|
|
57
46
|
});
|
|
58
47
|
}
|
|
59
|
-
|
|
60
|
-
super.
|
|
61
|
-
this.
|
|
62
|
-
source: sources.api(this._client),
|
|
63
|
-
options: this._options
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
_initSubscriptions(args) {
|
|
67
|
-
super._initSubscriptions(args);
|
|
68
|
-
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args))];
|
|
48
|
+
_initProperties(args) {
|
|
49
|
+
super._initProperties(args);
|
|
50
|
+
this._initAutocomplete(args);
|
|
69
51
|
}
|
|
70
|
-
|
|
71
|
-
// lifecycle //
|
|
72
52
|
autoQuery() {
|
|
73
53
|
let {
|
|
74
54
|
setValue = true,
|
|
@@ -92,40 +72,6 @@ class Search extends _base.default {
|
|
|
92
72
|
});
|
|
93
73
|
}
|
|
94
74
|
}
|
|
95
|
-
query(args) {
|
|
96
|
-
if (!args.q) {
|
|
97
|
-
throw new Error(`q is required in query() call`);
|
|
98
|
-
}
|
|
99
|
-
this._hub.update(_index.fields.query(), args);
|
|
100
|
-
}
|
|
101
|
-
_query(args) {
|
|
102
|
-
// start a new session
|
|
103
|
-
this.restart();
|
|
104
|
-
const {
|
|
105
|
-
session
|
|
106
|
-
} = this;
|
|
107
|
-
|
|
108
|
-
// build payload and trigger request
|
|
109
|
-
const payload = this._buildPayload(args);
|
|
110
|
-
const event = (0, _options.mergeApiOptions)(this._options.resolved.api, {
|
|
111
|
-
payload,
|
|
112
|
-
session
|
|
113
|
-
});
|
|
114
|
-
this._request(event);
|
|
115
|
-
}
|
|
116
|
-
_buildPayload(args) {
|
|
117
|
-
return args;
|
|
118
|
-
}
|
|
119
|
-
_request(event) {
|
|
120
|
-
this._hub.update(_index.fields.request(), event);
|
|
121
|
-
}
|
|
122
|
-
updateCompletions(event) {
|
|
123
|
-
// TODO: verify
|
|
124
|
-
this._hub.update(_index.fields.data(_constants.DATA_ASPECT.AUTOCOMPLETE), Object.assign({}, event, {
|
|
125
|
-
source: 'manual'
|
|
126
|
-
}));
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
75
|
notifyViewUpdate() {
|
|
130
76
|
let role = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.ROLE.PRODUCTS;
|
|
131
77
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
@@ -134,6 +80,13 @@ class Search extends _base.default {
|
|
|
134
80
|
super.notifyViewUpdate(role, ...args);
|
|
135
81
|
return this;
|
|
136
82
|
}
|
|
83
|
+
|
|
84
|
+
// destroy //
|
|
85
|
+
_destroy(options) {
|
|
86
|
+
this._feedback._destroy();
|
|
87
|
+
this._destroyAutocomplete();
|
|
88
|
+
super._destroy(options);
|
|
89
|
+
}
|
|
137
90
|
}
|
|
138
91
|
exports.default = Search;
|
|
139
|
-
(0,
|
|
92
|
+
(0, _autocompletable.makeAutocompletable)(Search.prototype);
|