@rh-support/utils 0.2.23 → 0.2.33

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/README.md CHANGED
@@ -9,3 +9,5 @@ import utils from 'utils';
9
9
 
10
10
  // TODO: DEMONSTRATE API
11
11
  ```
12
+
13
+ .
@@ -22,4 +22,5 @@ export * from './customElementUtils';
22
22
  export * from './userUtils';
23
23
  export * from './styleUtils';
24
24
  export * from './translation-helper';
25
+ export * from './outlier';
25
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC"}
package/lib/cjs/index.js CHANGED
@@ -34,3 +34,4 @@ __exportStar(require("./customElementUtils"), exports);
34
34
  __exportStar(require("./userUtils"), exports);
35
35
  __exportStar(require("./styleUtils"), exports);
36
36
  __exportStar(require("./translation-helper"), exports);
37
+ __exportStar(require("./outlier"), exports);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Outlier Function
3
+ * Refer: https://www.cuemath.com/outlier-formula/
4
+ *
5
+ * An outlier function which takers array of number and find high outlier and low outlier
6
+ * 1. Taker array of number and sort then in ascending order.
7
+ * 2. Calculate first(q1) and third(q3) quartile.
8
+ * 3. Calculate inter-quartile(iqr) range (q3-q1).
9
+ * 4. Find the upper boundary value by formula q3 + iqr*1.5.
10
+ * 5. Find the lower boundary value by formula q1 - iqr*1.5
11
+ *
12
+ * @param {number[]} numbers
13
+ * @returns {number[]} upper and lower boundary value
14
+ */
15
+ export declare const outlier: (array: Array<number>) => Array<number>;
16
+ //# sourceMappingURL=outlier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outlier.d.ts","sourceRoot":"","sources":["../../src/outlier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,OAAO,UAAW,MAAM,MAAM,CAAC,KAAG,MAAM,MAAM,CAkC1D,CAAC"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Outlier Function
4
+ * Refer: https://www.cuemath.com/outlier-formula/
5
+ *
6
+ * An outlier function which takers array of number and find high outlier and low outlier
7
+ * 1. Taker array of number and sort then in ascending order.
8
+ * 2. Calculate first(q1) and third(q3) quartile.
9
+ * 3. Calculate inter-quartile(iqr) range (q3-q1).
10
+ * 4. Find the upper boundary value by formula q3 + iqr*1.5.
11
+ * 5. Find the lower boundary value by formula q1 - iqr*1.5
12
+ *
13
+ * @param {number[]} numbers
14
+ * @returns {number[]} upper and lower boundary value
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.outlier = void 0;
18
+ var outlier = function (array) {
19
+ // Take array length
20
+ var arrayLength = array.length;
21
+ // Check if length is smaller than four then return array result as it is
22
+ if (arrayLength < 4) {
23
+ return array;
24
+ }
25
+ var q1, q3, iqr, upperBoundary, lowerBoundary;
26
+ // Make a copy of array plus sort it in ascending order
27
+ var sortedArray = array.slice().sort(function (a, b) { return a - b; });
28
+ // Find the quartiles range
29
+ // If median is odd adjust the index by minus one
30
+ if (((arrayLength - 1) / 4) % 1 === 0 || (arrayLength / 4) % 1 === 0) {
31
+ q1 = (1 / 2) * (sortedArray[Math.floor(arrayLength / 4) - 1] + sortedArray[Math.floor(arrayLength / 4)]);
32
+ q3 =
33
+ (1 / 2) *
34
+ (sortedArray[Math.ceil(arrayLength * (3 / 4)) - 1] + sortedArray[Math.ceil(arrayLength * (3 / 4))]);
35
+ }
36
+ else {
37
+ q1 = sortedArray[Math.floor(arrayLength / 4)];
38
+ q3 = sortedArray[Math.floor(arrayLength * (3 / 4))];
39
+ }
40
+ // Calculate inter-quartile range
41
+ iqr = q3 - q1;
42
+ // upper boundary
43
+ upperBoundary = q3 + iqr * 1.5;
44
+ // lower boundary
45
+ lowerBoundary = q1 - iqr * 1.5;
46
+ return [upperBoundary, lowerBoundary];
47
+ };
48
+ exports.outlier = outlier;
@@ -4,13 +4,20 @@ export interface ITroubleshootProductResponse {
4
4
  otherProducts: Partial<ISEProduct>[];
5
5
  productsResult: Partial<ISEProduct>[];
6
6
  }
7
- export declare const handleProductSearchResponse: (productsResultAll: ISEProduct[], productsResultEntitled?: IProductV2[]) => ITroubleshootProductResponse;
7
+ export declare const handleProductSearchResponse: (productsResultAll: ISEProduct[], productsResultEntitled?: IProductV2[], topCount?: number) => ITroubleshootProductResponse;
8
8
  /**
9
- * Tries to get top 5 products with priority given to recentlyFiledAgainst
9
+ * This method is used for parsing `hydra/rest/products/contact/{userName}` response form API
10
+ * and need to create partial response like method `handleProductSearchResponse`
11
+ * @param productsResultEntitled IProductV2[]
12
+ * @returns ITroubleshootProductResponse
13
+ */
14
+ export declare const handleEntitledProductResponse: (productsResultEntitled?: IProductV2[]) => ITroubleshootProductResponse;
15
+ /**
16
+ * Tries to get top products with priority given to recentlyFiledAgainst
10
17
  * before checking general top products from un-authed SE API
11
18
  * @param products Partial<ISEProduct>
12
19
  */
13
- export declare function getTopProducts(products: Partial<ISEProduct>[]): Partial<ISEProduct>[];
20
+ export declare function getTopProducts(products: Partial<ISEProduct>[], topCount?: number): Partial<ISEProduct>[];
14
21
  export declare function isOnlyVersion(versions: string[]): boolean;
15
22
  export declare function getVersionIfOnlyVersion(versions: string[]): string;
16
23
  export declare function getUniqueSortedVersions(versions: string[]): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"productsUtils.d.ts","sourceRoot":"","sources":["../../src/productsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAWhF,MAAM,WAAW,4BAA4B;IACzC,WAAW,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IACnC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IACrC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CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,SAAI,GAAG,OAAO,CAAC,UAAU,CAAC,EAAE,CAOnG;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,WAE/C;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAEzD;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAEzD;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,MAAM,MAAM,eAmBnD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAS,MAAM,EAAE,aAExC,CAAC;AAEF,UAAU,sBAAsB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAkBlE"}
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.getVersion = exports.versionSort = exports.versionSorter = exports.getUniqueSortedVersions = exports.getVersionIfOnlyVersion = exports.isOnlyVersion = exports.getTopProducts = exports.handleProductSearchResponse = void 0;
38
+ exports.getVersion = exports.versionSort = exports.versionSorter = exports.getUniqueSortedVersions = exports.getVersionIfOnlyVersion = exports.isOnlyVersion = exports.getTopProducts = exports.handleEntitledProductResponse = exports.handleProductSearchResponse = void 0;
39
39
  var difference_1 = __importDefault(require("lodash/difference"));
40
40
  var forEach_1 = __importDefault(require("lodash/forEach"));
41
41
  var isEmpty_1 = __importDefault(require("lodash/isEmpty"));
@@ -44,8 +44,9 @@ var orderBy_1 = __importDefault(require("lodash/orderBy"));
44
44
  var remove_1 = __importDefault(require("lodash/remove"));
45
45
  var uniq_1 = __importDefault(require("lodash/uniq"));
46
46
  var validatorUtils_1 = require("./validatorUtils");
47
- var handleProductSearchResponse = function (productsResultAll, productsResultEntitled) {
47
+ var handleProductSearchResponse = function (productsResultAll, productsResultEntitled, topCount) {
48
48
  if (productsResultEntitled === void 0) { productsResultEntitled = []; }
49
+ if (topCount === void 0) { topCount = 5; }
49
50
  var productsResultEntitledMap = {};
50
51
  forEach_1.default(productsResultEntitled, function (p) {
51
52
  // if (p.supportedForCustomer) { // Needs confirmation froom CCM team before adding
@@ -60,9 +61,8 @@ var handleProductSearchResponse = function (productsResultAll, productsResultEnt
60
61
  ? product.featuredVersion
61
62
  : (_d = product === null || product === void 0 ? void 0 : product.versions[0]) !== null && _d !== void 0 ? _d : '' });
62
63
  });
63
- // first top 5 products before sorting
64
64
  // we get products based on the highest number of support cases
65
- var topProducts = getTopProducts(productsResult);
65
+ var topProducts = getTopProducts(productsResult, topCount);
66
66
  var productsResultSorted = orderBy_1.default(productsResult, ['product'], ['asc']);
67
67
  return {
68
68
  productsResult: productsResultSorted,
@@ -72,17 +72,38 @@ var handleProductSearchResponse = function (productsResultAll, productsResultEnt
72
72
  };
73
73
  exports.handleProductSearchResponse = handleProductSearchResponse;
74
74
  /**
75
- * Tries to get top 5 products with priority given to recentlyFiledAgainst
75
+ * This method is used for parsing `hydra/rest/products/contact/{userName}` response form API
76
+ * and need to create partial response like method `handleProductSearchResponse`
77
+ * @param productsResultEntitled IProductV2[]
78
+ * @returns ITroubleshootProductResponse
79
+ */
80
+ var handleEntitledProductResponse = function (productsResultEntitled) {
81
+ if (productsResultEntitled === void 0) { productsResultEntitled = []; }
82
+ var productsResult = productsResultEntitled.map(function (product) {
83
+ return __assign(__assign({}, product), { product: product.name });
84
+ });
85
+ var topProducts = getTopProducts(productsResult);
86
+ var productsResultSorted = orderBy_1.default(productsResult, ['product'], ['asc']);
87
+ return {
88
+ productsResult: productsResultSorted,
89
+ topProducts: topProducts,
90
+ otherProducts: difference_1.default(productsResultSorted, topProducts),
91
+ };
92
+ };
93
+ exports.handleEntitledProductResponse = handleEntitledProductResponse;
94
+ /**
95
+ * Tries to get top products with priority given to recentlyFiledAgainst
76
96
  * before checking general top products from un-authed SE API
77
97
  * @param products Partial<ISEProduct>
78
98
  */
79
- function getTopProducts(products) {
99
+ function getTopProducts(products, topCount) {
100
+ if (topCount === void 0) { topCount = 5; }
80
101
  var toReturn = remove_1.default(__spreadArray([], __read(products)), function (o) { return o.recentlyFiledAgainst; });
81
- if (toReturn.length < 5) {
102
+ if (toReturn.length < topCount) {
82
103
  var generalTopProducts = remove_1.default(__spreadArray([], __read(products)), function (o) { return !o.recentlyFiledAgainst && o.isTopProduct; });
83
104
  toReturn.push.apply(toReturn, __spreadArray([], __read(generalTopProducts)));
84
105
  }
85
- return toReturn.slice(0, 5);
106
+ return toReturn.slice(0, topCount);
86
107
  }
87
108
  exports.getTopProducts = getTopProducts;
88
109
  function isOnlyVersion(versions) {
@@ -22,4 +22,5 @@ export * from './customElementUtils';
22
22
  export * from './userUtils';
23
23
  export * from './styleUtils';
24
24
  export * from './translation-helper';
25
+ export * from './outlier';
25
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC"}
package/lib/esm/index.js CHANGED
@@ -22,3 +22,4 @@ export * from './customElementUtils';
22
22
  export * from './userUtils';
23
23
  export * from './styleUtils';
24
24
  export * from './translation-helper';
25
+ export * from './outlier';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Outlier Function
3
+ * Refer: https://www.cuemath.com/outlier-formula/
4
+ *
5
+ * An outlier function which takers array of number and find high outlier and low outlier
6
+ * 1. Taker array of number and sort then in ascending order.
7
+ * 2. Calculate first(q1) and third(q3) quartile.
8
+ * 3. Calculate inter-quartile(iqr) range (q3-q1).
9
+ * 4. Find the upper boundary value by formula q3 + iqr*1.5.
10
+ * 5. Find the lower boundary value by formula q1 - iqr*1.5
11
+ *
12
+ * @param {number[]} numbers
13
+ * @returns {number[]} upper and lower boundary value
14
+ */
15
+ export declare const outlier: (array: Array<number>) => Array<number>;
16
+ //# sourceMappingURL=outlier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outlier.d.ts","sourceRoot":"","sources":["../../src/outlier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,OAAO,UAAW,MAAM,MAAM,CAAC,KAAG,MAAM,MAAM,CAkC1D,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Outlier Function
3
+ * Refer: https://www.cuemath.com/outlier-formula/
4
+ *
5
+ * An outlier function which takers array of number and find high outlier and low outlier
6
+ * 1. Taker array of number and sort then in ascending order.
7
+ * 2. Calculate first(q1) and third(q3) quartile.
8
+ * 3. Calculate inter-quartile(iqr) range (q3-q1).
9
+ * 4. Find the upper boundary value by formula q3 + iqr*1.5.
10
+ * 5. Find the lower boundary value by formula q1 - iqr*1.5
11
+ *
12
+ * @param {number[]} numbers
13
+ * @returns {number[]} upper and lower boundary value
14
+ */
15
+ export const outlier = (array) => {
16
+ // Take array length
17
+ const arrayLength = array.length;
18
+ // Check if length is smaller than four then return array result as it is
19
+ if (arrayLength < 4) {
20
+ return array;
21
+ }
22
+ let q1, q3, iqr, upperBoundary, lowerBoundary;
23
+ // Make a copy of array plus sort it in ascending order
24
+ const sortedArray = array.slice().sort((a, b) => a - b);
25
+ // Find the quartiles range
26
+ // If median is odd adjust the index by minus one
27
+ if (((arrayLength - 1) / 4) % 1 === 0 || (arrayLength / 4) % 1 === 0) {
28
+ q1 = (1 / 2) * (sortedArray[Math.floor(arrayLength / 4) - 1] + sortedArray[Math.floor(arrayLength / 4)]);
29
+ q3 =
30
+ (1 / 2) *
31
+ (sortedArray[Math.ceil(arrayLength * (3 / 4)) - 1] + sortedArray[Math.ceil(arrayLength * (3 / 4))]);
32
+ }
33
+ else {
34
+ q1 = sortedArray[Math.floor(arrayLength / 4)];
35
+ q3 = sortedArray[Math.floor(arrayLength * (3 / 4))];
36
+ }
37
+ // Calculate inter-quartile range
38
+ iqr = q3 - q1;
39
+ // upper boundary
40
+ upperBoundary = q3 + iqr * 1.5;
41
+ // lower boundary
42
+ lowerBoundary = q1 - iqr * 1.5;
43
+ return [upperBoundary, lowerBoundary];
44
+ };
@@ -4,13 +4,20 @@ export interface ITroubleshootProductResponse {
4
4
  otherProducts: Partial<ISEProduct>[];
5
5
  productsResult: Partial<ISEProduct>[];
6
6
  }
7
- export declare const handleProductSearchResponse: (productsResultAll: ISEProduct[], productsResultEntitled?: IProductV2[]) => ITroubleshootProductResponse;
7
+ export declare const handleProductSearchResponse: (productsResultAll: ISEProduct[], productsResultEntitled?: IProductV2[], topCount?: number) => ITroubleshootProductResponse;
8
8
  /**
9
- * Tries to get top 5 products with priority given to recentlyFiledAgainst
9
+ * This method is used for parsing `hydra/rest/products/contact/{userName}` response form API
10
+ * and need to create partial response like method `handleProductSearchResponse`
11
+ * @param productsResultEntitled IProductV2[]
12
+ * @returns ITroubleshootProductResponse
13
+ */
14
+ export declare const handleEntitledProductResponse: (productsResultEntitled?: IProductV2[]) => ITroubleshootProductResponse;
15
+ /**
16
+ * Tries to get top products with priority given to recentlyFiledAgainst
10
17
  * before checking general top products from un-authed SE API
11
18
  * @param products Partial<ISEProduct>
12
19
  */
13
- export declare function getTopProducts(products: Partial<ISEProduct>[]): Partial<ISEProduct>[];
20
+ export declare function getTopProducts(products: Partial<ISEProduct>[], topCount?: number): Partial<ISEProduct>[];
14
21
  export declare function isOnlyVersion(versions: string[]): boolean;
15
22
  export declare function getVersionIfOnlyVersion(versions: string[]): string;
16
23
  export declare function getUniqueSortedVersions(versions: string[]): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"productsUtils.d.ts","sourceRoot":"","sources":["../../src/productsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EA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AAU,EAAE,2BACP,UAAU,EAAE,aAC1B,MAAM,KACjB,4BA4BF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,4BACd,UAAU,EAAE,KACrC,4BAcF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,QAAQ,SAAI,GAAG,OAAO,CAAC,UAAU,CAAC,EAAE,CAOnG;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,WAE/C;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAEzD;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAEzD;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,MAAM,MAAM,eAmBnD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAS,MAAM,EAAE,aAExC,CAAC;AAEF,UAAU,sBAAsB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAkBlE"}
@@ -6,7 +6,7 @@ import orderBy from 'lodash/orderBy';
6
6
  import filter from 'lodash/remove';
7
7
  import uniq from 'lodash/uniq';
8
8
  import { isNumber } from './validatorUtils';
9
- export const handleProductSearchResponse = (productsResultAll, productsResultEntitled = []) => {
9
+ export const handleProductSearchResponse = (productsResultAll, productsResultEntitled = [], topCount = 5) => {
10
10
  const productsResultEntitledMap = {};
11
11
  forEach(productsResultEntitled, (p) => {
12
12
  // if (p.supportedForCustomer) { // Needs confirmation froom CCM team before adding
@@ -21,8 +21,25 @@ export const handleProductSearchResponse = (productsResultAll, productsResultEnt
21
21
  ? product.featuredVersion
22
22
  : (_d = product === null || product === void 0 ? void 0 : product.versions[0]) !== null && _d !== void 0 ? _d : '' });
23
23
  });
24
- // first top 5 products before sorting
25
24
  // we get products based on the highest number of support cases
25
+ const topProducts = getTopProducts(productsResult, topCount);
26
+ const productsResultSorted = orderBy(productsResult, ['product'], ['asc']);
27
+ return {
28
+ productsResult: productsResultSorted,
29
+ topProducts,
30
+ otherProducts: difference(productsResultSorted, topProducts),
31
+ };
32
+ };
33
+ /**
34
+ * This method is used for parsing `hydra/rest/products/contact/{userName}` response form API
35
+ * and need to create partial response like method `handleProductSearchResponse`
36
+ * @param productsResultEntitled IProductV2[]
37
+ * @returns ITroubleshootProductResponse
38
+ */
39
+ export const handleEntitledProductResponse = (productsResultEntitled = []) => {
40
+ const productsResult = productsResultEntitled.map((product) => {
41
+ return Object.assign(Object.assign({}, product), { product: product.name });
42
+ });
26
43
  const topProducts = getTopProducts(productsResult);
27
44
  const productsResultSorted = orderBy(productsResult, ['product'], ['asc']);
28
45
  return {
@@ -32,17 +49,17 @@ export const handleProductSearchResponse = (productsResultAll, productsResultEnt
32
49
  };
33
50
  };
34
51
  /**
35
- * Tries to get top 5 products with priority given to recentlyFiledAgainst
52
+ * Tries to get top products with priority given to recentlyFiledAgainst
36
53
  * before checking general top products from un-authed SE API
37
54
  * @param products Partial<ISEProduct>
38
55
  */
39
- export function getTopProducts(products) {
56
+ export function getTopProducts(products, topCount = 5) {
40
57
  const toReturn = filter([...products], (o) => o.recentlyFiledAgainst);
41
- if (toReturn.length < 5) {
58
+ if (toReturn.length < topCount) {
42
59
  const generalTopProducts = filter([...products], (o) => !o.recentlyFiledAgainst && o.isTopProduct);
43
60
  toReturn.push(...generalTopProducts);
44
61
  }
45
- return toReturn.slice(0, 5);
62
+ return toReturn.slice(0, topCount);
46
63
  }
47
64
  export function isOnlyVersion(versions) {
48
65
  return (versions === null || versions === void 0 ? void 0 : versions.length) && versions.length === 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/utils",
3
- "version": "0.2.23",
3
+ "version": "0.2.33",
4
4
  "description": "> TODO: description",
5
5
  "author": "Vikas Rathee <vrathee@redhat.com>",
6
6
  "license": "ISC",
@@ -45,7 +45,7 @@
45
45
  "prepublishOnly": "npm run build"
46
46
  },
47
47
  "peerDependencies": {
48
- "@cee-eng/hydrajs": "4.7.20",
48
+ "@cee-eng/hydrajs": "4.7.22",
49
49
  "@cee-eng/ui-toolkit": "1.1.6",
50
50
  "@rh-support/api": "0.3.9",
51
51
  "@rh-support/types": "0.2.0",
@@ -61,10 +61,10 @@
61
61
  "solr-query-builder": "1.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cee-eng/hydrajs": "4.7.20",
64
+ "@cee-eng/hydrajs": "4.7.22",
65
65
  "@cee-eng/ui-toolkit": "1.1.6",
66
- "@rh-support/api": "^0.3.12",
67
- "@rh-support/types": "^0.2.2",
66
+ "@rh-support/api": "0.3.13",
67
+ "@rh-support/types": "0.2.0",
68
68
  "dompurify": "^2.2.6",
69
69
  "dot": "^1.1.3",
70
70
  "i18next": "^19.0.1",
@@ -87,5 +87,5 @@
87
87
  "@types/react-dom": "^17.0.9",
88
88
  "moment-timezone": "^0.5.32"
89
89
  },
90
- "gitHead": "70f8095b855f531eb814e85cb5a77908405fff5f"
90
+ "gitHead": "5797cf1fd9b2d2406fa93933f91fcc0b0729e7a8"
91
91
  }