@bundle-stats/ui 3.2.0-beta.1 → 3.2.1-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.
Files changed (255) hide show
  1. package/.babelrc.js +3 -3
  2. package/CHANGELOG.md +20 -4
  3. package/lib/assets/icons/arrow.svg +1 -0
  4. package/lib/assets/icons/cancel.svg +1 -0
  5. package/lib/assets/icons/clock.svg +1 -0
  6. package/lib/assets/icons/close.svg +1 -0
  7. package/lib/assets/icons/commit.svg +1 -0
  8. package/lib/assets/icons/filter.svg +1 -0
  9. package/lib/assets/icons/help.svg +1 -0
  10. package/lib/assets/icons/menu.svg +1 -0
  11. package/lib/{ui/icon/assets → assets/icons}/sort.svg +0 -0
  12. package/lib/assets/icons/warning.svg +1 -0
  13. package/lib/assets/icons.svg +1 -0
  14. package/lib/components/bundle-assets/bundle-assets.js +3 -3
  15. package/lib/components/bundle-assets/bundle-assets.stories.js +19 -7
  16. package/lib/components/bundle-assets/bundle-assets.utils.js +95 -28
  17. package/lib/components/bundle-assets/index.js +115 -4
  18. package/lib/components/bundle-modules/bundle-modules.js +3 -3
  19. package/lib/components/bundle-modules/bundle-modules.utils.js +152 -0
  20. package/lib/components/bundle-modules/index.js +135 -4
  21. package/lib/components/bundle-packages/bundle-packages.js +3 -3
  22. package/lib/components/bundle-packages/{bundle-packages.container.js → bundle-packages.utils.js} +8 -42
  23. package/lib/components/bundle-packages/index.js +111 -3
  24. package/lib/components/metrics-table/metrics-table.js +3 -7
  25. package/lib/components/metrics-table-search/metrics-table-search.js +2 -1
  26. package/lib/components/metrics-table-search/metrics-table-search.module.css +2 -1
  27. package/lib/hooks/rows-filter.js +28 -0
  28. package/lib/hooks/rows-sort.js +54 -0
  29. package/lib/{hocs/with-search.js → hooks/search-params.js} +15 -64
  30. package/lib/ui/icon/icon.js +4 -191
  31. package/lib/ui/sort-dropdown/sort-dropdown.js +12 -13
  32. package/lib/ui/sort-dropdown/sort-dropdown.stories.js +2 -2
  33. package/lib/utils.js +6 -3
  34. package/lib-esm/app/app.js +60 -70
  35. package/lib-esm/app/app.stories.js +50 -71
  36. package/lib-esm/app/header/header.js +5 -3
  37. package/lib-esm/assets/icons/arrow.svg +1 -0
  38. package/lib-esm/assets/icons/cancel.svg +1 -0
  39. package/lib-esm/assets/icons/clock.svg +1 -0
  40. package/lib-esm/assets/icons/close.svg +1 -0
  41. package/lib-esm/assets/icons/commit.svg +1 -0
  42. package/lib-esm/assets/icons/filter.svg +1 -0
  43. package/lib-esm/assets/icons/help.svg +1 -0
  44. package/lib-esm/assets/icons/menu.svg +1 -0
  45. package/lib-esm/{ui/icon/assets → assets/icons}/sort.svg +0 -0
  46. package/lib-esm/assets/icons/warning.svg +1 -0
  47. package/lib-esm/assets/icons.svg +1 -0
  48. package/lib-esm/components/asset-info/asset-info.js +21 -17
  49. package/lib-esm/components/asset-info/asset-info.stories.js +29 -33
  50. package/lib-esm/components/browsertime-table/browsertime-table.js +6 -4
  51. package/lib-esm/components/browsertime-table/browsertime-table.stories.js +9 -13
  52. package/lib-esm/components/bundle-assets/bundle-assets.constants.js +17 -15
  53. package/lib-esm/components/bundle-assets/bundle-assets.js +107 -97
  54. package/lib-esm/components/bundle-assets/bundle-assets.stories.js +58 -63
  55. package/lib-esm/components/bundle-assets/bundle-assets.utils.js +65 -21
  56. package/lib-esm/components/bundle-assets/index.js +89 -2
  57. package/lib-esm/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.js +49 -51
  58. package/lib-esm/components/bundle-assets-totals-chart-bars/bundle-assets-totals-chart-bars.stories.js +9 -13
  59. package/lib-esm/components/bundle-assets-totals-table/bundle-assets-totals-table.js +14 -13
  60. package/lib-esm/components/bundle-assets-totals-table/bundle-assets-totals-table.stories.js +13 -19
  61. package/lib-esm/components/bundle-modules/bundle-modules.constants.js +17 -15
  62. package/lib-esm/components/bundle-modules/bundle-modules.js +112 -110
  63. package/lib-esm/components/bundle-modules/bundle-modules.stories.js +46 -58
  64. package/lib-esm/components/bundle-modules/bundle-modules.utils.js +98 -0
  65. package/lib-esm/components/bundle-modules/index.js +114 -3
  66. package/lib-esm/components/bundle-packages/bundle-packages.constants.js +17 -15
  67. package/lib-esm/components/bundle-packages/bundle-packages.js +71 -69
  68. package/lib-esm/components/bundle-packages/bundle-packages.stories.js +34 -46
  69. package/lib-esm/components/bundle-packages/bundle-packages.utils.js +44 -0
  70. package/lib-esm/components/bundle-packages/index.js +87 -2
  71. package/lib-esm/components/component-link.js +10 -13
  72. package/lib-esm/components/delta/delta.js +8 -6
  73. package/lib-esm/components/delta/delta.stories.js +26 -38
  74. package/lib-esm/components/duplicate-packages-warning/duplicate-packages-warning.js +11 -9
  75. package/lib-esm/components/duplicate-packages-warning/duplicate-packages-warning.stories.js +20 -26
  76. package/lib-esm/components/job-header/job-header.js +14 -11
  77. package/lib-esm/components/job-header/job-header.stories.js +12 -18
  78. package/lib-esm/components/job-meta/job-meta.js +15 -18
  79. package/lib-esm/components/job-meta/job-meta.stories.js +10 -12
  80. package/lib-esm/components/job-name/job-name.js +9 -12
  81. package/lib-esm/components/job-name/job-name.stories.js +15 -23
  82. package/lib-esm/components/jobs-header/jobs-header.js +12 -12
  83. package/lib-esm/components/jobs-header/jobs-header.stories.js +80 -86
  84. package/lib-esm/components/lighthouse-table/lighthouse-table.js +6 -4
  85. package/lib-esm/components/lighthouse-table/lighthouse-table.stories.js +10 -14
  86. package/lib-esm/components/metric/metric.js +15 -19
  87. package/lib-esm/components/metric/metric.stories.js +36 -58
  88. package/lib-esm/components/metrics-table/metrics-table.js +128 -139
  89. package/lib-esm/components/metrics-table/metrics-table.stories.js +27 -35
  90. package/lib-esm/components/metrics-table-options/metrics-table-options.js +16 -19
  91. package/lib-esm/components/metrics-table-options/metrics-table-options.stories.js +6 -12
  92. package/lib-esm/components/metrics-table-search/metrics-table-search.js +17 -18
  93. package/lib-esm/components/metrics-table-search/metrics-table-search.module.css +2 -1
  94. package/lib-esm/components/metrics-table-search/metrics-table-search.stories.js +4 -9
  95. package/lib-esm/components/metrics-table-title/metrics-table-title.js +9 -7
  96. package/lib-esm/components/module-info/module-info.js +15 -13
  97. package/lib-esm/components/module-info/module-info.stories.js +20 -22
  98. package/lib-esm/components/summary/summary.js +25 -27
  99. package/lib-esm/components/summary/summary.stories.js +31 -46
  100. package/lib-esm/components/summary-item/summary-item.js +27 -28
  101. package/lib-esm/components/summary-item/summary-item.stories.js +40 -50
  102. package/lib-esm/components/total-size-type-title/total-size-type-title.js +4 -2
  103. package/lib-esm/constants.js +25 -30
  104. package/lib-esm/hooks/rows-filter.js +20 -0
  105. package/lib-esm/hooks/rows-sort.js +22 -0
  106. package/lib-esm/hooks/search-params.js +170 -0
  107. package/lib-esm/layout/box/box.js +12 -19
  108. package/lib-esm/layout/box/box.stories.js +34 -46
  109. package/lib-esm/layout/flex-stack/flex-stack.js +9 -12
  110. package/lib-esm/layout/flex-stack/flex-stack.stories.js +39 -49
  111. package/lib-esm/layout/footer/footer.js +11 -11
  112. package/lib-esm/layout/footer/footer.stories.js +7 -11
  113. package/lib-esm/layout/header/header.js +10 -14
  114. package/lib-esm/layout/header/header.stories.js +50 -44
  115. package/lib-esm/layout/stack/stack.js +8 -6
  116. package/lib-esm/layout/stack/stack.stories.js +39 -49
  117. package/lib-esm/layout/sub-header/sub-header.js +14 -12
  118. package/lib-esm/layout/sub-header/sub-header.stories.js +57 -69
  119. package/lib-esm/prototypes/typography.stories.js +49 -58
  120. package/lib-esm/query-state.js +13 -16
  121. package/lib-esm/stories/wrapper.js +6 -12
  122. package/lib-esm/ui/alert/alert.js +6 -4
  123. package/lib-esm/ui/alert/alert.stories.js +14 -24
  124. package/lib-esm/ui/container/container.js +6 -9
  125. package/lib-esm/ui/container/container.stories.js +15 -17
  126. package/lib-esm/ui/dropdown/dropdown.js +13 -11
  127. package/lib-esm/ui/dropdown/dropdown.stories.js +22 -26
  128. package/lib-esm/ui/empty-set/empty-set.js +12 -12
  129. package/lib-esm/ui/empty-set/empty-set.stories.js +11 -19
  130. package/lib-esm/ui/file-name/file-name.js +6 -4
  131. package/lib-esm/ui/file-name/file-name.stories.js +12 -16
  132. package/lib-esm/ui/filters/filters.container.js +57 -76
  133. package/lib-esm/ui/filters/filters.js +71 -77
  134. package/lib-esm/ui/filters/filters.stories.js +82 -100
  135. package/lib-esm/ui/filters/filters.utils.js +26 -24
  136. package/lib-esm/ui/filters/index.js +1 -1
  137. package/lib-esm/ui/horizontal-bar-chart/horizontal-bar-chart.js +68 -78
  138. package/lib-esm/ui/horizontal-bar-chart/horizontal-bar-chart.stories.js +67 -77
  139. package/lib-esm/ui/icon/icon.js +13 -202
  140. package/lib-esm/ui/icon/icon.stories.js +16 -24
  141. package/lib-esm/ui/input/input.js +7 -10
  142. package/lib-esm/ui/input/input.stories.js +8 -12
  143. package/lib-esm/ui/loader/loader.js +6 -9
  144. package/lib-esm/ui/loader/loader.stories.js +5 -9
  145. package/lib-esm/ui/logo/logo.constants.js +6 -6
  146. package/lib-esm/ui/logo/logo.js +15 -15
  147. package/lib-esm/ui/logo/logo.stories.js +14 -22
  148. package/lib-esm/ui/panels/panels.js +13 -23
  149. package/lib-esm/ui/panels/panels.stories.js +14 -16
  150. package/lib-esm/ui/popover/popover.js +11 -9
  151. package/lib-esm/ui/popover/popover.stories.js +7 -11
  152. package/lib-esm/ui/skeleton/skeleton.js +6 -9
  153. package/lib-esm/ui/skeleton/skeleton.stories.js +2 -4
  154. package/lib-esm/ui/sort-dropdown/sort-dropdown.js +38 -38
  155. package/lib-esm/ui/sort-dropdown/sort-dropdown.stories.js +14 -16
  156. package/lib-esm/ui/table/table.js +26 -31
  157. package/lib-esm/ui/table/table.stories.js +84 -102
  158. package/lib-esm/ui/tabs/tabs.js +13 -21
  159. package/lib-esm/ui/tabs/tabs.stories.js +4 -6
  160. package/lib-esm/ui/toolbar/toolbar.js +7 -5
  161. package/lib-esm/ui/toolbar/toolbar.stories.js +14 -16
  162. package/lib-esm/ui/tooltip/tooltip.js +13 -16
  163. package/lib-esm/ui/tooltip/tooltip.stories.js +8 -12
  164. package/lib-esm/utils.js +20 -24
  165. package/package.json +25 -33
  166. package/src/assets/icons/arrow.svg +1 -0
  167. package/src/assets/icons/cancel.svg +1 -0
  168. package/src/assets/icons/clock.svg +1 -0
  169. package/src/assets/icons/close.svg +1 -0
  170. package/src/assets/icons/commit.svg +1 -0
  171. package/src/assets/icons/filter.svg +1 -0
  172. package/src/assets/icons/help.svg +1 -0
  173. package/src/assets/icons/menu.svg +1 -0
  174. package/src/{ui/icon/assets → assets/icons}/sort.svg +0 -0
  175. package/src/assets/icons/warning.svg +1 -0
  176. package/src/assets/icons.svg +1 -0
  177. package/src/components/bundle-assets/bundle-assets.jsx +3 -3
  178. package/src/components/bundle-assets/bundle-assets.utils.js +96 -17
  179. package/src/components/bundle-assets/index.jsx +89 -0
  180. package/src/components/bundle-modules/bundle-modules.jsx +3 -3
  181. package/src/components/bundle-modules/bundle-modules.utils.js +101 -0
  182. package/src/components/bundle-modules/index.jsx +107 -0
  183. package/src/components/bundle-packages/bundle-packages.jsx +3 -3
  184. package/src/components/bundle-packages/bundle-packages.utils.js +47 -0
  185. package/src/components/bundle-packages/index.jsx +84 -0
  186. package/src/components/metrics-table/metrics-table.jsx +2 -7
  187. package/src/components/metrics-table-search/metrics-table-search.jsx +1 -0
  188. package/src/components/metrics-table-search/metrics-table-search.module.css +2 -1
  189. package/src/hooks/rows-filter.js +16 -0
  190. package/src/hooks/rows-sort.js +24 -0
  191. package/src/hooks/search-params.js +153 -0
  192. package/src/ui/icon/icon.jsx +7 -42
  193. package/src/ui/sort-dropdown/sort-dropdown.jsx +11 -11
  194. package/src/utils.jsx +5 -3
  195. package/lib/components/bundle-assets/bundle-assets.container.js +0 -140
  196. package/lib/components/bundle-modules/bundle-modules.container.js +0 -222
  197. package/lib/hocs/with-custom-sort.js +0 -75
  198. package/lib/hocs/with-filtered-items.js +0 -54
  199. package/lib/ui/icon/assets/arrow.svg +0 -4
  200. package/lib/ui/icon/assets/branch.svg +0 -3
  201. package/lib/ui/icon/assets/cancel.svg +0 -4
  202. package/lib/ui/icon/assets/clock.svg +0 -3
  203. package/lib/ui/icon/assets/close.svg +0 -4
  204. package/lib/ui/icon/assets/commit.svg +0 -3
  205. package/lib/ui/icon/assets/filter.svg +0 -4
  206. package/lib/ui/icon/assets/help.svg +0 -4
  207. package/lib/ui/icon/assets/job.svg +0 -3
  208. package/lib/ui/icon/assets/menu.svg +0 -4
  209. package/lib/ui/icon/assets/package.svg +0 -3
  210. package/lib/ui/icon/assets/pull-request.svg +0 -3
  211. package/lib/ui/icon/assets/repository.svg +0 -3
  212. package/lib/ui/icon/assets/warning.svg +0 -4
  213. package/lib-esm/components/bundle-assets/bundle-assets.container.js +0 -119
  214. package/lib-esm/components/bundle-modules/bundle-modules.container.js +0 -175
  215. package/lib-esm/components/bundle-packages/bundle-packages.container.js +0 -91
  216. package/lib-esm/hocs/with-custom-sort.js +0 -43
  217. package/lib-esm/hocs/with-filtered-items.js +0 -35
  218. package/lib-esm/hocs/with-search.js +0 -214
  219. package/lib-esm/ui/icon/assets/arrow.svg +0 -4
  220. package/lib-esm/ui/icon/assets/branch.svg +0 -3
  221. package/lib-esm/ui/icon/assets/cancel.svg +0 -4
  222. package/lib-esm/ui/icon/assets/clock.svg +0 -3
  223. package/lib-esm/ui/icon/assets/close.svg +0 -4
  224. package/lib-esm/ui/icon/assets/commit.svg +0 -3
  225. package/lib-esm/ui/icon/assets/filter.svg +0 -4
  226. package/lib-esm/ui/icon/assets/help.svg +0 -4
  227. package/lib-esm/ui/icon/assets/job.svg +0 -3
  228. package/lib-esm/ui/icon/assets/menu.svg +0 -4
  229. package/lib-esm/ui/icon/assets/package.svg +0 -3
  230. package/lib-esm/ui/icon/assets/pull-request.svg +0 -3
  231. package/lib-esm/ui/icon/assets/repository.svg +0 -3
  232. package/lib-esm/ui/icon/assets/warning.svg +0 -4
  233. package/src/components/bundle-assets/bundle-assets.container.js +0 -146
  234. package/src/components/bundle-assets/index.js +0 -4
  235. package/src/components/bundle-modules/bundle-modules.container.js +0 -158
  236. package/src/components/bundle-modules/index.js +0 -4
  237. package/src/components/bundle-packages/bundle-packages.container.js +0 -93
  238. package/src/components/bundle-packages/index.js +0 -4
  239. package/src/hocs/with-custom-sort.jsx +0 -35
  240. package/src/hocs/with-filtered-items.jsx +0 -34
  241. package/src/hocs/with-search.jsx +0 -184
  242. package/src/ui/icon/assets/arrow.svg +0 -4
  243. package/src/ui/icon/assets/branch.svg +0 -3
  244. package/src/ui/icon/assets/cancel.svg +0 -4
  245. package/src/ui/icon/assets/clock.svg +0 -3
  246. package/src/ui/icon/assets/close.svg +0 -4
  247. package/src/ui/icon/assets/commit.svg +0 -3
  248. package/src/ui/icon/assets/filter.svg +0 -4
  249. package/src/ui/icon/assets/help.svg +0 -4
  250. package/src/ui/icon/assets/job.svg +0 -3
  251. package/src/ui/icon/assets/menu.svg +0 -4
  252. package/src/ui/icon/assets/package.svg +0 -3
  253. package/src/ui/icon/assets/pull-request.svg +0 -3
  254. package/src/ui/icon/assets/repository.svg +0 -3
  255. package/src/ui/icon/assets/warning.svg +0 -4
