@bundle-stats/ui 4.2.0-beta.1 → 4.3.0-beta.1

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 (73) hide show
  1. package/lib/components/bundle-assets/bundle-assets.module.css +1 -1
  2. package/lib/components/bundle-assets/bundle-assets.utils.js +1 -1
  3. package/lib/components/bundle-assets/bundle-assets.utils.js.map +1 -1
  4. package/lib/components/bundle-modules/bundle-modules.js +2 -1
  5. package/lib/components/bundle-modules/bundle-modules.js.map +1 -1
  6. package/lib/components/bundle-modules/bundle-modules.module.css +0 -4
  7. package/lib/components/bundle-modules/bundle-modules.utils.js +1 -1
  8. package/lib/components/bundle-modules/bundle-modules.utils.js.map +1 -1
  9. package/lib/components/bundle-modules/index.js +8 -2
  10. package/lib/components/bundle-modules/index.js.map +1 -1
  11. package/lib/components/bundle-packages/bundle-packages.utils.js +1 -1
  12. package/lib/components/bundle-packages/bundle-packages.utils.js.map +1 -1
  13. package/lib/components/metrics-table/index.js +19 -3
  14. package/lib/components/metrics-table/index.js.map +1 -1
  15. package/lib/components/metrics-table/metrics-table.js +13 -3
  16. package/lib/components/metrics-table/metrics-table.js.map +1 -1
  17. package/lib/components/metrics-table/metrics-table.module.css +27 -0
  18. package/lib/components/module-info/module-info.js +16 -24
  19. package/lib/components/module-info/module-info.js.map +1 -1
  20. package/lib/components/module-info/module-info.module.css +8 -27
  21. package/lib/components/summary-item/summary-item.js +1 -1
  22. package/lib/components/summary-item/summary-item.js.map +1 -1
  23. package/lib/components/summary-item/summary-item.module.css +5 -0
  24. package/lib/css/variables.css +2 -2
  25. package/lib/hooks/search-params.js +11 -2
  26. package/lib/hooks/search-params.js.map +1 -1
  27. package/lib-esm/components/bundle-assets/bundle-assets.module.css +1 -1
  28. package/lib-esm/components/bundle-assets/bundle-assets.utils.js +1 -1
  29. package/lib-esm/components/bundle-assets/bundle-assets.utils.js.map +1 -1
  30. package/lib-esm/components/bundle-modules/bundle-modules.js +2 -1
  31. package/lib-esm/components/bundle-modules/bundle-modules.js.map +1 -1
  32. package/lib-esm/components/bundle-modules/bundle-modules.module.css +0 -4
  33. package/lib-esm/components/bundle-modules/bundle-modules.utils.js +1 -1
  34. package/lib-esm/components/bundle-modules/bundle-modules.utils.js.map +1 -1
  35. package/lib-esm/components/bundle-modules/index.js +8 -2
  36. package/lib-esm/components/bundle-modules/index.js.map +1 -1
  37. package/lib-esm/components/bundle-packages/bundle-packages.utils.js +1 -1
  38. package/lib-esm/components/bundle-packages/bundle-packages.utils.js.map +1 -1
  39. package/lib-esm/components/metrics-table/index.js +6 -1
  40. package/lib-esm/components/metrics-table/index.js.map +1 -1
  41. package/lib-esm/components/metrics-table/metrics-table.js +13 -3
  42. package/lib-esm/components/metrics-table/metrics-table.js.map +1 -1
  43. package/lib-esm/components/metrics-table/metrics-table.module.css +27 -0
  44. package/lib-esm/components/module-info/module-info.js +17 -25
  45. package/lib-esm/components/module-info/module-info.js.map +1 -1
  46. package/lib-esm/components/module-info/module-info.module.css +8 -27
  47. package/lib-esm/components/summary-item/summary-item.js +1 -1
  48. package/lib-esm/components/summary-item/summary-item.js.map +1 -1
  49. package/lib-esm/components/summary-item/summary-item.module.css +5 -0
  50. package/lib-esm/css/variables.css +2 -2
  51. package/lib-esm/hooks/search-params.js +12 -3
  52. package/lib-esm/hooks/search-params.js.map +1 -1
  53. package/package.json +17 -17
  54. package/src/components/bundle-assets/bundle-assets.module.css +1 -1
  55. package/src/components/bundle-assets/bundle-assets.utils.js +1 -1
  56. package/src/components/bundle-modules/bundle-modules.jsx +9 -11
  57. package/src/components/bundle-modules/bundle-modules.module.css +0 -4
  58. package/src/components/bundle-modules/bundle-modules.utils.js +1 -1
  59. package/src/components/bundle-modules/index.jsx +15 -2
  60. package/src/components/bundle-packages/bundle-packages.utils.js +1 -1
  61. package/src/components/metrics-table/index.jsx +11 -0
  62. package/src/components/metrics-table/metrics-table.jsx +42 -5
  63. package/src/components/metrics-table/metrics-table.module.css +27 -0
  64. package/src/components/module-info/module-info.jsx +25 -55
  65. package/src/components/module-info/module-info.module.css +8 -27
  66. package/src/components/summary-item/summary-item.jsx +1 -1
  67. package/src/components/summary-item/summary-item.module.css +5 -0
  68. package/src/css/variables.css +2 -2
  69. package/src/hooks/search-params.js +23 -11
  70. package/tsconfig.json +3 -0
  71. package/types/components/metrics-table/index.d.ts +1 -1
  72. package/types/components/metrics-table/metrics-table.d.ts +3 -1
  73. package/src/components/metrics-table/index.js +0 -1
