Skip to content

Commit

Permalink
FIXUP
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Apr 3, 2022
1 parent 7ea9a01 commit 9c540bd
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions packages/ui/src/components/budget-insights/budget-insights.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { METRIC_COMPONENT_LINKS } from '@bundle-stats/utils';
import * as budgetsInsightsTransformer from '@bundle-stats/utils/lib-esm/transformers/budgets-insights';

import { Box } from '../../layout/box';
import { Stack } from '../../layout/stack';
Expand All @@ -13,30 +12,28 @@ import { ComponentLink } from '../component-link';
import css from './budget-insights.module.css';

const Budget = (props) => {
const { className, metricId, budgetInsight, CustomLink } = props;
const { className, metricId, budget, CustomLink } = props;
const componentLinkOptions = METRIC_COMPONENT_LINKS.get(metricId);
const budgetInsightInfo = budgetsInsightsTransformer.getInfo(metricId, budgetInsight);
const { data: messageData } = budgetInsightInfo.message;

return (
<CustomLink className={cx(css.budget, className)} {...componentLinkOptions?.link}>
<strong>{messageData.metricLabel}</strong>
{` value (`}
<strong>{messageData.currentValue}</strong>
{`) is ${messageData.diffLabel} `}
<strong>{messageData.budgetValue}</strong>
{` budget `}
{budget.message.text}
</CustomLink>
);
};

Budget.propTypes = {
className: PropTypes.string,
metricId: PropTypes.string.isRequired,
budgetInsight: PropTypes.shape({
currentValue: PropTypes.number.isRequired,
budgetValue: PropTypes.number.isRequired,
failed: PropTypes.bool.isRequired,
budget: PropTypes.shape({
message: PropTypes.shape({
text: PropTypes.string,
}),
data: PropTypes.shape({
currentValue: PropTypes.number.isRequired,
budgetValue: PropTypes.number.isRequired,
failed: PropTypes.bool.isRequired,
}),
}).isRequired,
CustomLink: PropTypes.elementType.isRequired,
};
Expand Down Expand Up @@ -146,7 +143,7 @@ export const BudgetInsights = (props) => {
<Budget
key={key}
metricId={`${source}.${key}`}
budgetInsight={budget}
budget={budget}
CustomLink={CustomLink}
/>
))}
Expand Down

0 comments on commit 9c540bd

Please sign in to comment.