Skip to content

Commit

Permalink
WIP: BundleAssetsTotalsTable - add budgets
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Dec 14, 2021
1 parent 9307393 commit 72d355e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/ui/src/components/budget-info/budget-info.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.root {
display: inline-block;
line-height: 1em;
}

/* Budget over */
.over .icon {
color: var(--color-danger-light);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import React, { useCallback, useMemo } from 'react';
import PropTypes from 'prop-types';
import { get } from 'lodash';
import { getBundleAssetsFileTypeComponentLink } from '@bundle-stats/utils';
import * as webpack from '@bundle-stats/utils/lib-esm/webpack';

import { ASSETS_SIZES_FILE_TYPE_MAP } from '../../constants';
import { FlexStack } from '../../layout/flex-stack';
import { MetricsTable } from '../metrics-table';
import { ComponentLink } from '../component-link';
import { BudgetInfo } from '../budget-info';
import css from './bundle-assets-totals-table.module.css';

export const BundleAssetsTotalsTable = ({
className,
jobs,
customComponentLink: CustomComponentLink,
}) => {
const items = useMemo(() => webpack.compareBySection.sizes(jobs), [jobs]);
const budgets = jobs[0].insights?.webpack?.budgets;

const renderRowHeader = useCallback(
(item) => {
const fileType = ASSETS_SIZES_FILE_TYPE_MAP[item.key];
const { section, title, params } = getBundleAssetsFileTypeComponentLink(fileType, item.label);
const [_, ...metricSlugs] = item.key.split('.');
const metricKey = metricSlugs.join('.');
const budget = get(budgets, metricKey);
const metric = webpack.getMetricType(metricKey);

return (
<CustomComponentLink section={section} title={title} params={params}>
{item.label}
<FlexStack space="xxsmall" className={css.itemTitleText}>
<span>{item.label}</span>
{budget && <BudgetInfo budget={budget} metric={metric} />}
</FlexStack>
</CustomComponentLink>
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.title {
color: var(--color-text-light);
.itemTitleText {
align-items: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,22 @@ export const EmptyBaseline = Template.bind();
EmptyBaseline.args = {
jobs: createJobs([{ webpack: currentStats }, null]),
};

export const WithBudgets = Template.bind();

WithBudgets.args = {
jobs: createJobs([{ webpack: currentStats }, { webpack: baselineStats }], {
webpack: {
budgets: [
{
metric: 'sizes.totalSizeByTypeJS',
value: 2 * 1024 * 1024,
},
{
metric: 'sizes.totalSizeByTypeCSS',
value: 20 * 1024,
},
],
},
}),
};

0 comments on commit 72d355e

Please sign in to comment.