@miso.ai/client-sdk-ui 1.11.6-beta.0 → 1.11.6-beta.1
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 +5 -7
- package/dist/cjs/actor/feedback.js +1 -2
- package/dist/cjs/actor/filters.js +20 -21
- package/dist/cjs/actor/hub.js +34 -8
- package/dist/cjs/actor/index.js +1 -2
- package/dist/cjs/actor/interactions.js +5 -7
- package/dist/cjs/actor/sessions.js +1 -2
- package/dist/cjs/actor/tracker.js +9 -12
- package/dist/cjs/actor/view.js +11 -20
- package/dist/cjs/actor/views.js +16 -21
- package/dist/cjs/affiliation/index.js +1 -2
- package/dist/cjs/combo/ask/elements.js +3 -4
- package/dist/cjs/combo/ask/index.js +1 -2
- package/dist/cjs/combo/ask/options.js +2 -6
- package/dist/cjs/defaults/ask/controls.js +1 -2
- package/dist/cjs/defaults/ask/index.js +1 -2
- package/dist/cjs/defaults/ask/templates.js +3 -6
- package/dist/cjs/defaults/common/templates.js +30 -41
- package/dist/cjs/defaults/hybrid-search/answer-box.js +9 -11
- package/dist/cjs/defaults/hybrid-search/controls.js +1 -2
- package/dist/cjs/defaults/hybrid-search/index.js +1 -2
- package/dist/cjs/defaults/hybrid-search/templates.js +2 -4
- package/dist/cjs/defaults/index.js +1 -2
- package/dist/cjs/element/container/miso-explore.js +7 -7
- package/dist/cjs/element/container/miso-hybrid-search.js +3 -3
- package/dist/cjs/element/container/miso-recommendation.js +3 -38
- package/dist/cjs/element/container/miso-search.js +3 -3
- package/dist/cjs/element/container/miso-unit.js +52 -0
- package/dist/cjs/element/index.js +1 -2
- package/dist/cjs/element/role/miso-component.js +3 -4
- package/dist/cjs/element/utils.js +6 -9
- package/dist/cjs/layout/affiliation/affiliation.js +4 -6
- package/dist/cjs/layout/banner/banner.js +1 -2
- package/dist/cjs/layout/button/more-button.js +1 -2
- package/dist/cjs/layout/container/container.js +7 -12
- package/dist/cjs/layout/error/error.js +1 -2
- package/dist/cjs/layout/input/facets.js +28 -41
- package/dist/cjs/layout/input/option-list.js +1 -2
- package/dist/cjs/layout/input/search-box.js +30 -39
- package/dist/cjs/layout/input/select.js +1 -2
- package/dist/cjs/layout/list/cards.js +1 -2
- package/dist/cjs/layout/list/carousel.js +1 -2
- package/dist/cjs/layout/list/collection.js +12 -16
- package/dist/cjs/layout/list/gallery.js +18 -26
- package/dist/cjs/layout/list/list.js +1 -2
- package/dist/cjs/layout/mixin/swipeable.js +3 -4
- package/dist/cjs/layout/mixin/trackable.js +3 -6
- package/dist/cjs/layout/progressive.js +1 -2
- package/dist/cjs/layout/radio/feedback.js +6 -8
- package/dist/cjs/layout/radio/radio.js +5 -6
- package/dist/cjs/layout/raf.js +6 -10
- package/dist/cjs/layout/template.js +7 -10
- package/dist/cjs/layout/templates.js +51 -71
- package/dist/cjs/layout/text/text.js +6 -8
- package/dist/cjs/layout/text/typewriter/index.js +14 -18
- package/dist/cjs/layout/text/typewriter/plaintext.js +8 -10
- package/dist/cjs/layout/text/typewriter/utils.js +12 -15
- package/dist/cjs/plugin.js +13 -3
- package/dist/cjs/source.js +6 -7
- package/dist/cjs/util/dom.js +1 -2
- package/dist/cjs/util/proxy.js +3 -4
- package/dist/cjs/util/trackers.js +1 -3
- package/dist/cjs/util/viewables.js +1 -2
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +17 -24
- package/dist/cjs/workflow/ask.js +1 -2
- package/dist/cjs/workflow/asks.js +4 -6
- package/dist/cjs/workflow/autocomplete.js +3 -4
- package/dist/cjs/workflow/base.js +56 -54
- package/dist/cjs/workflow/explore.js +18 -22
- package/dist/cjs/workflow/explores.js +18 -0
- package/dist/cjs/workflow/hybrid-search-answer.js +4 -3
- package/dist/cjs/workflow/index.js +3 -3
- package/dist/cjs/workflow/options/api.js +2 -6
- package/dist/cjs/workflow/options/auto-query.js +2 -4
- package/dist/cjs/workflow/options/configurable.js +2 -6
- package/dist/cjs/workflow/options/data-processor.js +1 -4
- package/dist/cjs/workflow/options/filters.js +1 -4
- package/dist/cjs/workflow/options/interactions.js +1 -4
- package/dist/cjs/workflow/options/layouts.js +2 -6
- package/dist/cjs/workflow/options/options.js +5 -8
- package/dist/cjs/workflow/options/pagination.js +1 -4
- package/dist/cjs/workflow/options/roles.js +1 -3
- package/dist/cjs/workflow/options/trackers.js +6 -16
- package/dist/cjs/workflow/processors.js +16 -22
- package/dist/cjs/workflow/recommendation.js +9 -52
- package/dist/cjs/workflow/recommendations.js +3 -23
- package/dist/cjs/workflow/search-based.js +12 -8
- package/dist/cjs/workflow/search.js +1 -5
- package/dist/cjs/workflow/unit.js +58 -0
- package/dist/cjs/workflow/units.js +37 -0
- package/dist/cjs/workflow/use-link.js +3 -6
- package/package.json +2 -2
- package/src/actor/filters.js +4 -2
- package/src/actor/hub.js +26 -5
- package/src/element/container/miso-explore.js +8 -8
- package/src/element/container/miso-hybrid-search.js +4 -4
- package/src/element/container/miso-recommendation.js +3 -45
- package/src/element/container/miso-search.js +4 -4
- package/src/element/container/miso-unit.js +55 -0
- package/src/layout/radio/radio.js +1 -0
- package/src/layout/templates.js +3 -2
- package/src/plugin.js +15 -2
- package/src/version.js +1 -1
- package/src/workflow/autocomplete.js +1 -0
- package/src/workflow/base.js +33 -23
- package/src/workflow/explore.js +13 -12
- package/src/workflow/explores.js +14 -0
- package/src/workflow/hybrid-search-answer.js +1 -1
- package/src/workflow/index.js +1 -1
- package/src/workflow/processors.js +2 -2
- package/src/workflow/recommendation.js +9 -47
- package/src/workflow/recommendations.js +3 -23
- package/src/workflow/search-based.js +4 -0
- package/src/workflow/unit.js +52 -0
- package/src/workflow/units.js +37 -0
package/package.json
CHANGED
package/src/actor/filters.js
CHANGED
|
@@ -67,10 +67,12 @@ export default class Filters {
|
|
|
67
67
|
this._events.emit('update', { updates, states, oldStates });
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
reset() {
|
|
71
|
-
|
|
70
|
+
reset({ silent = false } = {}) {
|
|
71
|
+
// TODO: review this
|
|
72
|
+
const oldStates = this._states;
|
|
72
73
|
this._states = undefined;
|
|
73
74
|
const states = this._getStates();
|
|
75
|
+
this._hub.update(fields.filters(), states, { silent });
|
|
74
76
|
this._events.emit('reset', { states, oldStates });
|
|
75
77
|
}
|
|
76
78
|
|
package/src/actor/hub.js
CHANGED
|
@@ -2,8 +2,9 @@ import { defineValues, EventEmitter } from '@miso.ai/commons';
|
|
|
2
2
|
|
|
3
3
|
export default class Hub {
|
|
4
4
|
|
|
5
|
-
constructor() {
|
|
5
|
+
constructor(options = {}) {
|
|
6
6
|
(this._events = new EventEmitter())._injectSubscribeInterface(this);
|
|
7
|
+
this._options = options;
|
|
7
8
|
this._states = {};
|
|
8
9
|
defineValues(this, {
|
|
9
10
|
states: new Proxy(this._states, {
|
|
@@ -12,15 +13,35 @@ export default class Hub {
|
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
update(name, state,
|
|
16
|
+
update(name, state, options = {}) {
|
|
16
17
|
this._states[name] = Object.freeze(state);
|
|
17
|
-
|
|
18
|
+
const event = Object.freeze({ action: 'update', name, state, ...options });
|
|
19
|
+
// callback after update, before emit
|
|
20
|
+
if (typeof this._options.onUpdate === 'function') {
|
|
21
|
+
this._options.onUpdate(event);
|
|
22
|
+
}
|
|
23
|
+
// emit
|
|
24
|
+
if (!options.silent) {
|
|
18
25
|
this._events.emit(name, state);
|
|
19
26
|
}
|
|
27
|
+
// callback after emit
|
|
28
|
+
if (typeof this._options.onEmit === 'function') {
|
|
29
|
+
this._options.onEmit(event);
|
|
30
|
+
}
|
|
20
31
|
}
|
|
21
32
|
|
|
22
|
-
trigger(name,
|
|
23
|
-
|
|
33
|
+
trigger(name, state) {
|
|
34
|
+
const event = Object.freeze({ action: 'trigger', name, state });
|
|
35
|
+
// callback before emit
|
|
36
|
+
if (typeof this._options.onUpdate === 'function') {
|
|
37
|
+
this._options.onUpdate(event);
|
|
38
|
+
}
|
|
39
|
+
// emit
|
|
40
|
+
this._events.emit(name, state);
|
|
41
|
+
// callback after emit
|
|
42
|
+
if (typeof this._options.onEmit === 'function') {
|
|
43
|
+
this._options.onEmit(event);
|
|
44
|
+
}
|
|
24
45
|
}
|
|
25
46
|
|
|
26
47
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import MisoUnitElement from './miso-unit.js';
|
|
2
2
|
|
|
3
3
|
const TAG_NAME = 'miso-explore';
|
|
4
4
|
|
|
5
|
-
export default class MisoExploreElement extends
|
|
6
|
-
|
|
7
|
-
static get observedAttributes() {
|
|
8
|
-
return MisoContainerElement.observedAttributes;
|
|
9
|
-
}
|
|
5
|
+
export default class MisoExploreElement extends MisoUnitElement {
|
|
10
6
|
|
|
11
7
|
static get tagName() {
|
|
12
8
|
return TAG_NAME;
|
|
13
9
|
}
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
return
|
|
11
|
+
static get observedAttributes() {
|
|
12
|
+
return MisoUnitElement.observedAttributes;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_getWorkflowByUnitId(client, unitId) {
|
|
16
|
+
return client.ui.explores.get(unitId);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
}
|
|
@@ -4,14 +4,14 @@ const TAG_NAME = 'miso-hybrid-search';
|
|
|
4
4
|
|
|
5
5
|
export default class MisoHybridSearchElement extends MisoContainerElement {
|
|
6
6
|
|
|
7
|
-
static get observedAttributes() {
|
|
8
|
-
return MisoContainerElement.observedAttributes;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
7
|
static get tagName() {
|
|
12
8
|
return TAG_NAME;
|
|
13
9
|
}
|
|
14
10
|
|
|
11
|
+
static get observedAttributes() {
|
|
12
|
+
return MisoContainerElement.observedAttributes;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
15
|
_getWorkflow(client) {
|
|
16
16
|
return client.ui.hybridSearch;
|
|
17
17
|
}
|
|
@@ -1,61 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import MisoUnitElement from './miso-unit.js';
|
|
2
2
|
|
|
3
3
|
const TAG_NAME = 'miso-recommendation';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const OBSERVED_ATTRIBUTES = Object.freeze([
|
|
7
|
-
...MisoContainerElement.observedAttributes,
|
|
8
|
-
ATTR_UNIT_ID,
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
export default class MisoRecommendationElement extends MisoContainerElement {
|
|
5
|
+
export default class MisoRecommendationElement extends MisoUnitElement {
|
|
12
6
|
|
|
13
7
|
static get tagName() {
|
|
14
8
|
return TAG_NAME;
|
|
15
9
|
}
|
|
16
10
|
|
|
17
11
|
static get observedAttributes() {
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_getWorkflow(client) {
|
|
22
|
-
return this._getWorkflowByUnitId(client, this.unitId);
|
|
12
|
+
return MisoUnitElement.observedAttributes;
|
|
23
13
|
}
|
|
24
14
|
|
|
25
15
|
_getWorkflowByUnitId(client, unitId) {
|
|
26
16
|
return client.ui.recommendations.get(unitId);
|
|
27
17
|
}
|
|
28
18
|
|
|
29
|
-
// properties //
|
|
30
|
-
get unitId() {
|
|
31
|
-
return this.getAttribute(ATTR_UNIT_ID) || undefined;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
set unitId(value) {
|
|
35
|
-
value = value && `${value}`;
|
|
36
|
-
if (value) {
|
|
37
|
-
this.setAttribute(ATTR_UNIT_ID, value);
|
|
38
|
-
} else {
|
|
39
|
-
this.removeAttribute(ATTR_UNIT_ID);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// lifecycle //
|
|
44
|
-
attributeChangedCallback(attr, oldValue, newValue) {
|
|
45
|
-
switch (attr) {
|
|
46
|
-
case ATTR_UNIT_ID:
|
|
47
|
-
this._handleUnitIdUpdate(oldValue, newValue);
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
super.attributeChangedCallback(attr, oldValue, newValue);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
_handleUnitIdUpdate(oldUnitId, newUnitId) {
|
|
55
|
-
if (oldUnitId === newUnitId || !this._client) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
this._setWorkflow(this._getWorkflowByUnitId(this._client, newUnitId));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
19
|
}
|
|
@@ -4,14 +4,14 @@ const TAG_NAME = 'miso-search';
|
|
|
4
4
|
|
|
5
5
|
export default class MisoSearchElement extends MisoContainerElement {
|
|
6
6
|
|
|
7
|
-
static get observedAttributes() {
|
|
8
|
-
return MisoContainerElement.observedAttributes;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
7
|
static get tagName() {
|
|
12
8
|
return TAG_NAME;
|
|
13
9
|
}
|
|
14
10
|
|
|
11
|
+
static get observedAttributes() {
|
|
12
|
+
return MisoContainerElement.observedAttributes;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
15
|
_getWorkflow(client) {
|
|
16
16
|
return client.ui.search;
|
|
17
17
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import MisoContainerElement from './miso-container.js';
|
|
2
|
+
|
|
3
|
+
const ATTR_UNIT_ID = 'unit-id';
|
|
4
|
+
const OBSERVED_ATTRIBUTES = Object.freeze([
|
|
5
|
+
...MisoContainerElement.observedAttributes,
|
|
6
|
+
ATTR_UNIT_ID,
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
export default class MisoUnitElement extends MisoContainerElement {
|
|
10
|
+
|
|
11
|
+
static get observedAttributes() {
|
|
12
|
+
return OBSERVED_ATTRIBUTES;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_getWorkflow(client) {
|
|
16
|
+
return this._getWorkflowByUnitId(client, this.unitId);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_getWorkflowByUnitId(client, unitId) {
|
|
20
|
+
throw new Error('Not implemented');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// properties //
|
|
24
|
+
get unitId() {
|
|
25
|
+
return this.getAttribute(ATTR_UNIT_ID) || undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
set unitId(value) {
|
|
29
|
+
value = value && `${value}`;
|
|
30
|
+
if (value) {
|
|
31
|
+
this.setAttribute(ATTR_UNIT_ID, value);
|
|
32
|
+
} else {
|
|
33
|
+
this.removeAttribute(ATTR_UNIT_ID);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// lifecycle //
|
|
38
|
+
attributeChangedCallback(attr, oldValue, newValue) {
|
|
39
|
+
switch (attr) {
|
|
40
|
+
case ATTR_UNIT_ID:
|
|
41
|
+
this._handleUnitIdUpdate(oldValue, newValue);
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
super.attributeChangedCallback(attr, oldValue, newValue);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_handleUnitIdUpdate(oldUnitId, newUnitId) {
|
|
49
|
+
if (oldUnitId === newUnitId || !this._client) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this._setWorkflow(this._getWorkflowByUnitId(this._client, newUnitId));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
@@ -50,6 +50,7 @@ export default class RadioLayout extends TemplateBasedLayout {
|
|
|
50
50
|
view.hub.on(this._field, () => this._refresh()),
|
|
51
51
|
proxyElement.on('click', (e) => this._handleClick(e)),
|
|
52
52
|
];
|
|
53
|
+
// TODO: it shall not carry the responsibility of setting default value
|
|
53
54
|
this._defaultValue ? this._select(this._defaultValue, { silent: true }) : this._clear({ silent: true });
|
|
54
55
|
}
|
|
55
56
|
|
package/src/layout/templates.js
CHANGED
|
@@ -100,8 +100,9 @@ export function imageInfoBlock(layout, data, meta) {
|
|
|
100
100
|
].join('')}</div>`;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
export function titleBlock({ className }, { title }) {
|
|
104
|
-
|
|
103
|
+
export function titleBlock({ className }, { title, _title_with_markups }) {
|
|
104
|
+
const text = _title_with_markups || escapeHtml(title);
|
|
105
|
+
return text ? `<div class="${className}__item-title">${text}</div>` : '';
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
export function brandBlock({ className }, { brand, brand_logo }) {
|
package/src/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, Resolution, defineAndUpgrade, delegateGetters, defineValues } from '@miso.ai/commons';
|
|
2
|
-
import { Asks, HybridSearch,
|
|
2
|
+
import { Asks, HybridSearch, Explores, Search, Recommendations } from './workflow/index.js';
|
|
3
3
|
import { AskCombo } from './combo/index.js';
|
|
4
4
|
import Layouts from './layouts.js';
|
|
5
5
|
import * as elements from './element/index.js';
|
|
@@ -23,6 +23,7 @@ export default class UiPlugin extends Component {
|
|
|
23
23
|
super('ui');
|
|
24
24
|
this.layouts = new Layouts(this);
|
|
25
25
|
this._recommendations = new WeakMap();
|
|
26
|
+
this._explores = new WeakMap();
|
|
26
27
|
this._asks = new WeakMap();
|
|
27
28
|
this._extensions = new WeakMap();
|
|
28
29
|
this._ready = new Resolution();
|
|
@@ -114,6 +115,14 @@ export default class UiPlugin extends Component {
|
|
|
114
115
|
return recommendations;
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
_getExplores(client) {
|
|
119
|
+
let explores = this._explores.get(client);
|
|
120
|
+
if (!explores) {
|
|
121
|
+
this._explores.set(client, explores = new Explores(this, client));
|
|
122
|
+
}
|
|
123
|
+
return explores;
|
|
124
|
+
}
|
|
125
|
+
|
|
117
126
|
_getAsks(client) {
|
|
118
127
|
let asks = this._asks.get(client);
|
|
119
128
|
if (!asks) {
|
|
@@ -180,8 +189,12 @@ class Ui {
|
|
|
180
189
|
return this._hybridSearch || (this._hybridSearch = new HybridSearch(this._plugin, this._client));
|
|
181
190
|
}
|
|
182
191
|
|
|
192
|
+
get explores() {
|
|
193
|
+
return this._explores || (this._explores = this._plugin._getExplores(this._client));
|
|
194
|
+
}
|
|
195
|
+
|
|
183
196
|
get explore() {
|
|
184
|
-
return this.
|
|
197
|
+
return this.explores.get(); // get default explore unit
|
|
185
198
|
}
|
|
186
199
|
|
|
187
200
|
get ready() {
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.11.6-beta.
|
|
1
|
+
export default '1.11.6-beta.1';
|
package/src/workflow/base.js
CHANGED
|
@@ -6,24 +6,6 @@ import { ContainerLayout, ErrorLayout } from '../layout/index.js';
|
|
|
6
6
|
import { WorkflowOptions, mergeApiOptions, makeConfigurable } from './options/index.js';
|
|
7
7
|
import { getRevision, writeDataStatus, writeMisoIdToMeta, buildBaseInteraction, writeAffiliationInfoToInteraction, mergeInteraction } from './processors.js';
|
|
8
8
|
|
|
9
|
-
// TODO: just bury this into hub
|
|
10
|
-
function injectLogger(hub, callback) {
|
|
11
|
-
const { update, trigger } = hub;
|
|
12
|
-
hub.update = (name, state, options) => {
|
|
13
|
-
const result = update.call(hub, name, state, options);
|
|
14
|
-
if (!options || !options.silent) {
|
|
15
|
-
callback('update', name, state, options);
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
hub.trigger = (...args) => {
|
|
20
|
-
const result = trigger.apply(hub, args);
|
|
21
|
-
callback('trigger', ...args);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
return hub;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
9
|
const DEFAULT_API_OPTIONS = Object.freeze({});
|
|
28
10
|
|
|
29
11
|
const DEFAULT_LAYOUTS = Object.freeze({
|
|
@@ -62,9 +44,14 @@ export default class Workflow extends Component {
|
|
|
62
44
|
this._extensions = plugin._getExtensions(client);
|
|
63
45
|
this._defaults = defaults;
|
|
64
46
|
this._options = options || new WorkflowOptions(context && context._options, defaults);
|
|
65
|
-
this._hub =
|
|
47
|
+
this._hub = new Hub({
|
|
48
|
+
onUpdate: event => this._onHubUpdate(event),
|
|
49
|
+
onEmit: event => this._onHubEmit(event),
|
|
50
|
+
});
|
|
66
51
|
this._sessionContext = new WeakMap();
|
|
67
52
|
|
|
53
|
+
client._events.emit('workflow', this);
|
|
54
|
+
|
|
68
55
|
this._initProperties(args);
|
|
69
56
|
this._initActors(args);
|
|
70
57
|
this._initSubscriptions(args);
|
|
@@ -108,8 +95,25 @@ export default class Workflow extends Component {
|
|
|
108
95
|
return context;
|
|
109
96
|
}
|
|
110
97
|
|
|
98
|
+
// hub //
|
|
99
|
+
_onHubUpdate(event) {
|
|
100
|
+
this._runCallbacks(this._client.meta.parent._hubUpdateCallbacks, event);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_onHubEmit(event) {
|
|
104
|
+
this._runCallbacks(this._client.meta.parent._hubEmitCallbacks, event);
|
|
105
|
+
this._emitAsWorkflowEvent(event);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_emitAsWorkflowEvent({ action: _action, name, state, silent }) {
|
|
109
|
+
if (!silent) {
|
|
110
|
+
this._emit(name, { _action, ...state });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
111
114
|
// properties //
|
|
112
115
|
get uuid() {
|
|
116
|
+
// TODO: review this
|
|
113
117
|
return this.session && this.session.uuid;
|
|
114
118
|
}
|
|
115
119
|
|
|
@@ -319,14 +323,20 @@ export default class Workflow extends Component {
|
|
|
319
323
|
}
|
|
320
324
|
|
|
321
325
|
// helper //
|
|
322
|
-
|
|
323
|
-
|
|
326
|
+
_runCallbacks(callbacks, event) {
|
|
327
|
+
for (const callback of callbacks) {
|
|
328
|
+
try {
|
|
329
|
+
callback({ workflow: this, ...event });
|
|
330
|
+
} catch(e) {
|
|
331
|
+
this._error(e);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
324
334
|
}
|
|
325
335
|
|
|
326
336
|
_emit(name, data) {
|
|
327
|
-
this._events.emit(name, data);
|
|
337
|
+
this._events.emit(name, { _event: name, ...data });
|
|
328
338
|
if (this._context) {
|
|
329
|
-
this._context._events.emit(name, { workflow: this, ...data });
|
|
339
|
+
this._context._events.emit(name, { workflow: this, _event: name, ...data });
|
|
330
340
|
}
|
|
331
341
|
}
|
|
332
342
|
|
package/src/workflow/explore.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { API } from '@miso.ai/commons';
|
|
2
|
-
import
|
|
2
|
+
import UnitWorkflow from './unit.js';
|
|
3
3
|
import { fields } from '../actor/index.js';
|
|
4
4
|
import { ROLE, EVENT_TYPE } from '../constants.js';
|
|
5
5
|
import { ListLayout, SearchBoxLayout } from '../layout/index.js';
|
|
@@ -7,19 +7,19 @@ import { mergeRolesOptions, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
|
|
|
7
7
|
import { enableUseLink, UseLinkMixin } from './use-link.js';
|
|
8
8
|
|
|
9
9
|
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
10
|
-
...
|
|
10
|
+
...UnitWorkflow.DEFAULT_API_OPTIONS,
|
|
11
11
|
group: API.GROUP.ASK,
|
|
12
12
|
name: API.NAME.RELATED_QUESTIONS,
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
const DEFAULT_LAYOUTS = Object.freeze({
|
|
16
|
-
...
|
|
16
|
+
...UnitWorkflow.DEFAULT_LAYOUTS,
|
|
17
17
|
[ROLE.RELATED_QUESTIONS]: [ListLayout.type, { itemType: 'question', link: { rel: 'noopener nofollow' } }],
|
|
18
18
|
[ROLE.QUERY]: [SearchBoxLayout.type, { placeholder: 'Ask a question' }],
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
const DEFAULT_TRACKERS = Object.freeze({
|
|
22
|
-
...
|
|
22
|
+
...UnitWorkflow.DEFAULT_TRACKERS,
|
|
23
23
|
[ROLE.RELATED_QUESTIONS]: DEFAULT_TRACKER_OPTIONS,
|
|
24
24
|
[ROLE.CONTAINER]: {
|
|
25
25
|
...DEFAULT_TRACKER_OPTIONS,
|
|
@@ -33,26 +33,26 @@ const DEFAULT_TRACKERS = Object.freeze({
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
const DEFAULT_OPTIONS = Object.freeze({
|
|
36
|
-
...
|
|
36
|
+
...UnitWorkflow.DEFAULT_OPTIONS,
|
|
37
37
|
api: DEFAULT_API_OPTIONS,
|
|
38
38
|
layouts: DEFAULT_LAYOUTS,
|
|
39
39
|
trackers: DEFAULT_TRACKERS,
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
const ROLES_OPTIONS = mergeRolesOptions(
|
|
42
|
+
const ROLES_OPTIONS = mergeRolesOptions(UnitWorkflow.ROLES_OPTIONS, {
|
|
43
43
|
main: ROLE.RELATED_QUESTIONS,
|
|
44
44
|
members: Object.keys(DEFAULT_LAYOUTS),
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
export default class Explore extends
|
|
47
|
+
export default class Explore extends UnitWorkflow {
|
|
48
48
|
|
|
49
|
-
constructor(
|
|
49
|
+
constructor(context, id) {
|
|
50
50
|
super({
|
|
51
51
|
name: 'explore',
|
|
52
|
-
|
|
53
|
-
client,
|
|
52
|
+
context,
|
|
54
53
|
roles: ROLES_OPTIONS,
|
|
55
54
|
defaults: DEFAULT_OPTIONS,
|
|
55
|
+
id,
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -79,12 +79,13 @@ export default class Explore extends Workflow {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
useApi(
|
|
82
|
+
useApi(...args) {
|
|
83
|
+
const options = (typeof args[0] === 'object' ? args[0] : args[1]) || {};
|
|
83
84
|
const { product_id } = options;
|
|
84
85
|
if (product_id) {
|
|
85
86
|
this._productId = product_id;
|
|
86
87
|
}
|
|
87
|
-
return super.useApi(
|
|
88
|
+
return super.useApi(...args);
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
useLink(fn, options) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import UnitWorkflowContext from './units.js';
|
|
2
|
+
import Explore from './explore.js';
|
|
3
|
+
|
|
4
|
+
export default class Explores extends UnitWorkflowContext {
|
|
5
|
+
|
|
6
|
+
constructor(plugin, client) {
|
|
7
|
+
super('explores', plugin, client);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
_create(unitId) {
|
|
11
|
+
return new Explore(this, unitId);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
@@ -36,7 +36,7 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
|
|
|
36
36
|
super.restart();
|
|
37
37
|
// cascade restart to the sibling
|
|
38
38
|
const results = this._superworkflow._results;
|
|
39
|
-
results._views.filters.reset();
|
|
39
|
+
results._views.filters.reset({ silent: true });
|
|
40
40
|
results.restart();
|
|
41
41
|
this._resultsSession = results.session; // keep track of the session
|
|
42
42
|
}
|
package/src/workflow/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as Asks } from './asks.js';
|
|
2
2
|
export { default as HybridSearch } from './hybrid-search.js';
|
|
3
|
-
export { default as Explore } from './explore.js';
|
|
4
3
|
export { default as Search } from './search.js';
|
|
5
4
|
export { default as Recommendations } from './recommendations.js';
|
|
5
|
+
export { default as Explores } from './explores.js';
|
|
@@ -175,10 +175,10 @@ export function concatItemsFromMoreResponse(oldData, newData, { role = ROLE.PROD
|
|
|
175
175
|
// use old values of facet_counts and total, for they are affected by product_id exclusion
|
|
176
176
|
return {
|
|
177
177
|
...newData,
|
|
178
|
-
facet_counts,
|
|
179
|
-
total,
|
|
180
178
|
value: {
|
|
181
179
|
...newData.value,
|
|
180
|
+
facet_counts,
|
|
181
|
+
total,
|
|
182
182
|
[role]: [...oldProducts, ...newProducts],
|
|
183
183
|
},
|
|
184
184
|
}
|
|
@@ -1,43 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { API } from '@miso.ai/commons';
|
|
2
|
+
import UnitWorkflow from './unit.js';
|
|
3
3
|
import { ListLayout } from '../layout/index.js';
|
|
4
4
|
import { ROLE } from '../constants.js';
|
|
5
5
|
import { mergeRolesOptions, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
|
|
6
|
-
import { mergeInteraction } from './processors.js';
|
|
7
6
|
|
|
8
7
|
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
9
|
-
...
|
|
8
|
+
...UnitWorkflow.DEFAULT_API_OPTIONS,
|
|
10
9
|
group: API.GROUP.RECOMMENDATION,
|
|
11
10
|
name: API.NAME.USER_TO_PRODUCTS,
|
|
12
11
|
payload: {
|
|
13
|
-
...
|
|
12
|
+
...UnitWorkflow.DEFAULT_API_OPTIONS.payload,
|
|
14
13
|
fl: ['*'],
|
|
15
14
|
},
|
|
16
15
|
});
|
|
17
16
|
|
|
18
17
|
const DEFAULT_LAYOUTS = Object.freeze({
|
|
19
|
-
...
|
|
18
|
+
...UnitWorkflow.DEFAULT_LAYOUTS,
|
|
20
19
|
[ROLE.PRODUCTS]: ListLayout.type,
|
|
21
20
|
});
|
|
22
21
|
|
|
23
22
|
const DEFAULT_TRACKERS = Object.freeze({
|
|
24
|
-
...
|
|
23
|
+
...UnitWorkflow.DEFAULT_TRACKERS,
|
|
25
24
|
[ROLE.PRODUCTS]: DEFAULT_TRACKER_OPTIONS,
|
|
26
25
|
});
|
|
27
26
|
|
|
28
27
|
const DEFAULT_OPTIONS = Object.freeze({
|
|
29
|
-
...
|
|
28
|
+
...UnitWorkflow.DEFAULT_OPTIONS,
|
|
30
29
|
api: DEFAULT_API_OPTIONS,
|
|
31
30
|
layouts: DEFAULT_LAYOUTS,
|
|
32
31
|
trackers: DEFAULT_TRACKERS,
|
|
33
32
|
});
|
|
34
33
|
|
|
35
|
-
const ROLES_OPTIONS = mergeRolesOptions(
|
|
34
|
+
const ROLES_OPTIONS = mergeRolesOptions(UnitWorkflow.ROLES_OPTIONS, {
|
|
36
35
|
main: ROLE.PRODUCTS,
|
|
37
36
|
members: Object.keys(DEFAULT_LAYOUTS),
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
export default class Recommendation extends
|
|
39
|
+
export default class Recommendation extends UnitWorkflow {
|
|
41
40
|
|
|
42
41
|
constructor(context, id) {
|
|
43
42
|
super({
|
|
@@ -49,17 +48,6 @@ export default class Recommendation extends Workflow {
|
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
_initProperties(args) {
|
|
53
|
-
super._initProperties(args);
|
|
54
|
-
const { id } = args;
|
|
55
|
-
defineValues(this, { id });
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
_initSession(args) {
|
|
59
|
-
this._context._members.set(args.id, this);
|
|
60
|
-
super._initSession(args);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
51
|
// lifecycle //
|
|
64
52
|
start() {
|
|
65
53
|
// in recommendation workflow, start() triggers query
|
|
@@ -72,30 +60,4 @@ export default class Recommendation extends Workflow {
|
|
|
72
60
|
return this;
|
|
73
61
|
}
|
|
74
62
|
|
|
75
|
-
// interactions //
|
|
76
|
-
_defaultProcessInteraction(payload, args) {
|
|
77
|
-
payload = super._defaultProcessInteraction(payload, args);
|
|
78
|
-
payload = this._writeUnitIdToInteraction(payload, args);
|
|
79
|
-
return payload;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_writeUnitIdToInteraction(payload) {
|
|
83
|
-
const unit_id = this.id;
|
|
84
|
-
const unit_instance_uuid = this.uuid;
|
|
85
|
-
return mergeInteraction(payload, {
|
|
86
|
-
context: {
|
|
87
|
-
custom_context: {
|
|
88
|
-
unit_id,
|
|
89
|
-
unit_instance_uuid,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// destroy //
|
|
96
|
-
_destroy(options) {
|
|
97
|
-
this._context._members.delete(this.id);
|
|
98
|
-
super._destroy(options);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
63
|
}
|