@bundle-stats/ui 4.16.0 → 4.17.0-beta.0

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 (90) hide show
  1. package/lib/components/asset-info/asset-info.js +4 -4
  2. package/lib/components/asset-info/asset-info.js.map +1 -1
  3. package/lib/components/asset-meta-tag/asset-meta-tag.js +17 -0
  4. package/lib/components/asset-meta-tag/asset-meta-tag.js.map +1 -0
  5. package/lib/components/asset-meta-tag/asset-meta-tag.module.css +55 -0
  6. package/lib/components/asset-meta-tag/index.js +18 -0
  7. package/lib/components/asset-meta-tag/index.js.map +1 -0
  8. package/lib/components/asset-name/asset-name.js +32 -0
  9. package/lib/components/asset-name/asset-name.js.map +1 -0
  10. package/lib/components/asset-name/asset-name.module.css +32 -0
  11. package/lib/components/asset-name/index.js +18 -0
  12. package/lib/components/asset-name/index.js.map +1 -0
  13. package/lib/components/asset-not-predictive/asset-not-predictive.js +4 -2
  14. package/lib/components/asset-not-predictive/asset-not-predictive.js.map +1 -1
  15. package/lib/components/bundle-assets/bundle-assets.js +3 -38
  16. package/lib/components/bundle-assets/bundle-assets.js.map +1 -1
  17. package/lib/components/bundle-assets/bundle-assets.module.css +0 -64
  18. package/lib/components/bundle-assets/bundle-assets.utils.js +56 -28
  19. package/lib/components/bundle-assets/bundle-assets.utils.js.map +1 -1
  20. package/lib/components/bundle-assets/index.js +1 -1
  21. package/lib/components/bundle-assets/index.js.map +1 -1
  22. package/lib/components/entry-info/entry-info.js +1 -1
  23. package/lib/components/entry-info/entry-info.js.map +1 -1
  24. package/lib/components/metrics-treemap/metrics-treemap.utils.js +0 -1
  25. package/lib/components/metrics-treemap/metrics-treemap.utils.js.map +1 -1
  26. package/lib/stories/wrapper.js +5 -2
  27. package/lib/stories/wrapper.js.map +1 -1
  28. package/lib/ui/tag/tag.js.map +1 -1
  29. package/lib-esm/components/asset-info/asset-info.js +4 -4
  30. package/lib-esm/components/asset-info/asset-info.js.map +1 -1
  31. package/lib-esm/components/asset-meta-tag/asset-meta-tag.js +10 -0
  32. package/lib-esm/components/asset-meta-tag/asset-meta-tag.js.map +1 -0
  33. package/lib-esm/components/asset-meta-tag/asset-meta-tag.module.css +55 -0
  34. package/lib-esm/components/asset-meta-tag/index.js +2 -0
  35. package/lib-esm/components/asset-meta-tag/index.js.map +1 -0
  36. package/lib-esm/components/asset-name/asset-name.js +25 -0
  37. package/lib-esm/components/asset-name/asset-name.js.map +1 -0
  38. package/lib-esm/components/asset-name/asset-name.module.css +32 -0
  39. package/lib-esm/components/asset-name/index.js +2 -0
  40. package/lib-esm/components/asset-name/index.js.map +1 -0
  41. package/lib-esm/components/asset-not-predictive/asset-not-predictive.js +4 -2
  42. package/lib-esm/components/asset-not-predictive/asset-not-predictive.js.map +1 -1
  43. package/lib-esm/components/bundle-assets/bundle-assets.js +3 -38
  44. package/lib-esm/components/bundle-assets/bundle-assets.js.map +1 -1
  45. package/lib-esm/components/bundle-assets/bundle-assets.module.css +0 -64
  46. package/lib-esm/components/bundle-assets/bundle-assets.utils.js +52 -24
  47. package/lib-esm/components/bundle-assets/bundle-assets.utils.js.map +1 -1
  48. package/lib-esm/components/bundle-assets/index.js +2 -2
  49. package/lib-esm/components/bundle-assets/index.js.map +1 -1
  50. package/lib-esm/components/entry-info/entry-info.js +1 -1
  51. package/lib-esm/components/entry-info/entry-info.js.map +1 -1
  52. package/lib-esm/components/metrics-treemap/metrics-treemap.utils.js +0 -1
  53. package/lib-esm/components/metrics-treemap/metrics-treemap.utils.js.map +1 -1
  54. package/lib-esm/stories/wrapper.js +5 -2
  55. package/lib-esm/stories/wrapper.js.map +1 -1
  56. package/lib-esm/ui/tag/tag.js.map +1 -1
  57. package/package.json +11 -11
  58. package/src/app/app-gladys.stories.tsx +41 -0
  59. package/src/app/app-home-assistant.stories.tsx +41 -0
  60. package/src/app/app-outline.stories.tsx +41 -0
  61. package/src/app/app.stories.tsx +127 -0
  62. package/src/components/asset-info/asset-info.tsx +14 -7
  63. package/src/components/asset-meta-tag/asset-meta-tag.module.css +55 -0
  64. package/src/components/asset-meta-tag/asset-meta-tag.tsx +34 -0
  65. package/src/components/asset-meta-tag/index.ts +1 -0
  66. package/src/components/asset-name/asset-name.module.css +32 -0
  67. package/src/components/asset-name/asset-name.stories.tsx +85 -0
  68. package/src/components/asset-name/asset-name.tsx +60 -0
  69. package/src/components/asset-name/index.ts +1 -0
  70. package/src/components/asset-not-predictive/asset-not-predictive.tsx +10 -8
  71. package/src/components/bundle-assets/__tests__/add-metric-report-asset-row-data.ts +181 -0
  72. package/src/components/bundle-assets/__tests__/get-asset-meta-status.ts +21 -0
  73. package/src/components/bundle-assets/__tests__/get-is-not-predictive.ts +119 -0
  74. package/src/components/bundle-assets/bundle-assets.jsx +15 -84
  75. package/src/components/bundle-assets/bundle-assets.module.css +0 -64
  76. package/src/components/bundle-assets/bundle-assets.utils.js +87 -26
  77. package/src/components/bundle-assets/index.jsx +2 -7
  78. package/src/components/entry-info/entry-info.tsx +1 -6
  79. package/src/components/metrics-treemap/metrics-treemap.utils.ts +0 -1
  80. package/src/stories/wrapper.jsx +21 -15
  81. package/src/types.d.ts +30 -1
  82. package/src/ui/tag/tag.tsx +4 -3
  83. package/types/components/asset-meta-tag/asset-meta-tag.d.ts +8 -0
  84. package/types/components/asset-meta-tag/index.d.ts +1 -0
  85. package/types/components/asset-name/asset-name.d.ts +8 -0
  86. package/types/components/asset-name/index.d.ts +1 -0
  87. package/types/components/asset-not-predictive/asset-not-predictive.d.ts +4 -4
  88. package/types/components/bundle-assets/bundle-assets.utils.d.ts +3 -3
  89. package/types/stories/wrapper.d.ts +1 -1
  90. package/types/ui/tag/tag.d.ts +4 -4
