Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import SummaryGrid from "components/SummaryGrid";
import { SUMMARY_VALUE_COMPONENT_TYPES } from "utils/constants";
import { getPoolColorStatus } from "utils/layouts";
import { intPercentXofY } from "utils/math";
import { getPoolColorStatusByLimit } from "utils/layouts";

const ExpensesBreakdownSummaryCards = ({ total = 0, previousTotal = 0, isLoading = false, pdfIds = {} }) => {
const percent = intPercentXofY(total, previousTotal);

const summaryData = [
{
key: "totalExpensesForSelectedPeriod",
valueComponentType: SUMMARY_VALUE_COMPONENT_TYPES.FormattedMoney,
valueComponentProps: {
value: total
},
color: getPoolColorStatus(percent),
color: getPoolColorStatusByLimit(total, previousTotal),
isLoading,
captionMessageId: "totalExpensesForSelectedPeriod",
pdfId: pdfIds.totalExpensesForSelectedPeriod
Expand Down
10 changes: 3 additions & 7 deletions ngui/ui/src/components/PoolsOverview/Summary/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import SummaryGrid from "components/SummaryGrid";
import { getPoolIdWithSubPools, getResourcesExpensesUrl } from "urls";
import { RECOMMENDATIONS_FILTER, POOL_ID_FILTER, SUMMARY_CARD_TYPES, SUMMARY_VALUE_COMPONENT_TYPES } from "utils/constants";
import { getCurrentMonthRange } from "utils/datetime";
import { getPoolColorStatus } from "utils/layouts";
import { intPercentXofY } from "utils/math";
import { getPoolColorStatusByLimit } from "utils/layouts";

type SummaryProps = {
data: {
Expand All @@ -19,9 +18,6 @@ type SummaryProps = {

const Summary = ({ data, isLoading = false }: SummaryProps) => {
const { id, limit = 0, cost = 0, forecast = 0, saving = 0 } = data;

const costPercent = intPercentXofY(cost, limit);
const forecastPercent = intPercentXofY(forecast, limit);
const { today, startOfMonth } = getCurrentMonthRange(true);

const { exceededPools, exceededByValue } = [data, ...(data.children ?? [])].reduce(
Expand Down Expand Up @@ -73,7 +69,7 @@ const Summary = ({ data, isLoading = false }: SummaryProps) => {
valueComponentProps: {
value: cost
},
color: getPoolColorStatus(costPercent),
color: getPoolColorStatusByLimit(cost, limit),
captionMessageId: "expensesThisMonth",
isLoading,
dataTestIds: {
Expand All @@ -87,7 +83,7 @@ const Summary = ({ data, isLoading = false }: SummaryProps) => {
value: forecast
},
captionMessageId: "forecastThisMonth",
color: getPoolColorStatus(forecastPercent),
color: getPoolColorStatusByLimit(forecast, limit),
isLoading,
dataTestIds: {
cardTestId: "card_forecast"
Expand Down
8 changes: 3 additions & 5 deletions ngui/ui/src/components/RegionExpenses/RegionExpenses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
EMPTY_UUID,
DATE_RANGE_TYPE
} from "utils/constants";
import { SPACING_2, getPoolColorStatus } from "utils/layouts";
import { SPACING_2, getPoolColorStatusByLimit } from "utils/layouts";
import { REGION_EXPENSES_HEIGHT } from "utils/maps";
import { percentXofY, intPercentXofY } from "utils/math";
import { percentXofY } from "utils/math";

const getGoToExpensesLink = (name, startDate, endDate) =>
getResourcesExpensesUrl({
Expand Down Expand Up @@ -95,16 +95,14 @@ const RegionExpenses = ({ expenses, isLoading = false }) => {
return getFilteredMarkers(markers, total, getColor);
}, [markers, theme.palette.chart, total]);

const percent = intPercentXofY(total, previousTotal);

const summaryData = [
{
key: "totalExpensesForSelectedPeriod",
valueComponentType: SUMMARY_VALUE_COMPONENT_TYPES.FormattedMoney,
valueComponentProps: {
value: total
},
color: getPoolColorStatus(percent),
color: getPoolColorStatusByLimit(total, previousTotal),
captionMessageId: "totalExpensesForSelectedPeriod",
isLoading
},
Expand Down
12 changes: 12 additions & 0 deletions ngui/ui/src/utils/layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ export const getPoolColorStatus = (percent = 0) => {
return SUCCESS;
};

export const getPoolColorStatusByLimit = (value: number, limit: number, threshold: number = 0.9) => {
const warningLimit = limit * threshold;
if (value > warningLimit && value <= limit) {
return WARNING;
}
if (value > limit) {
return ERROR;
}

return SUCCESS;
};

/**
* Calculate border styles for n*2 cards/nodes layouts (home page, integrations)
*
Expand Down