@bundle-stats/ui 3.3.0-alpha.0 → 3.3.0-alpha.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.
- package/CHANGELOG.md +11 -0
- package/lib/components/budget-info/budget-info.js +37 -10
- package/lib/components/budget-info/budget-info.module.css +25 -13
- package/lib/components/budget-info/budget-info.stories.js +21 -19
- package/lib/components/budget-insights/budget-insights.js +19 -19
- package/lib/components/budget-insights/budget-insights.stories.js +33 -33
- package/lib/components/bundle-assets-totals-table/bundle-assets-totals-table.js +2 -3
- package/lib/components/index.js +8 -0
- package/lib/components/summary/summary.js +1 -1
- package/lib/components/summary/summary.stories.js +12 -12
- package/lib/components/summary-item/summary-item.js +6 -6
- package/lib/components/summary-item/summary-item.stories.js +13 -13
- package/lib-esm/components/budget-info/budget-info.js +31 -10
- package/lib-esm/components/budget-info/budget-info.module.css +25 -13
- package/lib-esm/components/budget-info/budget-info.stories.js +19 -15
- package/lib-esm/components/budget-insights/budget-insights.js +21 -20
- package/lib-esm/components/budget-insights/budget-insights.stories.js +33 -33
- package/lib-esm/components/bundle-assets-totals-table/bundle-assets-totals-table.js +2 -3
- package/lib-esm/components/index.js +1 -0
- package/lib-esm/components/summary/summary.js +1 -1
- package/lib-esm/components/summary/summary.stories.js +12 -12
- package/lib-esm/components/summary-item/summary-item.js +6 -6
- package/lib-esm/components/summary-item/summary-item.stories.js +10 -10
- package/package.json +3 -3
- package/src/components/budget-info/budget-info.jsx +32 -16
- package/src/components/budget-info/budget-info.module.css +25 -13
- package/src/components/budget-insights/budget-insights.jsx +20 -15
- package/src/components/bundle-assets-totals-table/bundle-assets-totals-table.jsx +1 -2
- package/src/components/index.js +1 -0
- package/src/components/summary/summary.jsx +1 -1
- package/src/components/summary-item/summary-item.jsx +5 -5
|
@@ -5,22 +5,26 @@ import { BudgetInfo } from '.';
|
|
|
5
5
|
const stories = storiesOf('Components/BudgetInfo', module);
|
|
6
6
|
stories.addDecorator(getWrapperDecorator());
|
|
7
7
|
stories.add('default', () => /*#__PURE__*/React.createElement(BudgetInfo, {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
metric: {
|
|
14
|
-
formatter: v => v
|
|
8
|
+
metricId: "webpack.assetCount",
|
|
9
|
+
budgetInsight: {
|
|
10
|
+
budgetValue: 300,
|
|
11
|
+
currentValue: 250,
|
|
12
|
+
failed: false
|
|
15
13
|
}
|
|
16
14
|
}));
|
|
17
|
-
stories.add('
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
stories.add('error', () => /*#__PURE__*/React.createElement(BudgetInfo, {
|
|
16
|
+
metricId: "webpack.assetCount",
|
|
17
|
+
budgetInsight: {
|
|
18
|
+
budgetValue: 300,
|
|
19
|
+
currentValue: 350,
|
|
20
|
+
failed: true
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
stories.add('warning', () => /*#__PURE__*/React.createElement(BudgetInfo, {
|
|
24
|
+
metricId: "webpack.assetCount",
|
|
25
|
+
budgetInsight: {
|
|
26
|
+
budgetValue: 300,
|
|
27
|
+
currentValue: 300,
|
|
28
|
+
failed: false
|
|
25
29
|
}
|
|
26
30
|
}));
|
|
@@ -3,7 +3,8 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
3
3
|
import React, { useMemo, useState } from 'react';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import cx from 'classnames';
|
|
6
|
-
import { METRIC_COMPONENT_LINKS
|
|
6
|
+
import { METRIC_COMPONENT_LINKS } from '@bundle-stats/utils';
|
|
7
|
+
import * as budgetsInsightsTransformer from '@bundle-stats/utils/lib-esm/transformers/budgets-insights';
|
|
7
8
|
import { Box } from '../../layout/box';
|
|
8
9
|
import { Stack } from '../../layout/stack';
|
|
9
10
|
import { FlexStack } from '../../layout/flex-stack';
|
|
@@ -15,28 +16,28 @@ import css from './budget-insights.module.css';
|
|
|
15
16
|
const Budget = props => {
|
|
16
17
|
const {
|
|
17
18
|
className,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
budgetValue
|
|
19
|
+
metricId,
|
|
20
|
+
budgetInsight,
|
|
21
|
+
CustomLink
|
|
22
22
|
} = props;
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const componentLinkOptions = METRIC_COMPONENT_LINKS.get(metricId);
|
|
24
|
+
const budgetInsightInfo = budgetsInsightsTransformer.getInfo(metricId, budgetInsight);
|
|
25
|
+
const {
|
|
26
|
+
data: messageData
|
|
27
|
+
} = budgetInsightInfo.message;
|
|
25
28
|
return /*#__PURE__*/React.createElement(CustomLink, _extends({
|
|
26
29
|
className: cx(css.budget, className)
|
|
27
|
-
}, componentLinkOptions == null ? void 0 : componentLinkOptions.link), /*#__PURE__*/React.createElement("
|
|
28
|
-
className: css.budgetLabel
|
|
29
|
-
}, metric.label), ` is ${failed ? 'over' : 'under'} `, /*#__PURE__*/React.createElement("span", {
|
|
30
|
-
className: css.budgetValue
|
|
31
|
-
}, metric.formatter(budgetValue)), ` budget`);
|
|
30
|
+
}, componentLinkOptions == null ? void 0 : componentLinkOptions.link), /*#__PURE__*/React.createElement("strong", null, messageData.metricLabel), ` value (`, /*#__PURE__*/React.createElement("strong", null, messageData.currentValue), `) is ${messageData.diffLabel} `, /*#__PURE__*/React.createElement("strong", null, messageData.budgetValue), ` budget `);
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
Budget.propTypes = {
|
|
35
34
|
className: PropTypes.string,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
metricId: PropTypes.string.isRequired,
|
|
36
|
+
budgetInsight: PropTypes.shape({
|
|
37
|
+
currentValue: PropTypes.number.isRequired,
|
|
38
|
+
budgetValue: PropTypes.number.isRequired,
|
|
39
|
+
failed: PropTypes.bool.isRequired
|
|
40
|
+
}).isRequired,
|
|
40
41
|
CustomLink: PropTypes.elementType.isRequired
|
|
41
42
|
};
|
|
42
43
|
Budget.defaultProps = {
|
|
@@ -78,12 +79,12 @@ const BudgetsGroup = props => {
|
|
|
78
79
|
space: "none"
|
|
79
80
|
}, budgets.map(_ref => {
|
|
80
81
|
let [key, budget] = _ref;
|
|
81
|
-
return /*#__PURE__*/React.createElement(Budget,
|
|
82
|
+
return /*#__PURE__*/React.createElement(Budget, {
|
|
82
83
|
key: key,
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
metricId: `${source}.${key}`,
|
|
85
|
+
budgetInsight: budget,
|
|
85
86
|
CustomLink: CustomLink
|
|
86
|
-
}
|
|
87
|
+
});
|
|
87
88
|
}))));
|
|
88
89
|
};
|
|
89
90
|
|
|
@@ -14,44 +14,44 @@ Default.args = {
|
|
|
14
14
|
source: 'webpack',
|
|
15
15
|
budgets: {
|
|
16
16
|
totalSizeByTypeALL: {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
currentValue: 2097917,
|
|
18
|
+
budgetValue: 2097152,
|
|
19
|
+
failed: true
|
|
20
20
|
},
|
|
21
21
|
totalInitialSizeJS: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
currentValue: 1265645,
|
|
23
|
+
budgetValue: 524288,
|
|
24
|
+
failed: true
|
|
25
25
|
},
|
|
26
26
|
totalInitialSizeCSS: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
currentValue: 48866,
|
|
28
|
+
budgetValue: 51200,
|
|
29
|
+
failed: false
|
|
30
30
|
},
|
|
31
31
|
chunkCount: {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
currentValue: 12,
|
|
33
|
+
budgetValue: 50,
|
|
34
|
+
failed: false
|
|
35
35
|
},
|
|
36
36
|
moduleCount: {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
currentValue: 1059,
|
|
38
|
+
budgetValue: 2000,
|
|
39
|
+
failed: false
|
|
40
40
|
},
|
|
41
41
|
duplicatePackagesCount: {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
currentValue: 13,
|
|
43
|
+
budgetValue: 5,
|
|
44
|
+
failed: true
|
|
45
45
|
},
|
|
46
46
|
'sizes.totalSizeByTypeJS': {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
currentValue: 1981470,
|
|
48
|
+
budgetValue: 2097152,
|
|
49
|
+
failed: false
|
|
50
50
|
},
|
|
51
51
|
'sizes.totalSizeByTypeCSS': {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
currentValue: 56091,
|
|
53
|
+
budgetValue: 20480,
|
|
54
|
+
failed: true
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
};
|
|
@@ -60,14 +60,14 @@ FailedBudgets.args = {
|
|
|
60
60
|
source: 'webpack',
|
|
61
61
|
budgets: {
|
|
62
62
|
totalSizeByTypeALL: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
currentValue: 2097917,
|
|
64
|
+
budgetValue: 2097152,
|
|
65
|
+
failed: true
|
|
66
66
|
},
|
|
67
67
|
totalInitialSizeJS: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
currentValue: 1265645,
|
|
69
|
+
budgetValue: 524288,
|
|
70
|
+
failed: true
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
};
|
|
@@ -76,9 +76,9 @@ SingleBudget.args = {
|
|
|
76
76
|
source: 'webpack',
|
|
77
77
|
budgets: {
|
|
78
78
|
totalInitialSizeJS: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
currentValue: 524288,
|
|
80
|
+
budgetValue: 1265645,
|
|
81
|
+
failed: false
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
};
|
|
@@ -31,7 +31,6 @@ export const BundleAssetsTotalsTable = _ref => {
|
|
|
31
31
|
|
|
32
32
|
const budget = _get(budgets, metricKey);
|
|
33
33
|
|
|
34
|
-
const metric = webpack.getMetricType(metricKey);
|
|
35
34
|
return /*#__PURE__*/React.createElement(CustomComponentLink, {
|
|
36
35
|
section: section,
|
|
37
36
|
title: title,
|
|
@@ -40,8 +39,8 @@ export const BundleAssetsTotalsTable = _ref => {
|
|
|
40
39
|
space: "xxsmall",
|
|
41
40
|
className: css.itemTitleText
|
|
42
41
|
}, /*#__PURE__*/React.createElement("span", null, item.label), budget && /*#__PURE__*/React.createElement(BudgetInfo, {
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
metricId: item.key,
|
|
43
|
+
budgetInsight: budget
|
|
45
44
|
})));
|
|
46
45
|
}, [CustomComponentLink]);
|
|
47
46
|
return /*#__PURE__*/React.createElement(MetricsTable, {
|
|
@@ -4,6 +4,7 @@ export { BundleAssetsTotalsTable } from './bundle-assets-totals-table';
|
|
|
4
4
|
export { BundleAssetsTotalsChartBars } from './bundle-assets-totals-chart-bars';
|
|
5
5
|
export { BundlePackages } from './bundle-packages';
|
|
6
6
|
export { BundleModules } from './bundle-modules';
|
|
7
|
+
export { BudgetInsights } from './budget-insights';
|
|
7
8
|
export { ComponentLink } from './component-link';
|
|
8
9
|
export { DuplicatePackagesWarning } from './duplicate-packages-warning';
|
|
9
10
|
export { Delta } from './delta';
|
|
@@ -44,7 +44,7 @@ export const Summary = _ref => {
|
|
|
44
44
|
size: size,
|
|
45
45
|
id: metricId,
|
|
46
46
|
data: _get(data, metricId),
|
|
47
|
-
budget: _get(budgets,
|
|
47
|
+
budget: _get(budgets, metricId),
|
|
48
48
|
loading: loading,
|
|
49
49
|
showMetricDescription: true,
|
|
50
50
|
showDelta: showSummaryItemDelta && metricOptions.showDelta !== false
|
|
@@ -26,24 +26,24 @@ stories.add('budgets', () => /*#__PURE__*/React.createElement(Summary, {
|
|
|
26
26
|
budgets: {
|
|
27
27
|
webpack: {
|
|
28
28
|
totalSizeByTypeALL: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
currentValue: MULTIPLE_JOBS[0].summary.webpack.totalSizeByTypeALL.current,
|
|
30
|
+
budgetValue: 1024 * 1024,
|
|
31
|
+
failed: false
|
|
32
32
|
},
|
|
33
33
|
totalInitialSizeJS: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
currentValue: MULTIPLE_JOBS[0].summary.webpack.totalInitialSizeJS.current,
|
|
35
|
+
budgetValue: 512 * 1024,
|
|
36
|
+
failed: true
|
|
37
37
|
},
|
|
38
38
|
totalInitialSizeCSS: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
currentValue: MULTIPLE_JOBS[0].summary.webpack.totalInitialSizeCSS.current,
|
|
40
|
+
budgetValue: 50 * 1024,
|
|
41
|
+
failed: false
|
|
42
42
|
},
|
|
43
43
|
chunkCount: {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
currentValue: MULTIPLE_JOBS[0].summary.webpack.chunkCount.current,
|
|
45
|
+
budgetValue: 50,
|
|
46
|
+
failed: false
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -79,8 +79,8 @@ export const SummaryItem = _ref2 => {
|
|
|
79
79
|
icon: "help"
|
|
80
80
|
}, /*#__PURE__*/React.createElement(MetricInfoPopover, metric)), budget && /*#__PURE__*/React.createElement(BudgetInfo, {
|
|
81
81
|
className: css.budgetInfo,
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
metricId: id,
|
|
83
|
+
budgetInsight: budget
|
|
84
84
|
})), !loading ? /*#__PURE__*/React.createElement(Stack, null, /*#__PURE__*/React.createElement(Metric, {
|
|
85
85
|
className: css.currentMetric,
|
|
86
86
|
value: current,
|
|
@@ -137,10 +137,10 @@ SummaryItem.propTypes = {
|
|
|
137
137
|
/** Show delta */
|
|
138
138
|
showDelta: PropTypes.bool,
|
|
139
139
|
|
|
140
|
-
/** Budget data */
|
|
140
|
+
/** Budget insight data */
|
|
141
141
|
budget: PropTypes.shape({
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
currentBalue: PropTypes.number,
|
|
143
|
+
budgetValue: PropTypes.number,
|
|
144
|
+
failed: PropTypes.bool
|
|
145
145
|
})
|
|
146
146
|
};
|
|
@@ -33,22 +33,22 @@ export const ShowDeltaFalse = Template.bind();
|
|
|
33
33
|
ShowDeltaFalse.args = {
|
|
34
34
|
showDelta: false
|
|
35
35
|
};
|
|
36
|
-
export const
|
|
37
|
-
|
|
36
|
+
export const BudgetError = Template.bind();
|
|
37
|
+
BudgetError.args = {
|
|
38
38
|
showMetricDescription: true,
|
|
39
39
|
budget: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
currentValue: 120 * 1000,
|
|
41
|
+
budgetValue: 100 * 1000,
|
|
42
|
+
failed: true
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
export const
|
|
46
|
-
|
|
45
|
+
export const BudgetSuccess = Template.bind();
|
|
46
|
+
BudgetSuccess.args = {
|
|
47
47
|
showMetricDescription: true,
|
|
48
48
|
budget: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
currentValue: 120 * 1000,
|
|
50
|
+
budgetValue: 120 * 1024,
|
|
51
|
+
failed: false
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
export const Loading = Template.bind();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bundle-stats/ui",
|
|
3
|
-
"version": "3.3.0-alpha.
|
|
3
|
+
"version": "3.3.0-alpha.1",
|
|
4
4
|
"description": "UI components for BundleStats projects.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-esm/index.js",
|
|
@@ -84,11 +84,11 @@
|
|
|
84
84
|
"react-router-dom": "^5.3.0"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@bundle-stats/utils": "^3.3.0-alpha.
|
|
87
|
+
"@bundle-stats/utils": "^3.3.0-alpha.1",
|
|
88
88
|
"date-fns": "^2.6.0",
|
|
89
89
|
"query-string": "^7.0.0",
|
|
90
90
|
"reakit": "^1.3.6",
|
|
91
91
|
"use-query-params": "^1.2.2"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "b510975b373ee38b66899a990c7341d1a29a69e2"
|
|
94
94
|
}
|
|
@@ -1,46 +1,62 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import cx from 'classnames';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
+
import { InsightType } from '@bundle-stats/utils';
|
|
5
|
+
import * as budgetsInsightsTransformer from '@bundle-stats/utils/lib-esm/transformers/budgets-insights';
|
|
4
6
|
|
|
5
7
|
import { Icon } from '../../ui/icon';
|
|
6
8
|
import { Tooltip } from '../../ui/tooltip';
|
|
7
9
|
|
|
8
10
|
import css from './budget-info.module.css';
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
const INSIGHT_TYPE_MAP = {
|
|
13
|
+
[InsightType.SUCCESS]: {
|
|
14
|
+
className: css.success,
|
|
15
|
+
glyph: Icon.ICONS.CHECK_CIRCLE,
|
|
16
|
+
},
|
|
17
|
+
[InsightType.ERROR]: {
|
|
18
|
+
className: css.error,
|
|
19
|
+
glyph: Icon.ICONS.ALERT_CIRCLE,
|
|
20
|
+
},
|
|
21
|
+
[InsightType.WARNING]: {
|
|
22
|
+
className: css.warning,
|
|
23
|
+
glyph: Icon.ICONS.WARNING,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const BudgetInfo = ({ className = '', metricId, budgetInsight }) => {
|
|
28
|
+
const budgetInsightInfo = budgetsInsightsTransformer.getInfo(metricId, budgetInsight);
|
|
29
|
+
const { className: insightTypeClassName, glyph } = INSIGHT_TYPE_MAP[budgetInsightInfo.type];
|
|
30
|
+
|
|
31
|
+
const rootClassName = cx(css.root, insightTypeClassName, className);
|
|
32
|
+
const { data: messageData } = budgetInsightInfo.message;
|
|
12
33
|
|
|
13
34
|
return (
|
|
14
35
|
<Tooltip
|
|
15
36
|
className={rootClassName}
|
|
16
37
|
title={
|
|
17
38
|
<>
|
|
18
|
-
<strong>{
|
|
19
|
-
{`
|
|
20
|
-
{
|
|
21
|
-
{`
|
|
39
|
+
<strong>{messageData.metricLabel}</strong>
|
|
40
|
+
{` value (`}
|
|
41
|
+
<strong>{messageData.currentValue}</strong>
|
|
42
|
+
{`) is ${messageData.diffLabel} `}
|
|
43
|
+
<strong>{messageData.budgetValue}</strong>
|
|
44
|
+
{` budget `}
|
|
22
45
|
</>
|
|
23
46
|
}
|
|
24
47
|
>
|
|
25
|
-
<Icon
|
|
26
|
-
className={css.icon}
|
|
27
|
-
glyph={budget.failed ? Icon.ICONS.ALERT_CIRCLE : Icon.ICONS.CHECK_CIRCLE}
|
|
28
|
-
size="medium"
|
|
29
|
-
/>
|
|
48
|
+
<Icon className={css.icon} glyph={glyph} size="medium" />
|
|
30
49
|
</Tooltip>
|
|
31
50
|
);
|
|
32
51
|
};
|
|
33
52
|
|
|
34
53
|
BudgetInfo.propTypes = {
|
|
35
|
-
|
|
54
|
+
metricId: PropTypes.string.isRequired,
|
|
55
|
+
budgetInsight: PropTypes.shape({
|
|
36
56
|
currentValue: PropTypes.number,
|
|
37
57
|
budgetValue: PropTypes.number,
|
|
38
58
|
failed: PropTypes.bool,
|
|
39
59
|
}).isRequired,
|
|
40
|
-
metric: PropTypes.shape({
|
|
41
|
-
label: PropTypes.string,
|
|
42
|
-
formatter: PropTypes.func,
|
|
43
|
-
}).isRequired,
|
|
44
60
|
className: PropTypes.string,
|
|
45
61
|
};
|
|
46
62
|
|
|
@@ -3,26 +3,38 @@
|
|
|
3
3
|
line-height: 1em;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
/* Budget
|
|
7
|
-
.
|
|
8
|
-
color: var(--color-danger
|
|
6
|
+
/* Budget error */
|
|
7
|
+
.error .icon {
|
|
8
|
+
color: var(--color-danger);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
.
|
|
12
|
-
.
|
|
13
|
-
.
|
|
11
|
+
.error .icon:hover,
|
|
12
|
+
.error .icon:focus,
|
|
13
|
+
.error .icon:active
|
|
14
14
|
{
|
|
15
|
-
color: var(--color-danger);
|
|
15
|
+
color: var(--color-danger-light);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/* Budget
|
|
19
|
-
.
|
|
18
|
+
/* Budget success */
|
|
19
|
+
.success .icon {
|
|
20
|
+
color: var(--color-success);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.success .icon:hover,
|
|
24
|
+
.success .icon:focus,
|
|
25
|
+
.success .icon:active
|
|
26
|
+
{
|
|
20
27
|
color: var(--color-success-light);
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
30
|
+
/* Budget warning */
|
|
31
|
+
.warning .icon {
|
|
32
|
+
color: var(--color-warning-dark);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.warning .icon:hover,
|
|
36
|
+
.warning .icon:focus,
|
|
37
|
+
.warning .icon:active
|
|
26
38
|
{
|
|
27
|
-
color: var(--color-
|
|
39
|
+
color: var(--color-warning);
|
|
28
40
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, { useMemo, useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import cx from 'classnames';
|
|
4
|
-
import { METRIC_COMPONENT_LINKS
|
|
4
|
+
import { METRIC_COMPONENT_LINKS } from '@bundle-stats/utils';
|
|
5
|
+
import * as budgetsInsightsTransformer from '@bundle-stats/utils/lib-esm/transformers/budgets-insights';
|
|
5
6
|
|
|
6
7
|
import { Box } from '../../layout/box';
|
|
7
8
|
import { Stack } from '../../layout/stack';
|
|
@@ -12,26 +13,31 @@ import { ComponentLink } from '../component-link';
|
|
|
12
13
|
import css from './budget-insights.module.css';
|
|
13
14
|
|
|
14
15
|
const Budget = (props) => {
|
|
15
|
-
const { className,
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const { className, metricId, budgetInsight, CustomLink } = props;
|
|
17
|
+
const componentLinkOptions = METRIC_COMPONENT_LINKS.get(metricId);
|
|
18
|
+
const budgetInsightInfo = budgetsInsightsTransformer.getInfo(metricId, budgetInsight);
|
|
19
|
+
const { data: messageData } = budgetInsightInfo.message;
|
|
18
20
|
|
|
19
21
|
return (
|
|
20
22
|
<CustomLink className={cx(css.budget, className)} {...componentLinkOptions?.link}>
|
|
21
|
-
<
|
|
22
|
-
{`
|
|
23
|
-
<
|
|
24
|
-
{`
|
|
23
|
+
<strong>{messageData.metricLabel}</strong>
|
|
24
|
+
{` value (`}
|
|
25
|
+
<strong>{messageData.currentValue}</strong>
|
|
26
|
+
{`) is ${messageData.diffLabel} `}
|
|
27
|
+
<strong>{messageData.budgetValue}</strong>
|
|
28
|
+
{` budget `}
|
|
25
29
|
</CustomLink>
|
|
26
30
|
);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
Budget.propTypes = {
|
|
30
34
|
className: PropTypes.string,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
metricId: PropTypes.string.isRequired,
|
|
36
|
+
budgetInsight: PropTypes.shape({
|
|
37
|
+
currentValue: PropTypes.number.isRequired,
|
|
38
|
+
budgetValue: PropTypes.number.isRequired,
|
|
39
|
+
failed: PropTypes.bool.isRequired,
|
|
40
|
+
}).isRequired,
|
|
35
41
|
CustomLink: PropTypes.elementType.isRequired,
|
|
36
42
|
};
|
|
37
43
|
|
|
@@ -73,10 +79,9 @@ const BudgetsGroup = (props) => {
|
|
|
73
79
|
{budgets.map(([key, budget]) => (
|
|
74
80
|
<Budget
|
|
75
81
|
key={key}
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
metricId={`${source}.${key}`}
|
|
83
|
+
budgetInsight={budget}
|
|
78
84
|
CustomLink={CustomLink}
|
|
79
|
-
{...budget}
|
|
80
85
|
/>
|
|
81
86
|
))}
|
|
82
87
|
</Stack>
|
|
@@ -26,13 +26,12 @@ export const BundleAssetsTotalsTable = ({
|
|
|
26
26
|
const [_, ...metricSlugs] = item.key.split('.');
|
|
27
27
|
const metricKey = metricSlugs.join('.');
|
|
28
28
|
const budget = get(budgets, metricKey);
|
|
29
|
-
const metric = webpack.getMetricType(metricKey);
|
|
30
29
|
|
|
31
30
|
return (
|
|
32
31
|
<CustomComponentLink section={section} title={title} params={params}>
|
|
33
32
|
<FlexStack space="xxsmall" className={css.itemTitleText}>
|
|
34
33
|
<span>{item.label}</span>
|
|
35
|
-
{budget && <BudgetInfo
|
|
34
|
+
{budget && <BudgetInfo metricId={item.key} budgetInsight={budget} />}
|
|
36
35
|
</FlexStack>
|
|
37
36
|
</CustomComponentLink>
|
|
38
37
|
);
|
package/src/components/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { BundleAssetsTotalsTable } from './bundle-assets-totals-table';
|
|
|
4
4
|
export { BundleAssetsTotalsChartBars } from './bundle-assets-totals-chart-bars';
|
|
5
5
|
export { BundlePackages } from './bundle-packages';
|
|
6
6
|
export { BundleModules } from './bundle-modules';
|
|
7
|
+
export { BudgetInsights } from './budget-insights';
|
|
7
8
|
export { ComponentLink } from './component-link';
|
|
8
9
|
export { DuplicatePackagesWarning } from './duplicate-packages-warning';
|
|
9
10
|
export { Delta } from './delta';
|
|
@@ -34,7 +34,7 @@ export const Summary = ({
|
|
|
34
34
|
size={size}
|
|
35
35
|
id={metricId}
|
|
36
36
|
data={get(data, metricId)}
|
|
37
|
-
budget={get(budgets,
|
|
37
|
+
budget={get(budgets, metricId)}
|
|
38
38
|
loading={loading}
|
|
39
39
|
showMetricDescription
|
|
40
40
|
showDelta={showSummaryItemDelta && metricOptions.showDelta !== false}
|
|
@@ -71,7 +71,7 @@ export const SummaryItem = ({
|
|
|
71
71
|
</Popover>
|
|
72
72
|
)}
|
|
73
73
|
|
|
74
|
-
{budget && <BudgetInfo className={css.budgetInfo}
|
|
74
|
+
{budget && <BudgetInfo className={css.budgetInfo} metricId={id} budgetInsight={budget} />}
|
|
75
75
|
</FlexStack>
|
|
76
76
|
|
|
77
77
|
{!loading ? (
|
|
@@ -139,10 +139,10 @@ SummaryItem.propTypes = {
|
|
|
139
139
|
/** Show delta */
|
|
140
140
|
showDelta: PropTypes.bool,
|
|
141
141
|
|
|
142
|
-
/** Budget data */
|
|
142
|
+
/** Budget insight data */
|
|
143
143
|
budget: PropTypes.shape({
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
currentBalue: PropTypes.number,
|
|
145
|
+
budgetValue: PropTypes.number,
|
|
146
|
+
failed: PropTypes.bool,
|
|
147
147
|
}),
|
|
148
148
|
};
|