@@ -1,25 +1,22 @@
1
- var _excluded = ["className", "title", "children", "as", "containerRef", "darkMode"];
2
-
3
1
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
2
 
5
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
-
7
3
  import React from 'react';
8
4
  import PropTypes from 'prop-types';
9
5
  import cx from 'classnames';
10
6
  import { Tooltip as UITooltip, TooltipArrow as UITooltipArrow, TooltipReference as UITooltipReference, useTooltipState } from 'reakit/Tooltip';
11
7
  import css from './tooltip.module.css';
12
- export var Tooltip = function Tooltip(props) {
13
- var className = props.className,
14
- title = props.title,
15
- children = props.children,
16
- Component = props.as,
17
- ref = props.containerRef,
18
- darkMode = props.darkMode,
19
- restProps = _objectWithoutPropertiesLoose(props, _excluded);
20
-
21
- var rootClassName = cx(css.root, className);
22
- var tooltipProps = useTooltipState({
8
+ export const Tooltip = props => {
9
+ const {
10
+ className,
11
+ title,
12
+ children,
13
+ as: Component,
14
+ containerRef: ref,
15
+ darkMode,
16
+ ...restProps
17
+ } = props;
18
+ const rootClassName = cx(css.root, className);
19
+ const tooltipProps = useTooltipState({
23
20
  baseId: process.env.NODE_ENV === 'test' && 'id-test',
24
21
  placement: 'top'
25
22
  });
@@ -27,7 +24,7 @@ export var Tooltip = function Tooltip(props) {
27
24
  as: Component,
28
25
  className: rootClassName
29
26
  }, ref ? {
30
- ref: ref
27
+ ref
31
28
  } : {}, restProps, tooltipProps), children), title && /*#__PURE__*/React.createElement(UITooltip, _extends({}, tooltipProps, {
32
29
  className: cx(css.tooltip, darkMode && css.tooltipDarkMode)
33
30
  }), /*#__PURE__*/React.createElement(UITooltipArrow, _extends({}, tooltipProps, {
@@ -2,18 +2,14 @@ import React from 'react';
2
2
  import { storiesOf } from '@storybook/react';
3
3
  import { getWrapperDecorator } from '../../stories';
4
4
  import { Tooltip } from '.';
5
- var stories = storiesOf('UI/Tooltip', module);
5
+ const stories = storiesOf('UI/Tooltip', module);
6
6
  stories.addDecorator(getWrapperDecorator({
7
7
  padding: '64px'
8
8
  }));
9
- stories.add('default', function () {
10
- return /*#__PURE__*/React.createElement(Tooltip, {
11
- title: "View job #100"
12
- }, "Job #100");
13
- });
14
- stories.add('darkMode:false', function () {
15
- return /*#__PURE__*/React.createElement(Tooltip, {
16
- title: "View job #100",
17
- darkMode: false
18
- }, "Job #100");
19
- });
9
+ stories.add('default', () => /*#__PURE__*/React.createElement(Tooltip, {
10
+ title: "View job #100"
11
+ }, "Job #100"));
12
+ stories.add('darkMode:false', () => /*#__PURE__*/React.createElement(Tooltip, {
13
+ title: "View job #100",
14
+ darkMode: false
15
+ }, "Job #100"));
package/lib-esm/utils.js CHANGED
@@ -1,22 +1,15 @@
1
1
  import _chunk from "lodash/chunk";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
-
7
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
2
  import React from 'react';
10
3
  import cx from 'classnames';
11
4
  import COLORS from './chart-colors.json';
12
- export var getColors = function getColors(count) {
5
+ export const getColors = function (count) {
13
6
  if (count === void 0) {
14
7
  count = 2;
15
8
  }
16
9
 
17
- var chunks = _chunk(COLORS, Math.round(COLORS.length / count));
10
+ const chunks = _chunk(COLORS, Math.round(COLORS.length / count));
18
11
 
19
- return chunks.map(function (chunkColors, index) {
12
+ return chunks.map((chunkColors, index) => {
20
13
  if (index === 0) {
21
14
  return chunkColors[0];
22
15
  }
@@ -28,20 +21,23 @@ export var getColors = function getColors(count) {
28
21
  return chunkColors[Math.floor(chunkColors.length / 2)];
29
22
  });
30
23
  };
31
- export var getRenderChildWithClassName = function getRenderChildWithClassName(className) {
32
- return function (child) {
33
- if (child === null || child === '') {
34
- return null;
35
- }
24
+ export const getRenderChildWithClassName = className => child => {
25
+ if (child === null || child === '') {
26
+ return null;
27
+ }
36
28
 
37
- if (!(child != null && child.props)) {
38
- return /*#__PURE__*/React.createElement("div", {
39
- className: className
40
- }, child);
41
- }
29
+ const {
30
+ props
31
+ } = child;
32
+
33
+ if (!props) {
34
+ return /*#__PURE__*/React.createElement("div", {
35
+ className: className
36
+ }, child);
37
+ }
42
38
 
43
- return /*#__PURE__*/React.cloneElement(child, _objectSpread(_objectSpread({}, child.props), {}, {
44
- className: cx(className, child.props.className)
45
- }));
46
- };
39
+ return /*#__PURE__*/React.cloneElement(child, { ...props,
40
+ className: cx(className, props.className) // eslint-disable-line react/prop-types
41
+
42
+ });
47
43
  };
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@bundle-stats/ui",
3
- "version": "3.2.0-beta.1",
3
+ "version": "3.2.1-beta.3",
4
4
  "description": "UI components for BundleStats projects.",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
7
7
  "scripts": {
8
8
  "build": "npm run build-lib && npm run build-esm",
9
- "build-lib": "rm -fr ./lib && babel -D src -d lib --ignore **/__tests__/** --ignore /prototypes/** --presets=@babel/preset-env,@babel/preset-react",
10
- "build-esm": "rm -fr ./lib-esm && babel -D src -d lib-esm --ignore **/__tests__/** --ignore /prototypes/**",
9
+ "prebuild-lib": "rimraf ./lib",
10
+ "build-lib": "babel -D src -d lib --ignore **/__tests__/**/* --ignore /prototypes/** --presets=@babel/preset-env,@babel/preset-react",
11
+ "prebuild-esm": "rimraf ./lib-esm",
12
+ "build-esm": "babel -D src -d lib-esm --ignore **/__tests__/**/* --ignore /prototypes/**",
11
13
  "build-storybook": "npx build-storybook -c ./build/storybook",
12
14
  "generate-chart-colors": "node scripts/generate-chart-colors.js",
15
+ "generate-svg-sprite": "npx svg-sprite -s --si src/assets/icons/*.svg && mv symbol/svg/sprite.symbol.svg src/assets/icons.svg",
13
16
  "lint": "../../node_modules/.bin/eslint . --ext .jsx,.js",
14
17
  "start": "cross-env NODE_ENV=development start-storybook -c ./build/storybook -p 8080",
15
18
  "test": "npm run test:unit && npm run test:storyshots",
@@ -33,65 +36,54 @@
33
36
  },
34
37
  "homepage": "https://github.com/relative-ci/bundle-stats/blob/master/packages/ui#readme",
35
38
  "devDependencies": {
36
- "@babel/cli": "7.15.4",
37
- "@babel/core": "7.15.5",
38
- "@babel/plugin-proposal-class-properties": "7.14.5",
39
- "@babel/plugin-proposal-object-rest-spread": "7.15.6",
40
- "@babel/plugin-proposal-private-methods": "7.14.5",
41
- "@babel/preset-env": "7.15.6",
42
- "@babel/preset-react": "7.14.5",
39
+ "@babel/cli": "7.16.0",
40
+ "@babel/core": "7.16.0",
41
+ "@babel/preset-env": "7.16.4",
42
+ "@babel/preset-react": "7.16.0",
43
43
  "@simplyianm/babel-plugin-inline-react-svg": "1.2.0",
44
44
  "@storybook/addon-knobs": "6.3.1",
45
- "@storybook/addon-storyshots": "6.2.9",
46
- "@storybook/addons": "6.2.9",
47
- "@storybook/react": "6.2.9",
45
+ "@storybook/addon-storyshots": "6.3.12",
46
+ "@storybook/addons": "6.3.12",
47
+ "@storybook/react": "6.3.12",
48
48
  "babel-core": "7.0.0-bridge.0",
49
- "babel-jest": "26.6.3",
50
- "babel-loader": "8.2.2",
49
+ "babel-jest": "27.3.1",
51
50
  "babel-plugin-lodash": "3.3.4",
52
51
  "babel-plugin-require-context-hook": "1.0.0",
53
- "chromatic": "5.9.2",
52
+ "chromatic": "6.0.6",
54
53
  "classnames": "2.3.1",
55
54
  "colormap": "2.3.2",
56
- "core-js": "3.15.2",
55
+ "core-js": "3.19.1",
57
56
  "cross-env": "7.0.3",
58
- "css-loader": "5.2.6",
59
57
  "enzyme": "3.11.0",
60
58
  "enzyme-adapter-react-16": "1.15.6",
61
59
  "enzyme-to-json": "3.6.2",
62
60
  "hex-rgb": "5.0.0",
63
61
  "identity-obj-proxy": "3.0.0",
64
- "jest": "26.6.3",
62
+ "jest": "27.3.1",
65
63
  "jest-date-mock": "1.0.8",
66
64
  "lodash": "4.17.21",
67
- "markdown-loader-jest": "0.1.1",
68
65
  "prop-types": "15.7.2",
69
66
  "react": "16.14.0",
70
67
  "react-dom": "16.14.0",
71
68
  "react-router-dom": "5.3.0",
72
69
  "react-test-renderer": "16.14.0",
73
- "recompose": "0.30.0",
74
- "stats-webpack-plugin": "0.7.0",
75
- "style-loader": "2.0.0",
76
- "webpack": "4.46.0",
77
- "webpack-cli": "4.8.0"
70
+ "rimraf": "3.0.2"
78
71
  },
79
72
  "peerDependencies": {
80
73
  "classnames": "^2.2.6",
81
- "core-js": "^3.9.1",
82
- "lodash": "^4.17.11",
74
+ "core-js": "^3.16.2",
75
+ "lodash": "^4.17.21",
83
76
  "prop-types": "^15.7.2",
84
- "react": "^16.8.5",
85
- "react-dom": "^16.8.5",
86
- "react-router-dom": "^5.2.0",
87
- "recompose": "^0.30.0"
77
+ "react": "^16.14.0",
78
+ "react-dom": "^16.14.0",
79
+ "react-router-dom": "^5.3.0"
88
80
  },
89
81
  "dependencies": {
90
- "@bundle-stats/utils": "^3.2.0-beta.1",
82
+ "@bundle-stats/utils": "^3.2.1-beta.3",
91
83
  "date-fns": "^2.6.0",
92
84
  "query-string": "^7.0.0",
93
85
  "reakit": "^1.3.6",
94
86
  "use-query-params": "^1.2.2"
95
87
  },
96
- "gitHead": "c62576ef368adeddbc6a862005d5ccd99bac9be0"
88
+ "gitHead": "dc8af1ca0a607ef6443ceaa9311b2c0ae1e0037b"
97
89
  }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-down"><line x1="12" y1="5" x2="12" y2="19"></line><polyline points="19 12 12 19 5 12"></polyline></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x-circle"><circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-clock"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-git-commit"><circle cx="12" cy="12" r="4"></circle><line x1="1.05" y1="12" x2="7" y2="12"></line><line x1="17.01" y1="12" x2="22.96" y2="12"></line></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-bar-chart" transform="rotate(-90deg)"><line x1="12" y1="20" x2="12" y2="10"></line><line x1="18" y1="20" x2="18" y2="4"></line><line x1="6" y1="20" x2="6" y2="16"></line></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-help-circle"><circle cx="12" cy="12" r="10"></circle><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path><line x1="12" y1="17" x2="12.01" y2="17"></line></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>
File without changes
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-alert-triangle"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line></svg>
@@ -0,0 +1 @@
1
+ <svg width="16" height="16"><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="afeather afeather-arrow-down" id="arrow" xmlns="http://www.w3.org/2000/svg"><path d="M12 5v14M19 12l-7 7-7-7"/></symbol><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="bfeather bfeather-x-circle" id="cancel" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M15 9l-6 6M9 9l6 6"/></symbol><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="cfeather cfeather-clock" id="clock" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></symbol><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="dfeather dfeather-x" id="close" xmlns="http://www.w3.org/2000/svg"><path d="M18 6L6 18M6 6l12 12"/></symbol><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="efeather efeather-git-commit" id="commit" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="4"/><path d="M1.05 12H7M17.01 12h5.95"/></symbol><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="ffeather ffeather-bar-chart" id="filter" xmlns="http://www.w3.org/2000/svg"><path d="M12 20V10M18 20V4M6 20v-4"/></symbol><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="gfeather gfeather-help-circle" id="help" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 015.83 1c0 2-3 3-3 3M12 17h.01"/></symbol><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="hfeather hfeather-menu" id="menu" xmlns="http://www.w3.org/2000/svg"><path d="M3 12h18M3 6h18M3 18h18"/></symbol><symbol viewBox="0 0 24 24" fill="currentColor" id="sort" xmlns="http://www.w3.org/2000/svg"><path d="M3 18h6v-2H3v2zM3 6v2h18V6H3zm0 7h12v-2H3v2z"/><path d="M0 0h24v24H0z" fill="none"/></symbol><symbol viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="jfeather jfeather-alert-triangle" id="warning" xmlns="http://www.w3.org/2000/svg"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0zM12 9v4M12 17h.01"/></symbol></svg>
@@ -124,7 +124,7 @@ export const BundleAssets = (props) => {
124
124
  totalRowCount,
125
125
  filters,
126
126
  hasActiveFilters,
127
- sortItems,
127
+ sortFields,
128
128
  sort,
129
129
  updateSort,
130
130
  search,
@@ -154,7 +154,7 @@ export const BundleAssets = (props) => {
154
154
  className={css.toolbar}
155
155
  renderActions={({ actionClassName }) => (
156
156
  <FlexStack space="xsmall" className={cx(css.dropdown, actionClassName)}>
157
- <SortDropdown items={sortItems} {...sort} onChange={updateSort} />
157
+ <SortDropdown fields={sortFields} {...sort} onChange={updateSort} />
158
158
  <MetricsTableOptions
159
159
  handleViewAll={resetAllFilters}
160
160
  handleResetFilters={resetFilters}
@@ -267,7 +267,7 @@ BundleAssets.propTypes = {
267
267
  changed: PropTypes.bool,
268
268
  }).isRequired,
269
269
  hasActiveFilters: PropTypes.bool,
270
- sortItems: PropTypes.shape({
270
+ sortFields: PropTypes.shape({
271
271
  [PropTypes.string]: PropTypes.shape({
272
272
  label: PropTypes.string,
273
273
  defaultDirection: PropTypes.bool,
@@ -1,17 +1,96 @@
1
- /**
2
- * Get a list of all chunkIds across assets and runs
3
- *
4
- * @param {Array<Object>} items
5
- * @return {Array<string|number>}
6
- */
7
- export const getAllChunkIds = (items) =>
8
- items.reduce((agg, item) => {
9
- const itemChunkIds = item.runs.map((run) => run?.chunkId).filter((chunkId) => typeof(chunkId) !== 'undefined');
10
-
11
- return itemChunkIds.reduce((itemAgg, chunkId) => {
12
- if (itemAgg.includes(chunkId)) {
13
- return itemAgg;
14
- }
15
- return [...itemAgg, chunkId];
16
- }, agg);
17
- }, []);
1
+ import { get } from 'lodash';
2
+ import { ASSET_ENTRY_TYPE, ASSET_FILE_TYPE, ASSET_FILTERS, getFileType } from '@bundle-stats/utils';
3
+
4
+ import { SORT_BY_NAME, SORT_BY_DELTA, SORT_BY_SIZE } from './bundle-assets.constants';
5
+
6
+ export const addRowAssetFlags = (row) => {
7
+ const { runs } = row;
8
+
9
+ const isEntry = runs.map((run) => run?.isEntry).includes(true);
10
+ const isInitial = runs.map((run) => run?.isInitial).includes(true);
11
+ const isChunk = runs.map((run) => run?.isChunk).includes(true);
12
+
13
+ const isAsset = !(isEntry || isInitial || isChunk);
14
+
15
+ return {
16
+ ...row,
17
+ isEntry,
18
+ isInitial,
19
+ isChunk,
20
+ isAsset,
21
+ };
22
+ };
23
+
24
+ export const getIsNotPredictive = (key, runs) =>
25
+ runs.reduce((agg, current, index) => {
26
+ if (agg) {
27
+ return agg;
28
+ }
29
+
30
+ if (index + 1 === runs.length) {
31
+ return agg;
32
+ }
33
+
34
+ if (
35
+ current &&
36
+ runs[index + 1] &&
37
+ current.delta !== 0 &&
38
+ key !== current.name &&
39
+ current.name === runs[index + 1].name
40
+ ) {
41
+ return true;
42
+ }
43
+
44
+ return agg;
45
+ }, false);
46
+
47
+ export const addRowIsNotPredictive = (row) => ({
48
+ ...row,
49
+ isNotPredictive: getIsNotPredictive(row.key, row.runs),
50
+ });
51
+
52
+ export const getRowFilter = (filters) => (item) => {
53
+ if (filters[ASSET_FILTERS.CHANGED] && !item.changed) {
54
+ return false;
55
+ }
56
+
57
+ if (
58
+ !(
59
+ (filters[`${ASSET_ENTRY_TYPE}.${ASSET_FILTERS.ENTRY}`] && item.isEntry) ||
60
+ (filters[`${ASSET_ENTRY_TYPE}.${ASSET_FILTERS.INITIAL}`] && item.isInitial) ||
61
+ (filters[`${ASSET_ENTRY_TYPE}.${ASSET_FILTERS.CHUNK}`] && item.isChunk) ||
62
+ (filters[`${ASSET_ENTRY_TYPE}.${ASSET_FILTERS.ASSET}`] && item.isAsset)
63
+ )
64
+ ) {
65
+ return false;
66
+ }
67
+
68
+ if (!filters[`${ASSET_FILE_TYPE}.${getFileType(item.key)}`]) {
69
+ return false;
70
+ }
71
+
72
+ return true;
73
+ };
74
+
75
+ export const getCustomSort = (sortId) => (item) => {
76
+ if (sortId === SORT_BY_NAME) {
77
+ return item.key;
78
+ }
79
+
80
+ if (sortId === SORT_BY_DELTA) {
81
+ return get(item, 'runs[0].deltaPercentage', 0);
82
+ }
83
+
84
+ if (sortId === SORT_BY_SIZE) {
85
+ return get(item, 'runs[0].value', 0);
86
+ }
87
+
88
+ return [
89
+ !item.isNotPredictive,
90
+ !item.changed,
91
+ !item.isInitial,
92
+ !item.isEntry,
93
+ !item.isChunk,
94
+ item.key,
95
+ ];
96
+ };
@@ -0,0 +1,89 @@
1
+ import React, { useMemo } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import * as webpack from '@bundle-stats/utils/lib-esm/webpack';
4
+ import { ASSET_FILTERS } from '@bundle-stats/utils';
5
+ import {
6
+ getAssetEntryTypeFilters,
7
+ getAssetFileTypeFilters,
8
+ } from '@bundle-stats/utils/lib-esm/utils/component-links';
9
+
10
+ import { useRowsFilter } from '../../hooks/rows-filter';
11
+ import { useRowsSort } from '../../hooks/rows-sort';
12
+ import { useSearchParams } from '../../hooks/search-params';
13
+ import { BundleAssets as BundleAssetsComponent } from './bundle-assets';
14
+ import { addRowAssetFlags, addRowIsNotPredictive, getRowFilter, getCustomSort } from './bundle-assets.utils';
15
+ import { SORT_BY } from './bundle-assets.constants';
16
+
17
+ export const BundleAssets = (props) => {
18
+ const { jobs, filters, search, setState, sortBy, direction, ...restProps } = props;
19
+
20
+ const { defaultFilters, allEntriesFilters } = useMemo(
21
+ () => ({
22
+ defaultFilters: {
23
+ [ASSET_FILTERS.CHANGED]: jobs?.length > 1,
24
+ ...getAssetEntryTypeFilters(true),
25
+ ...getAssetFileTypeFilters(true),
26
+ },
27
+ allEntriesFilters: {
28
+ [ASSET_FILTERS.CHANGED]: false,
29
+ ...getAssetEntryTypeFilters(true),
30
+ ...getAssetFileTypeFilters(true),
31
+ },
32
+ }),
33
+ [jobs],
34
+ );
35
+
36
+ const searchParams = useSearchParams({
37
+ search,
38
+ filters,
39
+ defaultFilters,
40
+ allEntriesFilters,
41
+ setState,
42
+ });
43
+
44
+ const { rows, totalRowCount } = useMemo(() => {
45
+ const result = webpack.compareBySection.assets(jobs, [addRowAssetFlags, addRowIsNotPredictive]);
46
+ return { rows: result, totalRowCount: result.length };
47
+ }, [jobs]);
48
+
49
+ const filteredRows = useRowsFilter({
50
+ rows,
51
+ searchPattern: searchParams.searchPattern,
52
+ filters: searchParams.filters,
53
+ getRowFilter,
54
+ });
55
+
56
+ const sortParams = useRowsSort({
57
+ rows: filteredRows,
58
+ sortFields: SORT_BY,
59
+ sortBy,
60
+ sortDirection: direction,
61
+ getCustomSort,
62
+ });
63
+
64
+ return (
65
+ <BundleAssetsComponent
66
+ jobs={jobs}
67
+ {...restProps}
68
+ {...searchParams}
69
+ {...sortParams}
70
+ totalRowCount={totalRowCount}
71
+ />
72
+ );
73
+ };
74
+
75
+ BundleAssets.propTypes = {
76
+ jobs: PropTypes.arrayOf(PropTypes.object).isRequired, // eslint-disable-line react/forbid-prop-types
77
+ filters: PropTypes.object, // eslint-disable-line react/forbid-prop-types
78
+ search: PropTypes.string,
79
+ sortBy: PropTypes.string,
80
+ direction: PropTypes.string,
81
+ setState: PropTypes.func.isRequired,
82
+ };
83
+
84
+ BundleAssets.defaultProps = {
85
+ filters: undefined,
86
+ search: undefined,
87
+ sortBy: undefined,
88
+ direction: undefined,
89
+ };
@@ -90,7 +90,7 @@ export const BundleModules = ({
90
90
  resetFilters,
91
91
  resetAllFilters,
92
92
  filters,
93
- sortItems,
93
+ sortFields,
94
94
  sort,
95
95
  updateSort,
96
96
  search,
@@ -173,7 +173,7 @@ export const BundleModules = ({
173
173
  <FlexStack space="xxsmall" className={cx(css.dropdown, actionClassName)}>
174
174
  <SortDropdown
175
175
  className={css.tableDropdown}
176
- items={sortItems}
176
+ fields={sortFields}
177
177
  onChange={updateSort}
178
178
  {...sort}
179
179
  />
@@ -262,7 +262,7 @@ BundleModules.propTypes = {
262
262
 
263
263
  hasActiveFilters: PropTypes.bool,
264
264
 
265
- sortItems: PropTypes.shape({
265
+ sortFields: PropTypes.shape({
266
266
  [PropTypes.string]: PropTypes.shape({
267
267
  label: PropTypes.string,
268
268
  defaultDirection: PropTypes.bool,
@@ -0,0 +1,101 @@
1
+ import { useMemo } from 'react';
2
+ import { get, intersection, merge } from 'lodash';
3
+ import { MODULE_PATH_PACKAGES } from '@bundle-stats/utils/lib-esm/webpack';
4
+ import {
5
+ MODULE_CHUNK,
6
+ MODULE_FILTERS,
7
+ MODULE_FILE_TYPE,
8
+ MODULE_SOURCE_TYPE,
9
+ getModuleSourceFileType,
10
+ } from '@bundle-stats/utils';
11
+
12
+ import { SORT_BY_NAME, SORT_BY_SIZE, SORT_BY_DELTA } from './bundle-modules.constants';
13
+
14
+ export const addRowSourceFlag = (row) => {
15
+ const { key } = row;
16
+ const thirdParty = Boolean(key.match(MODULE_PATH_PACKAGES));
17
+ return { ...row, thirdParty };
18
+ };
19
+
20
+ export const getCustomSort = (sortBy) => (item) => {
21
+ if (sortBy === SORT_BY_NAME) {
22
+ return item.key;
23
+ }
24
+
25
+ if (sortBy === SORT_BY_SIZE) {
26
+ return get(item, 'runs[0].value', 0);
27
+ }
28
+
29
+ if (sortBy === SORT_BY_DELTA) {
30
+ return get(item, 'runs[0].deltaPercentage', 0);
31
+ }
32
+
33
+ return [!item.changed, item.key];
34
+ };
35
+
36
+ export const getRowFilter = (filters) => (row) => {
37
+ // Skip not changed rows
38
+ if (filters[MODULE_FILTERS.CHANGED] && !row.changed) {
39
+ return false;
40
+ }
41
+
42
+ // Skip not matching source type
43
+ if (
44
+ !(
45
+ (filters[`${MODULE_SOURCE_TYPE}.${MODULE_FILTERS.FIRST_PARTY}`] && row.thirdParty === false) ||
46
+ (filters[`${MODULE_SOURCE_TYPE}.${MODULE_FILTERS.THIRD_PARTY}`] && row.thirdParty === true)
47
+ )
48
+ ) {
49
+ return false;
50
+ }
51
+
52
+ // Skip not matching source file types
53
+ const fileType = getModuleSourceFileType(row.key);
54
+ if (!filters[`${MODULE_FILE_TYPE}.${fileType}`]) {
55
+ return false;
56
+ }
57
+
58
+ return true;
59
+ };
60
+
61
+ export const useModuleFilterByChunk = ({ jobs, filters, chunkIds }) => {
62
+ const filteredJobs = useMemo(() => {
63
+ // List of chunkIds with filter value set to `true`
64
+ const includedChunkIds = chunkIds.reduce((agg, chunkId) => {
65
+ if (get(filters, `${MODULE_CHUNK}.${chunkId}`)) {
66
+ return [...agg, chunkId];
67
+ }
68
+
69
+ return agg;
70
+ }, []);
71
+
72
+ // If all the filters are included, return jobs as they are
73
+ if (includedChunkIds.length === chunkIds.length) {
74
+ return jobs;
75
+ }
76
+
77
+ const jobsWithFilteredData = jobs.map((job) => {
78
+ const { modules } = job?.metrics?.webpack || {};
79
+
80
+ const filteredModules = Object.entries(modules).reduce((agg, [moduleId, moduleEntry]) => {
81
+ const match = intersection(moduleEntry.chunkIds, includedChunkIds);
82
+
83
+ if (match.length > 0) {
84
+ agg[moduleId] = moduleEntry; // eslint-disable-line no-param-reassign
85
+ }
86
+
87
+ return agg;
88
+ }, {});
89
+
90
+ // Copy job data into a new object to prevent mutations of the original data
91
+ const newJob = merge({}, job);
92
+ newJob.metrics.webpack.modules = filteredModules;
93
+
94
+ return newJob;
95
+ });
96
+
97
+ return jobsWithFilteredData;
98
+ }, [jobs, filters, chunkIds]);
99
+
100
+ return filteredJobs;
101
+ };