-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: ✨ adds Budget Summary Card #2974
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9adf2a8
wip: starts summary cards
fpigeonjr 23f1544
feat: BudgetSummaryCard
fpigeonjr f1d6b0f
chore: fix linting
fpigeonjr 14c0a45
added e2e test
Santi-3rd 0191ca5
Merge branch 'main' into OPS-2842/2972
fpigeonjr 47656f5
refactor: removes unneeded props
fpigeonjr e278e2f
Merge branch 'main' into OPS-2842/2972
fpigeonjr 4b67c8a
docs: adds type data
fpigeonjr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
frontend/src/components/CANs/CANSummaryCards/CANSummaryCards.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import BudgetSummaryCard from "../../UI/SummaryCard/BudgetSummaryCard"; | ||
|
||
/** | ||
* @component | ||
* @param {Object} props - Properties passed to component | ||
* @param {number} props.fiscalYear - The fiscal year. | ||
* @returns {JSX.Element} - The CANSummaryCards component. | ||
*/ | ||
const CANSummaryCards = ({ fiscalYear }) => { | ||
return ( | ||
<div className="display-flex flex-justify"> | ||
<p> Summary Cards Left</p> | ||
<BudgetSummaryCard | ||
title={`FY ${fiscalYear} CANs Available Budget *`} | ||
totalSpending={1_500_000} | ||
totalFunding={2_000_000} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CANSummaryCards; |
3 changes: 3 additions & 0 deletions
3
frontend/src/components/CANs/CANSummaryCards/CANSummaryCards.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
describe("CANSummaryCards", () => { | ||
it.todo("renders all summary cards", () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./CANSummaryCards"; |
96 changes: 96 additions & 0 deletions
96
frontend/src/components/UI/SummaryCard/BudgetSummaryCard/BudgetSummaryCard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import CurrencyFormat from "react-currency-format"; | ||
import CANFundingBar from "../../../CANs/CANFundingBar"; | ||
import CurrencyWithSmallCents from "../../CurrencyWithSmallCents/CurrencyWithSmallCents"; | ||
import RoundedBox from "../../RoundedBox"; | ||
import Tag from "../../Tag"; | ||
/** | ||
* @component | ||
* @param {Object} props - Properties passed to component | ||
* @param {string} props.title - The title of the card. | ||
* @param {number} props.totalSpending - The total spending. | ||
* @param {number} props.totalFunding - The total funding. | ||
* @returns {JSX.Element} - The BudgetSummaryCard component. | ||
*/ | ||
const BudgetSummaryCard = ({ title, totalSpending, totalFunding }) => { | ||
const overBudget = totalSpending > totalFunding; | ||
const remainingBudget = overBudget ? 0 : totalFunding - totalSpending; | ||
const graphData = [ | ||
{ | ||
id: 1, | ||
value: totalSpending, | ||
color: overBudget ? "var(--feedback-error)" : "var(--data-viz-budget-graph-2)" | ||
}, | ||
{ | ||
id: 2, | ||
value: remainingBudget, | ||
color: overBudget ? "var(--feedback-error)" : "var(--data-viz-budget-graph-1)" | ||
} | ||
]; | ||
|
||
return ( | ||
<RoundedBox | ||
className={"padding-y-205 padding-x-4 display-inline-block"} | ||
dataCy={`budget-summary-card`} | ||
style={{ height: "14.5rem" }} | ||
> | ||
<h3 | ||
className="margin-0 margin-bottom-2 font-12px text-base-dark text-normal" | ||
style={{ whiteSpace: "pre-line", lineHeight: "20px" }} | ||
> | ||
{title} | ||
</h3> | ||
|
||
<div className="font-32px margin-0 display-flex flex-justify flex-align-end"> | ||
<CurrencyWithSmallCents | ||
amount={remainingBudget} | ||
dollarsClasses="font-sans-xl text-bold margin-bottom-0" | ||
centsStyles={{ fontSize: "10px" }} | ||
/> | ||
{overBudget ? ( | ||
<Tag tagStyle={"lightTextRedBackground"}> | ||
<FontAwesomeIcon | ||
icon={faTriangleExclamation} | ||
title="Over Budget" | ||
/>{" "} | ||
Over Budget | ||
</Tag> | ||
) : ( | ||
<Tag tagStyle={"budgetAvailable"}>Available</Tag> | ||
)} | ||
</div> | ||
<div | ||
id="currency-summary-card" | ||
className="margin-top-2" | ||
> | ||
<CANFundingBar | ||
data={graphData} | ||
isStriped={true} | ||
overBudget={overBudget} | ||
/> | ||
</div> | ||
<div className="font-12px margin-top-2 display-flex flex-justify-end"> | ||
<div> | ||
Spending {""} | ||
<CurrencyFormat | ||
value={totalSpending || 0} | ||
displayType={"text"} | ||
thousandSeparator={true} | ||
prefix={"$"} | ||
renderText={(totalSpending) => <span>{totalSpending}</span>} | ||
/>{" "} | ||
of{" "} | ||
<CurrencyFormat | ||
value={totalFunding || 0} | ||
displayType={"text"} | ||
thousandSeparator={true} | ||
prefix={"$"} | ||
renderText={(totalFunding) => <span>{totalFunding}</span>} | ||
/> | ||
</div> | ||
</div> | ||
</RoundedBox> | ||
); | ||
}; | ||
export default BudgetSummaryCard; |
53 changes: 53 additions & 0 deletions
53
frontend/src/components/UI/SummaryCard/BudgetSummaryCard/BudgetSummaryCard.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { describe, it, expect } from "vitest"; | ||
import BudgetSummaryCard from "./BudgetSummaryCard"; | ||
|
||
describe("BudgetSummaryCard", () => { | ||
const defaultProps = { | ||
title: "Budget Summary", | ||
totalSpending: 15000, | ||
totalFunding: 20000 | ||
}; | ||
|
||
it("renders with all required props", () => { | ||
render(<BudgetSummaryCard {...defaultProps} />); | ||
|
||
expect(screen.getByText("Budget Summary")).toBeInTheDocument(); | ||
expect(screen.getByText("$ 5,000")).toBeInTheDocument(); | ||
expect(screen.getByText("Available")).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays over budget warning when spending exceeds funding", () => { | ||
const overBudgetProps = { | ||
...defaultProps, | ||
totalSpending: 25000, | ||
totalFunding: 20000 | ||
}; | ||
|
||
render(<BudgetSummaryCard {...overBudgetProps} />); | ||
|
||
expect(screen.getByTitle("Over Budget")).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays correct spending and funding amounts", () => { | ||
render(<BudgetSummaryCard {...defaultProps} />); | ||
|
||
const spendingText = screen.getByText(/\$15,000/); | ||
const fundingText = screen.getByText(/\$20,000/); | ||
|
||
expect(spendingText).toBeInTheDocument(); | ||
expect(fundingText).toBeInTheDocument(); | ||
}); | ||
|
||
it("handles zero values correctly", () => { | ||
const zeroProps = { | ||
...defaultProps, | ||
totalSpending: 0, | ||
totalFunding: 0 | ||
}; | ||
|
||
render(<BudgetSummaryCard {...zeroProps} />); | ||
|
||
expect(screen.queryAllByText("$0")).toHaveLength(2); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
frontend/src/components/UI/SummaryCard/BudgetSummaryCard/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from "./BudgetSummaryCard" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hard-coded for now but will replace with api data