@miso.ai/client-sdk-ui 1.11.4-beta.1 → 1.11.4-beta.3
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/filters.js +57 -11
- package/dist/cjs/actor/tracker.js +1 -6
- package/dist/cjs/actor/view.js +6 -8
- package/dist/cjs/actor/views.js +10 -26
- package/dist/cjs/constants.js +12 -2
- package/dist/cjs/element/role/index.js +7 -0
- package/dist/cjs/element/role/miso-sort.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +1 -1
- package/dist/cjs/layout/container/container.js +2 -2
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/facets.js +2 -2
- package/dist/cjs/layout/input/search-box.js +1 -1
- package/dist/cjs/layout/input/select.js +150 -0
- package/dist/cjs/layout/raf.js +2 -4
- package/dist/cjs/layout/trackable.js +3 -3
- package/dist/cjs/layout/triggerable.js +1 -1
- package/dist/cjs/util/trackers.js +2 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +2 -2
- package/dist/cjs/workflow/ask.js +4 -1
- package/dist/cjs/workflow/base.js +4 -4
- package/dist/cjs/workflow/context.js +3 -3
- package/dist/cjs/workflow/explore.js +2 -2
- package/dist/cjs/workflow/hybrid-search-answer.js +9 -7
- package/dist/cjs/workflow/hybrid-search-results.js +18 -16
- package/dist/cjs/workflow/hybrid-search-views.js +5 -12
- package/dist/cjs/workflow/hybrid-search.js +2 -2
- package/dist/cjs/workflow/options/api.js +56 -0
- package/dist/cjs/workflow/options/configurable.js +49 -0
- package/dist/cjs/workflow/options/data-processor.js +23 -0
- package/dist/cjs/workflow/options/filters.js +18 -0
- package/dist/cjs/workflow/options/index.js +115 -0
- package/dist/cjs/workflow/options/interactions.js +44 -0
- package/dist/cjs/workflow/options/layouts.js +83 -0
- package/dist/cjs/workflow/options/options.js +154 -0
- package/dist/cjs/workflow/options/pagination.js +28 -0
- package/dist/cjs/workflow/options/roles.js +17 -0
- package/dist/cjs/workflow/options/trackers.js +39 -0
- package/dist/cjs/workflow/options/utils.js +33 -0
- package/dist/cjs/workflow/processors.js +39 -33
- package/dist/cjs/workflow/recommendation.js +2 -2
- package/dist/cjs/workflow/search-based.js +59 -22
- package/package.json +2 -2
- package/src/actor/filters.js +53 -12
- package/src/actor/tracker.js +1 -6
- package/src/actor/view.js +7 -8
- package/src/actor/views.js +9 -30
- package/src/constants.js +11 -0
- package/src/element/role/index.js +1 -0
- package/src/element/role/miso-sort.js +16 -0
- package/src/layout/affiliation/affiliation.js +1 -1
- package/src/layout/container/container.js +2 -2
- package/src/layout/index.js +1 -0
- package/src/layout/input/facets.js +3 -2
- package/src/layout/input/search-box.js +1 -1
- package/src/layout/input/select.js +142 -0
- package/src/layout/raf.js +2 -2
- package/src/layout/trackable.js +3 -3
- package/src/layout/triggerable.js +1 -1
- package/src/util/trackers.js +2 -0
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +1 -1
- package/src/workflow/ask.js +4 -1
- package/src/workflow/base.js +1 -1
- package/src/workflow/context.js +1 -1
- package/src/workflow/explore.js +1 -1
- package/src/workflow/hybrid-search-answer.js +8 -3
- package/src/workflow/hybrid-search-results.js +21 -7
- package/src/workflow/hybrid-search-views.js +4 -12
- package/src/workflow/hybrid-search.js +3 -3
- package/src/workflow/options/api.js +46 -0
- package/src/workflow/options/configurable.js +48 -0
- package/src/workflow/options/data-processor.js +15 -0
- package/src/workflow/options/filters.js +10 -0
- package/src/workflow/options/index.js +10 -0
- package/src/workflow/options/interactions.js +36 -0
- package/src/workflow/options/layouts.js +73 -0
- package/src/workflow/options/options.js +169 -0
- package/src/workflow/options/pagination.js +18 -0
- package/src/workflow/options/roles.js +12 -0
- package/src/workflow/options/trackers.js +32 -0
- package/src/workflow/options/utils.js +26 -0
- package/src/workflow/processors.js +30 -34
- package/src/workflow/recommendation.js +1 -1
- package/src/workflow/search-based.js +58 -13
- package/dist/cjs/workflow/options.js +0 -448
- package/src/workflow/options.js +0 -433
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WorkflowOptions = exports.WorkflowContextOptions = void 0;
|
|
7
|
+
var _commons = require("@miso.ai/commons");
|
|
8
|
+
var _constants = require("../../constants.js");
|
|
9
|
+
var _api = require("./api.js");
|
|
10
|
+
var _layouts = require("./layouts.js");
|
|
11
|
+
var _dataProcessor = require("./data-processor.js");
|
|
12
|
+
var _trackers = require("./trackers.js");
|
|
13
|
+
var _interactions = require("./interactions.js");
|
|
14
|
+
var _filters = require("./filters.js");
|
|
15
|
+
var _pagination = require("./pagination.js");
|
|
16
|
+
const FEATURES = [{
|
|
17
|
+
key: _constants.WORKFLOW_CONFIGURABLE.API,
|
|
18
|
+
normalize: _api.normalizeApiOptions,
|
|
19
|
+
merge: _api.mergeApiOptions
|
|
20
|
+
}, {
|
|
21
|
+
key: _constants.WORKFLOW_CONFIGURABLE.LAYOUTS,
|
|
22
|
+
normalize: _layouts.normalizeLayoutsOptions,
|
|
23
|
+
merge: _layouts.mergeLayoutsOptions
|
|
24
|
+
}, {
|
|
25
|
+
key: _constants.WORKFLOW_CONFIGURABLE.DATA_PROCESSOR,
|
|
26
|
+
normalize: _dataProcessor.normalizeDataProcessorOptions,
|
|
27
|
+
merge: _dataProcessor.mergeDataProcessorOptions
|
|
28
|
+
}, {
|
|
29
|
+
key: _constants.WORKFLOW_CONFIGURABLE.TRACKERS,
|
|
30
|
+
normalize: _trackers.normalizeTrackersOptions,
|
|
31
|
+
merge: _trackers.mergeTrackersOptions
|
|
32
|
+
}, {
|
|
33
|
+
key: _constants.WORKFLOW_CONFIGURABLE.INTERACTIONS,
|
|
34
|
+
normalize: _interactions.normalizeInteractionsOptions,
|
|
35
|
+
merge: _interactions.mergeInteractionsOptions
|
|
36
|
+
}, {
|
|
37
|
+
key: _constants.WORKFLOW_CONFIGURABLE.FILTERS,
|
|
38
|
+
normalize: _filters.normalizeFiltersOptions,
|
|
39
|
+
merge: _filters.mergeFiltersOptions
|
|
40
|
+
}, {
|
|
41
|
+
key: _constants.WORKFLOW_CONFIGURABLE.PAGINATION,
|
|
42
|
+
normalize: _pagination.normalizePaginationOptions,
|
|
43
|
+
merge: _pagination.mergePaginationOptions
|
|
44
|
+
}];
|
|
45
|
+
class WorkflowContextOptions {
|
|
46
|
+
constructor() {
|
|
47
|
+
this._events = new _commons.EventEmitter({
|
|
48
|
+
target: this
|
|
49
|
+
});
|
|
50
|
+
this._globals = {};
|
|
51
|
+
}
|
|
52
|
+
_notify(name) {
|
|
53
|
+
this._events.emit(name);
|
|
54
|
+
this._events.emit('_update', name);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.WorkflowContextOptions = WorkflowContextOptions;
|
|
58
|
+
class WorkflowOptions {
|
|
59
|
+
constructor() {
|
|
60
|
+
let context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
61
|
+
let defaults = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
62
|
+
this._events = new _commons.EventEmitter({
|
|
63
|
+
target: this
|
|
64
|
+
});
|
|
65
|
+
this._defaults = defaults; // TODO: we should call normalize() on defaults
|
|
66
|
+
this._context = context || {};
|
|
67
|
+
this._locals = {};
|
|
68
|
+
(0, _commons.defineValues)(this, {
|
|
69
|
+
resolved: new ResolvedWorkflowOptions(this),
|
|
70
|
+
defaults
|
|
71
|
+
});
|
|
72
|
+
if (context && context.on) {
|
|
73
|
+
this._unsubscribes = [context.on('_update', name => this._notify(name))];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
_notify(name) {
|
|
77
|
+
this.resolved._invalidate(name);
|
|
78
|
+
this._events.emit(name);
|
|
79
|
+
}
|
|
80
|
+
_destroy() {
|
|
81
|
+
for (const unsubscribe of this._unsubscribes || []) {
|
|
82
|
+
unsubscribe();
|
|
83
|
+
}
|
|
84
|
+
this._unsubscribes = [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.WorkflowOptions = WorkflowOptions;
|
|
88
|
+
class ResolvedWorkflowOptions {
|
|
89
|
+
constructor(options) {
|
|
90
|
+
this._options = options;
|
|
91
|
+
this._cache = {};
|
|
92
|
+
}
|
|
93
|
+
_invalidate(key) {
|
|
94
|
+
this._cache[key] = undefined;
|
|
95
|
+
}
|
|
96
|
+
_get(_ref) {
|
|
97
|
+
let {
|
|
98
|
+
key,
|
|
99
|
+
merge
|
|
100
|
+
} = _ref;
|
|
101
|
+
if (this._cache[key] === undefined) {
|
|
102
|
+
const options = this._options;
|
|
103
|
+
const contextFeature = options._context[key];
|
|
104
|
+
this._cache[key] = merge(options._defaults[key], contextFeature && contextFeature.get(), options._locals[key]);
|
|
105
|
+
}
|
|
106
|
+
return this._cache[key];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
class WorkflowConfigurableFeature {
|
|
110
|
+
constructor(options, store, key, normalize, merge) {
|
|
111
|
+
this._options = options;
|
|
112
|
+
this._store = store;
|
|
113
|
+
this._key = key;
|
|
114
|
+
this._normalize = value => value !== undefined ? normalize(value) : undefined;
|
|
115
|
+
this._merge = merge;
|
|
116
|
+
}
|
|
117
|
+
get() {
|
|
118
|
+
return this._store[this._key];
|
|
119
|
+
}
|
|
120
|
+
set(value) {
|
|
121
|
+
this._set(this._normalize(value));
|
|
122
|
+
}
|
|
123
|
+
merge(value) {
|
|
124
|
+
this._set(this._merge(this.get(), this._normalize(value)));
|
|
125
|
+
}
|
|
126
|
+
_set(value) {
|
|
127
|
+
this._store[this._key] = value;
|
|
128
|
+
this._options._notify(this._key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const feature of FEATURES) {
|
|
132
|
+
const {
|
|
133
|
+
key,
|
|
134
|
+
normalize,
|
|
135
|
+
merge
|
|
136
|
+
} = feature;
|
|
137
|
+
Object.defineProperty(WorkflowContextOptions.prototype, key, {
|
|
138
|
+
get: function () {
|
|
139
|
+
const _key = `_${key}`;
|
|
140
|
+
return this[_key] || (this[_key] = new WorkflowConfigurableFeature(this, this._globals, key, normalize, merge));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(WorkflowOptions.prototype, key, {
|
|
144
|
+
get: function () {
|
|
145
|
+
const _key = `_${key}`;
|
|
146
|
+
return this[_key] || (this[_key] = new WorkflowConfigurableFeature(this, this._locals, key, normalize, merge));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(ResolvedWorkflowOptions.prototype, key, {
|
|
150
|
+
get: function () {
|
|
151
|
+
return this._get(feature);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mergePaginationOptions = mergePaginationOptions;
|
|
7
|
+
exports.normalizePaginationOptions = normalizePaginationOptions;
|
|
8
|
+
var _utils = require("./utils.js");
|
|
9
|
+
function normalizePaginationOptions(options) {
|
|
10
|
+
if (options === undefined) {
|
|
11
|
+
throw new Error(`Expect pagination options to be an object or a boolean value: ${options}`);
|
|
12
|
+
}
|
|
13
|
+
if (typeof options === 'boolean') {
|
|
14
|
+
options = {
|
|
15
|
+
active: options
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return options;
|
|
19
|
+
}
|
|
20
|
+
function mergePaginationOptions() {
|
|
21
|
+
for (var _len = arguments.length, optionsList = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22
|
+
optionsList[_key] = arguments[_key];
|
|
23
|
+
}
|
|
24
|
+
if (optionsList[optionsList.length - 1] === false) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return (0, _utils.mergeOptions)(optionsList, (merged, options) => Object.assign(merged, options));
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mergeRolesOptions = mergeRolesOptions;
|
|
7
|
+
function mergeRolesOptions(base, overrides) {
|
|
8
|
+
return Object.freeze(Object.assign({}, base, overrides, {
|
|
9
|
+
members: mergeRolesMembers(base.members, overrides.members),
|
|
10
|
+
mappings: Object.freeze(Object.assign({}, base.mappings, overrides.mappings))
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
function mergeRolesMembers() {
|
|
14
|
+
let base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
15
|
+
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
16
|
+
return [...new Set([...base, ...overrides])];
|
|
17
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mergeTrackersOptions = mergeTrackersOptions;
|
|
7
|
+
exports.normalizeTrackersOptions = normalizeTrackersOptions;
|
|
8
|
+
var _utils = require("./utils.js");
|
|
9
|
+
function normalizeTrackersOptions(options) {
|
|
10
|
+
if (options === undefined || options === false) {
|
|
11
|
+
return options;
|
|
12
|
+
}
|
|
13
|
+
const normalized = {};
|
|
14
|
+
for (const [role, args] of Object.entries(options)) {
|
|
15
|
+
normalized[role] = normalizeTrackerOptions(args);
|
|
16
|
+
}
|
|
17
|
+
return normalized;
|
|
18
|
+
}
|
|
19
|
+
function normalizeTrackerOptions(options) {
|
|
20
|
+
return options;
|
|
21
|
+
}
|
|
22
|
+
function mergeTrackersOptions() {
|
|
23
|
+
for (var _len = arguments.length, optionsList = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
24
|
+
optionsList[_key] = arguments[_key];
|
|
25
|
+
}
|
|
26
|
+
if (optionsList[optionsList.length - 1] === false) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return (0, _utils.mergeOptions)(optionsList, (merged, options) => Object.assign(merged, Object.assign({}, options, {
|
|
30
|
+
impression: mergeTrackerEventOptions(merged.impression, options.impression),
|
|
31
|
+
viewable: mergeTrackerEventOptions(merged.viewable, options.viewable),
|
|
32
|
+
click: mergeTrackerEventOptions(merged.click, options.click)
|
|
33
|
+
})));
|
|
34
|
+
}
|
|
35
|
+
function mergeTrackerEventOptions() {
|
|
36
|
+
let base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
37
|
+
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
38
|
+
return overrides === false || base === false ? overrides : Object.assign({}, base, overrides);
|
|
39
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.concatArrays = concatArrays;
|
|
7
|
+
exports.mergeOptions = mergeOptions;
|
|
8
|
+
exports.normalizeOptions = normalizeOptions;
|
|
9
|
+
var _commons = require("@miso.ai/commons");
|
|
10
|
+
function concatArrays(a0, a1) {
|
|
11
|
+
return a0 && a0.length ? a1 && a1.length ? [...a0, ...a1] : a0 : a1;
|
|
12
|
+
}
|
|
13
|
+
function mergeOptions(optionsList, merge) {
|
|
14
|
+
let merged = {};
|
|
15
|
+
for (const options of optionsList) {
|
|
16
|
+
if (!options) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
merged = merge(merged, options);
|
|
20
|
+
}
|
|
21
|
+
return (0, _commons.trimObj)(merged);
|
|
22
|
+
}
|
|
23
|
+
function normalizeOptions(options) {
|
|
24
|
+
if (options === undefined) {
|
|
25
|
+
throw new Error(`Expect options to be an object or a boolean value: ${options}`);
|
|
26
|
+
}
|
|
27
|
+
if (typeof options === 'boolean') {
|
|
28
|
+
options = {
|
|
29
|
+
active: options
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return options;
|
|
33
|
+
}
|
|
@@ -6,17 +6,55 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.buildBaseInteraction = buildBaseInteraction;
|
|
7
7
|
exports.concatItemsFromMoreResponse = concatItemsFromMoreResponse;
|
|
8
8
|
exports.getRevision = getRevision;
|
|
9
|
+
exports.mappingSortData = mappingSortData;
|
|
9
10
|
exports.mergeInteraction = mergeInteraction;
|
|
10
11
|
exports.retainFacetCountsInData = retainFacetCountsInData;
|
|
11
12
|
exports.writeAffiliationInfoToInteraction = writeAffiliationInfoToInteraction;
|
|
12
13
|
exports.writeAnswerStageToMeta = writeAnswerStageToMeta;
|
|
13
14
|
exports.writeDataStatus = writeDataStatus;
|
|
14
15
|
exports.writeExhaustionToData = writeExhaustionToData;
|
|
15
|
-
exports.writeFiltersToPayload = writeFiltersToPayload;
|
|
16
16
|
exports.writeKeywordsToData = writeKeywordsToData;
|
|
17
17
|
exports.writeMisoIdToMeta = writeMisoIdToMeta;
|
|
18
18
|
var _commons = require("@miso.ai/commons");
|
|
19
19
|
var _constants = require("../constants.js");
|
|
20
|
+
var _index = require("../actor/index.js");
|
|
21
|
+
// role mappings //
|
|
22
|
+
function mappingSortData(_) {
|
|
23
|
+
let {
|
|
24
|
+
hub,
|
|
25
|
+
workflowOptions = {}
|
|
26
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
27
|
+
const {
|
|
28
|
+
sort: {
|
|
29
|
+
options = []
|
|
30
|
+
} = {}
|
|
31
|
+
} = workflowOptions.filters || {};
|
|
32
|
+
if (!options.length) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
const {
|
|
36
|
+
sort
|
|
37
|
+
} = hub.states[_index.fields.filters()] || {};
|
|
38
|
+
const selectedField = sort && sort.field || findDefaultSortOption(options).field;
|
|
39
|
+
if (!selectedField) {
|
|
40
|
+
return options;
|
|
41
|
+
}
|
|
42
|
+
// mark selected
|
|
43
|
+
return options.map(option => {
|
|
44
|
+
return Object.assign({}, option, {
|
|
45
|
+
selected: option.field === selectedField
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function findDefaultSortOption(options) {
|
|
50
|
+
for (const option of options) {
|
|
51
|
+
if (option.default) {
|
|
52
|
+
return option;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return options[0];
|
|
56
|
+
}
|
|
57
|
+
|
|
20
58
|
// data //
|
|
21
59
|
function getRevision(data) {
|
|
22
60
|
return data && data.value && data.value.revision;
|
|
@@ -105,38 +143,6 @@ function writeAnswerStageToMeta(data) {
|
|
|
105
143
|
})
|
|
106
144
|
});
|
|
107
145
|
}
|
|
108
|
-
function writeFiltersToPayload() {
|
|
109
|
-
let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
110
|
-
let filters = arguments.length > 1 ? arguments[1] : undefined;
|
|
111
|
-
return (0, _commons.trimObj)(Object.assign({}, payload, composeFiltersPayload(filters)));
|
|
112
|
-
}
|
|
113
|
-
function composeFiltersPayload(filters) {
|
|
114
|
-
if (!filters) {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
const {
|
|
118
|
-
facets
|
|
119
|
-
} = filters;
|
|
120
|
-
return (0, _commons.trimObj)({
|
|
121
|
-
facet_filters: composeFacetFilters(facets)
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
function composeFacetFilters(facets) {
|
|
125
|
-
if (!facets) {
|
|
126
|
-
return undefined;
|
|
127
|
-
}
|
|
128
|
-
const filters = {};
|
|
129
|
-
for (const field in facets) {
|
|
130
|
-
const values = facets[field];
|
|
131
|
-
if (!values || !values.length) {
|
|
132
|
-
continue; // just in case
|
|
133
|
-
}
|
|
134
|
-
filters[field] = {
|
|
135
|
-
terms: values
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return Object.keys(filters).length ? filters : undefined;
|
|
139
|
-
}
|
|
140
146
|
function retainFacetCountsInData(data, currentFacetCounts) {
|
|
141
147
|
if (!currentFacetCounts) {
|
|
142
148
|
return data;
|
|
@@ -8,7 +8,7 @@ var _commons = require("@miso.ai/commons");
|
|
|
8
8
|
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
9
|
var _index = require("../layout/index.js");
|
|
10
10
|
var _constants = require("../constants.js");
|
|
11
|
-
var
|
|
11
|
+
var _index2 = require("./options/index.js");
|
|
12
12
|
var _processors = require("./processors.js");
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
@@ -29,7 +29,7 @@ const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OP
|
|
|
29
29
|
layouts: DEFAULT_LAYOUTS,
|
|
30
30
|
trackers: DEFAULT_TRACKERS
|
|
31
31
|
}));
|
|
32
|
-
const ROLES_OPTIONS = (0,
|
|
32
|
+
const ROLES_OPTIONS = (0, _index2.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
33
33
|
main: _constants.ROLE.PRODUCTS,
|
|
34
34
|
members: Object.keys(DEFAULT_LAYOUTS)
|
|
35
35
|
});
|
|
@@ -10,10 +10,8 @@ var _index = require("../actor/index.js");
|
|
|
10
10
|
var _constants = require("../constants.js");
|
|
11
11
|
var _index2 = require("../layout/index.js");
|
|
12
12
|
var _processors = require("./processors.js");
|
|
13
|
-
var
|
|
14
|
-
const _excluded = ["filters"];
|
|
13
|
+
var _index3 = require("./options/index.js");
|
|
15
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
17
15
|
const DEFAULT_ROWS = 10;
|
|
18
16
|
const DEFAULT_PAGE_LIMIT = 10;
|
|
19
17
|
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
@@ -37,6 +35,7 @@ const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LA
|
|
|
37
35
|
format: 'number'
|
|
38
36
|
}],
|
|
39
37
|
[_constants.ROLE.FACETS]: [_index2.FacetsLayout.type],
|
|
38
|
+
[_constants.ROLE.SORT]: [_index2.SelectLayout.type],
|
|
40
39
|
[_constants.ROLE.MORE]: [_index2.MoreButtonLayout.type]
|
|
41
40
|
}));
|
|
42
41
|
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
|
|
@@ -53,17 +52,18 @@ const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OP
|
|
|
53
52
|
trackers: DEFAULT_TRACKERS,
|
|
54
53
|
pagination: DEFAULT_PAGINATION
|
|
55
54
|
}));
|
|
56
|
-
const ROLES_OPTIONS = (0,
|
|
55
|
+
const ROLES_OPTIONS = (0, _index3.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
57
56
|
main: _constants.ROLE.PRODUCTS,
|
|
58
57
|
members: Object.keys(DEFAULT_LAYOUTS),
|
|
59
58
|
mappings: {
|
|
60
|
-
[_constants.ROLE.FACETS]: 'facet_counts'
|
|
59
|
+
[_constants.ROLE.FACETS]: 'facet_counts',
|
|
60
|
+
[_constants.ROLE.SORT]: _processors.mappingSortData
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
class SearchBasedWorkflow extends _base.default {
|
|
64
64
|
_initSubscriptions(args) {
|
|
65
65
|
super._initSubscriptions(args);
|
|
66
|
-
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args)), this._hub.on(_index.fields.filters(),
|
|
66
|
+
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args)), this._hub.on(_index.fields.filters(), () => this._refine()), this._hub.on(_index.fields.more(), () => this._more()), this._views.get(_constants.ROLE.SORT).on('select', event => this._handleSortSelect(event))];
|
|
67
67
|
}
|
|
68
68
|
restart() {
|
|
69
69
|
super.restart();
|
|
@@ -99,7 +99,7 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
99
99
|
payload
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
_refine(
|
|
102
|
+
_refine() {
|
|
103
103
|
// remember current facet_counts
|
|
104
104
|
const {
|
|
105
105
|
facet_counts
|
|
@@ -111,9 +111,7 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
111
111
|
|
|
112
112
|
// payload
|
|
113
113
|
const query = this._getQuery();
|
|
114
|
-
const payload = this._buildPayload(
|
|
115
|
-
filters
|
|
116
|
-
}));
|
|
114
|
+
const payload = this._buildPayload(query);
|
|
117
115
|
this._request({
|
|
118
116
|
payload
|
|
119
117
|
});
|
|
@@ -133,10 +131,7 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
133
131
|
|
|
134
132
|
// payload
|
|
135
133
|
const query = this._getQuery();
|
|
136
|
-
|
|
137
|
-
let payload = this._buildPayload(Object.assign({}, query, {
|
|
138
|
-
filters
|
|
139
|
-
}));
|
|
134
|
+
let payload = this._buildPayload(query);
|
|
140
135
|
payload = this._processPayloadForMoreRequest(payload);
|
|
141
136
|
this._request({
|
|
142
137
|
payload
|
|
@@ -149,16 +144,44 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
149
144
|
_getPageSize() {
|
|
150
145
|
return this._options.resolved.api.payload.rows;
|
|
151
146
|
}
|
|
152
|
-
_buildPayload() {
|
|
153
|
-
|
|
154
|
-
let {
|
|
155
|
-
filters
|
|
156
|
-
} = _ref,
|
|
157
|
-
payload = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
158
|
-
payload = (0, _processors.writeFiltersToPayload)(payload, filters);
|
|
147
|
+
_buildPayload(payload) {
|
|
148
|
+
payload = this._writeFiltersToPayload(payload);
|
|
159
149
|
payload = this._writePageInfoToPayload(payload);
|
|
160
150
|
return payload;
|
|
161
151
|
}
|
|
152
|
+
_writeFiltersToPayload(payload) {
|
|
153
|
+
const filters = this._hub.states[_index.fields.filters()];
|
|
154
|
+
const {
|
|
155
|
+
facets,
|
|
156
|
+
sort
|
|
157
|
+
} = filters || {};
|
|
158
|
+
return (0, _commons.trimObj)(Object.assign({}, payload, {
|
|
159
|
+
facet_filters: this._buildFacetFilters(facets),
|
|
160
|
+
order_by: this._buildOrderBy(sort)
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
_buildFacetFilters(facets) {
|
|
164
|
+
if (!facets) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
const filters = {};
|
|
168
|
+
for (const field in facets) {
|
|
169
|
+
const values = facets[field];
|
|
170
|
+
if (!values || !values.length) {
|
|
171
|
+
continue; // just in case
|
|
172
|
+
}
|
|
173
|
+
filters[field] = {
|
|
174
|
+
terms: values
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return Object.keys(filters).length ? filters : undefined;
|
|
178
|
+
}
|
|
179
|
+
_buildOrderBy(sort) {
|
|
180
|
+
if (!sort) {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
return (0, _commons.asArray)(sort);
|
|
184
|
+
}
|
|
162
185
|
_writePageInfoToPayload(payload) {
|
|
163
186
|
return Object.assign({}, payload, {
|
|
164
187
|
_meta: Object.assign({}, payload._meta, {
|
|
@@ -215,9 +238,23 @@ class SearchBasedWorkflow extends _base.default {
|
|
|
215
238
|
role: this._roles.main
|
|
216
239
|
});
|
|
217
240
|
}
|
|
241
|
+
|
|
242
|
+
// view actions //
|
|
243
|
+
_handleSortSelect() {
|
|
244
|
+
let {
|
|
245
|
+
value
|
|
246
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
247
|
+
if (!value) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this._views.filters.update({
|
|
251
|
+
sort: value
|
|
252
|
+
});
|
|
253
|
+
this._views.filters.apply();
|
|
254
|
+
}
|
|
218
255
|
}
|
|
219
256
|
exports.default = SearchBasedWorkflow;
|
|
220
|
-
(0,
|
|
257
|
+
(0, _index3.makeConfigurable)(SearchBasedWorkflow.prototype, [_constants.WORKFLOW_CONFIGURABLE.PAGINATION, _constants.WORKFLOW_CONFIGURABLE.FILTERS]);
|
|
221
258
|
Object.assign(SearchBasedWorkflow, {
|
|
222
259
|
DEFAULT_API_OPTIONS,
|
|
223
260
|
DEFAULT_LAYOUTS,
|
package/package.json
CHANGED
package/src/actor/filters.js
CHANGED
|
@@ -12,43 +12,84 @@ function mergeState(state = {}, update = {}) {
|
|
|
12
12
|
}));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
function optionsToState({ sort } = {}) {
|
|
16
|
+
// TODO: facets
|
|
17
|
+
return trimObj({
|
|
18
|
+
facets: Object.freeze({}),
|
|
19
|
+
sort: sortOptionsToState(sort),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function sortOptionsToState(sort) {
|
|
24
|
+
if (!sort) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const { options = [] } = sort;
|
|
28
|
+
for (const option of options) {
|
|
29
|
+
if (option.default) {
|
|
30
|
+
return Object.freeze(option);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Object.freeze(options[0]);
|
|
34
|
+
}
|
|
35
|
+
|
|
15
36
|
export default class Filters {
|
|
16
37
|
|
|
17
38
|
constructor(views, { facets: facetsOptions } = {}) {
|
|
18
39
|
this._views = views;
|
|
19
40
|
this._hub = views._hub;
|
|
20
|
-
this._states = this._initialStates = mergeState({}); // TODO: support custom initial states
|
|
21
41
|
const error = this._error = this._error.bind(this);
|
|
22
42
|
this._events = new EventEmitter({ target: this, error });
|
|
23
43
|
defineValues(this, { facets: new Facets(this, facetsOptions) });
|
|
44
|
+
|
|
45
|
+
this._unsubscribes = [
|
|
46
|
+
views._options.on('filters', () => this._syncOptions()),
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
this._syncOptions();
|
|
50
|
+
this._states = undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_syncOptions() {
|
|
54
|
+
const options = this._views._options.resolved.filters;
|
|
55
|
+
this._initialStates = optionsToState(options);
|
|
56
|
+
this.apply({ silent: true });
|
|
24
57
|
}
|
|
25
58
|
|
|
26
|
-
|
|
27
|
-
return this._states;
|
|
59
|
+
_getStates() {
|
|
60
|
+
return this._states || this._initialStates;
|
|
28
61
|
}
|
|
29
62
|
|
|
30
63
|
update(updates) {
|
|
31
|
-
const oldStates = this.
|
|
32
|
-
|
|
64
|
+
const oldStates = this._getStates();
|
|
65
|
+
this._states = mergeState({ ...oldStates, ...updates });
|
|
66
|
+
const states = this._getStates();
|
|
33
67
|
this._events.emit('update', { updates, states, oldStates });
|
|
34
68
|
}
|
|
35
69
|
|
|
36
70
|
reset() {
|
|
37
|
-
const oldStates = this.
|
|
38
|
-
|
|
71
|
+
const oldStates = this.states;
|
|
72
|
+
this._states = undefined;
|
|
73
|
+
const states = this._getStates();
|
|
39
74
|
this._events.emit('reset', { states, oldStates });
|
|
40
75
|
}
|
|
41
76
|
|
|
42
|
-
apply() {
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
77
|
+
apply({ silent = false } = {}) {
|
|
78
|
+
const states = this._getStates();
|
|
79
|
+
this._hub.update(fields.filters(), states, { silent });
|
|
80
|
+
!silent && this._events.emit('apply');
|
|
45
81
|
}
|
|
46
82
|
|
|
47
83
|
_error(error) {
|
|
48
84
|
this._views._error(error);
|
|
49
85
|
}
|
|
50
86
|
|
|
51
|
-
_destroy() {
|
|
87
|
+
_destroy() {
|
|
88
|
+
for (const unsubscribe of this._unsubscribes) {
|
|
89
|
+
unsubscribe();
|
|
90
|
+
}
|
|
91
|
+
this._unsubscribes = [];
|
|
92
|
+
}
|
|
52
93
|
|
|
53
94
|
}
|
|
54
95
|
|
|
@@ -87,7 +128,7 @@ class Facets {
|
|
|
87
128
|
}
|
|
88
129
|
|
|
89
130
|
_select(field, value) {
|
|
90
|
-
const values = this._options.
|
|
131
|
+
const values = this._options.multivalued ? [...(this._filters._states.facets[field] || []), value] : [value];
|
|
91
132
|
values.sort();
|
|
92
133
|
this._filters.update({ facets: { [field]: values } });
|
|
93
134
|
}
|
package/src/actor/tracker.js
CHANGED
|
@@ -7,20 +7,15 @@ const VALUELESS_ITEMS = [Symbol('valueless')];
|
|
|
7
7
|
|
|
8
8
|
export default class Tracker {
|
|
9
9
|
|
|
10
|
-
constructor({ hub, role, valueless = false
|
|
10
|
+
constructor({ hub, role, valueless = false }) {
|
|
11
11
|
this._hub = hub;
|
|
12
12
|
this._role = role;
|
|
13
13
|
this._valueless = !!valueless;
|
|
14
|
-
this._options = options;
|
|
15
14
|
// TODO: know item type
|
|
16
15
|
|
|
17
16
|
this._states = new States(this._getSessionId());
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
get options() {
|
|
21
|
-
return typeof this._options === 'function' ? this._options() : this._options;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
19
|
getState(item) {
|
|
25
20
|
return this._states.getFullState(item);
|
|
26
21
|
}
|