@miso.ai/client-sdk-ui 1.12.3-beta.6 → 1.12.4-beta.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/data.js +15 -11
- package/dist/cjs/defaults/ask/controls.js +3 -6
- package/dist/cjs/defaults/ask/templates.js +1 -0
- package/dist/cjs/defaults/common/templates.js +4 -2
- package/dist/cjs/element/container/miso-ask.js +48 -6
- package/dist/cjs/element/container/miso-container.js +2 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +2 -88
- package/dist/cjs/workflow/ask.js +13 -9
- package/dist/cjs/workflow/asks.js +36 -1
- package/dist/cjs/workflow/base.js +14 -9
- package/dist/cjs/workflow/hybrid-search-answer.js +40 -68
- package/dist/cjs/workflow/hybrid-search-views.js +12 -11
- package/dist/cjs/workflow/hybrid-search.js +99 -46
- package/dist/cjs/workflow/options/auto-query.js +31 -0
- package/dist/cjs/workflow/processors.js +107 -0
- package/dist/cjs/workflow/search-based.js +16 -30
- package/package.json +2 -2
- package/src/actor/data.js +10 -7
- package/src/defaults/ask/controls.js +3 -6
- package/src/defaults/ask/templates.js +1 -1
- package/src/defaults/common/templates.js +2 -2
- package/src/element/container/miso-ask.js +53 -5
- package/src/element/container/miso-container.js +3 -0
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +4 -83
- package/src/workflow/ask.js +11 -10
- package/src/workflow/asks.js +39 -2
- package/src/workflow/base.js +13 -9
- package/src/workflow/hybrid-search-answer.js +25 -62
- package/src/workflow/hybrid-search-views.js +14 -12
- package/src/workflow/hybrid-search.js +93 -47
- package/src/workflow/options/auto-query.js +36 -2
- package/src/workflow/processors.js +86 -2
- package/src/workflow/search-based.js +14 -27
- package/dist/cjs/workflow/hybrid-search-results.js +0 -87
- package/src/workflow/hybrid-search-results.js +0 -91
|
@@ -4,17 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _searchBased = _interopRequireDefault(require("./search-based.js"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const RESULTS_ROLE_MEMBERS = _searchBased.default.ROLES_OPTIONS.members;
|
|
9
10
|
function getSubworkflowByRole(role) {
|
|
10
11
|
// TODO: ROLE.ERROR
|
|
11
|
-
return
|
|
12
|
+
return RESULTS_ROLE_MEMBERS.includes(role) ? 'results' : 'answer';
|
|
12
13
|
}
|
|
13
14
|
class HybridSearchViewsActor {
|
|
14
|
-
constructor(
|
|
15
|
-
this.
|
|
15
|
+
constructor(subviews) {
|
|
16
|
+
this._subviews = subviews;
|
|
16
17
|
this._containers = new Set();
|
|
17
18
|
}
|
|
19
|
+
get filters() {
|
|
20
|
+
return this._subviews.results.filters;
|
|
21
|
+
}
|
|
18
22
|
get(role) {
|
|
19
23
|
return this._getSubviews(role).get(role);
|
|
20
24
|
}
|
|
@@ -31,8 +35,8 @@ class HybridSearchViewsActor {
|
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
removeContainer(element) {
|
|
34
|
-
for (const
|
|
35
|
-
|
|
38
|
+
for (const subviews of this._getAllSubviews()) {
|
|
39
|
+
subviews.removeContainer(element);
|
|
36
40
|
}
|
|
37
41
|
this._containers.delete(element);
|
|
38
42
|
}
|
|
@@ -55,14 +59,11 @@ class HybridSearchViewsActor {
|
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
// helpers //
|
|
58
|
-
_getSubworkflow(role) {
|
|
59
|
-
return this._workflow._getSubworkflow(getSubworkflowByRole(role));
|
|
60
|
-
}
|
|
61
62
|
_getAllSubviews() {
|
|
62
|
-
return
|
|
63
|
+
return Object.values(this._subviews);
|
|
63
64
|
}
|
|
64
65
|
_getSubviews(role) {
|
|
65
|
-
return this.
|
|
66
|
+
return this._subviews[getSubworkflowByRole(role)];
|
|
66
67
|
}
|
|
67
68
|
_getViewByElement(element) {
|
|
68
69
|
let {
|
|
@@ -5,16 +5,16 @@ 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
8
|
var _searchBased = _interopRequireDefault(require("./search-based.js"));
|
|
10
9
|
var _answerBased = _interopRequireDefault(require("./answer-based.js"));
|
|
11
10
|
var _constants = require("../constants.js");
|
|
12
11
|
var _index = require("../layout/index.js");
|
|
13
12
|
var _templates = require("../layout/templates.js");
|
|
14
13
|
var _hybridSearchAnswer = _interopRequireDefault(require("./hybrid-search-answer.js"));
|
|
15
|
-
var _hybridSearchResults = _interopRequireDefault(require("./hybrid-search-results.js"));
|
|
16
14
|
var _hybridSearchViews = _interopRequireDefault(require("./hybrid-search-views.js"));
|
|
17
15
|
var _index2 = require("./options/index.js");
|
|
16
|
+
var _processors = require("./processors.js");
|
|
17
|
+
var _autocompletable = require("./autocompletable.js");
|
|
18
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
19
|
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
20
20
|
group: _commons.API.GROUP.ASK,
|
|
@@ -78,83 +78,136 @@ const ROLES_OPTIONS = Object.freeze({
|
|
|
78
78
|
members: Object.keys(DEFAULT_LAYOUTS),
|
|
79
79
|
mappings: Object.freeze(Object.assign({}, _answerBased.default.ROLES_OPTIONS.mappings, _searchBased.default.ROLES_OPTIONS.mappings))
|
|
80
80
|
});
|
|
81
|
-
|
|
81
|
+
const EXTRA_OPTIONS = Object.freeze({
|
|
82
|
+
api: Object.freeze({
|
|
83
|
+
polling: false
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
class HybridSearch extends _searchBased.default {
|
|
82
87
|
constructor(plugin, client) {
|
|
83
88
|
super({
|
|
84
89
|
name: 'hybrid-search',
|
|
85
90
|
plugin,
|
|
86
91
|
client,
|
|
87
92
|
roles: ROLES_OPTIONS,
|
|
88
|
-
defaults: DEFAULT_OPTIONS
|
|
93
|
+
defaults: DEFAULT_OPTIONS,
|
|
94
|
+
extraOptions: EXTRA_OPTIONS
|
|
89
95
|
});
|
|
90
96
|
}
|
|
91
97
|
_initProperties(args) {
|
|
92
98
|
super._initProperties(args);
|
|
93
|
-
this.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
throw new Error(`Invalid subworkflow: ${name}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
_initActors() {
|
|
106
|
-
this._views = new _hybridSearchViews.default(this);
|
|
107
|
-
}
|
|
108
|
-
_initSession() {
|
|
109
|
-
this._results._sessions.restart();
|
|
110
|
-
this._answer._sessions.restart();
|
|
99
|
+
this._initAutocomplete(args);
|
|
100
|
+
this._answer = new _hybridSearchAnswer.default(this);
|
|
101
|
+
}
|
|
102
|
+
_initActors(args) {
|
|
103
|
+
super._initActors(args);
|
|
104
|
+
this._views = new _hybridSearchViews.default({
|
|
105
|
+
results: this._views,
|
|
106
|
+
answer: this._answer._views
|
|
107
|
+
});
|
|
111
108
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
restart({
|
|
110
|
+
type
|
|
111
|
+
} = {}) {
|
|
112
|
+
super.restart();
|
|
113
|
+
if (!type || type === _constants.REQUEST_TYPE.QUERY) {
|
|
114
|
+
this._answer.restart();
|
|
115
|
+
}
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
// properties //
|
|
120
119
|
get answer() {
|
|
121
120
|
return this._answer;
|
|
122
121
|
}
|
|
123
|
-
get results() {
|
|
124
|
-
return this._results;
|
|
125
|
-
}
|
|
126
122
|
get questionId() {
|
|
127
123
|
return this._answer.questionId;
|
|
128
124
|
}
|
|
129
|
-
get filters() {
|
|
130
|
-
return this._results._views.filters;
|
|
131
|
-
}
|
|
132
|
-
get autocomplete() {
|
|
133
|
-
return this._answer.autocomplete;
|
|
134
|
-
}
|
|
135
125
|
|
|
136
126
|
// query //
|
|
137
|
-
|
|
138
|
-
|
|
127
|
+
_buildPayload(payload, type) {
|
|
128
|
+
payload = super._buildPayload(payload, type);
|
|
129
|
+
// borrow the work from the sibling
|
|
130
|
+
payload = (0, _processors.disableAnswerForNonQueryRequest)(payload, type);
|
|
131
|
+
payload = (0, _processors.writeQuestionSourceToPayload)(payload);
|
|
132
|
+
payload = this._writeQuestionIdToPayload(payload, type);
|
|
133
|
+
if (payload.answer !== false) {
|
|
134
|
+
// uses autoQuery params, so we want to apply to this workflow
|
|
135
|
+
payload = _answerBased.default.prototype._writeWikiLinkTemplateToPayload.call(this, payload);
|
|
136
|
+
}
|
|
137
|
+
return payload;
|
|
138
|
+
}
|
|
139
|
+
_buildOrderBy(sort) {
|
|
140
|
+
if (!sort) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
// works differently than search
|
|
144
|
+
return sort.field;
|
|
145
|
+
}
|
|
146
|
+
_writeQuestionIdToPayload(payload, type) {
|
|
147
|
+
if (type === _constants.REQUEST_TYPE.QUERY) {
|
|
148
|
+
return payload;
|
|
149
|
+
}
|
|
150
|
+
const question_id = this._answer.questionId;
|
|
151
|
+
if (!question_id) {
|
|
152
|
+
return payload;
|
|
153
|
+
}
|
|
154
|
+
return (0, _commons.mergeApiPayloads)(payload, {
|
|
155
|
+
metadata: {
|
|
156
|
+
question_id
|
|
157
|
+
}
|
|
158
|
+
});
|
|
139
159
|
}
|
|
140
|
-
|
|
141
|
-
|
|
160
|
+
|
|
161
|
+
// data //
|
|
162
|
+
_defaultProcessData(data, oldData) {
|
|
163
|
+
data = super._defaultProcessData(data, oldData);
|
|
164
|
+
(0, _processors.writeMisoIdToSession)(data);
|
|
165
|
+
return data;
|
|
166
|
+
}
|
|
167
|
+
_updateDataInHub(data, oldData) {
|
|
168
|
+
this._dispatchDataToAnswerWorkflow(data);
|
|
169
|
+
data = (0, _processors.carryOverQuestionIdToData)(data, oldData); // TODO: may as well move to process data
|
|
170
|
+
super._updateDataInHub(data, oldData);
|
|
171
|
+
}
|
|
172
|
+
_dispatchDataToAnswerWorkflow(data) {
|
|
173
|
+
const {
|
|
174
|
+
request
|
|
175
|
+
} = data;
|
|
176
|
+
if (!request) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const {
|
|
180
|
+
type,
|
|
181
|
+
payload
|
|
182
|
+
} = request;
|
|
183
|
+
if (type !== _constants.REQUEST_TYPE.QUERY || !payload || payload.answer === false) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
switch (data.status) {
|
|
187
|
+
case _constants.STATUS.LOADING:
|
|
188
|
+
// share the loading status with its sibling
|
|
189
|
+
this._answer._doLoading(data);
|
|
190
|
+
break;
|
|
191
|
+
case _constants.STATUS.READY:
|
|
192
|
+
// start a query with retrieved question ID, if any
|
|
193
|
+
this._answer._queryWithQuestionId(data);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
142
196
|
}
|
|
143
197
|
|
|
144
198
|
// interactions //
|
|
145
199
|
_defaultProcessInteraction(payload, args) {
|
|
146
|
-
payload =
|
|
147
|
-
payload =
|
|
200
|
+
payload = super._defaultProcessInteraction(payload, args);
|
|
201
|
+
payload = (0, _processors.writeAnswerInfoToInteraction)(payload, args);
|
|
148
202
|
return payload;
|
|
149
203
|
}
|
|
150
204
|
|
|
151
205
|
// destroy //
|
|
152
206
|
_destroy() {
|
|
153
|
-
|
|
154
|
-
subworkflow.destroy();
|
|
155
|
-
}
|
|
207
|
+
this._answer.destroy();
|
|
156
208
|
super._destroy();
|
|
157
209
|
}
|
|
158
210
|
}
|
|
159
211
|
exports.default = HybridSearch;
|
|
160
|
-
(0, _index2.makeConfigurable)(HybridSearch.prototype, [_constants.WORKFLOW_CONFIGURABLE.PAGINATION, _constants.WORKFLOW_CONFIGURABLE.FILTERS]);
|
|
212
|
+
(0, _index2.makeConfigurable)(HybridSearch.prototype, [_constants.WORKFLOW_CONFIGURABLE.PAGINATION, _constants.WORKFLOW_CONFIGURABLE.FILTERS]);
|
|
213
|
+
(0, _autocompletable.makeAutocompletable)(HybridSearch.prototype);
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.DEFAULT_AUTO_QUERY_SOURCE_PARAM = exports.DEFAULT_AUTO_QUERY_PARAM = void 0;
|
|
7
7
|
exports.autoQuery = autoQuery;
|
|
8
8
|
exports.normalizeAutoQueryOptions = normalizeAutoQueryOptions;
|
|
9
|
+
exports.updateQueryParametersInUrl = updateQueryParametersInUrl;
|
|
9
10
|
var _commons = require("@miso.ai/commons");
|
|
10
11
|
var _constants = require("../../constants.js");
|
|
11
12
|
const _excluded = ["setValue", "focus", "updateUrl", "param", "sourceParam"];
|
|
@@ -57,4 +58,34 @@ function autoQuery(options = {}) {
|
|
|
57
58
|
qs
|
|
58
59
|
}));
|
|
59
60
|
}
|
|
61
|
+
}
|
|
62
|
+
function updateQueryParametersInUrl({
|
|
63
|
+
value,
|
|
64
|
+
request
|
|
65
|
+
}) {
|
|
66
|
+
if (!this._autoQuery || !this._autoQuery.updateUrl) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const {
|
|
70
|
+
param,
|
|
71
|
+
sourceParam
|
|
72
|
+
} = this._autoQuery;
|
|
73
|
+
const query = value && (value.question || value.keyword) || request && request.payload && (request.payload.question || request.payload.q);
|
|
74
|
+
const querySource = request && request.payload && request.payload.metadata && request.payload.metadata.question_source;
|
|
75
|
+
if (!query) {
|
|
76
|
+
return; // at initial phase
|
|
77
|
+
}
|
|
78
|
+
const url = new URL(window.location);
|
|
79
|
+
const currentQuery = url.searchParams.get(param);
|
|
80
|
+
const currentQuerySource = url.searchParams.get(sourceParam) || _constants.QUESTION_SOURCE.ORGANIC;
|
|
81
|
+
if (query === currentQuery && querySource === currentQuerySource) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
url.searchParams.set(param, query);
|
|
85
|
+
if (querySource === _constants.QUESTION_SOURCE.ORGANIC) {
|
|
86
|
+
url.searchParams.delete(sourceParam);
|
|
87
|
+
} else {
|
|
88
|
+
url.searchParams.set(sourceParam, querySource);
|
|
89
|
+
}
|
|
90
|
+
window.history.replaceState({}, '', url);
|
|
60
91
|
}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.buildBaseInteraction = buildBaseInteraction;
|
|
7
|
+
exports.carryOverQuestionIdToData = carryOverQuestionIdToData;
|
|
7
8
|
exports.concatItemsFromMoreResponse = concatItemsFromMoreResponse;
|
|
8
9
|
exports.disableAnswerForNonQueryRequest = disableAnswerForNonQueryRequest;
|
|
9
10
|
exports.getRevision = getRevision;
|
|
@@ -14,6 +15,8 @@ exports.mappingSortData = mappingSortData;
|
|
|
14
15
|
exports.mappingSuggestionsData = mappingSuggestionsData;
|
|
15
16
|
exports.retainFacetCountsInData = retainFacetCountsInData;
|
|
16
17
|
exports.writeAffiliationInfoToInteraction = writeAffiliationInfoToInteraction;
|
|
18
|
+
exports.writeAnswerClickInfoToInteraction = writeAnswerClickInfoToInteraction;
|
|
19
|
+
exports.writeAnswerInfoToInteraction = writeAnswerInfoToInteraction;
|
|
17
20
|
exports.writeAnswerStageToMeta = writeAnswerStageToMeta;
|
|
18
21
|
exports.writeDataStatus = writeDataStatus;
|
|
19
22
|
exports.writeEventTargetToInteraction = writeEventTargetToInteraction;
|
|
@@ -23,12 +26,17 @@ exports.writeMisoIdAsRootMisoId = writeMisoIdAsRootMisoId;
|
|
|
23
26
|
exports.writeMisoIdFromSession = writeMisoIdFromSession;
|
|
24
27
|
exports.writeMisoIdToMeta = writeMisoIdToMeta;
|
|
25
28
|
exports.writeMisoIdToSession = writeMisoIdToSession;
|
|
29
|
+
exports.writeQuestionInfoToInteraction = writeQuestionInfoToInteraction;
|
|
30
|
+
exports.writeQuestionSourceToPayload = writeQuestionSourceToPayload;
|
|
26
31
|
exports.writeRequestFromPreviousData = writeRequestFromPreviousData;
|
|
32
|
+
exports.writeRequestInfoToInteraction = writeRequestInfoToInteraction;
|
|
27
33
|
exports.writeRequestMetadataToInteraction = writeRequestMetadataToInteraction;
|
|
28
34
|
exports.writeUnanswerableToMeta = writeUnanswerableToMeta;
|
|
29
35
|
var _commons = require("@miso.ai/commons");
|
|
30
36
|
var _constants = require("../constants.js");
|
|
31
37
|
var _index = require("../actor/index.js");
|
|
38
|
+
const _excluded = ["qs"];
|
|
39
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
32
40
|
// role mappings //
|
|
33
41
|
function mappingSortData(_, {
|
|
34
42
|
hub,
|
|
@@ -113,6 +121,17 @@ function mappingFollowUpQuestionsData(data) {
|
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
// payload //
|
|
124
|
+
function writeQuestionSourceToPayload(_ref = {}) {
|
|
125
|
+
let {
|
|
126
|
+
qs
|
|
127
|
+
} = _ref,
|
|
128
|
+
payload = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
129
|
+
return (0, _commons.mergeApiPayloads)(payload, {
|
|
130
|
+
metadata: {
|
|
131
|
+
question_source: qs || _constants.QUESTION_SOURCE.ORGANIC // might be null, not undefined
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
116
135
|
function disableAnswerForNonQueryRequest(payload, type) {
|
|
117
136
|
if (type === _constants.REQUEST_TYPE.QUERY) {
|
|
118
137
|
return payload;
|
|
@@ -365,6 +384,19 @@ function writeExhaustionToData(data, {
|
|
|
365
384
|
})
|
|
366
385
|
});
|
|
367
386
|
}
|
|
387
|
+
function carryOverQuestionIdToData(data, oldData) {
|
|
388
|
+
const {
|
|
389
|
+
question_id
|
|
390
|
+
} = oldData && oldData.value || {};
|
|
391
|
+
if (!question_id) {
|
|
392
|
+
return data;
|
|
393
|
+
}
|
|
394
|
+
return Object.assign({}, data, {
|
|
395
|
+
value: Object.assign({}, data.value, {
|
|
396
|
+
question_id
|
|
397
|
+
})
|
|
398
|
+
});
|
|
399
|
+
}
|
|
368
400
|
|
|
369
401
|
// interactions //
|
|
370
402
|
function buildBaseInteraction(args) {
|
|
@@ -420,6 +452,32 @@ function writeRequestMetadataToInteraction(payload, args) {
|
|
|
420
452
|
}
|
|
421
453
|
});
|
|
422
454
|
}
|
|
455
|
+
function writeRequestInfoToInteraction(payload, args) {
|
|
456
|
+
const {
|
|
457
|
+
data
|
|
458
|
+
} = args;
|
|
459
|
+
if (!data) {
|
|
460
|
+
return payload;
|
|
461
|
+
}
|
|
462
|
+
const requestPayload = data.request && data.request.payload;
|
|
463
|
+
if (!requestPayload) {
|
|
464
|
+
return payload;
|
|
465
|
+
}
|
|
466
|
+
const {
|
|
467
|
+
question,
|
|
468
|
+
q,
|
|
469
|
+
fq
|
|
470
|
+
} = requestPayload;
|
|
471
|
+
return (0, _commons.mergeInteractions)(payload, {
|
|
472
|
+
context: {
|
|
473
|
+
custom_context: {
|
|
474
|
+
question,
|
|
475
|
+
q,
|
|
476
|
+
fq
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
423
481
|
function writeAffiliationInfoToInteraction(payload, args) {
|
|
424
482
|
if (args.role !== _constants.ROLE.AFFILIATION) {
|
|
425
483
|
return payload;
|
|
@@ -438,6 +496,55 @@ function writeAffiliationInfoToInteraction(payload, args) {
|
|
|
438
496
|
}
|
|
439
497
|
});
|
|
440
498
|
}
|
|
499
|
+
function writeAnswerInfoToInteraction(payload, args) {
|
|
500
|
+
payload = writeQuestionInfoToInteraction(payload, args);
|
|
501
|
+
payload = writeAnswerClickInfoToInteraction(payload, args);
|
|
502
|
+
payload = writeEventTargetToInteraction(payload, args);
|
|
503
|
+
return payload;
|
|
504
|
+
}
|
|
505
|
+
function writeQuestionInfoToInteraction(payload = {}, {
|
|
506
|
+
data
|
|
507
|
+
} = {}) {
|
|
508
|
+
if (!data) {
|
|
509
|
+
return payload;
|
|
510
|
+
}
|
|
511
|
+
const {
|
|
512
|
+
request = {},
|
|
513
|
+
value = {}
|
|
514
|
+
} = data;
|
|
515
|
+
const {
|
|
516
|
+
question_source
|
|
517
|
+
} = request.payload && request.payload.metadata || {};
|
|
518
|
+
const {
|
|
519
|
+
question_id
|
|
520
|
+
} = value;
|
|
521
|
+
return (0, _commons.mergeInteractions)(payload, {
|
|
522
|
+
context: {
|
|
523
|
+
custom_context: {
|
|
524
|
+
question_source,
|
|
525
|
+
question_id
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
function writeAnswerClickInfoToInteraction(payload, args) {
|
|
531
|
+
if (args.role !== _constants.ROLE.ANSWER) {
|
|
532
|
+
return payload;
|
|
533
|
+
}
|
|
534
|
+
const {
|
|
535
|
+
items = []
|
|
536
|
+
} = args;
|
|
537
|
+
return (0, _commons.mergeInteractions)(payload, {
|
|
538
|
+
context: {
|
|
539
|
+
custom_context: {
|
|
540
|
+
urls: items.map(item => item.url),
|
|
541
|
+
texts: items.map(item => item.text),
|
|
542
|
+
class_names: items.map(item => item.className),
|
|
543
|
+
attributes: items.map(item => item.attributes)
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
}
|
|
441
548
|
function writeEventTargetToInteraction(payload, {
|
|
442
549
|
event_target
|
|
443
550
|
} = {}) {
|
|
@@ -90,16 +90,19 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
90
90
|
this._hub.update(_index.fields.query(), args);
|
|
91
91
|
}
|
|
92
92
|
_query(args) {
|
|
93
|
+
const type = _constants.REQUEST_TYPE.QUERY;
|
|
94
|
+
|
|
93
95
|
// reset filters view
|
|
94
96
|
this._views.filters.reset({
|
|
95
97
|
silent: true
|
|
96
98
|
});
|
|
97
99
|
|
|
98
100
|
// start a new session
|
|
99
|
-
this.restart(
|
|
101
|
+
this.restart({
|
|
102
|
+
type
|
|
103
|
+
});
|
|
100
104
|
|
|
101
105
|
// payload
|
|
102
|
-
const type = _constants.REQUEST_TYPE.QUERY;
|
|
103
106
|
const payload = this._buildPayload(args, type);
|
|
104
107
|
this._request({
|
|
105
108
|
payload,
|
|
@@ -107,6 +110,8 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
107
110
|
});
|
|
108
111
|
}
|
|
109
112
|
_refine() {
|
|
113
|
+
const type = _constants.REQUEST_TYPE.REFINE;
|
|
114
|
+
|
|
110
115
|
// remember current facet_counts
|
|
111
116
|
const {
|
|
112
117
|
facet_counts
|
|
@@ -114,10 +119,11 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
114
119
|
this._currentFacetCounts = facet_counts;
|
|
115
120
|
|
|
116
121
|
// start a new session
|
|
117
|
-
this.restart(
|
|
122
|
+
this.restart({
|
|
123
|
+
type
|
|
124
|
+
});
|
|
118
125
|
|
|
119
126
|
// payload
|
|
120
|
-
const type = _constants.REQUEST_TYPE.REFINE;
|
|
121
127
|
const query = this._getQuery();
|
|
122
128
|
const payload = this._buildPayload(query, type);
|
|
123
129
|
this._request({
|
|
@@ -228,9 +234,13 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
228
234
|
});
|
|
229
235
|
return data;
|
|
230
236
|
}
|
|
231
|
-
|
|
237
|
+
_updateData(data) {
|
|
238
|
+
super._updateData(data);
|
|
239
|
+
_index3.updateQueryParametersInUrl.call(this, data);
|
|
240
|
+
}
|
|
241
|
+
_updateDataInHub(data, oldData) {
|
|
232
242
|
data = this._appendResultsFromMoreRequest(data);
|
|
233
|
-
super._updateDataInHub(data);
|
|
243
|
+
super._updateDataInHub(data, oldData);
|
|
234
244
|
}
|
|
235
245
|
_appendResultsFromMoreRequest(data) {
|
|
236
246
|
const {
|
|
@@ -271,30 +281,6 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
271
281
|
payload = this._writeRootMisoIdToInteraction(payload);
|
|
272
282
|
return payload;
|
|
273
283
|
}
|
|
274
|
-
_writeRequestInfoToInteraction(payload, args) {
|
|
275
|
-
const {
|
|
276
|
-
data
|
|
277
|
-
} = args;
|
|
278
|
-
if (!data) {
|
|
279
|
-
return payload;
|
|
280
|
-
}
|
|
281
|
-
const requestPayload = data.request && data.request.payload;
|
|
282
|
-
if (!requestPayload) {
|
|
283
|
-
return payload;
|
|
284
|
-
}
|
|
285
|
-
const {
|
|
286
|
-
q,
|
|
287
|
-
fq
|
|
288
|
-
} = requestPayload;
|
|
289
|
-
return (0, _commons.mergeInteractions)(payload, {
|
|
290
|
-
context: {
|
|
291
|
-
custom_context: {
|
|
292
|
-
q,
|
|
293
|
-
fq
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
284
|
_writeRootMisoIdToInteraction(payload) {
|
|
299
285
|
const data = this._hub.states[_index.fields.data()];
|
|
300
286
|
const {
|
package/package.json
CHANGED
package/src/actor/data.js
CHANGED
|
@@ -3,10 +3,11 @@ import { isCurrentSession } from './utils.js';
|
|
|
3
3
|
|
|
4
4
|
export default class DataActor {
|
|
5
5
|
|
|
6
|
-
constructor(hub, { source, options }) {
|
|
6
|
+
constructor(hub, { source, options, polling = true }) {
|
|
7
7
|
this._hub = hub;
|
|
8
8
|
this._source = source;
|
|
9
9
|
this._options = options;
|
|
10
|
+
this._polling = polling;
|
|
10
11
|
this._unsubscribes = [
|
|
11
12
|
hub.on(fields.session(), session => this._handleSession(session)),
|
|
12
13
|
hub.on(fields.request(), event => this._handleRequest(event)),
|
|
@@ -57,13 +58,15 @@ export default class DataActor {
|
|
|
57
58
|
if (response._response) {
|
|
58
59
|
this._emitResponseWithSessionCheck({ session, request, value: response._response });
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (this._polling) {
|
|
62
|
+
let value;
|
|
63
|
+
for await (value of response) {
|
|
64
|
+
// A new session invalidates ongoing data fetch for the old session, terminating the loop
|
|
65
|
+
if (!isCurrentSession(this._hub, session)) {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
this._emitResponse({ session, request, value });
|
|
65
69
|
}
|
|
66
|
-
this._emitResponse({ session, request, value });
|
|
67
70
|
}
|
|
68
71
|
} else {
|
|
69
72
|
this._emitResponseWithSessionCheck({ session, request, value: response });
|
|
@@ -41,10 +41,7 @@ export function wireRelatedResources(client, element) {
|
|
|
41
41
|
if (!element) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
container.workflow = event.workflow;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
44
|
+
for (const container of element.querySelectorAll('miso-ask')) {
|
|
45
|
+
container.setAttribute('workflow', 'active');
|
|
46
|
+
}
|
|
50
47
|
}
|
|
@@ -95,7 +95,7 @@ class Sections extends _Sections {
|
|
|
95
95
|
relatedResourcesSection(options) {
|
|
96
96
|
const { container, phrase, section } = this._helpers;
|
|
97
97
|
const { features = {}, logo = true } = options;
|
|
98
|
-
const body = features.relatedResources === false ? '' : container(options, { name: 'related-resources', visibleWhen: 'nonempty', logo }, [
|
|
98
|
+
const body = features.relatedResources === false ? '' : container(options, { name: 'related-resources', visibleWhen: 'nonempty', workflow: 'active', logo }, [
|
|
99
99
|
phrase(options, { name: 'related-resources', tag: 'h2' }),
|
|
100
100
|
'<miso-related-resources></miso-related-resources>',
|
|
101
101
|
]);
|
|
@@ -126,10 +126,10 @@ export class Helpers {
|
|
|
126
126
|
}, body);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
container({ classPrefix, circledCitationIndex, parentQuestionId }, { name, extraNames = [], visibleWhen, trait, logo = false }, body) {
|
|
129
|
+
container({ classPrefix, circledCitationIndex, parentQuestionId, workflow }, { name, extraNames = [], visibleWhen, trait, logo = false }, body) {
|
|
130
130
|
const classes = [name, ...extraNames].map(name => `${classPrefix}__${name}-container`);
|
|
131
131
|
circledCitationIndex && classes.push('miso-circled-citation-index');
|
|
132
|
-
return this.element(this._context.CONAINER_TAG, { classes, visibleWhen, trait, logo, parentQuestionId }, body);
|
|
132
|
+
return this.element(this._context.CONAINER_TAG, { classes, visibleWhen, trait, logo, parentQuestionId, workflow }, body);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
element(tag, attributes = {}, body = '') {
|