@procraft/widget-order 2.22.4 → 2.22.5

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/utils.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export declare const roundByStep: (v: number, s?: number) => number;
2
+ export declare const roundStd: (num: number, decimalPlaces: number) => number;
package/dist/utils.js CHANGED
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.roundByStep = void 0;
3
+ exports.roundStd = exports.roundByStep = void 0;
4
4
  const roundByStep = (v, s = 1.0) => {
5
- var inv = 1.0 / s;
5
+ const inv = 1.0 / s;
6
6
  return Math.round(v * inv) / inv;
7
7
  };
8
8
  exports.roundByStep = roundByStep;
9
+ const roundStd = (num, decimalPlaces) => {
10
+ const p = Math.pow(10, decimalPlaces);
11
+ const e = Number.EPSILON * num * p;
12
+ return Math.round((num * p) + e) / p;
13
+ };
14
+ exports.roundStd = roundStd;
9
15
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,WAAW,GAAG,CAAC,CAAS,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE;IAC9C,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IAClB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACrC,CAAC,CAAA;AAHY,QAAA,WAAW,eAGvB"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,WAAW,GAAG,CAAC,CAAS,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE;IAC9C,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IACpB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACrC,CAAC,CAAA;AAHY,QAAA,WAAW,eAGvB;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,aAAqB,EAAE,EAAE;IAC3D,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;IACtC,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,GAAG,GAAG,CAAC,CAAC;IAEnC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC,CAAA;AALY,QAAA,QAAQ,YAKpB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@procraft/widget-order",
3
3
  "description": "Order widget for landing",
4
- "version": "2.22.4",
4
+ "version": "2.22.5",
5
5
  "private": false,
6
6
  "main": "dist",
7
7
  "scripts": {
@@ -6,7 +6,7 @@ import {
6
6
  OrderCatalogItemFragment,
7
7
  OrderReviewCustom,
8
8
  } from '../../../modules/gql/generated/types'
9
- import { roundByStep } from '../../../utils'
9
+ import { roundByStep, roundStd } from '../../../utils'
10
10
  import { Stars } from '../Stars'
11
11
  import { ReviewFilters } from './Filters'
12
12
  import { ReviewOrderBy } from './Filters/interfaces'
@@ -34,14 +34,13 @@ export const calcRatingAverage = (item: OrderCatalogItemFragment) => {
34
34
  []
35
35
  )
36
36
 
37
- const rating = roundByStep(
38
- (reviewItems?.reduce((curr, next) => {
39
- return curr + next.rating
40
- }, 0) || 0) / (reviewItems?.length || 0),
41
- 0.5
42
- );
37
+ const preparedValue = (reviewItems?.reduce((curr, next) => curr + next.rating, 0) || 0) /
38
+ (reviewItems?.length || 0);
43
39
 
44
- return rating
40
+ const ratingHalfMean = roundByStep(preparedValue, .5);
41
+ const ratingStd = roundStd(preparedValue, 1);
42
+
43
+ return {ratingHalfMean, ratingStd}
45
44
  }
46
45
 
47
46
  export const ReviewsPopup: React.FC<ReviewsPopupProps> = ({
@@ -113,7 +112,7 @@ export const ReviewsPopup: React.FC<ReviewsPopupProps> = ({
113
112
  return null
114
113
  }
115
114
 
116
- const rating = calcRatingAverage(item)
115
+ const {ratingHalfMean, ratingStd} = calcRatingAverage(item)
117
116
 
118
117
  const portal = ReactDom.createPortal(
119
118
  <ReviewsPopupStyled>
@@ -140,8 +139,8 @@ export const ReviewsPopup: React.FC<ReviewsPopupProps> = ({
140
139
  {item.name}
141
140
  {item.reviewsCount ? (
142
141
  <>
143
- <span className="mean-val">{rating}</span>
144
- <Stars rating={rating} />{' '}
142
+ <span className="mean-val">{ratingStd}</span>
143
+ <Stars rating={ratingHalfMean} />{' '}
145
144
  <span className="reviews">{item.reviewsCount}</span>
146
145
  </>
147
146
  ) : null}
@@ -24,14 +24,14 @@ export const Reviews: React.FC<ReviewsProps> = ({
24
24
  return null
25
25
  }
26
26
 
27
- const rating = calcRatingAverage(item);
27
+ const {ratingHalfMean, ratingStd} = calcRatingAverage(item);
28
28
 
29
29
  return (
30
30
  <>
31
31
  <ReviewsStyled {...other}>
32
32
  <ReviewsLinkStyled onClick={toggleActive}>
33
- <span className="mean-val">{rating}</span>
34
- <Stars rating={rating} /> {reviewsCount}{' '}
33
+ <span className="mean-val">{ratingStd}</span>
34
+ <Stars rating={ratingHalfMean} /> {reviewsCount}{' '}
35
35
  <Recliner
36
36
  one="отзыв"
37
37
  two="отзыва"
package/src/utils.ts CHANGED
@@ -1,4 +1,11 @@
1
1
  export const roundByStep = (v: number, s = 1.0) => {
2
- var inv = 1.0 / s;
2
+ const inv = 1.0 / s;
3
3
  return Math.round(v * inv) / inv;
4
+ }
5
+
6
+ export const roundStd = (num: number, decimalPlaces: number) => {
7
+ const p = Math.pow(10, decimalPlaces);
8
+ const e = Number.EPSILON * num * p;
9
+
10
+ return Math.round((num * p) + e) / p;
4
11
  }