Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BundleModules chunk count #4055

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/ui/src/components/bundle-modules/bundle-modules.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import cx from 'classnames';
import isEmpty from 'lodash/isEmpty';
import get from 'lodash/get';
import uniq from 'lodash/uniq';
import {
FILE_TYPE_LABELS,
MODULE_SOURCE_FILE_TYPES,
Expand Down Expand Up @@ -161,6 +162,46 @@ export const BundleModules = ({
[jobs, chunks, CustomComponentLink, filters, search],
);

const renderHeaderCustomCells = useCallback(() => {
return [
{
className: css.colChunkCount,
children: 'Chunks',
},
];
}, []);

const renderHeaderCustomSumCells = useCallback((tableItems) => {
const uniqChunks = uniq(tableItems.map((item) => item.runs[0].chunkIds).flat());

return [
{
className: css.colChunkCount,
children: uniqChunks.length,
},
];
}, []);

const renderRowCustomCells = useCallback((item) => {
const run = item.runs[0];

if (!run) {
return [
{
className: css.colChunkCount,
children: null,
},
];
}

return [
{
className: css.colChunkCount,
children: run.chunkIds?.length || 1,
},
];
}, []);

const emptyMessage = useMemo(() => (
<EmptySet
resources="modules"
Expand Down Expand Up @@ -212,7 +253,10 @@ export const BundleModules = ({
className={css.table}
items={items}
runs={jobs}
renderHeaderCustomCells={renderHeaderCustomCells}
renderHeaderCustomSumCells={renderHeaderCustomSumCells}
renderRowHeader={renderRowHeader}
renderRowCustomCells={renderRowCustomCells}
emptyMessage={emptyMessage}
showHeaderSum
title={metricsTableTitle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@
.root .name:focus .nameText {
text-decoration: underline;
}

.root .colChunkCount {
width: 5%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export const addRowFlags = (row) => {
// eslint-disable-next-line no-param-reassign
row.fileType = getModuleSourceFileType(row.key);

// Add chunk count field
if (runs?.[0]) {
// eslint-disable-next-line no-param-reassign
row.runs[0].chunkCount = row.runs[0].chunkIds?.length || 0;
}

return row;
};

Expand Down
199 changes: 121 additions & 78 deletions packages/ui/src/components/metrics-table/metrics-table.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import isEmpty from 'lodash/isEmpty';
import noop from 'lodash/noop';
import sum from 'lodash/sum';
import { MetricTypes, getGlobalMetricType, getMetricRunInfo } from '@bundle-stats/utils';

Expand Down Expand Up @@ -55,106 +56,104 @@ const ColumnSum = ({ rows, isBaseline, runIndex, updateSort, sort }) => {
return (
<>
<Table.Th className={cx(styles.value, styles.sum)}>
{(updateSort && sort) ? (
<SortButton
fieldPath={fieldPath}
fieldName="value"
label="absolute value"
updateSort={updateSort}
sort={sort}
>
<Metric value={infoTotal.displayValue} />
</SortButton>
) : (
<SortButton
fieldPath={fieldPath}
fieldName="value"
label="absolute value"
updateSort={updateSort}
sort={sort}
>
<Metric value={infoTotal.displayValue} />
)}
</SortButton>
</Table.Th>
{!isBaseline && (
<>
<Table.Th className={cx(styles.delta, styles.sum)}>
{(updateSort && sort) ? (
<SortButton
fieldPath={fieldPath}
fieldName="delta"
label="absolute change"
updateSort={updateSort}
sort={sort}
>
<Delta displayValue={infoTotal.displayDelta} deltaType={infoTotal.deltaType} />
</SortButton>
) : (
<SortButton
fieldPath={fieldPath}
fieldName="delta"
label="absolute change"
updateSort={updateSort}
sort={sort}
>
<Delta displayValue={infoTotal.displayDelta} deltaType={infoTotal.deltaType} />
)}
</SortButton>
</Table.Th>
<Table.Th className={cx(styles.delta, styles.deltaPercentage, styles.sum)}>
{(updateSort && sort) ? (
<SortButton
fieldPath={fieldPath}
fieldName="deltaPercentage"
label="absolute percentual change"
updateSort={updateSort}
sort={sort}
>
<Delta
displayValue={infoTotal.displayDeltaPercentage}
deltaType={infoTotal.deltaType}
/>
</SortButton>
) : (
<SortButton
fieldPath={fieldPath}
fieldName="deltaPercentage"
label="absolute percentual change"
updateSort={updateSort}
sort={sort}
>
<Delta
displayValue={infoTotal.displayDeltaPercentage}
deltaType={infoTotal.deltaType}
/>
)}
</SortButton>
</Table.Th>
</>
)}
</>
);
};

const Row = ({ item, renderRowHeader }) => (
<Table.Tr className={cx(!item.changed && styles.unchanged)}>
<Table.Th className={styles.metricName}>{renderRowHeader(item)}</Table.Th>
const Row = (props) => {
const { item, renderHeader, renderCustomCells } = props;

{item.runs.map((run, index) => {
const isBaseline = index === item.runs.length - 1;
const valueClassName = cx(styles.value, !isBaseline && styles.current);
const rowHeader = useMemo(() => renderHeader(item), [renderHeader, item]);
const customCells = useMemo(() => renderCustomCells(item), [renderCustomCells, item]);

// Empty cells if no value
if (!run || typeof run.value === 'undefined') {
return (
<>
<Table.Td className={valueClassName}>-</Table.Td>
{!isBaseline && <Table.Td className={styles.delta} />}
{!isBaseline && <Table.Td className={cx(styles.delta, styles.deltaPercentage)} />}
</>
);
}
return (
<Table.Tr className={cx(!item.changed && styles.unchanged)}>
<Table.Th className={styles.metricName}>{rowHeader}</Table.Th>

const { displayValue, deltaPercentage, displayDelta, displayDeltaPercentage, deltaType } =
run;
{customCells
? customCells.map((customCell) => (
<Table.Td {...customCell} className={cx(styles.value, customCell.className)} />
))
: null}

return (
<>
<Table.Td className={valueClassName}>
<Metric value={displayValue} />
</Table.Td>
{!isBaseline && typeof deltaPercentage === 'number' && (
{item.runs.map((run, index) => {
const isBaseline = index === item.runs.length - 1;
const valueClassName = cx(styles.value, !isBaseline && styles.current);

// Empty cells if no value
if (!run || typeof run.value === 'undefined') {
return (
<>
<Table.Td className={styles.delta}>
<Delta displayValue={displayDelta} deltaType={deltaType} />
</Table.Td>
<Table.Td className={cx(styles.delta, styles.deltaPercentage)}>
<Delta displayValue={displayDeltaPercentage} deltaType={deltaType} />
</Table.Td>
<Table.Td className={valueClassName}>-</Table.Td>
{!isBaseline && <Table.Td className={styles.delta} />}
{!isBaseline && <Table.Td className={cx(styles.delta, styles.deltaPercentage)} />}
</>
)}
</>
);
})}
</Table.Tr>
);
);
}

const { displayValue, deltaPercentage, displayDelta, displayDeltaPercentage, deltaType } =
run;

return (
<>
<Table.Td className={valueClassName}>
<Metric value={displayValue} />
</Table.Td>
{!isBaseline && typeof deltaPercentage === 'number' && (
<>
<Table.Td className={styles.delta}>
<Delta displayValue={displayDelta} deltaType={deltaType} />
</Table.Td>
<Table.Td className={cx(styles.delta, styles.deltaPercentage)}>
<Delta displayValue={displayDeltaPercentage} deltaType={deltaType} />
</Table.Td>
</>
)}
</>
);
})}
</Table.Tr>
);
};

Row.propTypes = {
item: PropTypes.shape({
Expand All @@ -169,12 +168,16 @@ Row.propTypes = {
}),
),
}).isRequired,
renderRowHeader: PropTypes.func.isRequired,
renderHeader: PropTypes.func.isRequired,
renderCustomCells: PropTypes.func.isRequired,
};

export const MetricsTable = ({
className,
renderRowHeader,
renderRowCustomCells,
renderHeaderCustomCells,
renderHeaderCustomSumCells,
runs,
items,
emptyMessage,
Expand All @@ -199,6 +202,8 @@ export const MetricsTable = ({
const showItems = !showEmpty;
const hasHiddenItems = items?.length > VISIBLE_COUNT;
const visibleItems = !hasHiddenItems || showAllItems ? items : items?.slice(0, VISIBLE_COUNT);
const headerCustomCells = renderHeaderCustomCells();
const headerCustomSumCells = renderHeaderCustomSumCells(items);

return (
<Table className={rootClassName} compact {...restProps}>
Expand All @@ -207,12 +212,39 @@ export const MetricsTable = ({
<Table.Th className={styles.metricName} rowSpan={showHeaderSum ? 2 : 1}>
{title || ' '}
</Table.Th>
{headerCustomCells
? headerCustomCells.map((headerCustomCell) => (
<Table.Th
{...headerCustomCell}
className={cx(styles.job, headerCustomCell.className)}
/>
))
: null}
{runs.map((run, runIndex) => (
<ColumnJob run={run} isBaseline={runIndex === runs.length - 1} />
))}
</Table.Tr>

{showHeaderSum && (
<Table.Tr className={styles.headerRow}>
{headerCustomSumCells
? headerCustomSumCells.map((headerCustomSumCell) => (
<Table.Th
{...headerCustomSumCell}
className={cx(styles.value, styles.sum, headerCustomSumCell.className)}
>
<SortButton
fieldPath="runs[0]"
fieldName="chunkCount"
label="chunk count"
updateSort={updateSort}
sort={sort}
>
{headerCustomSumCell.children}
</SortButton>
</Table.Th>
))
: null}
{runs.map((run, runIndex) => (
<ColumnSum
rows={items}
Expand Down Expand Up @@ -242,7 +274,12 @@ export const MetricsTable = ({
{showItems && (
<>
{visibleItems.map((item) => (
<Row key={item.key} item={item} renderRowHeader={renderRowHeader} />
<Row
key={item.key}
item={item}
renderHeader={renderRowHeader}
renderCustomCells={renderRowCustomCells}
/>
))}

{hasHiddenItems && (
Expand Down Expand Up @@ -278,6 +315,9 @@ export const MetricsTable = ({
MetricsTable.defaultProps = {
className: '',
renderRowHeader: (item) => item.label,
renderRowCustomCells: noop,
renderHeaderCustomCells: noop,
renderHeaderCustomSumCells: noop,
emptyMessage: 'No entries found.',
showHeaderSum: false,
title: '',
Expand All @@ -286,6 +326,9 @@ MetricsTable.defaultProps = {
MetricsTable.propTypes = {
className: PropTypes.string,
renderRowHeader: PropTypes.func,
renderRowCustomCells: PropTypes.func,
renderHeaderCustomCells: PropTypes.func,
renderHeaderCustomSumCells: PropTypes.func,
runs: PropTypes.arrayOf(
PropTypes.shape({
internalBuildNumber: PropTypes.number,
Expand Down
Loading