Skip to content

Commit

Permalink
fix(ui): ModuleInfo - skip diff when baseline is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Aug 24, 2024
1 parent f0b1323 commit 1e8bc8f
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/ui/src/components/module-info/module-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ import { ModuleSizeMetric, ModuleSizeMetrics } from '../../constants';

interface DuplicateInstancesProps {
current: number;
baseline: number;
baseline?: number;
}

const DuplicateInstances = ({ current, baseline }: DuplicateInstancesProps) => {
const runInfo = getMetricRunInfo(
{ biggerIsBetter: false, formatter: formatNumber },
{
biggerIsBetter: false,
formatter: formatNumber,
},
current,
baseline,
) as MetricRunInfo;
Expand Down Expand Up @@ -145,7 +148,7 @@ interface ModuleSizeRunInfoProps {
const ModuleSizeRunInfo = (props: ModuleSizeRunInfoProps) => {
const { metric, title, titleTooltip, current, baseline } = props;

const runInfo = getMetricRunInfo(metric, current || 0, baseline || 0) as MetricRunInfo;
const runInfo = getMetricRunInfo(metric, current || 0, baseline) as MetricRunInfo;

return (
<RunInfo
Expand All @@ -155,7 +158,7 @@ const ModuleSizeRunInfo = (props: ModuleSizeRunInfoProps) => {
delta={runInfo.displayDeltaPercentage}
deltaPercentage={runInfo.displayDelta}
deltaType={runInfo.deltaType}
baseline={metric.formatter(baseline || 0)}
baseline={baseline ? metric.formatter(baseline) : undefined}
/>
);
};
Expand All @@ -176,24 +179,24 @@ const renderRunInfo = (item: ReportMetricRow) => {
metric={metric}
title={ModuleSizeMetrics[ModuleSizeMetric.TOTAL_SIZE].label}
titleTooltip={ModuleSizeMetrics[ModuleSizeMetric.TOTAL_SIZE].tooltip}
current={currentRun.sizeTotal}
baseline={baselineRun?.sizeTotal || 0}
current={currentRun?.sizeTotal}
baseline={baselineRun?.sizeTotal}
/>
<ModuleSizeRunInfo
metric={metric}
title={ModuleSizeMetrics[ModuleSizeMetric.DUPLICATE_SIZE].label}
titleTooltip={ModuleSizeMetrics[ModuleSizeMetric.DUPLICATE_SIZE].tooltip}
current={currentRun.sizeDuplicate}
baseline={baselineRun?.sizeDuplicate || 0}
current={currentRun?.sizeDuplicate}
baseline={baselineRun?.sizeDuplicate}
/>
</>
)}
<ModuleSizeRunInfo
metric={metric}
title={ModuleSizeMetrics[ModuleSizeMetric.SIZE].label}
titleTooltip={ModuleSizeMetrics[ModuleSizeMetric.SIZE].tooltip}
current={currentRun.size}
baseline={baselineRun?.size || 0}
current={currentRun?.size}
baseline={baselineRun?.size}
/>
</FlexStack>
);
Expand Down Expand Up @@ -244,8 +247,12 @@ export const ModuleInfo = (props: ModuleInfoProps & React.ComponentProps<'div'>)
? MODULE_SOURCE_TYPE_LABELS.THIRD_PARTY
: MODULE_SOURCE_TYPE_LABELS.FIRST_PARTY;

const currentChunkCount = (item.runs[0]?.chunkIds || []).length;
const baselineChunkCount = (item.runs[item.runs.length - 1]?.chunkIds || []).length;
const currentRun = item.runs[0];
const baselineRun = item.runs.length > 1 ? item.runs[item.runs.length - 1] : undefined;

const currentChunkCount = currentRun?.chunkIds?.length || 0;
const baselineChunkCount = baselineRun?.chunkIds?.length || 0;

const currentDuplicateInstances = currentChunkCount > 0 ? currentChunkCount - 1 : 0;
const baselineDuplicateInstances = baselineChunkCount > 0 ? baselineChunkCount - 1 : 0;
const hasDuplicates = currentDuplicateInstances !== 0 || baselineDuplicateInstances !== 0;
Expand Down Expand Up @@ -286,7 +293,7 @@ export const ModuleInfo = (props: ModuleInfoProps & React.ComponentProps<'div'>)
<EntryInfo.Meta label="Duplicates" tooltip="Module duplicate instances">
<DuplicateInstances
current={currentDuplicateInstances}
baseline={baselineDuplicateInstances}
baseline={baselineRun ? baselineDuplicateInstances : undefined}
/>
</EntryInfo.Meta>
)}
Expand Down

0 comments on commit 1e8bc8f

Please sign in to comment.