@@ -3,70 +3,6 @@
3
3
  max-width: 240px;
4
4
  }
5
5
 
6
- .assetNameWrapper {
7
- }
8
-
9
- .assetName {}
10
-
11
- .notPredictive {
12
- margin-right: var(--space-xxsmall);
13
- display: inline-block;
14
- width: var(--space-small);
15
- height: var(--space-small);
16
- }
17
-
18
- .notPredictiveAnchor {}
19
-
20
- .notPredictiveIcon {
21
- color: var(--color-warning-dark);
22
- }
23
-
24
- .assetNameTags {
25
- display: inline;
26
- margin-right: var(--space-xxxsmall);
27
- }
28
-
29
- .assetNameTags:empty {
30
- display: none;
31
- }
32
-
33
- .assetNameTag {
34
- vertical-align: middle;
35
- }
36
-
37
- .assetNameTag + .assetNameTag {
38
- margin-left: 2px;
39
- }
40
-
41
- .assetNameTagEntry {
42
- background: var(--color-info-dark);
43
- }
44
-
45
- .assetNameTagEntry::before {
46
- content: 'e';
47
- }
48
-
49
- .assetNameTagInitial {
50
- background: var(--color-info);
51
- }
52
-
53
- .assetNameTagInitial::before {
54
- content: 'i';
55
- }
56
-
57
- .assetNameTagChunk {
58
- background: var(--color-info-light);
59
- }
60
-
61
- .assetNameTagChunk::before {
62
- content: 'c';
63
- }
64
-
65
- .assetNameText {
66
- display: inline-block;
67
- vertical-align: middle;
68
- }
69
-
70
6
  .root .assetName:hover,
