@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
package/lib/cjs/apiUtils.js
CHANGED
|
@@ -4,39 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.haventLoadedProductsMetadata = exports.haventLoadedMetadata = exports.getApiDeletionStatus = exports.getApiUpdationStatus = exports.getApiCreationStatus = exports.getApiResourceObject = void 0;
|
|
7
|
-
|
|
8
|
-
function getApiResourceObject(data, isFetching, isError, errorMessage, error) {
|
|
9
|
-
|
|
10
|
-
if (isFetching === void 0) { isFetching = false; }
|
|
11
|
-
if (isError === void 0) { isError = false; }
|
|
12
|
-
if (errorMessage === void 0) { errorMessage = ''; }
|
|
13
|
-
if (error === void 0) { error = null; }
|
|
14
|
-
return { data: data, isFetching: isFetching, isError: isError, errorMessage: errorMessage, error: error };
|
|
7
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
8
|
+
function getApiResourceObject(data = undefined, isFetching = false, isError = false, errorMessage = '', error = null) {
|
|
9
|
+
return { data, isFetching, isError, errorMessage, error };
|
|
15
10
|
}
|
|
16
11
|
exports.getApiResourceObject = getApiResourceObject;
|
|
17
|
-
function getApiCreationStatus(isCreating, isError, errorMessage) {
|
|
18
|
-
|
|
19
|
-
if (isError === void 0) { isError = false; }
|
|
20
|
-
if (errorMessage === void 0) { errorMessage = ''; }
|
|
21
|
-
return { isCreating: isCreating, isError: isError, errorMessage: errorMessage };
|
|
12
|
+
function getApiCreationStatus(isCreating = false, isError = false, errorMessage = '') {
|
|
13
|
+
return { isCreating, isError, errorMessage };
|
|
22
14
|
}
|
|
23
15
|
exports.getApiCreationStatus = getApiCreationStatus;
|
|
24
|
-
function getApiUpdationStatus(isUpdating, isError, errorMessage) {
|
|
25
|
-
|
|
26
|
-
if (isError === void 0) { isError = false; }
|
|
27
|
-
if (errorMessage === void 0) { errorMessage = ''; }
|
|
28
|
-
return { isUpdating: isUpdating, isError: isError, errorMessage: errorMessage };
|
|
16
|
+
function getApiUpdationStatus(isUpdating = false, isError = false, errorMessage = '') {
|
|
17
|
+
return { isUpdating, isError, errorMessage };
|
|
29
18
|
}
|
|
30
19
|
exports.getApiUpdationStatus = getApiUpdationStatus;
|
|
31
|
-
function getApiDeletionStatus(isDeleting, isError, errorMessage) {
|
|
32
|
-
|
|
33
|
-
if (isError === void 0) { isError = false; }
|
|
34
|
-
if (errorMessage === void 0) { errorMessage = ''; }
|
|
35
|
-
return { isDeleting: isDeleting, isError: isError, errorMessage: errorMessage };
|
|
20
|
+
function getApiDeletionStatus(isDeleting = false, isError = false, errorMessage = '') {
|
|
21
|
+
return { isDeleting, isError, errorMessage };
|
|
36
22
|
}
|
|
37
23
|
exports.getApiDeletionStatus = getApiDeletionStatus;
|
|
38
24
|
function haventLoadedMetadata(apiResponse, isEmptyCallback) {
|
|
39
|
-
|
|
25
|
+
const isDataEmpty = isEmptyCallback ? isEmptyCallback : isEmpty_1.default;
|
|
40
26
|
return isDataEmpty(apiResponse.data) && !apiResponse.isFetching && !apiResponse.isError;
|
|
41
27
|
}
|
|
42
28
|
exports.haventLoadedMetadata = haventLoadedMetadata;
|
package/lib/cjs/appUtils.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.setSecuredSupport = exports.getUserAgentForCaseMode = exports.setStrataHeaders = exports.getStrataHeaders = exports.getAppVersion = exports.getAccessHostname = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
8
|
+
const getAccessHostname = () => {
|
|
9
9
|
// returns the current access.redhat.com hostname (e.g if qa then would return access.qa.redhat.com)
|
|
10
10
|
if (typeof window !== 'undefined' && window) {
|
|
11
11
|
if (prodHostNames.indexOf(window.location.hostname) !== -1) {
|
|
@@ -26,18 +26,18 @@ var getAccessHostname = function () {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
exports.getAccessHostname = getAccessHostname;
|
|
29
|
-
|
|
29
|
+
const getAppVersion = () => {
|
|
30
30
|
return get_1.default(window.seVersionInfo || window.supportVersionInfo || {}, 'packageVersion');
|
|
31
31
|
};
|
|
32
32
|
exports.getAppVersion = getAppVersion;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
redhat_client: appName
|
|
33
|
+
const strataHeaders = {};
|
|
34
|
+
const getStrataHeaders = (appName, accountNumber) => ({
|
|
35
|
+
redhat_client: `${appName} ${exports.getAppVersion()}`,
|
|
36
36
|
account_number: accountNumber,
|
|
37
|
-
});
|
|
37
|
+
});
|
|
38
38
|
exports.getStrataHeaders = getStrataHeaders;
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const setStrataHeaders = (appName, accountNumber) => {
|
|
40
|
+
const newStrataHeaders = exports.getStrataHeaders(appName, accountNumber);
|
|
41
41
|
strataHeaders.redhat_client = newStrataHeaders.redhat_client;
|
|
42
42
|
strataHeaders.account_number = newStrataHeaders.account_number;
|
|
43
43
|
};
|
|
@@ -45,23 +45,22 @@ exports.setStrataHeaders = setStrataHeaders;
|
|
|
45
45
|
// Host names for all the app's different environments.
|
|
46
46
|
// the actual redhat url needs to always be in the first position of the arrays
|
|
47
47
|
// because the getAccessHostname function depends on that being the case for getting the current access hostname.
|
|
48
|
-
|
|
48
|
+
const prodHostNames = [
|
|
49
49
|
'access.redhat.com',
|
|
50
50
|
'prod.foo.redhat.com',
|
|
51
51
|
'fooprod.redhat.com',
|
|
52
52
|
'attachment-viewer.cee.redhat.com',
|
|
53
53
|
];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return isCaseCreate ?
|
|
54
|
+
const qaHostNames = ['access.qa.redhat.com', 'qa.foo.redhat.com', 'fooqa.redhat.com', 'sos-viewer.corp.qa.redhat.com'];
|
|
55
|
+
const fteHostNames = ['access.devgssfte.devlab.phx1.redhat.com', 'fte.foo.redhat.com', 'foofte.redhat.com'];
|
|
56
|
+
const ciHostNames = ['access.devgssci.devlab.phx1.redhat.com', 'ci.foo.redhat.com', 'fooci.redhat.com'];
|
|
57
|
+
const stageHostNames = ['access.stage.redhat.com', 'stage.foo.redhat.com', 'foostage.redhat.com'];
|
|
58
|
+
const getUserAgentForCaseMode = (isCaseCreate) => {
|
|
59
|
+
return isCaseCreate ? `Portal Case Management ${exports.getAppVersion()}` : `Solution Engine ${exports.getAppVersion()}`;
|
|
60
60
|
};
|
|
61
61
|
exports.getUserAgentForCaseMode = getUserAgentForCaseMode;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (isGs4 === void 0) { isGs4 = false; }
|
|
62
|
+
const securedSupport = { pathPrefix: '', isGs4: false };
|
|
63
|
+
const setSecuredSupport = (isGs4 = false) => {
|
|
65
64
|
securedSupport.isGs4 = isGs4;
|
|
66
65
|
securedSupport.pathPrefix = isGs4 ? '/secure-support' : '';
|
|
67
66
|
};
|
package/lib/cjs/cacheUtils.js
CHANGED
|
@@ -8,62 +8,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
15
|
exports.CacheUtilsService = exports.isFirefox = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
16
|
+
const filter_1 = __importDefault(require("lodash/filter"));
|
|
17
|
+
const forEach_1 = __importDefault(require("lodash/forEach"));
|
|
18
|
+
const includes_1 = __importDefault(require("lodash/includes"));
|
|
46
19
|
function isFirefox() {
|
|
47
20
|
return 'MozAppearance' in document.documentElement.style;
|
|
48
21
|
}
|
|
49
22
|
exports.isFirefox = isFirefox;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var _this = this;
|
|
23
|
+
class CacheUtilsService {
|
|
24
|
+
constructor(localForage, options) {
|
|
53
25
|
this.indexDBAvailable = true;
|
|
54
26
|
// For FF only attempt to determine if indexDB is available, this mainly affects
|
|
55
27
|
// FF private mode
|
|
56
28
|
localForage.config(options);
|
|
57
29
|
try {
|
|
58
30
|
if (isFirefox() && window.indexedDB) {
|
|
59
|
-
|
|
60
|
-
db.onerror =
|
|
61
|
-
|
|
31
|
+
const db = indexedDB.open('test');
|
|
32
|
+
db.onerror = () => {
|
|
33
|
+
this.indexDBAvailable = false;
|
|
62
34
|
};
|
|
63
35
|
}
|
|
64
36
|
}
|
|
65
37
|
catch (e) {
|
|
66
|
-
console.warn(
|
|
38
|
+
console.warn(`IndexDB unavailable.`);
|
|
67
39
|
this.indexDBAvailable = false;
|
|
68
40
|
}
|
|
69
41
|
// For FF, if indexDB isn't available and localStorage is, prefer localStorage
|
|
@@ -76,59 +48,59 @@ var CacheUtilsService = /** @class */ (function () {
|
|
|
76
48
|
}
|
|
77
49
|
this.localForage = localForage;
|
|
78
50
|
}
|
|
79
|
-
|
|
80
|
-
return namespace
|
|
81
|
-
}
|
|
82
|
-
|
|
51
|
+
makeKey(namespace, key) {
|
|
52
|
+
return `${namespace}-${key}`;
|
|
53
|
+
}
|
|
54
|
+
set(namespace, key, obj, options) {
|
|
83
55
|
if (!obj.lastModifiedDate) {
|
|
84
56
|
obj.lastModifiedDate = new Date().toISOString();
|
|
85
57
|
}
|
|
86
58
|
return this.setWithFullKey(this.makeKey(namespace, key), obj);
|
|
87
|
-
}
|
|
88
|
-
|
|
59
|
+
}
|
|
60
|
+
setWithFullKey(key, obj) {
|
|
89
61
|
try {
|
|
90
62
|
return this.localForage.setItem(key, obj);
|
|
91
63
|
}
|
|
92
64
|
catch (e) {
|
|
93
|
-
console.warn(
|
|
65
|
+
console.warn(`Unable to set ${key} due to: ${e.message}`);
|
|
94
66
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
67
|
+
}
|
|
68
|
+
get(namespace, key) {
|
|
97
69
|
return this.getWithFullKey(this.makeKey(namespace, key));
|
|
98
|
-
}
|
|
99
|
-
|
|
70
|
+
}
|
|
71
|
+
getWithFullKey(key) {
|
|
100
72
|
try {
|
|
101
73
|
return this.localForage.getItem(key);
|
|
102
74
|
}
|
|
103
75
|
catch (e) {
|
|
104
|
-
console.warn(
|
|
76
|
+
console.warn(`Unable to get ${key} due to: ${e.message}`);
|
|
105
77
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
78
|
+
}
|
|
79
|
+
delete(namespace, key) {
|
|
108
80
|
return this.deleteWithFullKey(this.makeKey(namespace, key));
|
|
109
|
-
}
|
|
110
|
-
|
|
81
|
+
}
|
|
82
|
+
deleteWithFullKey(key) {
|
|
111
83
|
try {
|
|
112
84
|
return this.localForage.removeItem(key);
|
|
113
85
|
}
|
|
114
86
|
catch (e) {
|
|
115
|
-
console.warn(
|
|
87
|
+
console.warn(`Unable to delete ${key} due to: ${e.message}`);
|
|
116
88
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
89
|
+
}
|
|
90
|
+
clear() {
|
|
119
91
|
try {
|
|
120
92
|
return this.localForage.clear();
|
|
121
93
|
}
|
|
122
94
|
catch (e) {
|
|
123
|
-
console.warn(
|
|
95
|
+
console.warn(`Unable to clear all cache: ${e.message}`);
|
|
124
96
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
97
|
+
}
|
|
98
|
+
keys(namespace) {
|
|
127
99
|
try {
|
|
128
100
|
if (namespace) {
|
|
129
|
-
return this.localForage.keys().then(
|
|
101
|
+
return this.localForage.keys().then((keys) => {
|
|
130
102
|
if (keys) {
|
|
131
|
-
return filter_1.default(keys,
|
|
103
|
+
return filter_1.default(keys, (key) => includes_1.default(key, namespace));
|
|
132
104
|
}
|
|
133
105
|
else {
|
|
134
106
|
return [];
|
|
@@ -140,38 +112,26 @@ var CacheUtilsService = /** @class */ (function () {
|
|
|
140
112
|
}
|
|
141
113
|
}
|
|
142
114
|
catch (e) {
|
|
143
|
-
console.warn(
|
|
115
|
+
console.warn(`Unable to get keys from namespace ${namespace} due to: ${e.message}`);
|
|
144
116
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
return [3 /*break*/, 3];
|
|
165
|
-
case 2:
|
|
166
|
-
e_1 = _a.sent();
|
|
167
|
-
console.warn("Could not expire indexdb cache: " + e_1.message);
|
|
168
|
-
return [3 /*break*/, 3];
|
|
169
|
-
case 3: return [2 /*return*/];
|
|
170
|
-
}
|
|
171
|
-
});
|
|
117
|
+
}
|
|
118
|
+
expireCache() {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
try {
|
|
121
|
+
const keys = yield this.keys();
|
|
122
|
+
forEach_1.default(keys, (k) => {
|
|
123
|
+
this.localForage.getItem(k).then((c) => {
|
|
124
|
+
if (c.expiresAt && +new Date() > c.expiresAt) {
|
|
125
|
+
this.localForage.removeItem(k);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
console.warn(`Could not expire indexdb cache: ${e.message}`);
|
|
132
|
+
}
|
|
172
133
|
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return CacheUtilsService;
|
|
176
|
-
}());
|
|
134
|
+
}
|
|
135
|
+
}
|
|
177
136
|
exports.CacheUtilsService = CacheUtilsService;
|
|
137
|
+
CacheUtilsService.localStorageAvailable = true;
|
package/lib/cjs/caseUtils.js
CHANGED
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.toOldCaseTypeSwitcher = exports.toOldCaseTypeMapper = exports.toNewCaseTypeSwitcher = exports.toNewCaseTypeMapper = exports.severitySort = exports.linkifyLinks = exports.areAllValidCaseNumbers = exports.isValidCaseNumber = exports.isOpenShiftOnlineProduct = exports.isSev2 = exports.isSev1 = exports.isPremiumEntitlement = exports.autoEnableFtsOnCaseViewEditPage = exports.isFtsEditableOnEditPage = exports.showFtsOnCaseViewEditPage = exports.showFtsOnCreateCasePage = exports.humanizeSize = exports.canManageCase = exports.NewCaseTypes = exports.PreviousCaseTypes = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const find_1 = __importDefault(require("lodash/find"));
|
|
8
|
+
const includes_1 = __importDefault(require("lodash/includes"));
|
|
9
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
10
10
|
// Old Case Types
|
|
11
11
|
var PreviousCaseTypes;
|
|
12
12
|
(function (PreviousCaseTypes) {
|
|
@@ -39,14 +39,14 @@ function canManageCase(loggedInUserJwtToken) {
|
|
|
39
39
|
}
|
|
40
40
|
exports.canManageCase = canManageCase;
|
|
41
41
|
function humanizeSize(fileSize) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
let i = -1;
|
|
43
|
+
let size = fileSize;
|
|
44
|
+
const byteUnits = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
45
45
|
do {
|
|
46
46
|
size = size / 1024;
|
|
47
47
|
i++;
|
|
48
48
|
} while (size >= 1024 && byteUnits[i + 1]);
|
|
49
|
-
return Math.max(size, 0.1).toFixed(1)
|
|
49
|
+
return `${Math.max(size, 0.1).toFixed(1)} ${byteUnits[i]}`;
|
|
50
50
|
}
|
|
51
51
|
exports.humanizeSize = humanizeSize;
|
|
52
52
|
function showFtsOnCreateCasePage(slaProcessId, severity) {
|
|
@@ -86,7 +86,7 @@ function isOpenShiftOnlineProduct(product) {
|
|
|
86
86
|
exports.isOpenShiftOnlineProduct = isOpenShiftOnlineProduct;
|
|
87
87
|
function isValidCaseNumber(caseNumber) {
|
|
88
88
|
// eslint-disable-next-line no-useless-escape
|
|
89
|
-
|
|
89
|
+
const validCaseNumberFormat = /^\d{8}$/;
|
|
90
90
|
if (caseNumber && caseNumber.trim().match(validCaseNumberFormat)) {
|
|
91
91
|
return true;
|
|
92
92
|
}
|
|
@@ -96,15 +96,14 @@ function isValidCaseNumber(caseNumber) {
|
|
|
96
96
|
}
|
|
97
97
|
exports.isValidCaseNumber = isValidCaseNumber;
|
|
98
98
|
function areAllValidCaseNumbers(items) {
|
|
99
|
-
return isEmpty_1.default(find_1.default(items,
|
|
99
|
+
return isEmpty_1.default(find_1.default(items, (item) => !isValidCaseNumber(item.trim())));
|
|
100
100
|
}
|
|
101
101
|
exports.areAllValidCaseNumbers = areAllValidCaseNumbers;
|
|
102
|
-
function linkifyLinks(text) {
|
|
103
|
-
|
|
104
|
-
var replacePattern1 = /(\b(https:)\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gim;
|
|
102
|
+
function linkifyLinks(text = '') {
|
|
103
|
+
const replacePattern1 = /(\b(https:)\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])/gim;
|
|
105
104
|
function getUrl(match) {
|
|
106
|
-
|
|
107
|
-
return
|
|
105
|
+
const openInNewTab = !match.includes('showModal=');
|
|
106
|
+
return `<a href="${match}"${openInNewTab ? ' target="_blank" rel="noopener noreferrer"' : ''}>${match}</a>`;
|
|
108
107
|
}
|
|
109
108
|
return text ? text.replace(replacePattern1, getUrl) : '';
|
|
110
109
|
}
|
|
@@ -124,7 +123,7 @@ function severitySort(sevA, sevB) {
|
|
|
124
123
|
exports.severitySort = severitySort;
|
|
125
124
|
// To convert array of old case types to new support types
|
|
126
125
|
function toNewCaseTypeMapper(allCaseTypes) {
|
|
127
|
-
|
|
126
|
+
let newCaseTypeArray = allCaseTypes === null || allCaseTypes === void 0 ? void 0 : allCaseTypes.map((value) => {
|
|
128
127
|
switch (value) {
|
|
129
128
|
case PreviousCaseTypes.DEFECT_BUG:
|
|
130
129
|
return NewCaseTypes.BUG_DEFECT;
|
|
@@ -175,7 +174,7 @@ function toNewCaseTypeSwitcher(caseType) {
|
|
|
175
174
|
exports.toNewCaseTypeSwitcher = toNewCaseTypeSwitcher;
|
|
176
175
|
// To convert array of new support types to old case types
|
|
177
176
|
function toOldCaseTypeMapper(allCaseTypes) {
|
|
178
|
-
|
|
177
|
+
let oldCaseTypeArray = allCaseTypes === null || allCaseTypes === void 0 ? void 0 : allCaseTypes.map((value) => {
|
|
179
178
|
switch (value) {
|
|
180
179
|
case NewCaseTypes.BUG_DEFECT:
|
|
181
180
|
return PreviousCaseTypes.DEFECT_BUG;
|
package/lib/cjs/csvUtils.js
CHANGED
|
@@ -2,65 +2,37 @@
|
|
|
2
2
|
// Most of it is copied from https://github.com/react-csv/react-csv/blob/master/src/core.js
|
|
3
3
|
// except we add the transform a column functionality and also we escape the double quotes
|
|
4
4
|
// for every value so that we dont break the csv
|
|
5
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
6
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
7
|
-
if (!m) return o;
|
|
8
|
-
var i = m.call(o), r, ar = [], e;
|
|
9
|
-
try {
|
|
10
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
11
|
-
}
|
|
12
|
-
catch (error) { e = { error: error }; }
|
|
13
|
-
finally {
|
|
14
|
-
try {
|
|
15
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
16
|
-
}
|
|
17
|
-
finally { if (e) throw e.error; }
|
|
18
|
-
}
|
|
19
|
-
return ar;
|
|
20
|
-
};
|
|
21
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
22
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
23
|
-
to[j] = from[i];
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
6
|
exports.downloadCSV = exports.buildURI = exports.toCSV = exports.string2csv = exports.jsons2csv = exports.arrays2csv = exports.joiner = exports.elementOrEmpty = exports.getHeaderValue = exports.jsons2arrays = exports.jsonsHeaders = exports.isArrays = exports.isJsons = exports.escapeDoubleQuotes = exports.isSafari = void 0;
|
|
28
7
|
/**
|
|
29
8
|
* Simple safari detection based on user agent test
|
|
30
9
|
*/
|
|
31
|
-
|
|
10
|
+
const isSafari = () => /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
32
11
|
exports.isSafari = isSafari;
|
|
33
|
-
|
|
12
|
+
const escapeDoubleQuotes = (data) => (data && typeof data === 'string' ? data.replace(/"/g, '""') : data);
|
|
34
13
|
exports.escapeDoubleQuotes = escapeDoubleQuotes;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return Array.isArray(array) && array.every(function (row) { return typeof row === 'object' && !(row instanceof Array); });
|
|
38
|
-
};
|
|
14
|
+
const defaultTransformFn = (data) => data;
|
|
15
|
+
const isJsons = (array) => Array.isArray(array) && array.every((row) => typeof row === 'object' && !(row instanceof Array));
|
|
39
16
|
exports.isJsons = isJsons;
|
|
40
|
-
|
|
17
|
+
const isArrays = (array) => Array.isArray(array) && array.every((row) => Array.isArray(row));
|
|
41
18
|
exports.isArrays = isArrays;
|
|
42
|
-
|
|
43
|
-
return Array.from(array.map(function (json) { return Object.keys(json); }).reduce(function (a, b) { return new Set(__spreadArray(__spreadArray([], __read(a)), __read(b))); }, []));
|
|
44
|
-
};
|
|
19
|
+
const jsonsHeaders = (array) => Array.from(array.map((json) => Object.keys(json)).reduce((a, b) => new Set([...a, ...b]), []));
|
|
45
20
|
exports.jsonsHeaders = jsonsHeaders;
|
|
46
|
-
|
|
21
|
+
const jsons2arrays = (jsons, headers) => {
|
|
47
22
|
headers = headers || exports.jsonsHeaders(jsons);
|
|
48
23
|
// allow headers to have custom labels, defaulting to having the header data key be the label
|
|
49
|
-
|
|
50
|
-
|
|
24
|
+
let headerLabels = headers;
|
|
25
|
+
let headerKeys = headers;
|
|
51
26
|
if (exports.isJsons(headers)) {
|
|
52
|
-
headerLabels = headers.map(
|
|
53
|
-
headerKeys = headers.map(
|
|
27
|
+
headerLabels = headers.map((header) => header.label);
|
|
28
|
+
headerKeys = headers.map((header) => ({ key: header['key'], transformFn: header['transform'] }));
|
|
54
29
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
return __spreadArray([headerLabels], __read(data));
|
|
30
|
+
const data = jsons.map((object) => headerKeys.map((header) => exports.getHeaderValue(header.key, object, header.transformFn)));
|
|
31
|
+
return [headerLabels, ...data];
|
|
59
32
|
};
|
|
60
33
|
exports.jsons2arrays = jsons2arrays;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var foundValue = property
|
|
34
|
+
const getHeaderValue = (property, obj, transformFn = defaultTransformFn) => {
|
|
35
|
+
const foundValue = property
|
|
64
36
|
.replace(/\[([^\]]+)]/g, '.$1')
|
|
65
37
|
.split('.')
|
|
66
38
|
.reduce(function (o, p, i, arr) {
|
|
@@ -80,73 +52,52 @@ var getHeaderValue = function (property, obj, transformFn) {
|
|
|
80
52
|
: transformFn(foundValue);
|
|
81
53
|
};
|
|
82
54
|
exports.getHeaderValue = getHeaderValue;
|
|
83
|
-
|
|
55
|
+
const elementOrEmpty = (element) => (element || element === 0 ? element : '');
|
|
84
56
|
exports.elementOrEmpty = elementOrEmpty;
|
|
85
|
-
|
|
86
|
-
if (separator === void 0) { separator = ','; }
|
|
87
|
-
if (enclosingCharacter === void 0) { enclosingCharacter = '"'; }
|
|
57
|
+
const joiner = (data, separator = ',', enclosingCharacter = '"') => {
|
|
88
58
|
return data
|
|
89
|
-
.filter(
|
|
90
|
-
.map(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
})
|
|
96
|
-
.join("\n");
|
|
59
|
+
.filter((e) => e)
|
|
60
|
+
.map((row) => row
|
|
61
|
+
.map((element) => exports.elementOrEmpty(element))
|
|
62
|
+
.map((column) => `${enclosingCharacter}${column}${enclosingCharacter}`)
|
|
63
|
+
.join(separator))
|
|
64
|
+
.join(`\n`);
|
|
97
65
|
};
|
|
98
66
|
exports.joiner = joiner;
|
|
99
|
-
|
|
100
|
-
return exports.joiner(headers ? __spreadArray([headers], __read(data)) : data, separator, enclosingCharacter);
|
|
101
|
-
};
|
|
67
|
+
const arrays2csv = (data, headers, separator, enclosingCharacter) => exports.joiner(headers ? [headers, ...data] : data, separator, enclosingCharacter);
|
|
102
68
|
exports.arrays2csv = arrays2csv;
|
|
103
|
-
|
|
104
|
-
return exports.joiner(exports.jsons2arrays(data, headers), separator, enclosingCharacter);
|
|
105
|
-
};
|
|
69
|
+
const jsons2csv = (data, headers, separator, enclosingCharacter) => exports.joiner(exports.jsons2arrays(data, headers), separator, enclosingCharacter);
|
|
106
70
|
exports.jsons2csv = jsons2csv;
|
|
107
|
-
|
|
108
|
-
if (separator === void 0) { separator = ','; }
|
|
109
|
-
if (enclosingCharacter === void 0) { enclosingCharacter = '"'; }
|
|
110
|
-
return headers ? headers.join(separator) + "\n" + data : data;
|
|
111
|
-
};
|
|
71
|
+
const string2csv = (data, headers, separator = ',', enclosingCharacter = '"') => headers ? `${headers.join(separator)}\n${data}` : data;
|
|
112
72
|
exports.string2csv = string2csv;
|
|
113
|
-
|
|
114
|
-
if (separator === void 0) { separator = ','; }
|
|
115
|
-
if (enclosingCharacter === void 0) { enclosingCharacter = '"'; }
|
|
73
|
+
const toCSV = (data, headers, separator = ',', enclosingCharacter = '"') => {
|
|
116
74
|
if (exports.isJsons(data))
|
|
117
75
|
return exports.jsons2csv(data, headers, separator, enclosingCharacter);
|
|
118
76
|
if (exports.isArrays(data))
|
|
119
77
|
return exports.arrays2csv(data, headers, separator, enclosingCharacter);
|
|
120
78
|
if (typeof data === 'string')
|
|
121
79
|
return exports.string2csv(data, headers, separator);
|
|
122
|
-
throw new TypeError(
|
|
80
|
+
throw new TypeError(`Data should be a "String", "Array of arrays" OR "Array of objects" `);
|
|
123
81
|
};
|
|
124
82
|
exports.toCSV = toCSV;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
var blob = new Blob([uFEFF ? '\uFEFF' : '', csv], { type: type });
|
|
132
|
-
var dataURI = "data:" + type + ";charset=utf-8," + (uFEFF ? '\uFEFF' : '') + csv;
|
|
133
|
-
var URL = window.URL || window.webkitURL;
|
|
83
|
+
const buildURI = (data, headers, uFEFF = true, separator = ',', enclosingCharacter = '"') => {
|
|
84
|
+
const csv = exports.toCSV(data, headers, separator, enclosingCharacter);
|
|
85
|
+
const type = exports.isSafari() ? 'application/csv' : 'text/csv';
|
|
86
|
+
const blob = new Blob([uFEFF ? '\uFEFF' : '', csv], { type });
|
|
87
|
+
const dataURI = `data:${type};charset=utf-8,${uFEFF ? '\uFEFF' : ''}${csv}`;
|
|
88
|
+
const URL = window.URL || window.webkitURL;
|
|
134
89
|
return typeof URL.createObjectURL === 'undefined' ? dataURI : URL.createObjectURL(blob);
|
|
135
90
|
};
|
|
136
91
|
exports.buildURI = buildURI;
|
|
137
|
-
|
|
138
|
-
if (fileName === void 0) { fileName = 'csvGenerator'; }
|
|
139
|
-
if (uFEFF === void 0) { uFEFF = true; }
|
|
140
|
-
if (separator === void 0) { separator = ','; }
|
|
141
|
-
if (enclosingCharacter === void 0) { enclosingCharacter = '"'; }
|
|
92
|
+
const downloadCSV = (data, headers, fileName = 'csvGenerator', uFEFF = true, separator = ',', enclosingCharacter = '"') => {
|
|
142
93
|
// If this browser is IE 11, it does not support the `download` attribute
|
|
143
94
|
if (window.navigator.msSaveOrOpenBlob) {
|
|
144
|
-
|
|
95
|
+
let blob = new Blob([uFEFF ? '\uFEFF' : '', exports.toCSV(data, headers, separator, enclosingCharacter)]);
|
|
145
96
|
window.navigator.msSaveBlob(blob, fileName);
|
|
146
97
|
}
|
|
147
98
|
else {
|
|
148
|
-
|
|
149
|
-
|
|
99
|
+
const uri = exports.buildURI(data, headers);
|
|
100
|
+
const element = document.createElement('a');
|
|
150
101
|
element.setAttribute('href', uri);
|
|
151
102
|
element.setAttribute('target', '_self');
|
|
152
103
|
element.setAttribute('download', fileName);
|
|
@@ -14,7 +14,7 @@ var CustomElements;
|
|
|
14
14
|
* the pfelement does not get defined twice.
|
|
15
15
|
*/
|
|
16
16
|
function requireCustomElement(elements) {
|
|
17
|
-
elements.forEach(
|
|
17
|
+
elements.forEach((elementObj) => {
|
|
18
18
|
if (window.customElements.get(elementObj.element) === undefined) {
|
|
19
19
|
elementObj.requireCb();
|
|
20
20
|
}
|