-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(package-actions): Consolidate package checks for now (#281)
- Loading branch information
Kevin Haube
authored
Jan 2, 2024
1 parent
37e9867
commit 21a821f
Showing
7 changed files
with
83 additions
and
86 deletions.
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
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
9 changes: 4 additions & 5 deletions
9
src/packages/shared-utils/package-actions/getAvailableActions.ts
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,18 +1,17 @@ | ||
import { | ||
ActionAvailabilityCheck, | ||
CognitoUserAttributes, | ||
OsMainSourceItem, | ||
PlanTypeCheck, | ||
PlanType, | ||
} from "../../shared-types"; | ||
import rules from "./rules"; | ||
import { PackageCheck } from "../packageCheck"; | ||
|
||
export const getAvailableActions = ( | ||
user: CognitoUserAttributes, | ||
result: OsMainSourceItem | ||
) => { | ||
const actionChecker = ActionAvailabilityCheck(result); | ||
return PlanTypeCheck(result.planType).is([PlanType.MED_SPA]) | ||
? rules.filter((r) => r.check(actionChecker, user)).map((r) => r.action) | ||
const checks = PackageCheck(result); | ||
return checks.planTypeIs([PlanType.MED_SPA]) | ||
? rules.filter((r) => r.check(checks, user)).map((r) => r.action) | ||
: []; | ||
}; |
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,71 @@ | ||
import { OsMainSourceItem, PlanType, SEATOOL_STATUS } from "../shared-types"; | ||
import { getLatestRai } from "./rai-helper"; | ||
|
||
const secondClockStatuses = [ | ||
SEATOOL_STATUS.PENDING, | ||
SEATOOL_STATUS.PENDING_APPROVAL, | ||
SEATOOL_STATUS.PENDING_CONCURRENCE, | ||
]; | ||
|
||
const checkPlan = (planType: PlanType | null, validPlanTypes: PlanType[]) => | ||
!planType | ||
? false | ||
: validPlanTypes.includes(planType.toLowerCase() as PlanType); | ||
|
||
const checkStatus = (seatoolStatus: string, authorized: string | string[]) => | ||
typeof authorized === "string" | ||
? seatoolStatus === authorized | ||
: authorized.includes(seatoolStatus); | ||
|
||
/** A object of booleans and methods handling common conditions | ||
* for business logic. */ | ||
export const PackageCheck = ({ | ||
seatoolStatus, | ||
rais, | ||
raiWithdrawEnabled, | ||
planType, | ||
}: OsMainSourceItem) => { | ||
const latestRai = getLatestRai(rais); | ||
const planChecks = { | ||
isSpa: checkPlan(planType, [PlanType.MED_SPA, PlanType.CHIP_SPA]), | ||
isWaiver: checkPlan(planType, []), | ||
/** Keep excess methods to a minimum with `is` **/ | ||
planTypeIs: (validPlanTypes: PlanType[]) => | ||
checkPlan(planType, validPlanTypes), | ||
}; | ||
const statusChecks = { | ||
/** Is in any of our pending statuses, sans Pending-RAI **/ | ||
isInActivePendingStatus: checkStatus(seatoolStatus, [ | ||
...secondClockStatuses, | ||
SEATOOL_STATUS.PENDING_OFF_THE_CLOCK, | ||
]), | ||
/** Is in a second clock status and RAI has been received **/ | ||
isInSecondClock: | ||
!planChecks.planTypeIs([PlanType.CHIP_SPA]) && | ||
checkStatus(seatoolStatus, secondClockStatuses) && | ||
latestRai?.status === "received", | ||
/** Is in any status except Package Withdrawn **/ | ||
isNotWithdrawn: !checkStatus(seatoolStatus, SEATOOL_STATUS.WITHDRAWN), | ||
/** Added for elasticity, but common checks should always bubble up as | ||
* object attributes! **/ | ||
hasStatus: (authorizedStatuses: string | string[]) => | ||
checkStatus(seatoolStatus, authorizedStatuses), | ||
}; | ||
const raiChecks = { | ||
/** Latest RAI is requested and status is Pending-RAI **/ | ||
hasRequestedRai: latestRai?.status === "requested", | ||
/** Latest RAI is not null **/ | ||
hasLatestRai: latestRai !== null, | ||
/** Latest RAI has been responded to **/ | ||
hasRaiResponse: latestRai?.status === "received", | ||
/** RAI Withdraw has been enabled **/ | ||
hasEnabledRaiWithdraw: raiWithdrawEnabled, | ||
}; | ||
return { | ||
...planChecks, | ||
...statusChecks, | ||
...raiChecks, | ||
}; | ||
}; | ||
|
||
export type IPackageCheck = ReturnType<typeof PackageCheck>; |
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