-
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
refactor: displays CAN obligate_by as MM/DD/YY #2873
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Gets the last day of the fiscal year for a given year. | ||
* @param {number} fiscalYear - The fiscal year | ||
* @returns {Date} The last day of the fiscal year | ||
*/ | ||
const getLastDayOfFiscalYear = (fiscalYear) => { | ||
// Fiscal year ends on September 30 | ||
return new Date(fiscalYear, 8, 30); // Month is 0-indexed, so 8 is September | ||
}; | ||
/** | ||
* Formats the obligate by date to the last day of the fiscal year. | ||
* @param {number | undefined} obligateBy - The obligate by value | ||
* @returns {string} Formatted date string or "TBD" | ||
*/ | ||
export const formatObligateBy = (obligateBy) => { | ||
if (!obligateBy) return "TBD"; // Default value | ||
if (typeof obligateBy !== "number" || isNaN(obligateBy)) return "TBD"; // Default if parsing fails | ||
|
||
const lastDay = getLastDayOfFiscalYear(obligateBy); | ||
|
||
// Format as MM/DD/YY | ||
return lastDay.toLocaleDateString("en-US", { | ||
month: "2-digit", | ||
day: "2-digit", | ||
year: "2-digit" | ||
}); | ||
}; |
24 changes: 24 additions & 0 deletions
24
frontend/src/components/CANs/CANTable/CANTable.helpers.test.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,24 @@ | ||
import { formatObligateBy } from "./CANTable.helpers"; | ||
|
||
describe("formatObligateBy", () => { | ||
test('returns "TBD" for undefined input', () => { | ||
expect(formatObligateBy(undefined)).toBe("TBD"); | ||
}); | ||
|
||
test('returns "TBD" for non-numeric input', () => { | ||
expect(formatObligateBy("not a number")).toBe("TBD"); | ||
}); | ||
|
||
test('returns "TBD" for NaN input', () => { | ||
expect(formatObligateBy(NaN)).toBe("TBD"); | ||
}); | ||
|
||
test("formats valid fiscal year correctly", () => { | ||
expect(formatObligateBy(2023)).toBe("09/30/23"); | ||
}); | ||
|
||
test("handles different fiscal years", () => { | ||
expect(formatObligateBy(2024)).toBe("09/30/24"); | ||
expect(formatObligateBy(2025)).toBe("09/30/25"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import _ from "lodash"; | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import PaginationNav from "../../UI/PaginationNav"; | ||
import Tooltip from "../../UI/USWDS/Tooltip"; | ||
import CANTableHead from "./CANTableHead"; | ||
import CANTableRow from "./CANTableRow"; | ||
import styles from "./style.module.css"; | ||
import { formatObligateBy } from "./CANTable.helpers"; | ||
|
||
/** | ||
* CANTable component of CanList | ||
* @component | ||
|
@@ -16,7 +17,7 @@ import styles from "./style.module.css"; | |
const CANTable = ({ cans }) => { | ||
const CANS_PER_PAGE = 10; | ||
const [currentPage, setCurrentPage] = React.useState(1); | ||
let cansPerPage = _.cloneDeep(cans); | ||
let cansPerPage = [...cans]; | ||
cansPerPage = cansPerPage.slice((currentPage - 1) * CANS_PER_PAGE, currentPage * CANS_PER_PAGE); | ||
|
||
if (cans.length === 0) { | ||
|
@@ -26,18 +27,18 @@ const CANTable = ({ cans }) => { | |
return ( | ||
<> | ||
<table className={`usa-table usa-table--borderless width-full ${styles.tableHover}`}> | ||
<TableHead /> | ||
<CANTableHead /> | ||
<tbody> | ||
{cansPerPage.map((can) => ( | ||
<CANTableRow | ||
key={can.id} | ||
canId={can.id} | ||
name={can.display_name} | ||
nickname={can.nick_name} | ||
name={can.display_name ?? ""} | ||
nickname={can.nick_name ?? ""} | ||
portfolio={can.portfolio.abbreviation} | ||
fiscalYear={can.funding_budgets[0]?.fiscal_year ?? "TBD"} | ||
activePeriod={can.active_period ?? "TBD"} | ||
obligateBy={can.obligate_by ?? "09/30/25"} | ||
activePeriod={can.active_period?.toString() ?? "TBD"} | ||
obligateBy={formatObligateBy(can.obligate_by)} | ||
transfer={can.funding_details.method_of_transfer ?? "TBD"} | ||
fyBudget={can.funding_budgets[0]?.budget ?? 0} | ||
/> | ||
|
@@ -56,67 +57,6 @@ const CANTable = ({ cans }) => { | |
); | ||
}; | ||
|
||
const TableHead = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to its own component |
||
const availbleTooltip = | ||
"$ Available is the remaining amount of the total budget that is available to plan from (Total FY Budget minus budget lines in Planned, Executing or Obligated Status)"; | ||
return ( | ||
<thead> | ||
<tr> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
CAN | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Portfolio | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
FY | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Active Period | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Obligate By | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Transfer | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
FY Budget | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
<Tooltip label={availbleTooltip}> | ||
<span>$ Available</span> | ||
</Tooltip> | ||
</th> | ||
</tr> | ||
</thead> | ||
); | ||
}; | ||
|
||
CANTable.propTypes = { | ||
cans: PropTypes.array.isRequired | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Tooltip from "../../UI/USWDS/Tooltip"; | ||
|
||
const CANTableHead = () => { | ||
const availbleTooltip = | ||
"$ Available is the remaining amount of the total budget that is available to plan from (Total FY Budget minus budget lines in Planned, Executing or Obligated Status)"; | ||
|
||
return ( | ||
<thead> | ||
<tr> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
CAN | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Portfolio | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
FY | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Active Period | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Obligate By | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
Transfer | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
FY Budget | ||
</th> | ||
<th | ||
scope="col" | ||
style={{ whiteSpace: "nowrap" }} | ||
> | ||
<Tooltip label={availbleTooltip}> | ||
<span>$ Available</span> | ||
</Tooltip> | ||
</th> | ||
</tr> | ||
</thead> | ||
); | ||
}; | ||
|
||
export default CANTableHead; |
Oops, something went wrong.
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.
added
obligate_by
and sorted alphebetically