@miso.ai/client-sdk-ui 1.9.2-beta.0 → 1.9.3-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/util/states.js +8 -4
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/ask.js +26 -3
- package/package.json +2 -2
- package/src/util/states.js +8 -3
- package/src/version.js +1 -1
- package/src/workflow/ask.js +21 -2
package/dist/cjs/util/states.js
CHANGED
|
@@ -40,18 +40,18 @@ class States {
|
|
|
40
40
|
getFullState(productId) {
|
|
41
41
|
// when we receive a bind event, impression is trigger, making an entry here
|
|
42
42
|
// so if the state is not found, the product is not present yet => all untracked
|
|
43
|
-
const state = this._states.get(productId);
|
|
43
|
+
const state = this._states.get(getKey(productId));
|
|
44
44
|
return state ? Object.assign({}, state) : STATES.UNTRACKED;
|
|
45
45
|
}
|
|
46
46
|
get(productId, type) {
|
|
47
|
-
const state = this._states.get(productId);
|
|
47
|
+
const state = this._states.get(getKey(productId));
|
|
48
48
|
return state && state[type] || UNTRACKED;
|
|
49
49
|
}
|
|
50
50
|
set(productIds, type, status) {
|
|
51
51
|
(0, _constants.validateEventType)(type);
|
|
52
52
|
(0, _constants.validateTrackingStatus)(status);
|
|
53
53
|
for (const productId of (0, _commons.asArray)(productIds)) {
|
|
54
|
-
this._setOne(productId, type, status);
|
|
54
|
+
this._setOne(getKey(productId), type, status);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
_setOne(productId, type, status) {
|
|
@@ -62,4 +62,8 @@ class States {
|
|
|
62
62
|
return productIds.filter(productId => this.get(productId, type) !== TRIGGERED);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
exports.default = States;
|
|
65
|
+
exports.default = States;
|
|
66
|
+
function getKey(value) {
|
|
67
|
+
// TODO: ad-hoc!
|
|
68
|
+
return value.product_id || value.text || value;
|
|
69
|
+
}
|
package/dist/cjs/version.js
CHANGED
package/dist/cjs/workflow/ask.js
CHANGED
|
@@ -71,12 +71,13 @@ class Ask extends _base.default {
|
|
|
71
71
|
defaults: DEFAULT_OPTIONS
|
|
72
72
|
});
|
|
73
73
|
this._context = context;
|
|
74
|
+
this._autoQuery = false;
|
|
74
75
|
(0, _commons.defineValues)(this, {
|
|
75
76
|
parentQuestionId
|
|
76
77
|
});
|
|
77
78
|
this._feedback = new _index.FeedbackActor(this._hub);
|
|
78
79
|
this._setSuggestedQuestions();
|
|
79
|
-
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), payload => this.query(payload)), this._hub.on(_index.fields.
|
|
80
|
+
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), payload => this.query(payload)), this._hub.on(_index.fields.view(_constants.ROLE.ANSWER), data => this._onAnswerViewUpdate(data)), this._views.get(_constants.ROLE.ANSWER).on('citation-click', event => this._onCitationClick(event))];
|
|
80
81
|
parentQuestionId && context._byPqid.set(parentQuestionId, this);
|
|
81
82
|
context._events.emit('create', this);
|
|
82
83
|
this.reset(); // create a session so query suggestions can be tracked
|
|
@@ -110,10 +111,11 @@ class Ask extends _base.default {
|
|
|
110
111
|
|
|
111
112
|
// lifecycle //
|
|
112
113
|
autoQuery() {
|
|
113
|
-
let {
|
|
114
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
115
|
+
const {
|
|
114
116
|
setValue = true,
|
|
115
117
|
focus = true
|
|
116
|
-
} =
|
|
118
|
+
} = this._autoQuery = options;
|
|
117
119
|
const q = new URLSearchParams(window.location.search).get('q');
|
|
118
120
|
const {
|
|
119
121
|
layout
|
|
@@ -187,6 +189,27 @@ class Ask extends _base.default {
|
|
|
187
189
|
if (!value) {
|
|
188
190
|
return data;
|
|
189
191
|
}
|
|
192
|
+
const {
|
|
193
|
+
question_id: questionId,
|
|
194
|
+
question
|
|
195
|
+
} = value;
|
|
196
|
+
|
|
197
|
+
// capture question ID and register at context
|
|
198
|
+
if (!this._questionId && questionId) {
|
|
199
|
+
this._questionId = questionId;
|
|
200
|
+
this._context._byQid.set(questionId, this);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// update URL if autoQuery.updateUrl is not false
|
|
204
|
+
if (this._autoQuery && this._autoQuery.updateUrl !== false) {
|
|
205
|
+
const url = new URL(window.location);
|
|
206
|
+
const currentQuestion = url.searchParams.get('q');
|
|
207
|
+
if (question !== currentQuestion) {
|
|
208
|
+
url.searchParams.set('q', question);
|
|
209
|
+
window.history.replaceState({}, '', url);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
190
213
|
// 1. put answer_stage to meta
|
|
191
214
|
// 2. mark ongoing flag
|
|
192
215
|
return Object.assign({}, data, {
|
package/package.json
CHANGED
package/src/util/states.js
CHANGED
|
@@ -31,12 +31,12 @@ export default class States {
|
|
|
31
31
|
getFullState(productId) {
|
|
32
32
|
// when we receive a bind event, impression is trigger, making an entry here
|
|
33
33
|
// so if the state is not found, the product is not present yet => all untracked
|
|
34
|
-
const state = this._states.get(productId);
|
|
34
|
+
const state = this._states.get(getKey(productId));
|
|
35
35
|
return state ? { ...state } : STATES.UNTRACKED;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
get(productId, type) {
|
|
39
|
-
const state = this._states.get(productId);
|
|
39
|
+
const state = this._states.get(getKey(productId));
|
|
40
40
|
return state && state[type] || UNTRACKED;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -44,7 +44,7 @@ export default class States {
|
|
|
44
44
|
validateEventType(type);
|
|
45
45
|
validateTrackingStatus(status);
|
|
46
46
|
for (const productId of asArray(productIds)) {
|
|
47
|
-
this._setOne(productId, type, status);
|
|
47
|
+
this._setOne(getKey(productId), type, status);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -58,3 +58,8 @@ export default class States {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
}
|
|
61
|
+
|
|
62
|
+
function getKey(value) {
|
|
63
|
+
// TODO: ad-hoc!
|
|
64
|
+
return value.product_id || value.text || value;
|
|
65
|
+
}
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.9.
|
|
1
|
+
export default '1.9.3-beta.0';
|
package/src/workflow/ask.js
CHANGED
|
@@ -54,6 +54,7 @@ export default class Ask extends Workflow {
|
|
|
54
54
|
defaults: DEFAULT_OPTIONS,
|
|
55
55
|
});
|
|
56
56
|
this._context = context;
|
|
57
|
+
this._autoQuery = false;
|
|
57
58
|
defineValues(this, { parentQuestionId });
|
|
58
59
|
|
|
59
60
|
this._feedback = new FeedbackActor(this._hub);
|
|
@@ -62,7 +63,6 @@ export default class Ask extends Workflow {
|
|
|
62
63
|
this._unsubscribes = [
|
|
63
64
|
...this._unsubscribes,
|
|
64
65
|
this._hub.on(fields.query(), payload => this.query(payload)),
|
|
65
|
-
this._hub.on(fields.data(), data => this._onDataUpdate(data)),
|
|
66
66
|
this._hub.on(fields.view(ROLE.ANSWER), data => this._onAnswerViewUpdate(data)),
|
|
67
67
|
this._views.get(ROLE.ANSWER).on('citation-click', event => this._onCitationClick(event)),
|
|
68
68
|
];
|
|
@@ -97,7 +97,8 @@ export default class Ask extends Workflow {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// lifecycle //
|
|
100
|
-
autoQuery(
|
|
100
|
+
autoQuery(options = {}) {
|
|
101
|
+
const { setValue = true, focus = true } = this._autoQuery = options;
|
|
101
102
|
const q = new URLSearchParams(window.location.search).get('q');
|
|
102
103
|
const { layout } = this._views.get(ROLE.QUERY);
|
|
103
104
|
if (layout) {
|
|
@@ -151,6 +152,24 @@ export default class Ask extends Workflow {
|
|
|
151
152
|
if (!value) {
|
|
152
153
|
return data;
|
|
153
154
|
}
|
|
155
|
+
const { question_id: questionId, question } = value;
|
|
156
|
+
|
|
157
|
+
// capture question ID and register at context
|
|
158
|
+
if (!this._questionId && questionId) {
|
|
159
|
+
this._questionId = questionId;
|
|
160
|
+
this._context._byQid.set(questionId, this);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// update URL if autoQuery.updateUrl is not false
|
|
164
|
+
if (this._autoQuery && this._autoQuery.updateUrl !== false) {
|
|
165
|
+
const url = new URL(window.location);
|
|
166
|
+
const currentQuestion = url.searchParams.get('q');
|
|
167
|
+
if (question !== currentQuestion) {
|
|
168
|
+
url.searchParams.set('q', question);
|
|
169
|
+
window.history.replaceState({}, '', url);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
154
173
|
// 1. put answer_stage to meta
|
|
155
174
|
// 2. mark ongoing flag
|
|
156
175
|
return {
|