@@ -107,17 +107,15 @@ const RowHeader = ({ row, chunks, labels, CustomComponentLink }) => {
107
107
  }
108
108
 
109
109
  return (
110
- <HoverCard label={content} hoverCardClassName={css.nameHoverCard}>
111
- {({ close }) => (
112
- <ModuleInfo
113
- item={row}
114
- chunks={chunks}
115
- chunkIds={chunkIds}
116
- labels={labels}
117
- customComponentLink={CustomComponentLink}
118
- onClick={close}
119
- />
120
- )}
110
+ <HoverCard label={content}>
111
+ <ModuleInfo
112
+ className={css.namePopover}
113
+ item={row}
114
+ chunks={chunks}
115
+ chunkIds={chunkIds}
116
+ labels={labels}
117
+ customComponentLink={CustomComponentLink}
118
+ />
121
119
  </HoverCard>
122
120
  );
123
121
  };
@@ -25,7 +25,3 @@
25
25
  display: inline;
26
26
  vertical-align: middle;
27
27
  }
28
-
29
- .nameHoverCard {
30
- max-width: 480px;
31
- }
@@ -35,7 +35,7 @@ export const getCustomSort = (sortBy) => (item) => {
35
35
  }
36
36
 
37
37
  if (sortBy === SORT_BY_DELTA) {
38
- return item?.runs?.[0]?.deltaPercentage || 0;
38
+ return item?.runs?.[0]?.delta ? Math.abs(item.runs[0].delta) : 0;
39
39
  }
40
40
 
41
41
  return [!item.changed, item.key];
