@rh-support/utils 2.0.7 → 2.0.8
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/lib/cjs/apiUtils.js +10 -24
- package/lib/cjs/appUtils.js +18 -19
- package/lib/cjs/cacheUtils.js +53 -93
- package/lib/cjs/caseUtils.js +15 -16
- package/lib/cjs/csvUtils.js +38 -87
- package/lib/cjs/customElementUtils.js +1 -1
- package/lib/cjs/dateUtils.js +19 -25
- package/lib/cjs/dropdownUtils.js +8 -10
- package/lib/cjs/eventUtils.js +4 -5
- package/lib/cjs/hostNameUtils.js +7 -7
- package/lib/cjs/hydraConfigUtils.js +14 -37
- package/lib/cjs/insightRuleInfoUtils.js +7 -7
- package/lib/cjs/lruCacheUtils.js +18 -20
- package/lib/cjs/outlier.js +4 -4
- package/lib/cjs/productsUtils.js +39 -77
- package/lib/cjs/promiseUtils.js +9 -44
- package/lib/cjs/recommendationUtils.js +7 -19
- package/lib/cjs/scrollUtils.js +14 -25
- package/lib/cjs/searchApiUtils.js +10 -21
- package/lib/cjs/sentry.js +6 -19
- package/lib/cjs/solrUtils.js +81 -108
- package/lib/cjs/translation-helper.js +2 -2
- package/lib/cjs/urlUtils.js +25 -38
- package/lib/cjs/userUtils.js +2 -2
- package/lib/cjs/validatorUtils.js +7 -7
- package/package.json +6 -2
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.cleanupMarkDown = exports.decodeMarkTag = exports.truncate = exports.replaceHighlightingData = exports.computeRecommendationAbstract = exports.computeRecommendationTitle = exports.getRecommendationAbstract = exports.getRecommendationTitle = void 0;
|
|
18
|
-
|
|
7
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
19
8
|
function getRecommendationTitle(doc) {
|
|
20
9
|
return !isEmpty_1.default(doc.publishedTitle) ? doc.publishedTitle : doc.allTitle;
|
|
21
10
|
}
|
|
@@ -25,22 +14,21 @@ function getRecommendationAbstract(doc) {
|
|
|
25
14
|
}
|
|
26
15
|
exports.getRecommendationAbstract = getRecommendationAbstract;
|
|
27
16
|
function computeRecommendationTitle(doc) {
|
|
28
|
-
|
|
17
|
+
const title = getRecommendationTitle(doc);
|
|
29
18
|
return { __html: decodeMarkTag(title) };
|
|
30
19
|
}
|
|
31
20
|
exports.computeRecommendationTitle = computeRecommendationTitle;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var abstract = getRecommendationAbstract(doc);
|
|
21
|
+
const computeRecommendationAbstract = (doc, truncateLen = 128) => {
|
|
22
|
+
const abstract = getRecommendationAbstract(doc);
|
|
35
23
|
return { __html: truncate(cleanupMarkDown(decodeMarkTag(abstract)), truncateLen) };
|
|
36
24
|
};
|
|
37
25
|
exports.computeRecommendationAbstract = computeRecommendationAbstract;
|
|
38
26
|
function replaceHighlightingData(docs, highlighting) {
|
|
39
|
-
return docs.map(
|
|
27
|
+
return docs.map((doc) => {
|
|
40
28
|
// highlight id is either uri or view_uri
|
|
41
29
|
// when we are uploading a file before adding issue summary no highlighting doc is present hence passing an empty object
|
|
42
|
-
|
|
43
|
-
return
|
|
30
|
+
const highlightObj = highlighting[doc.resource_uri] || highlighting[doc.uri] || highlighting[doc.view_uri] || {};
|
|
31
|
+
return Object.assign(Object.assign({}, doc), { abstract: (highlightObj.abstract && highlightObj.abstract[0]) || doc.abstract || '', publishedAbstract: (highlightObj.publishedAbstract && highlightObj.publishedAbstract[0]) || doc.publishedAbstract || '', issue: highlightObj.issue || doc.issue || [] });
|
|
44
32
|
});
|
|
45
33
|
}
|
|
46
34
|
exports.replaceHighlightingData = replaceHighlightingData;
|
package/lib/cjs/scrollUtils.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.isElementInViewport = exports.scrollIntoView = void 0;
|
|
18
|
-
|
|
7
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
19
8
|
function scrollIntoView(sectionRef, options) {
|
|
20
9
|
var _a, _b, _c;
|
|
21
10
|
if (isEmpty_1.default(sectionRef === null || sectionRef === void 0 ? void 0 : sectionRef.current))
|
|
@@ -32,39 +21,39 @@ function scrollIntoView(sectionRef, options) {
|
|
|
32
21
|
}
|
|
33
22
|
}
|
|
34
23
|
// lets you delay scroll, else will just run in the next cycle of the javascript event loop
|
|
35
|
-
setTimeout(
|
|
24
|
+
setTimeout(() => {
|
|
36
25
|
var _a, _b, _c;
|
|
37
26
|
// if an offset or navBar is specified then element.scrollIntoView wont work and you need to use window.scrollTo
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
const hasNavbar = !!((_a = options === null || options === void 0 ? void 0 : options.navBarRef) === null || _a === void 0 ? void 0 : _a.current);
|
|
28
|
+
const hasOffset = !!(options === null || options === void 0 ? void 0 : options.offset);
|
|
40
29
|
if (hasNavbar || hasOffset) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
const sectionRect = sectionRef.current.getBoundingClientRect();
|
|
31
|
+
let elementTopPosition = sectionRect.top;
|
|
32
|
+
let top = elementTopPosition - ((_b = options === null || options === void 0 ? void 0 : options.offset) !== null && _b !== void 0 ? _b : 0);
|
|
44
33
|
if (hasNavbar) {
|
|
45
|
-
|
|
34
|
+
const navRect = options.navBarRef.current.getBoundingClientRect();
|
|
46
35
|
// elementTopPosition = already_scrolled - (nav height - section top)
|
|
47
36
|
elementTopPosition = window.pageYOffset - (navRect.height - sectionRect.top);
|
|
48
|
-
|
|
37
|
+
top = elementTopPosition - ((_c = options === null || options === void 0 ? void 0 : options.offset) !== null && _c !== void 0 ? _c : 0);
|
|
49
38
|
}
|
|
50
39
|
// window.scrollTo can throw an error when passing in options, so this try/catch catches the error
|
|
51
40
|
// and only uses the window.scrollTo without the options.
|
|
52
41
|
try {
|
|
53
42
|
window.scrollTo({
|
|
54
|
-
top
|
|
43
|
+
top,
|
|
55
44
|
behavior: 'smooth',
|
|
56
45
|
});
|
|
57
46
|
}
|
|
58
47
|
catch (e) {
|
|
59
|
-
window.scrollTo(0,
|
|
48
|
+
window.scrollTo(0, top);
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
51
|
else {
|
|
63
52
|
try {
|
|
64
|
-
sectionRef.current.scrollIntoView(
|
|
53
|
+
sectionRef.current.scrollIntoView(Object.assign(Object.assign({}, (options || {})), { behavior: 'smooth' }));
|
|
65
54
|
}
|
|
66
55
|
catch (e) {
|
|
67
|
-
sectionRef.current.scrollIntoView(
|
|
56
|
+
sectionRef.current.scrollIntoView(Object.assign(Object.assign({}, (options || {})), { behavior: 'auto' }));
|
|
68
57
|
}
|
|
69
58
|
}
|
|
70
59
|
}, (_c = options === null || options === void 0 ? void 0 : options.timeout) !== null && _c !== void 0 ? _c : 0);
|
|
@@ -75,7 +64,7 @@ function isElementInViewport(el, topStaticNavRef) {
|
|
|
75
64
|
if (isEmpty_1.default(el === null || el === void 0 ? void 0 : el.current)) {
|
|
76
65
|
return false;
|
|
77
66
|
}
|
|
78
|
-
|
|
67
|
+
const topNavHeight = (_b = (_a = topStaticNavRef === null || topStaticNavRef === void 0 ? void 0 : topStaticNavRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0;
|
|
79
68
|
var rect = el.current.getBoundingClientRect();
|
|
80
69
|
return (rect.top - topNavHeight >= 0 &&
|
|
81
70
|
rect.left >= 0 &&
|
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
6
|
exports.getSolrParams = exports.addFiltersToFieldQueries = exports.issuesDefaultParamsObj = exports.documentKindToInclude = void 0;
|
|
18
|
-
|
|
7
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
19
8
|
exports.documentKindToInclude = 'documentKind:("Solution" OR "Video" OR "Article" OR "Errata" OR "Vulnerability" OR "Cve" OR "LabInfo")';
|
|
20
9
|
exports.issuesDefaultParamsObj = {
|
|
21
10
|
q: '*:*',
|
|
@@ -32,27 +21,27 @@ exports.issuesDefaultParamsObj = {
|
|
|
32
21
|
'hl.fragsize': 0,
|
|
33
22
|
};
|
|
34
23
|
function addFiltersToFieldQueries(fqArray, additionalFilters) {
|
|
35
|
-
Object.keys(additionalFilters).forEach(
|
|
24
|
+
Object.keys(additionalFilters).forEach((_key) => {
|
|
36
25
|
var _a;
|
|
37
|
-
|
|
26
|
+
const val = additionalFilters[_key];
|
|
38
27
|
if (Array.isArray(val) && val.length > 0) {
|
|
39
|
-
|
|
28
|
+
const query = `${_key}:(${val.join(' OR ')})`;
|
|
40
29
|
query && fqArray.push(query);
|
|
41
30
|
}
|
|
42
31
|
else if (typeof val === 'object') {
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
const excludeFlag = val === null || val === void 0 ? void 0 : val.exclude;
|
|
33
|
+
const values = (_a = val === null || val === void 0 ? void 0 : val.values) !== null && _a !== void 0 ? _a : [];
|
|
45
34
|
if (values.length < 1)
|
|
46
35
|
return;
|
|
47
|
-
|
|
48
|
-
query && fqArray.push(
|
|
36
|
+
const query = `${_key}:(${values.join(' OR ')})`;
|
|
37
|
+
query && fqArray.push(`${excludeFlag ? '-' : ''}${query}`);
|
|
49
38
|
}
|
|
50
39
|
});
|
|
51
40
|
}
|
|
52
41
|
exports.addFiltersToFieldQueries = addFiltersToFieldQueries;
|
|
53
42
|
function getSolrParams(rows, highlighted_fragment_size, additionalFilters, QueryFields) {
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
const cloneIssueParams = cloneDeep_1.default(exports.issuesDefaultParamsObj);
|
|
44
|
+
const issueParamsObj = Object.assign(Object.assign({}, cloneIssueParams), { rows, 'hl.fragsize': highlighted_fragment_size, seQueryFields: QueryFields || false });
|
|
56
45
|
additionalFilters && addFiltersToFieldQueries(issueParamsObj.fq, additionalFilters);
|
|
57
46
|
return issueParamsObj;
|
|
58
47
|
}
|
package/lib/cjs/sentry.js
CHANGED
|
@@ -1,25 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.sendToSentry = void 0;
|
|
15
4
|
/**
|
|
16
5
|
* Send current user context to Raven (JS error logging library).
|
|
17
6
|
*/
|
|
18
|
-
function sendToSentry(error, additionalTags, message, extra) {
|
|
7
|
+
function sendToSentry(error, additionalTags = {}, message = '', extra) {
|
|
19
8
|
var _a, _b;
|
|
20
|
-
|
|
21
|
-
if (message === void 0) { message = ''; }
|
|
22
|
-
var state = window.sessionjs._state;
|
|
9
|
+
const state = window.sessionjs._state;
|
|
23
10
|
function expiresIn() {
|
|
24
11
|
try {
|
|
25
12
|
return state.keycloak.tokenParsed['exp'] - Math.ceil(new Date().getTime() / 1000) + state.keycloak.timeSkew;
|
|
@@ -28,8 +15,8 @@ function sendToSentry(error, additionalTags, message, extra) {
|
|
|
28
15
|
return null;
|
|
29
16
|
}
|
|
30
17
|
}
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
const token = window.sessionjs.getToken();
|
|
19
|
+
const userInfo = {
|
|
33
20
|
user_id: token.user_id,
|
|
34
21
|
account_id: token.account_id,
|
|
35
22
|
account_number: token.account_number,
|
|
@@ -43,9 +30,9 @@ function sendToSentry(error, additionalTags, message, extra) {
|
|
|
43
30
|
user_info: userInfo,
|
|
44
31
|
});
|
|
45
32
|
// setting additional tags for debug purpose
|
|
46
|
-
|
|
33
|
+
let tagsContext = Object.assign(Object.assign({ is_authenticated: window.sessionjs.isAuthenticated(), is_token_expired: state.keycloak.authenticated ? state.keycloak.isTokenExpired(0) : null, token_expires_in: expiresIn() }, additionalTags), { app_name: (_b = window.app) !== null && _b !== void 0 ? _b : 'Portal Case Management' });
|
|
47
34
|
window === null || window === void 0 ? void 0 : window.Raven.setTagsContext(tagsContext);
|
|
48
|
-
window === null || window === void 0 ? void 0 : window.Raven.captureException(error, { extra
|
|
35
|
+
window === null || window === void 0 ? void 0 : window.Raven.captureException(error, { extra });
|
|
49
36
|
if (message)
|
|
50
37
|
window === null || window === void 0 ? void 0 : window.Raven.captureMessage(message, { level: 'error' });
|
|
51
38
|
}
|
package/lib/cjs/solrUtils.js
CHANGED
|
@@ -1,119 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
19
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
20
|
-
to[j] = from[i];
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
4
|
};
|
|
26
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
6
|
exports.parseSolrQuery = exports.buildSolrQuery = exports.solrResponseToPivotFields = exports.solrResponseToFacetFields = exports.solr = void 0;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
7
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
8
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
9
|
+
const lucene_1 = __importDefault(require("lucene"));
|
|
10
|
+
const solr_query_builder_1 = __importDefault(require("solr-query-builder"));
|
|
32
11
|
function If(cond, v) {
|
|
33
12
|
return !isEmpty_1.default(cond) ? v || cond : '';
|
|
34
13
|
}
|
|
35
|
-
function processFQValue(val,
|
|
36
|
-
var join = _a.join;
|
|
14
|
+
function processFQValue(val, { join }) {
|
|
37
15
|
// val can be one of
|
|
38
16
|
// ['certificatoin', 'ecosystem'] (array)
|
|
39
17
|
// OR 'certification|ecosystem' (stringifiedArray seprated with pipe)
|
|
40
18
|
// OR 'certification' (string)
|
|
41
19
|
// OR '*' (star is a special case)
|
|
42
|
-
|
|
20
|
+
const _val = Array.isArray(val) ? val : val.split('|').length === 1 ? val : val.split('|');
|
|
43
21
|
if (Array.isArray(_val)) {
|
|
44
|
-
return
|
|
22
|
+
return `(${_val.map((v) => `"${v}"`).join(` ${join} `)})`;
|
|
45
23
|
}
|
|
46
24
|
else if (val === '*') {
|
|
47
25
|
return val;
|
|
48
26
|
}
|
|
49
27
|
else {
|
|
50
|
-
return "
|
|
28
|
+
return `"${_val}"`;
|
|
51
29
|
}
|
|
52
30
|
}
|
|
53
31
|
function solr(init) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
fq:
|
|
60
|
-
if (options === void 0) { options = { processValue: { join: 'OR' } }; }
|
|
32
|
+
let query = init || {};
|
|
33
|
+
let beginOr = false;
|
|
34
|
+
let partialOrQuery = [];
|
|
35
|
+
let partialTag = [];
|
|
36
|
+
const solr = {
|
|
37
|
+
fq: (k, v, tag, options = { processValue: { join: 'OR' } }) => {
|
|
61
38
|
if (isEmpty_1.default(v))
|
|
62
39
|
return solr;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
40
|
+
const _fq = query.fq || [];
|
|
41
|
+
const _tag = If(tag, `{!tag=${tag}}`);
|
|
42
|
+
const _v = processFQValue(v, options.processValue);
|
|
43
|
+
const pair = `${k}:${_v}`;
|
|
44
|
+
const newfq = [..._fq, `${_tag}${pair}`];
|
|
68
45
|
if (!beginOr) {
|
|
69
46
|
query = Object.assign({}, query, { fq: newfq });
|
|
70
47
|
}
|
|
71
48
|
else {
|
|
72
49
|
if (tag) {
|
|
73
|
-
partialTag =
|
|
50
|
+
partialTag = [...partialTag, tag];
|
|
74
51
|
}
|
|
75
|
-
partialOrQuery =
|
|
52
|
+
partialOrQuery = [...partialOrQuery, `${pair}`];
|
|
76
53
|
}
|
|
77
54
|
return solr;
|
|
78
55
|
},
|
|
79
|
-
preBuiltfq:
|
|
56
|
+
preBuiltfq: (k, v, tag) => {
|
|
80
57
|
if (isEmpty_1.default(v))
|
|
81
58
|
return solr;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
59
|
+
const _fq = query.fq || [];
|
|
60
|
+
const _tag = If(tag, `{!tag=${tag}}`);
|
|
61
|
+
const newfq = [..._fq, `${_tag}${v}`];
|
|
85
62
|
query = Object.assign({}, query, { fq: newfq });
|
|
86
63
|
return solr;
|
|
87
64
|
},
|
|
88
|
-
facetField:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
65
|
+
facetField: (facet, excludeTags) => {
|
|
66
|
+
const _facetField = query['facet.field'] || [];
|
|
67
|
+
const _excludeTags = If(excludeTags, `{!ex=${excludeTags && excludeTags.join(',')}}`);
|
|
68
|
+
const newFacetField = [..._facetField, `${_excludeTags}${facet}`];
|
|
92
69
|
query = Object.assign({}, query, { 'facet.field': newFacetField });
|
|
93
70
|
return solr;
|
|
94
71
|
},
|
|
95
|
-
pivotField:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
72
|
+
pivotField: (pivot, excludeTags) => {
|
|
73
|
+
const _facetPivot = query['facet.pivot'] || [];
|
|
74
|
+
const _excludeTags = If(excludeTags, `{!ex=${excludeTags && excludeTags.join(',')}}`);
|
|
75
|
+
const newPivotField = [..._facetPivot, `${_excludeTags}${pivot}`];
|
|
99
76
|
query = Object.assign({}, query, { 'facet.pivot': newPivotField });
|
|
100
77
|
return solr;
|
|
101
78
|
},
|
|
102
|
-
value:
|
|
79
|
+
value: () => {
|
|
103
80
|
return query;
|
|
104
81
|
},
|
|
105
|
-
beginOr:
|
|
82
|
+
beginOr: () => {
|
|
106
83
|
beginOr = true;
|
|
107
84
|
partialOrQuery = [];
|
|
108
85
|
partialTag = [];
|
|
109
86
|
return solr;
|
|
110
87
|
},
|
|
111
|
-
endOr:
|
|
88
|
+
endOr: () => {
|
|
112
89
|
beginOr = false;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
90
|
+
const _fq = query.fq || [];
|
|
91
|
+
const _tag = partialTag.length > 0 ? `{!tag=${partialTag}}` : '';
|
|
92
|
+
const orQuery = partialOrQuery.join(' OR ');
|
|
93
|
+
const newFq = [..._fq, `${_tag}${orQuery}`];
|
|
117
94
|
query = Object.assign({}, query, { fq: newFq });
|
|
118
95
|
return solr;
|
|
119
96
|
},
|
|
@@ -128,15 +105,15 @@ exports.solr = solr;
|
|
|
128
105
|
* with key being the facet key and value being of type IFacetResponse
|
|
129
106
|
*/
|
|
130
107
|
function solrResponseToFacetFields(solrResponse) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
Object.keys(solrFacets).forEach(
|
|
134
|
-
|
|
108
|
+
const solrFacets = get_1.default(solrResponse, 'facet_counts.facet_fields', {});
|
|
109
|
+
const facets = {};
|
|
110
|
+
Object.keys(solrFacets).forEach((_facetKey) => {
|
|
111
|
+
const facetKey = _facetKey;
|
|
135
112
|
facets[facetKey] = [];
|
|
136
|
-
for (
|
|
113
|
+
for (let i = 0; i < solrFacets[facetKey].length; i += 2) {
|
|
137
114
|
// take every second element
|
|
138
115
|
// replace non-breakable spaces with space
|
|
139
|
-
|
|
116
|
+
const item = solrFacets[facetKey][i].replace(/\s/g, ' ');
|
|
140
117
|
if (item) {
|
|
141
118
|
facets[facetKey].push({ value: item, count: solrFacets[facetKey][i + 1] });
|
|
142
119
|
}
|
|
@@ -153,12 +130,12 @@ exports.solrResponseToFacetFields = solrResponseToFacetFields;
|
|
|
153
130
|
* value being of type IFacetResponse and also next pivot as the key and its value again of type IFacetResponse.
|
|
154
131
|
*/
|
|
155
132
|
function solrResponseToPivotFields(solrResponse) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
Object.keys(solrPivots).forEach(
|
|
159
|
-
|
|
133
|
+
const solrPivots = get_1.default(solrResponse, 'facet_counts.facet_pivot', {});
|
|
134
|
+
const pivots = {};
|
|
135
|
+
Object.keys(solrPivots).forEach((_pivotKey) => {
|
|
136
|
+
const pivotKey = _pivotKey;
|
|
160
137
|
pivots[pivotKey] = [];
|
|
161
|
-
for (
|
|
138
|
+
for (let i = 0; i < solrPivots[pivotKey].length; i++) {
|
|
162
139
|
pivots[pivotKey].push(createPivotObject(solrPivots[pivotKey][i]));
|
|
163
140
|
}
|
|
164
141
|
});
|
|
@@ -166,17 +143,17 @@ function solrResponseToPivotFields(solrResponse) {
|
|
|
166
143
|
}
|
|
167
144
|
exports.solrResponseToPivotFields = solrResponseToPivotFields;
|
|
168
145
|
function createPivotObject(data) {
|
|
169
|
-
|
|
146
|
+
const valueObj = {
|
|
170
147
|
field: data.field,
|
|
171
148
|
value: data.value,
|
|
172
149
|
count: data.count,
|
|
173
150
|
};
|
|
174
151
|
if (data.pivot && data.pivot.length > 0) {
|
|
175
|
-
|
|
152
|
+
const pivotValuesMap = data.pivot.map((item) => ({
|
|
176
153
|
value: item.value,
|
|
177
154
|
count: item.count,
|
|
178
|
-
})
|
|
179
|
-
|
|
155
|
+
}));
|
|
156
|
+
const pivotKey = data.pivot[0].field;
|
|
180
157
|
valueObj[pivotKey] = pivotValuesMap;
|
|
181
158
|
}
|
|
182
159
|
return valueObj;
|
|
@@ -188,19 +165,18 @@ function createPivotObject(data) {
|
|
|
188
165
|
* string query by ORing the values of same type(for ex. all the version will be ORed) and ANDing the
|
|
189
166
|
* children values with parent values. Uses solr-query-builder library internally
|
|
190
167
|
*/
|
|
191
|
-
function buildSolrQuery(fieldValueMap, wrapWithParentheses) {
|
|
192
|
-
|
|
193
|
-
var solrQuery = new solr_query_builder_1.default();
|
|
168
|
+
function buildSolrQuery(fieldValueMap, wrapWithParentheses = false) {
|
|
169
|
+
let solrQuery = new solr_query_builder_1.default();
|
|
194
170
|
wrapWithParentheses && solrQuery.begin();
|
|
195
|
-
Object.keys(fieldValueMap).forEach(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
currentItem.forEach(
|
|
171
|
+
Object.keys(fieldValueMap).forEach((key) => {
|
|
172
|
+
const fields = key.split(',');
|
|
173
|
+
const noOfPasses = fields.length;
|
|
174
|
+
const currentItem = fieldValueMap[key] || [];
|
|
175
|
+
currentItem.forEach((item, index, array) => {
|
|
200
176
|
solrQuery = solrQuery.begin().where(item['field']).equals(item['value']);
|
|
201
|
-
|
|
177
|
+
let currentPass = 0;
|
|
202
178
|
currentPass++;
|
|
203
|
-
|
|
179
|
+
const itemForQuery = item[fields[currentPass]];
|
|
204
180
|
if (currentPass === noOfPasses - 1) {
|
|
205
181
|
solrQuery = joinValuesWithOr(solrQuery, itemForQuery);
|
|
206
182
|
}
|
|
@@ -222,8 +198,8 @@ function joinValuesWithOr(currentQuery, values) {
|
|
|
222
198
|
if (values.length < 1) {
|
|
223
199
|
return currentQuery;
|
|
224
200
|
}
|
|
225
|
-
|
|
226
|
-
values.forEach(
|
|
201
|
+
let _currentQuery = currentQuery.begin();
|
|
202
|
+
values.forEach((item, index, array) => {
|
|
227
203
|
_currentQuery = _currentQuery.where(item['field']).equals(item['value']);
|
|
228
204
|
if (index !== array.length - 1) {
|
|
229
205
|
_currentQuery = _currentQuery.or();
|
|
@@ -232,7 +208,7 @@ function joinValuesWithOr(currentQuery, values) {
|
|
|
232
208
|
return _currentQuery.end();
|
|
233
209
|
}
|
|
234
210
|
function makeQueryRecursively(currentQuery, values, currentPass, noOfPasses, fields) {
|
|
235
|
-
values.forEach(
|
|
211
|
+
values.forEach((i, index, array) => {
|
|
236
212
|
currentQuery = currentQuery.begin();
|
|
237
213
|
currentQuery = currentQuery.where(i['field']).equals(i['value']);
|
|
238
214
|
if (currentPass === noOfPasses - 1) {
|
|
@@ -258,11 +234,11 @@ function makeQueryRecursively(currentQuery, values, currentPass, noOfPasses, fie
|
|
|
258
234
|
function parseSolrQuery(query) {
|
|
259
235
|
if (!query)
|
|
260
236
|
return {};
|
|
261
|
-
|
|
237
|
+
const parsedQuery = lucene_1.default.parse(query);
|
|
262
238
|
if (isEmpty_1.default(parsedQuery)) {
|
|
263
239
|
return {};
|
|
264
240
|
}
|
|
265
|
-
|
|
241
|
+
const filterObject = {};
|
|
266
242
|
traverseTree(parsedQuery, filterObject);
|
|
267
243
|
return filterObject;
|
|
268
244
|
}
|
|
@@ -299,12 +275,11 @@ function traverseTree(ast, filterObject) {
|
|
|
299
275
|
}
|
|
300
276
|
}
|
|
301
277
|
function calculateSolrField(node, filterObject) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
var fieldValues = [];
|
|
278
|
+
const fieldName = node.field;
|
|
279
|
+
const fieldValues = [];
|
|
305
280
|
getValues(node, fieldValues);
|
|
306
281
|
if (filterObject[fieldName]) {
|
|
307
|
-
|
|
282
|
+
filterObject[fieldName].push(...fieldValues);
|
|
308
283
|
}
|
|
309
284
|
else {
|
|
310
285
|
filterObject[fieldName] = fieldValues;
|
|
@@ -314,18 +289,16 @@ function calculateSolrField(node, filterObject) {
|
|
|
314
289
|
// HINT: To make it support more level create new getPivotValues
|
|
315
290
|
// function instead of using getValues
|
|
316
291
|
function calculateSolrPivotField(node, filterObject) {
|
|
317
|
-
var _a;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
var vals = [];
|
|
292
|
+
var _a, _b;
|
|
293
|
+
const pivot0Field = (_a = node === null || node === void 0 ? void 0 : node.left) === null || _a === void 0 ? void 0 : _a.field;
|
|
294
|
+
const pivot0Value = (_b = node === null || node === void 0 ? void 0 : node.left) === null || _b === void 0 ? void 0 : _b.term;
|
|
295
|
+
const vals = [];
|
|
322
296
|
getValues(node.right, vals);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
_a);
|
|
297
|
+
const a = {
|
|
298
|
+
field: pivot0Field,
|
|
299
|
+
value: pivot0Value,
|
|
300
|
+
[node.right.left.field]: vals,
|
|
301
|
+
};
|
|
329
302
|
if (filterObject[pivot0Field]) {
|
|
330
303
|
filterObject[pivot0Field].push(a);
|
|
331
304
|
}
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getText = void 0;
|
|
7
|
-
|
|
7
|
+
const i18next_1 = __importDefault(require("i18next"));
|
|
8
8
|
/**
|
|
9
9
|
* Translate the string using i18n.t
|
|
10
10
|
* @param {string} key the string to be translated
|
|
@@ -14,7 +14,7 @@ var i18next_1 = __importDefault(require("i18next"));
|
|
|
14
14
|
* use getText only in the case when neither <Trans /> nor useTranslation() is available
|
|
15
15
|
*/
|
|
16
16
|
function getText(key, args) {
|
|
17
|
-
|
|
17
|
+
const translatedString = i18next_1.default.t(key, args);
|
|
18
18
|
if (!translatedString) {
|
|
19
19
|
return key;
|
|
20
20
|
}
|