From eef96e2ed57001c229c0e076f100a28678d3ee12 Mon Sep 17 00:00:00 2001 From: Jalen Wu Date: Wed, 18 Sep 2024 23:50:14 -0400 Subject: [PATCH 1/3] #2808: Added a function in work-package.utils to get overdue work packages --- src/frontend/src/utils/work-package.utils.ts | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/utils/work-package.utils.ts b/src/frontend/src/utils/work-package.utils.ts index 31ebcb98fa..27024ad148 100644 --- a/src/frontend/src/utils/work-package.utils.ts +++ b/src/frontend/src/utils/work-package.utils.ts @@ -1,4 +1,4 @@ -import { WbsElement, wbsPipe } from 'shared'; +import { WbsElement, WbsElementStatus, wbsPipe, WorkPackage } from 'shared'; import { WPFormType } from './form'; export const getTitleFromFormType = (formType: WPFormType, wbsElement: WbsElement): string => { @@ -11,3 +11,23 @@ export const getTitleFromFormType = (formType: WPFormType, wbsElement: WbsElemen return `${wbsPipe(wbsElement.wbsNum)} - ${wbsElement.name}`; } }; + +/** + * Given a list of work packages, return the work packages that are overdue. + * @param wpList a list of work packages. + * @returns a list of work packages that are overdue. + */ +export const getOverdueWorkPackages = (wpList : WorkPackage[]) : WorkPackage[] => { + const overdueWorkPackages : WorkPackage[] = []; + + for(let i = 0; i < wpList.length ; i++){ + const curr = wpList[i]; + + // if the work package is anything but complete and the end date is before today, it is overdue. + if(curr.status !== WbsElementStatus.Complete && curr.endDate < new Date()){ + overdueWorkPackages.push(curr); + } + } + + return overdueWorkPackages; +}; \ No newline at end of file From 3bc421ea2381e6bf924aa1bcf1c4c0a560b42dcb Mon Sep 17 00:00:00 2001 From: Jalen Wu Date: Thu, 19 Sep 2024 00:14:37 -0400 Subject: [PATCH 2/3] #2808 formatting changes --- src/frontend/src/utils/work-package.utils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/utils/work-package.utils.ts b/src/frontend/src/utils/work-package.utils.ts index 27024ad148..a4aa31a854 100644 --- a/src/frontend/src/utils/work-package.utils.ts +++ b/src/frontend/src/utils/work-package.utils.ts @@ -17,17 +17,17 @@ export const getTitleFromFormType = (formType: WPFormType, wbsElement: WbsElemen * @param wpList a list of work packages. * @returns a list of work packages that are overdue. */ -export const getOverdueWorkPackages = (wpList : WorkPackage[]) : WorkPackage[] => { - const overdueWorkPackages : WorkPackage[] = []; +export const getOverdueWorkPackages = (wpList: WorkPackage[]): WorkPackage[] => { + const overdueWorkPackages: WorkPackage[] = []; - for(let i = 0; i < wpList.length ; i++){ + for (let i = 0; i < wpList.length; i++) { const curr = wpList[i]; // if the work package is anything but complete and the end date is before today, it is overdue. - if(curr.status !== WbsElementStatus.Complete && curr.endDate < new Date()){ + if (curr.status !== WbsElementStatus.Complete && curr.endDate < new Date()) { overdueWorkPackages.push(curr); } } return overdueWorkPackages; -}; \ No newline at end of file +}; From 5b3b38d894d848f16de7d83d2804fa80fc747d71 Mon Sep 17 00:00:00 2001 From: Jalen Wu Date: Thu, 19 Sep 2024 00:25:55 -0400 Subject: [PATCH 3/3] #2808 used filter to make function less verbose --- src/frontend/src/utils/work-package.utils.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/frontend/src/utils/work-package.utils.ts b/src/frontend/src/utils/work-package.utils.ts index a4aa31a854..8a631082f5 100644 --- a/src/frontend/src/utils/work-package.utils.ts +++ b/src/frontend/src/utils/work-package.utils.ts @@ -18,16 +18,5 @@ export const getTitleFromFormType = (formType: WPFormType, wbsElement: WbsElemen * @returns a list of work packages that are overdue. */ export const getOverdueWorkPackages = (wpList: WorkPackage[]): WorkPackage[] => { - const overdueWorkPackages: WorkPackage[] = []; - - for (let i = 0; i < wpList.length; i++) { - const curr = wpList[i]; - - // if the work package is anything but complete and the end date is before today, it is overdue. - if (curr.status !== WbsElementStatus.Complete && curr.endDate < new Date()) { - overdueWorkPackages.push(curr); - } - } - - return overdueWorkPackages; + return wpList.filter((wp) => wp.status !== WbsElementStatus.Complete && wp.endDate < new Date()); };