@@ -24,8 +24,21 @@ import { SORT_BY } from './bundle-modules.constants';
24
24
  export const BundleModules = (props) => {
25
25
  const { jobs, filters, search, setState, sortBy, direction, ...restProps } = props;
26
26
 
27
- const chunks = uniqBy(jobs.map((job) => job?.meta?.webpack?.chunks || []).flat(), ({ id }) => id);
28
- const chunkIds = chunks?.map(({ id }) => id);
27
+ const { chunks, chunkIds } = useMemo(
28
+ () => {
29
+ const bundleChunks = uniqBy(
30
+ jobs.map((job) => job?.meta?.webpack?.chunks || []).flat(),
31
+ ({ id }) => id
32
+ );
33
+ const bundleChunkIds = bundleChunks?.map(({ id }) => id);
34
+
35
+ return {
36
+ chunks: bundleChunks,
37
+ chunkIds: bundleChunkIds,
38
+ };
39
+ },
40
+ [jobs],
41
+ );
29
42
 
30
43
  const { defaultFilters, allEntriesFilters } = useMemo(
31
44
  () => ({
@@ -31,7 +31,7 @@ export const getCustomSort = (sortId) => (item) => {
31
31
  }
32
32
 
33
33
  if (sortId === SORT_BY_DELTA) {
34
- return item?.runs?.[0]?.deltaPercentage || 0;
34
+ return item?.runs?.[0]?.delta ? Math.abs(item.runs[0].delta) : 0;
35
35
  }
36
36
 
37
37
  if (sortId === SORT_BY_SIZE) {
@@ -0,0 +1,11 @@
1
+ import React, { useState } from 'react';
2
+
3
+ import { MetricsTable as BaseComponent } from './metrics-table';
4
+
5
+ export const MetricsTable = (props) => {
6
+ const [showAllItems, setShowAllItems] = useState(false);
7
+
8
+ return (
9
+ <BaseComponent {...props} showAllItems={showAllItems} setShowAllItems={setShowAllItems} />
10
+ );
11
+ };
@@ -12,6 +12,7 @@ import { JobName } from '../job-name';
12
12
  import styles from './metrics-table.module.css';
13
13
 
14
14
  const METRIC_TYPE_DATA = getGlobalMetricType(null, METRIC_TYPE_FILE_SIZE);
15
+ const VISIBLE_COUNT = 500;
15
16
 
16
17
  const getRowsRunTotal = (rows, runIndex) => sum(rows.map((row) => row?.runs?.[runIndex]?.value || 0));
17
18
 
@@ -164,6 +165,8 @@ export const MetricsTable = ({
164
165
  showHeaderSum,
165
166
  headerRows,
166
167
  title,
168
+ showAllItems,
169
+ setShowAllItems,
167
170
  ...restProps
168
171
  }) => {
169
172
  const { headers, columnClassNames } = useMemo(() => {
@@ -183,6 +186,11 @@ export const MetricsTable = ({
183
186
  showHeaderSum && styles.showHeaderSum,
184
187
  );
185
188
 
189
+ const showEmpty = isEmpty(items);
190
+ const showItems = !showEmpty;
191
+ const hasHiddenItems = items?.length > VISIBLE_COUNT;
192
+ const visibleItems = !hasHiddenItems || showAllItems ? items : items?.slice(0, VISIBLE_COUNT);
193
+
186
194
  return (
187
195
  <Table className={rootClassName} compact {...restProps}>
188
196
  <Table.THead>
@@ -201,17 +209,46 @@ export const MetricsTable = ({
201
209
  })}
202
210
  </Table.THead>
203
211
  <Table.TBody>
204
- {!isEmpty(items) ? (
205
- items.map((item) => (
206
- <MetricsTableRow key={item.key} item={item} renderRowHeader={renderRowHeader} />
207
- ))
208
- ) : (
212
+ {showEmpty && (
209
213
  <Table.Tr>
210
214
  <Table.Td className={styles.empty} colSpan={columnClassNames?.length || 1}>
211
215
  {emptyMessage}
212
216
  </Table.Td>
213
217
  </Table.Tr>
214
218
  )}
219
+
220
+ {showItems && (
221
+ <>
222
+ {visibleItems.map((item) => (
223
+ <MetricsTableRow key={item.key} item={item} renderRowHeader={renderRowHeader} />
224
+ ))}
225
+
226
+ {hasHiddenItems && (
227
+ <Table.Tr>
228
+ <Table.Td className={styles.showAllItems} colSpan={columnClassNames?.length || 1}>
229
+ {showAllItems ? (
230
+ <button
231
+ onClick={() => setShowAllItems(false)}
232
+ type="button"
233
+ className={styles.showAllItemsButton}
234
+ >
235
+ Show less
236
+ </button>
237
+ ) : (
238
+ <button
239
+ onClick={() => setShowAllItems(true)}
240
+ type="button"
241
+ className={styles.showAllItemsButton}
242
+ >
243
+ Show all
244
+ </button>
245
+ )
246
+ }
247
+ </Table.Td>
248
+ </Table.Tr>
249
+ )}
250
+ </>
251
+ )}
215
252
  </Table.TBody>
216
253
  </Table>
217
254
  );
@@ -15,6 +15,10 @@
15
15
  width: 100%;
16
16
  }
17
17
 
18
+ .tableHeaderRunMetric {
19
+ text-transform: none;
20
+ }
21
+
18
22
  .root .value {
19
23
  padding-left: var(--space-large);
20
24
  text-align: right;
@@ -67,6 +71,29 @@
67
71
  text-align: center;
68
72
  }
69
73
 
74
+ .root .showAllItems {
75
+ background: none !important;
76
+ text-align: center;
77
+ }
78
+
79
+ /** show all */
80
+ .showAllItemsButton {
81
+ appearance: none;
82
+ background: none;
83
+ margin: 0;
84
+ border: 0;
85
+ padding: var(--space-xxxsmall);
86
+ color: var(--color-primary);
87
+ text-decoration: underline;
88
+ cursor: pointer;
89
+ }
90
+
91
+ .showAllItemsButton:hover,
92
+ .showAllItemsButton:focus,
93
+ .showAllItemsButton:active {
94
+ color: var(--color-primary-dark);
95
+ }
96
+
70
97
  /** Breakpoints */
71
98
  .root tr {
72
99
  display: flex;
@@ -1,14 +1,11 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import cx from 'classnames';
4
3
  import isEmpty from 'lodash/isEmpty';
5
4
  import noop from 'lodash/noop';
6
- import { getBundleModulesByChunk, getBundleModulesBySearch } from '@bundle-stats/utils';
5
+ import { getBundleModulesByChunk } from '@bundle-stats/utils';
7
6
 
8
7
  import { Stack } from '../../layout/stack';
9
- import { FlexStack } from '../../layout/flex-stack';
10
8
  import { FileName } from '../../ui/file-name';
11
- import { Tag } from '../../ui/tag';
12
9
  import { ComponentLink } from '../component-link';
13
10
  import css from './module-info.module.css';
14
11
 
@@ -24,34 +21,25 @@ export const ModuleInfo = (props) => {
24
21
  } = props;
25
22
 
26
23
  return (
27
- <Stack space="small" className={cx(css.root, className)}>
28
- {item.runs.map((run, index) => (
29
- <Stack space="xsmall" key={`module-info-${run?.name || index}-${index}`} className={css.run}>
30
- <Stack space="xxxsmall">
31
- <FlexStack space="xxxsmall" alignItems="center" as="h4" className={css.title}>
32
- <span>{labels[index]}</span>
33
- <Tag className={css.titleTag}>{index === 0 ? 'current' : 'baseline'}</Tag>
34
- </FlexStack>
35
- <FileName className={css.fileName} as="code" name={run?.name || '-'} />
36
- </Stack>
24
+ <Stack space="xsmall" className={className}>
25
+ {item.runs.map((run, index) => {
26
+ const TitleComponent = index !== 0 ? 'h4' : 'h3';
27
+ const key = `module-info-${run?.name || index}-${index}`;
37
28
 
38
- {/**
39
- * Render chunks only for the current run
40
- * we do not have the correct chunk ids for baselines
41
- */}
42
- {index === 0 && !isEmpty(run?.chunkIds) && (
43
- <Stack className={css.chunks}>
44
- <h5>Chunks</h5>
45
- <ul className={css.list}>
46
- {run.chunkIds.map((chunkId) => {
47
- const chunk = chunks?.find(({ id }) => id === chunkId);
29
+ return (
30
+ <Stack space="xxxsmall" key={key}>
31
+ <TitleComponent>{labels[index]}</TitleComponent>
32
+ {index === 0 && !isEmpty(run?.chunkIds) && (
33
+ <div className={css.chunks}>
34
+ <span className={css.chunksTitle}>Chunks:</span>
35
+ {run.chunkIds.map((chunkId) => {
36
+ const chunk = chunks?.find(({ id }) => id === chunkId);
48
37
 
49
- if (!chunk) {
50
- return null;
51
- }
38
+ if (!chunk) {
39
+ return null;
40
+ }
52
41
 
53
- return (
54
- <li>
42
+ return (
55
43
  <CustomComponentLink
56
44
  {...getBundleModulesByChunk(chunkIds, chunkId)}
57
45
  onClick={onClick}
@@ -59,33 +47,15 @@ export const ModuleInfo = (props) => {
59
47
  >
60
48
  {chunk.name}
61
49
  </CustomComponentLink>
62
- </li>
63
- );
64
- })}
65
- </ul>
66
- </Stack>
67
- )}
50
+ );
51
+ })}
52
+ </div>
53
+ )}
68
54
 
69
- {run?.reasons && (
70
- <Stack>
71
- <h5>Reasons</h5>
72
- <ul className={css.list}>
73
- {run.reasons.map((reason) => (
74
- <li key={reason}>
75
- <CustomComponentLink
76
- {...getBundleModulesBySearch(`^${reason}$`)}
77
- onClick={onClick}
78
- className={css.reasonLink}
79
- >
80
- <FileName name={reason} className={css.reason} />
81
- </CustomComponentLink>
82
- </li>
83
- ))}
84
- </ul>
85
- </Stack>
86
- )}
87
- </Stack>
88
- ))}
55
+ <FileName className={css.fileName} as="code" name={run?.name || '-'} />
56
+ </Stack>
57
+ );
58
+ })}
89
59
  </Stack>
90
60
  );
91
61
  };
@@ -1,40 +1,21 @@
1
- .titleTag {
2
- border: 1px solid var(--color-outline);
3
- background: var(--color-highlight);
4
- color: var(--color-text-light);
1
+ .chunksTitle {
2
+ margin-right: var(--space-xxxsmall);
5
3
  }
6
4
 
7
- .run:first-child .title {
8
- font-size: var(--size-xlarge);
5
+ .chunksItems {
6
+ display: inline;
9
7
  }
10
8
 
11
9
  .chunksItem {
12
10
  overflow-wrap: break-word;
13
11
  }
14
12
 
13
+ .chunksItem + .chunksItem {
14
+ margin-left: var(--space-xxxsmall);
15
+ }
16
+
15
17
  .fileName {
16
18
  max-width: 100%;
17
19
  padding: 2px;
18
20
  background: var(--color-highlight-warning);
19
21
  }
20
-
21
- .reasonLink {
22
- text-decoration: underline;
23
- }
24
-
25
- .reasonLink .reason {
26
- text-decoration: inherit;
27
- }
28
-
29
- .reason {
30
- display: inline;
31
- }
32
-
33
- .list {
34
- padding: 0 0 0 var(--space-small);
35
- list-style: outside;
36
- }
37
-
38
- .list li::marker {
39
- color: var(--color-text-ultra-light);
40
- }
@@ -63,7 +63,7 @@ export const SummaryItem = ({
63
63
  const rootClassName = cx(css.root, className, css[size], showDelta && css.showDelta);
64
64
 
65
65
  return (
66
- <Stack space="xxxsmall" as={Component} className={rootClassName} {...props}>
66
+ <Stack space="xxsmall" as={Component} className={rootClassName} {...props}>
67
67
  <FlexStack space="xxxsmall" alignItems="center" as="h3" className={css.title}>
68
68
  <span>
69
69
  {metric.label}
@@ -6,6 +6,11 @@
6
6
  white-space: nowrap;
7
7
  }
8
8
 
9
+ .titleIcon {
10
+ margin-top: -4px !important;
11
+ margin-bottom: -4px !important;
12
+ }
13
+
9
14
  .currentMetric {
10
15
  color: var(--color-heading);
11
16
  font-size: var(--size-large);
@@ -23,8 +23,8 @@
23
23
  --size-xxlarge: 1.424rem;
24
24
  --size-xxxlarge: 1.602rem;
25
25
 
26
- --line-height: 1.66em;
27
- --line-height-heading: 1.33em;
26
+ --line-height: 1.66;
27
+ --line-height-heading: 1.33;
28
28
 
29
29
  /*
30
30
  * Color scheme:
@@ -1,4 +1,4 @@
1
- import { useCallback, useLayoutEffect, useReducer } from 'react';
1
+ import { useCallback, useLayoutEffect, useMemo, useReducer } from 'react';
2
2
  import isEqual from 'lodash/isEqual';
3
3
  import merge from 'lodash/merge';
4
4
 
@@ -150,14 +150,26 @@ export const useSearchParams = ({
150
150
  dispatch({ type: ACTION_RESET_ALL });
151
151
  }, [dispatch]);
152
152
 
153
- return {
154
- search,
155
- searchPattern,
156
- filters,
157
- hasActiveFilters: !isEqual(allEntriesFilters, filters),
158
- updateSearch: handleUpdateSearch,
159
- updateFilters: handleUpdateFilters,
160
- resetFilters: handleResetFilters,
161
- resetAllFilters: handleResetAllFilters,
162
- };
153
+ return useMemo(
154
+ () => ({
155
+ search,
156
+ searchPattern,
157
+ filters,
158
+ hasActiveFilters: !isEqual(allEntriesFilters, filters),
159
+ updateSearch: handleUpdateSearch,
160
+ updateFilters: handleUpdateFilters,
161
+ resetFilters: handleResetFilters,
162
+ resetAllFilters: handleResetAllFilters,
163
+ }),
164
+ [
165
+ search,
166
+ searchPattern,
167
+ filters,
168
+ allEntriesFilters,
169
+ handleUpdateSearch,
170
+ handleUpdateFilters,
171
+ handleResetFilters,
172
+ handleResetAllFilters,
173
+ ],
174
+ );
163
175
  };
package/tsconfig.json CHANGED
@@ -1,4 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "include": ["src/**/*"],
4
+ "compilerOptions": {
5
+ "jsx": "react"
6
+ }
4
7
  }
@@ -1 +1 @@
1
- export * from "./metrics-table";
1
+ export function MetricsTable(props: any): JSX.Element;
@@ -1,4 +1,4 @@
1
- export function MetricsTable({ className, renderRowHeader, runs, items, emptyMessage, showHeaderSum, headerRows, title, ...restProps }: {
1
+ export function MetricsTable({ className, renderRowHeader, runs, items, emptyMessage, showHeaderSum, headerRows, title, showAllItems, setShowAllItems, ...restProps }: {
2
2
  [x: string]: any;
3
3
  className: any;
4
4
  renderRowHeader: any;
@@ -8,6 +8,8 @@ export function MetricsTable({ className, renderRowHeader, runs, items, emptyMes
8
8
  showHeaderSum: any;
9
9
  headerRows: any;
10
10
  title: any;
11
+ showAllItems: any;
12
+ setShowAllItems: any;
11
13
  }): JSX.Element;
12
14
  export namespace MetricsTable {
13
15
  namespace defaultProps {
@@ -1 +0,0 @@
1
- export * from './metrics-table';