Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 283x 1529x 1529x 1529x 179x 1529x 1708x 1708x 14319x 1529x 1708x 179x 1529x 1708x 511x 1529x 1529x 2x 4x 1529x 18348x 1529x 1526x 1529x | import { Action, FullUser, opensearch } from "shared-types";
import { PackageCheck } from "../package-check";
import rules from "./rules";
export const getAvailableActions = (user: FullUser, result: opensearch.main.Document) => {
const allActions: Action[][] = [];
const allMembers = [result];
if (result.appkChildren) {
allMembers.push(...result.appkChildren.map((el) => el._source));
}
allMembers.forEach((element) => {
const checks = PackageCheck(element);
allActions.push([
...(checks.isWaiver || checks.isSpa
? rules.filter((r) => r.check(checks, user)).map((r) => r.action)
: []),
]);
});
let commonActions = allActions.reduce((acc, currentActions, index) => {
if (index === 0) return currentActions;
return acc.filter((action: Action) => currentActions.includes(action));
}, []);
const allRaiRequestedDates = allMembers
.filter((member) => (member as opensearch.main.SeatoolDocument)?.raiRequestedDate !== undefined)
.map((member) => (member as opensearch.main.SeatoolDocument)?.raiRequestedDate);
const isRaiRequestedDateIdentical = allRaiRequestedDates.every((date, _, arr) => date === arr[0]);
if (!isRaiRequestedDateIdentical) {
const actionsToRemove = [Action.RESPOND_TO_RAI, Action.WITHDRAW_RAI];
commonActions = commonActions.filter((action: any) => !actionsToRemove.includes(action));
}
// We are sorting the actions based on the value they are in the order of the enum.
// If we want to update this order just move the values around.
const actionOrder = Object.values(Action);
const orderMap = new Map(actionOrder.map((action, index) => [action, index]));
const sortedActions = commonActions.sort(
(a, b) => (orderMap.get(a) ?? Infinity) - (orderMap.get(b) ?? Infinity),
);
return sortedActions;
};
|