Skip to content

Commit

Permalink
feat: add state for funding recieved table and updated currency input…
Browse files Browse the repository at this point in the history
… component
  • Loading branch information
fpigeonjr committed Jan 9, 2025
1 parent 56444d1 commit bc5d4a0
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 144 deletions.
4 changes: 3 additions & 1 deletion frontend/src/components/CANs/CANBudgetForm/CANBudgetForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import icons from "../../../uswds/img/sprite.svg";

/**
* @typedef {Object} CANBudgetFormProps
* @property {string} totalFunding
* @property {string} budgetAmount
* @property {(arg: string) => string} cn
* @property {Object} res
Expand All @@ -17,7 +18,7 @@ import icons from "../../../uswds/img/sprite.svg";
* @param {CANBudgetFormProps} props
* @returns {JSX.Element} - The component JSX.
*/
const CANBudgetForm = ({ budgetAmount, cn, res, fiscalYear, handleAddBudget, runValidate, setBudgetAmount }) => {
const CANBudgetForm = ({ totalFunding, budgetAmount, cn, res, fiscalYear, handleAddBudget, runValidate, setBudgetAmount }) => {
const fillColor = budgetAmount ? "#005ea2" : "#757575";

return (
Expand All @@ -37,6 +38,7 @@ const CANBudgetForm = ({ budgetAmount, cn, res, fiscalYear, handleAddBudget, run
value={budgetAmount || ""}
messages={res.getErrors("budget-amount")}
className={cn("budget-amount")}
placeholder={`$${totalFunding}`}
/>
</div>
<button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import { faClock } from "@fortawesome/free-regular-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import CurrencyFormat from "react-currency-format";
import { calculatePercent, formatDateToMonthDayYear } from "../../../helpers/utils";
import Table from "../../UI/Table";
import TableRowExpandable from "../../UI/TableRowExpandable";
import {
changeBgColorIfExpanded,
expandedRowBGColor,
removeBorderBottomIfExpanded
} from "../../UI/TableRowExpandable/TableRowExpandable.helpers";
import { useTableRow } from "../../UI/TableRowExpandable/TableRowExpandable.hooks";
import { NO_DATA } from "../../../constants";
import CANFundingReceivedTableRow from "./CANFundingReceivedTableRow";

/**
* @typedef {import("../../../components/CANs/CANTypes").FundingReceived} FundingReceived
*/
Expand All @@ -27,128 +17,14 @@ import { NO_DATA } from "../../../constants";
* @returns {JSX.Element} - The component JSX.
*/
const CANFundingReceivedTable = ({ fundingReceived, totalFunding }) => {
const { isExpanded, setIsExpanded, setIsRowActive } = useTableRow();
const borderExpandedStyles = removeBorderBottomIfExpanded(isExpanded);
const bgExpandedStyles = changeBgColorIfExpanded(isExpanded);

/**
* Component for displaying funding received data in a table format
* @component ExpandedData - Displays additional details when a row is expanded
* @param {Object} props
* @param {string} props.createdBy - Name of user who created the funding entry
* @param {string} props.createdOn - Date when funding entry was created
* @param {string} [props.notes] - Additional notes for the funding entry
* @returns {JSX.Element} Table cell containing expanded details
*/
const ExpandedData = ({ createdBy, createdOn, notes }) => (
<td
colSpan={9}
className="border-top-none"
style={expandedRowBGColor}
>
<div className="display-flex padding-right-9">
<dl className="font-12px">
<dt className="margin-0 text-base-dark">Created By</dt>
<dd
id={`created-by-name`}
className="margin-0"
>
{createdBy ?? NO_DATA}
</dd>
<dt className="margin-0 text-base-dark display-flex flex-align-center margin-top-2">
<FontAwesomeIcon
icon={faClock}
className="height-2 width-2 margin-right-1"
/>
{formatDateToMonthDayYear(createdOn)}
</dt>
</dl>
<dl
className="font-12px"
style={{ marginLeft: "9.0625rem" }}
>
<dt className="margin-0 text-base-dark">Notes</dt>
<dd
className="margin-0"
style={{ maxWidth: "400px" }}
>
{notes ?? "No notes added."}
</dd>
</dl>
</div>
</td>
);

/**
* @component TableRowData component renders a table row
* @param {Object} props - The properties object.
* @param {number} props.rowId - The identifier for the row.
* @param {number} props.fiscalYear - The fiscal year for the funding data.
* @param {number} [props.funding] - The amount of funding received.
* @param {number} props.totalFunding - The total funding available.
* @returns {JSX.Element} The rendered table row data.
*/
const TableRowData = ({ rowId, fiscalYear, funding = 0, totalFunding }) => (
<>
<th
scope="row"
className={`${borderExpandedStyles}`}
style={bgExpandedStyles}
>
{rowId}
</th>
<td
className={borderExpandedStyles}
style={bgExpandedStyles}
>
{fiscalYear}
</td>
<td
className={borderExpandedStyles}
style={bgExpandedStyles}
>
<CurrencyFormat
value={funding}
displayType={"text"}
thousandSeparator={true}
prefix={"$"}
decimalScale={2}
fixedDecimalScale
/>
</td>
<td
className={borderExpandedStyles}
style={bgExpandedStyles}
>
{calculatePercent(funding, totalFunding)}%
</td>
</>
);

return (
<Table tableHeadings={["Funding ID", "FY", "Funding Received", "% of Total FY Budget"]}>
{fundingReceived.map((row) => {
{fundingReceived.map((fundingRow) => {
return (
<TableRowExpandable
key={row.id}
tableRowData={
<TableRowData
rowId={row.id}
fiscalYear={row.fiscal_year}
funding={row.funding}
totalFunding={totalFunding}
/>
}
expandedData={
<ExpandedData
createdBy={row.created_by_user}
createdOn={row.created_on}
notes={row.notes}
/>
}
isExpanded={isExpanded}
setIsExpanded={setIsExpanded}
setIsRowActive={setIsRowActive}
<CANFundingReceivedTableRow
key={fundingRow.id}
fundingReceived={fundingRow}
totalFunding={totalFunding}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { faClock } from "@fortawesome/free-regular-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import CurrencyFormat from "react-currency-format";
import { calculatePercent, formatDateToMonthDayYear } from "../../../helpers/utils";
import {
changeBgColorIfExpanded,
expandedRowBGColor,
removeBorderBottomIfExpanded
} from "../../UI/TableRowExpandable/TableRowExpandable.helpers";
import { useTableRow } from "../../UI/TableRowExpandable/TableRowExpandable.hooks";
import { NO_DATA } from "../../../constants";
import TableRowExpandable from "../../UI/TableRowExpandable";

/**
* @typedef {import("../../../components/CANs/CANTypes").FundingReceived} FundingReceived
*/

/**
* @typedef {Object} CANFundingReceivedTableRowProps
* @property {string} totalFunding
* @property {FundingReceived} fundingReceived data for table
*/

/**
* @component - The CAN Funding component.
* @param {CANFundingReceivedTableRowProps} props
* @returns {JSX.Element} - The component JSX.
*/

const CANFundingReceivedTableRow = ({ fundingReceived, totalFunding }) => {
const { isExpanded, setIsExpanded, setIsRowActive } = useTableRow();
const borderExpandedStyles = removeBorderBottomIfExpanded(isExpanded);
const bgExpandedStyles = changeBgColorIfExpanded(isExpanded);

/**
* Component for displaying funding received data in a table format
* @component ExpandedData - Displays additional details when a row is expanded
* @param {Object} props
* @param {string} props.createdBy - Name of user who created the funding entry
* @param {string} props.createdOn - Date when funding entry was created
* @param {string} [props.notes] - Additional notes for the funding entry
* @returns {JSX.Element} Table cell containing expanded details
*/
const ExpandedData = ({ createdBy, createdOn, notes }) => (
<td
colSpan={9}
className="border-top-none"
style={expandedRowBGColor}
>
<div className="display-flex padding-right-9">
<dl className="font-12px">
<dt className="margin-0 text-base-dark">Created By</dt>
<dd
id={`created-by-name`}
className="margin-0"
>
{createdBy ?? NO_DATA}
</dd>
<dt className="margin-0 text-base-dark display-flex flex-align-center margin-top-2">
<FontAwesomeIcon
icon={faClock}
className="height-2 width-2 margin-right-1"
/>
{formatDateToMonthDayYear(createdOn)}
</dt>
</dl>
<dl
className="font-12px"
style={{ marginLeft: "9.0625rem" }}
>
<dt className="margin-0 text-base-dark">Notes</dt>
<dd
className="margin-0"
style={{ maxWidth: "400px" }}
>
{notes ?? "No notes added."}
</dd>
</dl>
</div>
</td>
);

/**
* @component TableRowData component renders a table row
* @param {Object} props - The properties object.
* @param {number} props.rowId - The identifier for the row.
* @param {number} props.fiscalYear - The fiscal year for the funding data.
* @param {number} [props.funding] - The amount of funding received.
* @param {number} props.totalFunding - The total funding available.
* @returns {JSX.Element} The rendered table row data.
*/
const TableRowData = ({ rowId, fiscalYear, funding = 0, totalFunding }) => (
<>
<th
scope="row"
className={`${borderExpandedStyles}`}
style={bgExpandedStyles}
>
{rowId}
</th>
<td
className={borderExpandedStyles}
style={bgExpandedStyles}
>
{fiscalYear}
</td>
<td
className={borderExpandedStyles}
style={bgExpandedStyles}
>
<CurrencyFormat
value={funding}
displayType={"text"}
thousandSeparator={true}
prefix={"$"}
decimalScale={2}
fixedDecimalScale
/>
</td>
<td
className={borderExpandedStyles}
style={bgExpandedStyles}
>
{calculatePercent(funding, totalFunding)}%
</td>
</>
);
return (
<TableRowExpandable
tableRowData={
<TableRowData
rowId={fundingReceived.id}
fiscalYear={fundingReceived.fiscal_year}
funding={fundingReceived.funding}
totalFunding={+totalFunding}
/>
}
expandedData={
<ExpandedData
createdBy={fundingReceived.created_by_user.full_name}
createdOn={fundingReceived.created_on}
notes={fundingReceived.notes}
/>
}
isExpanded={isExpanded}
setIsExpanded={setIsExpanded}
setIsRowActive={setIsRowActive}
/>
);
};

export default CANFundingReceivedTableRow;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CurrencyFormat from "react-currency-format";
* @param {string | number} [props.value] - The value of the input field.(optional)
* @param {string} [props.className] - Additional CSS classes to apply to the component (optional).
* @param {Function} [props.setEnteredAmount] - A function to call when the input value changes.
* @param {string} [props.placeholder] - The placeholder text to display in the input
* @returns {JSX.Element} - The rendered component.
*/
const CurrencyInput = ({
Expand All @@ -23,7 +24,8 @@ const CurrencyInput = ({
messages = [],
value,
className,
setEnteredAmount
setEnteredAmount,
placeholder = "$"
}) => {
return (
<div className={cx("usa-form-group", pending && "pending", className)}>
Expand All @@ -49,7 +51,7 @@ const CurrencyInput = ({
thousandSeparator={true}
decimalScale={2}
renderText={(value) => value}
placeholder="$"
placeholder={placeholder}
onValueChange={(values) => {
const { floatValue } = values;
setEnteredAmount(floatValue);
Expand Down
Loading

0 comments on commit bc5d4a0

Please sign in to comment.