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 49 50 51 52 53 54 55 56 57 58 59 60 61 | 4x 171x 134x 284x 284x 4x 4x 4x 4x 4x 2x 2x 2x 2x 2x 4x | import { TPatchPayload } from "@services/api/accessControl/accessControl";
import { IAssignmentFilter, TPermissionsData } from "../types";
type TReduceDataFn = (
filter: IAssignmentFilter,
data?: TPermissionsData,
) => TPermissionsData;
export const dataReducerWithFilter: TReduceDataFn = (filter, data) => {
if (!data) return {};
return Object.entries(data).reduce((acc, [key, values]) => {
Iif (
(filter.assigned === 1 && values.isDeny) ||
(filter.assigned === 0 && !values.isDeny)
) {
return acc;
}
return {
...acc,
[key]: values,
};
}, {});
};
type Assignment = "allow" | "detach";
type Effect = "allow" | "deny";
type PayloadType = {
assignment: Assignment[];
effect: Effect[];
};
const actionValues: PayloadType = {
assignment: ["allow", "detach"],
effect: ["allow", "deny"],
};
type TCreatePayload = (
data: TPermissionsData,
payloadType: keyof PayloadType,
) => TPatchPayload;
export const createPayload: TCreatePayload = (data, payloadType) => {
const payload = {} as TPatchPayload;
const actions = actionValues[payloadType];
Object.values(data).forEach((value) => {
const attribute =
payloadType === "assignment" ? !value.isAttached : value.isDeny;
const action = attribute ? actions[1] : actions[0];
const id = value.id;
const prevValues = payload[action] || [];
payload[action] = [...prevValues, id];
});
return payload;
};
|