71
7
  .root .assetName:active,
72
8
  .root .assetName:focus {
@@ -1,26 +1,21 @@
1
- import { ASSET_ENTRY_TYPE, ASSET_FILE_TYPE, ASSET_FILTERS, getFileType } from '@bundle-stats/utils';
2
-
3
- export const addRowAssetFlags = (row) => {
4
- const { runs } = row;
1
+ /**
2
+ * @type {import('@bundle-stats/utils').ReportMetricRow} ReportMetricRow
3
+ * @type {import('../../types').ReportMetricAssetRow} ReportMetricAssetRow
4
+ * @type {import('../../types').ReportMetricAssetRowMetaStatus} ReportMetricAssetRowFlagStatus
5
+ */
5
6
 
6
- const isEntry = runs.map((run) => run?.isEntry).includes(true);
7
- const isInitial = runs.map((run) => run?.isInitial).includes(true);
8
- const isChunk = runs.map((run) => run?.isChunk).includes(true);
9
- const isAsset = !(isEntry || isInitial || isChunk);
10
- const fileType = getFileType(row.key);
7
+ import { ASSET_ENTRY_TYPE, ASSET_FILE_TYPE, ASSET_FILTERS, getFileType } from '@bundle-stats/utils';
11
8
 
12
- return {
13
- ...row,
14
- isEntry,
15
- isInitial,
16
- isChunk,
17
- isAsset,
18
- fileType,
19
- };
20
- };
9
+ /**
10
+ * Check if the asset cache is not predictive
11
+ *
12
+ * @param {ReportMetricRow} row
13
+ * @returns {boolean}
14
+ */
15
+ export const getIsNotPredictive = (row) => {
16
+ const { key, runs } = row;
21
17
 
22
- export const getIsNotPredictive = (key, runs) =>
23
- runs.reduce((agg, current, index) => {
18
+ return runs.reduce((agg, current, index) => {
24
19
  if (agg) {
25
20
  return agg;
26
21
  }
@@ -32,20 +27,86 @@ export const getIsNotPredictive = (key, runs) =>
32
27
  if (
33
28
  current &&
34
29
  runs[index + 1] &&
35
- current.delta !== 0 &&
36
30
  key !== current.name &&
37
- current.name === runs[index + 1].name
31
+ current.name === runs[index + 1].name &&
32
+ current.value !== runs[index + 1].value
38
33
  ) {
39
34
  return true;
40
35
  }
41
36
 
42
37
  return agg;
43
38
  }, false);
39
+ };
40
+
41
+ /**
42
+ * @param {Array<boolean>}
43
+ * @returns {ReportMetricAssetRowFlagStatus | boolean}
44
+ */
45
+ export const getAssetMetaStatus = (values) => {
46
+ if (!values.includes(true)) {
47
+ return false;
48
+ }
49
+
50
+ // filter empty runs
51
+ const metaValues = values.filter((value) => typeof value !== 'undefined');
52
+
53
+ const current = metaValues[0];
54
+ const metaValuesLength = metaValues.length;
55
+
56
+ if (metaValuesLength === 1) {
57
+ return Boolean(current);
58
+ }
59
+
60
+ const baseline = metaValues[metaValuesLength - 1];
44
61
 
45
- export const addRowIsNotPredictive = (row) => ({
46
- ...row,
47
- isNotPredictive: getIsNotPredictive(row.key, row.runs),
48
- });
62
+ if (current && !baseline) {
63
+ return 'added';
64
+ }
65
+
66
+ if (!current && baseline) {
67
+ return 'removed';
68
+ }
69
+
70
+ return true;
71
+ };
72
+
73
+ /**
74
+ * Add asset row flags
75
+ *
76
+ * @param {ReportMetricRow} row
77
+ * @returns {ReportMetricAssetRow}
78
+ */
79
+ export const addMetricReportAssetRowData = (row) => {
80
+ const { runs } = row;
81
+
82
+ // Collect meta for each run
83
+ const runsEntry = [];
84
+ const runsInitial = [];
85
+ const runsChunk = [];
86
+
87
+ runs.forEach((run) => {
88
+ runsEntry.push(run?.isEntry);
89
+ runsInitial.push(run?.isInitial);
90
+ runsChunk.push(run?.isChunk);
91
+ });
92
+
93
+ const isEntry = getAssetMetaStatus(runsEntry);
94
+ const isInitial = getAssetMetaStatus(runsInitial);
95
+ const isChunk = getAssetMetaStatus(runsChunk);
96
+ const isAsset = !(isEntry || isInitial || isChunk);
97
+ const isNotPredictive = getIsNotPredictive(row);
98
+ const fileType = getFileType(row.key);
99
+
100
+ return {
101
+ ...row,
102
+ isEntry,
103
+ isInitial,
104
+ isChunk,
105
+ isAsset,
106
+ isNotPredictive,
107
+ fileType,
108
+ };
109
+ };
49
110
 
50
111
  export const getRowFilter = (filters) => (item) => {
51
112
  if (filters[ASSET_FILTERS.CHANGED] && !item.changed) {
@@ -13,12 +13,7 @@ import { useSearchParams } from '../../hooks/search-params';
13
13
  import { useEntryInfo } from '../../hooks/entry-info';
14
14
  import { getJobsChunksData } from '../../utils/jobs';
15
15
  import { BundleAssets as BundleAssetsComponent } from './bundle-assets';
16
- import {
17
- addRowAssetFlags,
18
- addRowIsNotPredictive,
19
- getRowFilter,
20
- getCustomSort,
21
- } from './bundle-assets.utils';
16
+ import { addMetricReportAssetRowData, getRowFilter, getCustomSort } from './bundle-assets.utils';
22
17
 
23
18
  export const BundleAssets = (props) => {
24
19
  const { jobs, filters, search, setState, sortBy, direction, ...restProps } = props;
@@ -50,7 +45,7 @@ export const BundleAssets = (props) => {
50
45
  });
51
46
 
52
47
  const { rows, totalRowCount } = useMemo(() => {
53
- const result = webpack.compareBySection.assets(jobs, [addRowAssetFlags, addRowIsNotPredictive]);
48
+ const result = webpack.compareBySection.assets(jobs, [addMetricReportAssetRowData]);
54
49
  return { rows: result, totalRowCount: result.length };
55
50
  }, [jobs]);
56
51
 
@@ -145,12 +145,7 @@ export const EntryInfo = (props: EntryInfoProps & React.ComponentProps<'div'>) =
145
145
  </Table.Th>
146
146
  <Table.Td className={cx(css.runsCell, css.runsColName)}>
147
147
  {rowRun?.[runNameSelector] ? (
148
- <FlexStack
149
- space="xxxsmall"
150
- alignItems="center"
151
- as="h3"
152
- className={css.label}
153
- >
148
+ <FlexStack space="xxxsmall" alignItems="center" className={css.label}>
154
149
  <FileName
155
150
  as="code"
156
151
  name={rowRun[runNameSelector]}
@@ -141,7 +141,6 @@ export function getTreemapNodesGroupedByPath(items: Array<ReportMetricRow>): Tre
141
141
  };
142
142
 
143
143
  const childrenTotal = setTreeNode(treeNodes, baseSlugs, 0, treeNode);
144
- console.log(childrenTotal);
145
144
 
146
145
  total.current += childrenTotal.current;
147
146
  total.baseline =
@@ -1,19 +1,25 @@
1
1
  import React from 'react';
2
2
  import { MemoryRouter } from 'react-router-dom';
3
3
 
4
- export const getWrapperDecorator = (customWrapperStyles = {}) => (storyFn) => {
5
- const wrapperStyles = {
6
- width: '100%',
7
- height: '100%',
8
- padding: '24px',
9
- ...customWrapperStyles,
10
- };
4
+ import { QueryStateProvider } from '../query-state';
5
+
6
+ export const getWrapperDecorator =
7
+ (customWrapperStyles = {}) =>
8
+ (Story) => {
9
+ const wrapperStyles = {
10
+ width: '100%',
11
+ height: '100%',
12
+ padding: '24px',
13
+ ...customWrapperStyles,
14
+ };
11
15
 
12
- return (
13
- <MemoryRouter initialEntries={[{ pathname: '/', key: 'home' }]}>
14
- <div style={wrapperStyles}>
15
- {storyFn()}
16
- </div>
17
- </MemoryRouter>
18
- );
19
- };
16
+ return (
17
+ <MemoryRouter initialEntries={[{ pathname: '/', key: 'home' }]}>
18
+ <QueryStateProvider>
19
+ <div style={wrapperStyles}>
20
+ <Story />
21
+ </div>
22
+ </QueryStateProvider>
23
+ </MemoryRouter>
24
+ );
25
+ };
package/src/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ReportMetricRow } from '@bundle-stats/utils';
2
- import type { Module } from '@bundle-stats/utils/types/webpack/types';
2
+ import type { Asset, Module } from '@bundle-stats/utils/types/webpack/types';
3
3
 
4
4
  export interface SortAction {
5
5
  field: string;
@@ -19,6 +19,35 @@ type FilterGroupFieldData = {
19
19
 
20
20
  type FilterFieldsData = Record<string, FilterFieldData | FilterGroupFieldData>;
21
21
 
22
+ export type ReportMetricAssetRowMetaStatus = 'added' | 'removed';
23
+
24
+ export type ReportMetricAssetRow = {
25
+ /**
26
+ * Asset isEntry - at least one run has isEntry truthy
27
+ */
28
+ isEntry: ReportMetricAssetRowMetaStatus | boolean;
29
+ /**
30
+ * Asset isInitial - at least one run has isInitial truthy
31
+ */
32
+ isInitial: ReportMetricAssetRowMetaStatus | boolean;
33
+ /**
34
+ * Asset isChunk - at least one run has isChunk truthy
35
+ */
36
+ isChunk: ReportMetricAssetRowMetaStatus | boolean;
37
+ /**
38
+ * Asset isAsset - at least one run has isAsset truthy
39
+ */
40
+ isAsset: boolean;
41
+ /**
42
+ * Asset name is not predictive
43
+ */
44
+ isNotPredictive: boolean;
45
+ /**
46
+ * Report asset row isEntry - at least one run has isEntry
47
+ */
48
+ fileType: string;
49
+ } & Omit<ReportMetricRow, 'runs'> & { runs: Array<(Asset & ReportMetricRun) | null> };
50
+
22
51
  export type ReportMetricModuleRow = {
23
52
  thirdParty: boolean;
24
53
  duplicated: boolean;
@@ -1,16 +1,17 @@
1
+ import type { ComponentProps } from 'react';
1
2
  import React from 'react';
2
3
  import cx from 'classnames';
3
4
 
4
5
  import { KIND, SIZE } from '../../tokens';
5
6
  import css from './tag.module.css';
6
7
 
7
- interface TagProps {
8
+ export type TagProps = {
8
9
  as?: React.ElementType;
9
10
  kind?: (typeof KIND)[keyof typeof KIND];
10
11
  size?: (typeof SIZE)[keyof typeof SIZE];
11
- }
12
+ } & ComponentProps<'span'>;
12
13
 
13
- export const Tag = (props: TagProps & React.ComponentProps<'span'>) => {
14
+ export const Tag = (props: TagProps) => {
14
15
  const {
15
16
  className = '',
16
17
  as: Component = 'span',
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { TagProps } from '../../ui/tag';
3
+ import type { ReportMetricAssetRowMetaStatus } from '../../types';
4
+ export type AssetMetaTagProps = {
5
+ tag: 'entry' | 'initial' | 'chunk';
6
+ status: ReportMetricAssetRowMetaStatus | boolean;
7
+ } & TagProps;
8
+ export declare const AssetMetaTag: (props: AssetMetaTagProps) => React.JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './asset-meta-tag';
@@ -0,0 +1,8 @@
1
+ import React, { ElementType } from 'react';
2
+ import { ReportMetricAssetRow } from '../../types';
3
+ export type AssetNameProps = {
4
+ className?: string;
5
+ row: ReportMetricAssetRow;
6
+ customComponentLink: ElementType;
7
+ };
8
+ export declare const AssetName: (props: AssetNameProps) => React.JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './asset-name';
@@ -1,8 +1,8 @@
1
+ import type { ComponentProps } from 'react';
1
2
  import React from 'react';
2
3
  import type { Asset } from '@bundle-stats/utils/types/webpack';
3
- interface AssetNotPredictiveProps {
4
+ export type AssetNotPredictiveProps = {
4
5
  runs?: Array<Asset>;
5
6
  labels?: Array<string>;
6
- }
7
- export declare const AssetNotPredictive: (props: AssetNotPredictiveProps & React.ComponentProps<"div">) => React.JSX.Element;
8
- export {};
7
+ } & ComponentProps<'div'>;
8
+ export declare const AssetNotPredictive: (props: AssetNotPredictiveProps) => React.JSX.Element;
@@ -1,5 +1,5 @@
1
- export function addRowAssetFlags(row: any): any;
2
- export function getIsNotPredictive(key: any, runs: any): any;
3
- export function addRowIsNotPredictive(row: any): any;
1
+ export function getIsNotPredictive(row: ReportMetricRow): boolean;
2
+ export function getAssetMetaStatus(values: any): ReportMetricAssetRowFlagStatus | boolean;
3
+ export function addMetricReportAssetRowData(row: ReportMetricRow): ReportMetricAssetRow;
4
4
  export function getRowFilter(filters: any): (item: any) => boolean;
5
5
  export function getCustomSort(item: any): any[];
@@ -1,2 +1,2 @@
1
- export function getWrapperDecorator(customWrapperStyles?: {}): (storyFn: any) => React.JSX.Element;
1
+ export function getWrapperDecorator(customWrapperStyles?: {}): (Story: any) => React.JSX.Element;
2
2
  import React from 'react';
@@ -1,12 +1,13 @@
1
+ import type { ComponentProps } from 'react';
1
2
  import React from 'react';
2
3
  import { KIND, SIZE } from '../../tokens';
3
- interface TagProps {
4
+ export type TagProps = {
4
5
  as?: React.ElementType;
5
6
  kind?: (typeof KIND)[keyof typeof KIND];
6
7
  size?: (typeof SIZE)[keyof typeof SIZE];
7
- }
8
+ } & ComponentProps<'span'>;
8
9
  export declare const Tag: {
9
- (props: TagProps & React.ComponentProps<"span">): React.JSX.Element;
10
+ (props: TagProps): React.JSX.Element;
10
11
  KINDS: {
11
12
  readonly DEFAULT: "default";
12
13
  readonly SUCCESS: "success";
@@ -20,4 +21,3 @@ export declare const Tag: {
20
21
  readonly LARGE: "large";
21
22
  };
22
23
  };
23
- export {};