All files / src/features/Permissions/ModalV2/utils permissionPanel.utils.ts

78.94% Statements 15/19
50% Branches 6/12
80% Functions 4/5
76.47% Lines 13/17

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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80        4x                                           4x         82x 82x 41x   41x 63x           109x     4x                                           4x       171x 171x   171x          
import { groupData } from "features/Permissions/Modal/utils";
import { IAssignmentFilter, TPermissionsData } from "../types";
import { dataReducerWithFilter } from "./permissionData.utils";
 
const defaultTabs = [
  {
    label: "Acquirer",
    hidden: false,
    disabled: true,
  },
  {
    label: "Provider",
    hidden: false,
    disabled: true,
  },
  {
    label: "Merchant",
    hidden: false,
    disabled: true,
  },
];
 
type TGroup = {
  [k: string]: string[];
};
 
export const generateDynamicTabs = (
  showLatest: boolean,
  dataGroups: TGroup,
  latestDataGroups: TGroup,
) => {
  let dynamicTabs: typeof defaultTabs = [];
  if (!showLatest && !Object.keys(dataGroups).length) {
    dynamicTabs = defaultTabs;
  } else {
    const groups = showLatest ? latestDataGroups : dataGroups;
    dynamicTabs = Object.keys(groups).map((g) => ({
      label: g,
      disabled: false,
      hidden: false,
    }));
  }
  return dynamicTabs.sort((a, b) => a.label.localeCompare(b.label));
};
 
export const updateDataHandler = (key: string, value: boolean, old: any) => {
  if (!old || !old[key])
    return {
      assigned: value || false,
      key,
      data: old,
    };
 
  const assigned = value;
  return {
    assigned,
    key,
    data: {
      ...old,
      [key]: {
        ...old[key],
        assigned,
      },
    },
  };
};
 
export const generateGroupedData = (
  filter: IAssignmentFilter,
  rawData?: TPermissionsData,
) => {
  const customData = dataReducerWithFilter(filter, rawData);
  const groups = groupData(customData);
 
  return {
    data: customData,
    groups,
  };
};