@miso.ai/client-sdk-ui 1.11.0-beta.8 → 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 +28 -9
- 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 +20 -9
- 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
|
@@ -9,42 +9,47 @@ var _index = require("../actor/index.js");
|
|
|
9
9
|
var sources = _interopRequireWildcard(require("../source.js"));
|
|
10
10
|
var _constants = require("../constants.js");
|
|
11
11
|
var _index2 = require("../layout/index.js");
|
|
12
|
-
var _utils = require("./utils.js");
|
|
13
12
|
var _options = require("./options.js");
|
|
14
13
|
var _processors = require("./processors.js");
|
|
15
|
-
const _excluded = ["layouts", "interactions"],
|
|
16
|
-
_excluded2 = ["custom_context"],
|
|
17
|
-
_excluded3 = ["context"];
|
|
18
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
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; }
|
|
20
|
-
|
|
16
|
+
// TODO: just bury this into hub
|
|
17
|
+
function injectLogger(hub, callback) {
|
|
18
|
+
const {
|
|
19
|
+
update,
|
|
20
|
+
trigger
|
|
21
|
+
} = hub;
|
|
22
|
+
hub.update = (name, state, options) => {
|
|
23
|
+
if (!options || !options.silent) {
|
|
24
|
+
callback('update', name, state, options);
|
|
25
|
+
}
|
|
26
|
+
return update.call(hub, name, state, options);
|
|
27
|
+
};
|
|
28
|
+
hub.trigger = function () {
|
|
29
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
|
+
args[_key] = arguments[_key];
|
|
31
|
+
}
|
|
32
|
+
callback('trigger', ...args);
|
|
33
|
+
return trigger.apply(hub, args);
|
|
34
|
+
};
|
|
35
|
+
return hub;
|
|
36
|
+
}
|
|
37
|
+
const DEFAULT_API_OPTIONS = Object.freeze({});
|
|
21
38
|
const DEFAULT_LAYOUTS = Object.freeze({
|
|
22
39
|
[_constants.ROLE.CONTAINER]: _index2.ContainerLayout.type,
|
|
23
40
|
[_constants.ROLE.ERROR]: _index2.ErrorLayout.type
|
|
24
41
|
});
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
const DEFAULT_TRACKERS = Object.freeze({});
|
|
43
|
+
const DEFAULT_OPTIONS = Object.freeze({
|
|
44
|
+
api: DEFAULT_API_OPTIONS,
|
|
45
|
+
layouts: DEFAULT_LAYOUTS,
|
|
46
|
+
trackers: DEFAULT_TRACKERS
|
|
47
|
+
});
|
|
48
|
+
const ROLES_OPTIONS = Object.freeze({
|
|
49
|
+
mappings: {
|
|
50
|
+
[_constants.ROLE.ERROR]: data => data.error
|
|
28
51
|
}
|
|
29
52
|
});
|
|
30
|
-
function mergeDefaults(workflow) {
|
|
31
|
-
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32
|
-
let {
|
|
33
|
-
layouts,
|
|
34
|
-
interactions
|
|
35
|
-
} = _ref,
|
|
36
|
-
defaults = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
37
|
-
const DEFAULT_INTERACTIONS = {
|
|
38
|
-
preprocess: [payload => workflow._preprocessInteraction(payload)]
|
|
39
|
-
};
|
|
40
|
-
return Object.assign({}, defaults, {
|
|
41
|
-
layouts: (0, _options.mergeLayoutsOptions)(DEFAULT_LAYOUTS, layouts),
|
|
42
|
-
interactions: (0, _options.mergeInteractionsOptions)(DEFAULT_INTERACTIONS, interactions)
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function getRevision(data) {
|
|
46
|
-
return data && data.value && data.value.revision;
|
|
47
|
-
}
|
|
48
53
|
class Workflow extends _commons.Component {
|
|
49
54
|
constructor(args) {
|
|
50
55
|
var _this;
|
|
@@ -65,23 +70,25 @@ class Workflow extends _commons.Component {
|
|
|
65
70
|
}));
|
|
66
71
|
this._name = args.name;
|
|
67
72
|
this._roles = args.roles;
|
|
68
|
-
this._rolesConfig = Object.assign({}, ROLES_CONFIG, args.rolesConfig);
|
|
69
73
|
this._extensions = plugin._getExtensions(client);
|
|
70
|
-
this.
|
|
71
|
-
this.
|
|
74
|
+
this._defaults = args.defaults;
|
|
75
|
+
this._options = options || new _options.WorkflowOptions(context && context._options, args.defaults);
|
|
76
|
+
this._hub = injectLogger(new _index.Hub(), function () {
|
|
72
77
|
return _this._log(...arguments);
|
|
73
78
|
});
|
|
74
79
|
this._initProperties(args);
|
|
75
80
|
this._initActors(args);
|
|
76
81
|
this._initSubscriptions(args);
|
|
77
|
-
this.
|
|
82
|
+
this._initSession(args);
|
|
78
83
|
}
|
|
79
84
|
_initProperties() {}
|
|
80
|
-
_initActors() {
|
|
85
|
+
_initActors(_ref) {
|
|
86
|
+
let {
|
|
87
|
+
name,
|
|
88
|
+
roles
|
|
89
|
+
} = _ref;
|
|
81
90
|
const hub = this._hub;
|
|
82
91
|
const client = this._client;
|
|
83
|
-
const roles = this._roles;
|
|
84
|
-
const rolesConfig = this._rolesConfig;
|
|
85
92
|
const options = this._options;
|
|
86
93
|
const extensions = this._extensions;
|
|
87
94
|
const layouts = this._plugin.layouts;
|
|
@@ -94,20 +101,25 @@ class Workflow extends _commons.Component {
|
|
|
94
101
|
extensions,
|
|
95
102
|
layouts,
|
|
96
103
|
roles,
|
|
97
|
-
rolesConfig,
|
|
98
104
|
options,
|
|
99
|
-
workflow:
|
|
105
|
+
workflow: name
|
|
100
106
|
});
|
|
101
107
|
this._interactions = new _index.InteractionsActor(hub, {
|
|
102
108
|
client,
|
|
103
109
|
options
|
|
104
110
|
});
|
|
105
111
|
}
|
|
106
|
-
_initSubscriptions() {
|
|
107
|
-
|
|
112
|
+
_initSubscriptions(_ref2) {
|
|
113
|
+
let {
|
|
114
|
+
roles
|
|
115
|
+
} = _ref2;
|
|
116
|
+
this._unsubscribes = [this._hub.on(_index.fields.response(), data => this.updateData(data)), this._hub.on(_index.fields.tracker(), args => this._onTracker(args))];
|
|
117
|
+
if (roles.main) {
|
|
118
|
+
this._unsubscribes.push(this._hub.on(_index.fields.view(roles.main), state => this._onMainViewUpdate(state)));
|
|
119
|
+
}
|
|
108
120
|
}
|
|
109
|
-
|
|
110
|
-
this.
|
|
121
|
+
_initSession() {
|
|
122
|
+
this.restart();
|
|
111
123
|
}
|
|
112
124
|
get uuid() {
|
|
113
125
|
return this.session && this.session.uuid;
|
|
@@ -115,12 +127,6 @@ class Workflow extends _commons.Component {
|
|
|
115
127
|
get session() {
|
|
116
128
|
return this._hub.states[_index.fields.session()];
|
|
117
129
|
}
|
|
118
|
-
get active() {
|
|
119
|
-
const {
|
|
120
|
-
session
|
|
121
|
-
} = this;
|
|
122
|
-
return !!session && session.active;
|
|
123
|
-
}
|
|
124
130
|
get states() {
|
|
125
131
|
return this._hub.states;
|
|
126
132
|
}
|
|
@@ -133,20 +139,57 @@ class Workflow extends _commons.Component {
|
|
|
133
139
|
}
|
|
134
140
|
|
|
135
141
|
// lifecycle //
|
|
136
|
-
reset() {
|
|
137
|
-
this._sessions.new();
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
start() {
|
|
141
|
-
this._sessions.start();
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
142
|
restart() {
|
|
143
|
+
this._emitInterruptEventIfNecessary();
|
|
145
144
|
this._sessions.restart();
|
|
146
145
|
return this;
|
|
147
146
|
}
|
|
147
|
+
_emitInterruptEventIfNecessary() {
|
|
148
|
+
const {
|
|
149
|
+
main
|
|
150
|
+
} = this._roles;
|
|
151
|
+
if (!main) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const state = this._hub.states[_index.fields.view(main)] || {};
|
|
155
|
+
if (state.session && state.status === _constants.STATUS.LOADING) {
|
|
156
|
+
// it's interrupted by a new question
|
|
157
|
+
this._emitLifecycleEvent('interrupt', state);
|
|
158
|
+
this._emitLifecycleEvent('finally', state);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
_onMainViewUpdate(state) {
|
|
162
|
+
const {
|
|
163
|
+
status
|
|
164
|
+
} = state;
|
|
165
|
+
const done = status === _constants.STATUS.READY;
|
|
166
|
+
const erroneous = status === _constants.STATUS.ERRONEOUS;
|
|
167
|
+
const eventName = erroneous ? 'error' : status;
|
|
168
|
+
this._emitLifecycleEvent(eventName, state);
|
|
169
|
+
if (done) {
|
|
170
|
+
this._emitLifecycleEvent('done', state);
|
|
171
|
+
}
|
|
172
|
+
if (done || erroneous) {
|
|
173
|
+
this._emitLifecycleEvent('finally', state);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
_emitLifecycleEvent(name, event) {
|
|
177
|
+
this._emit(name, event);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// request //
|
|
181
|
+
_request() {
|
|
182
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
183
|
+
const {
|
|
184
|
+
session
|
|
185
|
+
} = this;
|
|
186
|
+
const event = (0, _options.mergeApiOptions)(this._options.resolved.api, Object.assign({}, options, {
|
|
187
|
+
session
|
|
188
|
+
}));
|
|
189
|
+
this._hub.update(_index.fields.request(), event);
|
|
190
|
+
}
|
|
148
191
|
|
|
149
|
-
//
|
|
192
|
+
// data //
|
|
150
193
|
updateData(data) {
|
|
151
194
|
if (!data) {
|
|
152
195
|
throw new Error(`Data is required.`);
|
|
@@ -165,9 +208,9 @@ class Workflow extends _commons.Component {
|
|
|
165
208
|
}
|
|
166
209
|
|
|
167
210
|
// compare revision to omit outdated data, if any
|
|
168
|
-
const revision = getRevision(data);
|
|
211
|
+
const revision = (0, _processors.getRevision)(data);
|
|
169
212
|
if (!(0, _commons.isNullLike)(revision)) {
|
|
170
|
-
const currentRevision = getRevision(this._hub.states[_index.fields.data()]);
|
|
213
|
+
const currentRevision = (0, _processors.getRevision)(this._hub.states[_index.fields.data()]);
|
|
171
214
|
if (!(0, _commons.isNullLike)(currentRevision) && revision <= currentRevision) {
|
|
172
215
|
return;
|
|
173
216
|
}
|
|
@@ -176,8 +219,6 @@ class Workflow extends _commons.Component {
|
|
|
176
219
|
return this;
|
|
177
220
|
}
|
|
178
221
|
_updateData(data) {
|
|
179
|
-
this._sessions.start(); // in case session not started yet
|
|
180
|
-
|
|
181
222
|
data = this._defaultProcessData(data);
|
|
182
223
|
for (const process of this._options.resolved.dataProcessor) {
|
|
183
224
|
data = process(data);
|
|
@@ -193,23 +234,9 @@ class Workflow extends _commons.Component {
|
|
|
193
234
|
this._hub.update(_index.fields.data(), data);
|
|
194
235
|
}
|
|
195
236
|
|
|
196
|
-
/*
|
|
197
|
-
_mergeDataIfNecessary(data) {
|
|
198
|
-
if (!data._inst || !data._inst.merge) {
|
|
199
|
-
return data;
|
|
200
|
-
}
|
|
201
|
-
return {
|
|
202
|
-
...this._hub.states[fields.data()],
|
|
203
|
-
...data,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
_handleResponseObject() {}
|
|
207
|
-
*/
|
|
208
|
-
|
|
209
237
|
// TODO: notifyViewUpdateAll()
|
|
210
238
|
|
|
211
239
|
notifyViewUpdate(role, state) {
|
|
212
|
-
this._assertActive();
|
|
213
240
|
state = Object.assign({
|
|
214
241
|
status: _constants.STATUS.READY,
|
|
215
242
|
session: this.session
|
|
@@ -222,30 +249,59 @@ class Workflow extends _commons.Component {
|
|
|
222
249
|
get trackers() {
|
|
223
250
|
return this._views.trackers;
|
|
224
251
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
} = {}
|
|
233
|
-
} = _ref2,
|
|
234
|
-
context = _objectWithoutPropertiesLoose(_ref2.context, _excluded2),
|
|
235
|
-
payload = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
252
|
+
_onTracker(args) {
|
|
253
|
+
const payload = this._buildInteraction(args);
|
|
254
|
+
this._sendInteraction(payload);
|
|
255
|
+
}
|
|
256
|
+
_buildInteraction(args) {
|
|
257
|
+
let payload = (0, _processors.buildBaseInteraction)(args);
|
|
258
|
+
payload = this._defaultProcessInteraction(payload, args);
|
|
236
259
|
const {
|
|
237
|
-
|
|
238
|
-
|
|
260
|
+
preprocess = []
|
|
261
|
+
} = this._options.resolved.interactions;
|
|
262
|
+
for (const p of preprocess) {
|
|
263
|
+
payload = p(payload, args);
|
|
264
|
+
}
|
|
265
|
+
return payload;
|
|
266
|
+
}
|
|
267
|
+
_defaultProcessInteraction(payload, args) {
|
|
268
|
+
payload = this._writeApiInfoToInteraction(payload, args);
|
|
269
|
+
payload = this._writeMisoIdToInteraction(payload, args);
|
|
270
|
+
payload = (0, _processors.writeAffiliationInfoToInteraction)(payload, args);
|
|
271
|
+
return payload;
|
|
272
|
+
}
|
|
273
|
+
_writeApiInfoToInteraction(payload) {
|
|
274
|
+
const {
|
|
275
|
+
group,
|
|
276
|
+
name
|
|
239
277
|
} = this._options.resolved.api;
|
|
240
|
-
return
|
|
241
|
-
context:
|
|
242
|
-
custom_context:
|
|
243
|
-
api_group,
|
|
244
|
-
api_name
|
|
245
|
-
}
|
|
246
|
-
}
|
|
278
|
+
return (0, _processors.mergeInteraction)(payload, {
|
|
279
|
+
context: {
|
|
280
|
+
custom_context: {
|
|
281
|
+
api_group: group,
|
|
282
|
+
api_name: name
|
|
283
|
+
}
|
|
284
|
+
}
|
|
247
285
|
});
|
|
248
286
|
}
|
|
287
|
+
_writeMisoIdToInteraction(payload, args) {
|
|
288
|
+
// TODO: ad-hoc, try to pass info from tracker
|
|
289
|
+
const state = this._hub.states[_index.fields.view(args.role)] || {};
|
|
290
|
+
const miso_id = state.meta && state.meta.miso_id || undefined;
|
|
291
|
+
return miso_id ? (0, _processors.mergeInteraction)(payload, {
|
|
292
|
+
miso_id
|
|
293
|
+
}) : payload;
|
|
294
|
+
}
|
|
295
|
+
_sendInteraction(payload) {
|
|
296
|
+
const {
|
|
297
|
+
handle
|
|
298
|
+
} = this._options.resolved.interactions;
|
|
299
|
+
if (typeof handle === 'function') {
|
|
300
|
+
handle(payload);
|
|
301
|
+
} else {
|
|
302
|
+
this._hub.trigger(_index.fields.interaction(), payload);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
249
305
|
|
|
250
306
|
// destroy //
|
|
251
307
|
destroy(options) {
|
|
@@ -280,11 +336,13 @@ class Workflow extends _commons.Component {
|
|
|
280
336
|
}, data));
|
|
281
337
|
}
|
|
282
338
|
}
|
|
283
|
-
_assertActive() {
|
|
284
|
-
if (!this.active) {
|
|
285
|
-
throw new Error(`Unit is not active yet. Call unit.start() to activate it.`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
339
|
}
|
|
289
340
|
exports.default = Workflow;
|
|
290
|
-
(0, _options.makeConfigurable)(Workflow.prototype);
|
|
341
|
+
(0, _options.makeConfigurable)(Workflow.prototype);
|
|
342
|
+
Object.assign(Workflow, {
|
|
343
|
+
DEFAULT_API_OPTIONS,
|
|
344
|
+
DEFAULT_LAYOUTS,
|
|
345
|
+
DEFAULT_TRACKERS,
|
|
346
|
+
DEFAULT_OPTIONS,
|
|
347
|
+
ROLES_OPTIONS
|
|
348
|
+
});
|
|
@@ -6,18 +6,19 @@ 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 _options = require("./options.js");
|
|
10
9
|
var _index = require("../actor/index.js");
|
|
11
10
|
var _constants = require("../constants.js");
|
|
12
11
|
var _index2 = require("../layout/index.js");
|
|
12
|
+
var _options = require("./options.js");
|
|
13
|
+
var _useLink = require("./use-link.js");
|
|
13
14
|
const _excluded = ["value"];
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
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; }
|
|
16
|
-
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
17
|
+
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
17
18
|
group: _commons.API.GROUP.ASK,
|
|
18
19
|
name: _commons.API.NAME.RELATED_QUESTIONS
|
|
19
|
-
});
|
|
20
|
-
const DEFAULT_LAYOUTS = Object.freeze({
|
|
20
|
+
}));
|
|
21
|
+
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
|
|
21
22
|
[_constants.ROLE.RELATED_QUESTIONS]: [_index2.ListLayout.type, {
|
|
22
23
|
itemType: 'question',
|
|
23
24
|
link: {
|
|
@@ -27,18 +28,22 @@ const DEFAULT_LAYOUTS = Object.freeze({
|
|
|
27
28
|
[_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
|
|
28
29
|
placeholder: 'Ask a question'
|
|
29
30
|
}]
|
|
30
|
-
});
|
|
31
|
-
const DEFAULT_TRACKERS = Object.freeze({
|
|
31
|
+
}));
|
|
32
|
+
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
|
|
32
33
|
[_constants.ROLE.RELATED_QUESTIONS]: {},
|
|
33
34
|
[_constants.ROLE.CONTAINER]: {},
|
|
34
35
|
[_constants.ROLE.QUERY]: {
|
|
35
36
|
[_constants.EVENT_TYPE.SUBMIT]: {}
|
|
36
37
|
}
|
|
37
|
-
});
|
|
38
|
-
const DEFAULT_OPTIONS = Object.freeze({
|
|
38
|
+
}));
|
|
39
|
+
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
|
|
39
40
|
api: DEFAULT_API_OPTIONS,
|
|
40
41
|
layouts: DEFAULT_LAYOUTS,
|
|
41
42
|
trackers: DEFAULT_TRACKERS
|
|
43
|
+
}));
|
|
44
|
+
const ROLES_OPTIONS = (0, _options.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
45
|
+
main: _constants.ROLE.RELATED_QUESTIONS,
|
|
46
|
+
members: Object.keys(DEFAULT_LAYOUTS)
|
|
42
47
|
});
|
|
43
48
|
class Explore extends _base.default {
|
|
44
49
|
constructor(plugin, client) {
|
|
@@ -46,7 +51,7 @@ class Explore extends _base.default {
|
|
|
46
51
|
name: 'explore',
|
|
47
52
|
plugin,
|
|
48
53
|
client,
|
|
49
|
-
roles:
|
|
54
|
+
roles: ROLES_OPTIONS,
|
|
50
55
|
defaults: DEFAULT_OPTIONS
|
|
51
56
|
});
|
|
52
57
|
}
|
|
@@ -57,7 +62,7 @@ class Explore extends _base.default {
|
|
|
57
62
|
}
|
|
58
63
|
_initSubscriptions(args) {
|
|
59
64
|
super._initSubscriptions(args);
|
|
60
|
-
this._unsubscribes = [...this._unsubscribes, this._views.get(_constants.ROLE.RELATED_QUESTIONS).on('click', event => this._handleRelatedQuestionClick(event)), this._hub.on(_index.fields.query(),
|
|
65
|
+
this._unsubscribes = [...this._unsubscribes, this._views.get(_constants.ROLE.RELATED_QUESTIONS).on('click', event => this._handleRelatedQuestionClick(event)), this._hub.on(_index.fields.query(), args => this._query(args))];
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
// configuration //
|
|
@@ -76,34 +81,24 @@ class Explore extends _base.default {
|
|
|
76
81
|
}
|
|
77
82
|
return super.useApi(options);
|
|
78
83
|
}
|
|
79
|
-
useLink(fn) {
|
|
80
|
-
if (typeof fn !== 'function' && fn !== false) {
|
|
81
|
-
throw new Error('useLink(fn) expects fn to be a function or false');
|
|
82
|
-
}
|
|
83
|
-
this._linkFn = fn;
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
84
|
|
|
87
85
|
// lifecycle //
|
|
88
86
|
start() {
|
|
89
87
|
let {
|
|
90
88
|
relatedQuestions = true
|
|
91
89
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
92
|
-
if (
|
|
93
|
-
throw new Error('
|
|
90
|
+
if (this._linkFn === undefined) {
|
|
91
|
+
throw new Error('Must define link mapping function with useLink(fn) before calling start()');
|
|
94
92
|
}
|
|
95
|
-
this._sessions.start();
|
|
96
93
|
// in explore workflow, start() triggers query
|
|
97
94
|
// TODO: we should still make the query lifecycle
|
|
98
|
-
const {
|
|
99
|
-
session
|
|
100
|
-
} = this;
|
|
101
95
|
if (relatedQuestions) {
|
|
102
|
-
this.
|
|
103
|
-
session
|
|
104
|
-
}));
|
|
96
|
+
this._request();
|
|
105
97
|
} else {
|
|
106
98
|
// TODO: ad-hoc
|
|
99
|
+
const {
|
|
100
|
+
session
|
|
101
|
+
} = this;
|
|
107
102
|
this.updateData({
|
|
108
103
|
session,
|
|
109
104
|
request: {},
|
|
@@ -124,16 +119,24 @@ class Explore extends _base.default {
|
|
|
124
119
|
}
|
|
125
120
|
_defaultProcessData(data) {
|
|
126
121
|
data = super._defaultProcessData(data);
|
|
127
|
-
|
|
122
|
+
data = this._addUrlToRelatedQuestions(data);
|
|
123
|
+
return data;
|
|
124
|
+
}
|
|
125
|
+
_addUrlToRelatedQuestions(data) {
|
|
126
|
+
const {
|
|
128
127
|
value
|
|
129
128
|
} = data;
|
|
130
|
-
if (!value) {
|
|
129
|
+
if (!value || !value.related_questions) {
|
|
131
130
|
return data;
|
|
132
131
|
}
|
|
133
|
-
|
|
134
|
-
const related_questions = value.related_questions.map(
|
|
132
|
+
const linkFn = this._linkFn && this._linkFn[0];
|
|
133
|
+
const related_questions = value.related_questions.map(linkFn ? text => ({
|
|
135
134
|
text,
|
|
136
|
-
url: this.
|
|
135
|
+
url: this._getSubmitUrl({
|
|
136
|
+
q: text
|
|
137
|
+
}, {
|
|
138
|
+
generated: true
|
|
139
|
+
})
|
|
137
140
|
}) : text => ({
|
|
138
141
|
text
|
|
139
142
|
}));
|
|
@@ -152,26 +155,25 @@ class Explore extends _base.default {
|
|
|
152
155
|
question
|
|
153
156
|
})));
|
|
154
157
|
}
|
|
155
|
-
query() {
|
|
156
|
-
|
|
157
|
-
q
|
|
158
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
159
|
-
if (!this._linkFn) {
|
|
160
|
-
return;
|
|
158
|
+
query(args) {
|
|
159
|
+
if (!args.q) {
|
|
160
|
+
throw new Error(`q is required in query() call`);
|
|
161
161
|
}
|
|
162
|
-
|
|
163
|
-
window.open(url, '_blank');
|
|
162
|
+
this._hub.update(_index.fields.query(), args);
|
|
164
163
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
_query(args) {
|
|
165
|
+
this._submitToPage(args);
|
|
166
|
+
}
|
|
167
|
+
_getSubmitUrl(args) {
|
|
168
|
+
let {
|
|
169
|
+
generated = false
|
|
170
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
171
|
+
let url = _useLink.UseLinkMixin.prototype._getSubmitUrl.call(this, args);
|
|
171
172
|
if (!generated || !this._productId) {
|
|
172
173
|
return url;
|
|
173
174
|
}
|
|
174
175
|
return `${url}&qs=${encodeURIComponent(this._productId)}`;
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
|
-
exports.default = Explore;
|
|
178
|
+
exports.default = Explore;
|
|
179
|
+
(0, _useLink.enableUseLink)(Explore.prototype);
|
|
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _answerBased = _interopRequireDefault(require("./answer-based.js"));
|
|
8
8
|
var _constants = require("../constants.js");
|
|
9
|
+
var _options = require("./options.js");
|
|
9
10
|
var _processors = require("./processors.js");
|
|
11
|
+
var _autocompletable = require("./autocompletable.js");
|
|
10
12
|
const _excluded = ["q", "qs"];
|
|
11
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
14
|
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; }
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const ROLES_OPTIONS = (0, _options.mergeRolesOptions)(_answerBased.default.ROLES_OPTIONS, {
|
|
16
|
+
mappings: {
|
|
17
|
+
[_constants.ROLE.QUESTION]: _constants.ROLE.KEYWORDS
|
|
16
18
|
}
|
|
17
19
|
});
|
|
18
20
|
class HybridSearchAnswer extends _answerBased.default {
|
|
@@ -22,16 +24,17 @@ class HybridSearchAnswer extends _answerBased.default {
|
|
|
22
24
|
plugin: superworkflow._plugin,
|
|
23
25
|
client: superworkflow._client,
|
|
24
26
|
options: superworkflow._options,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
defaults: superworkflow._defaults,
|
|
28
|
+
roles: ROLES_OPTIONS,
|
|
27
29
|
superworkflow
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
_initProperties(args) {
|
|
31
33
|
super._initProperties(args);
|
|
34
|
+
this._initAutocomplete(args);
|
|
32
35
|
this._superworkflow = args.superworkflow;
|
|
33
36
|
}
|
|
34
|
-
|
|
37
|
+
_initSession() {} // no reset here, will manually reset later
|
|
35
38
|
|
|
36
39
|
restart() {
|
|
37
40
|
super.restart();
|
|
@@ -85,5 +88,12 @@ class HybridSearchAnswer extends _answerBased.default {
|
|
|
85
88
|
session: this._resultsSession
|
|
86
89
|
}));
|
|
87
90
|
}
|
|
91
|
+
|
|
92
|
+
// destroy //
|
|
93
|
+
_destroy(options) {
|
|
94
|
+
this._destroyAutocomplete();
|
|
95
|
+
super._destroy(options);
|
|
96
|
+
}
|
|
88
97
|
}
|
|
89
|
-
exports.default = HybridSearchAnswer;
|
|
98
|
+
exports.default = HybridSearchAnswer;
|
|
99
|
+
(0, _autocompletable.makeAutocompletable)(HybridSearchAnswer.prototype);
|