All files / react-app/src/features/dashboard/Lists/waivers index.tsx

97.61% Statements 41/42
97.95% Branches 48/49
100% Functions 27/27
97.36% Lines 37/38

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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166                      5x 14x 1x     13x 897x   13x   13x                             28x           28x 869x         28x   869x         28x 869x           28x 28x 14x     14x     28x       28x     869x 869x 582x 430x                                     28x                   28x       87x               28x                   28x   58x           28x                   28x 29x         28x 869x         5x 26x      
import { useMemo } from "react";
import { CMS_READ_ONLY_ROLES, opensearch, SEATOOL_STATUS, UserRoles } from "shared-types";
import { formatActionType, formatDateToET, formatDateToUTC } from "shared-utils";
 
import { OneMacUser } from "@/api";
import { OsMainView, OsTableColumn } from "@/components";
import { BLANK_VALUE } from "@/consts";
import { removeUnderscoresAndCapitalize } from "@/utils";
 
import { CellDetailsLink, renderCellActions, renderCellDate } from "../renderCells";
 
const getColumns = ({ isCms, user }: OneMacUser): OsTableColumn[] => {
  if (!user || user === null) {
    return [];
  }
 
  const getDraftAwareSubmitterName = (data: opensearch.main.Document) =>
    data.seatoolStatus === SEATOOL_STATUS.DRAFT ? BLANK_VALUE : (data.submitterName ?? BLANK_VALUE);
 
  return [
    // hide actions column for: readonly,help desk
    ...(!CMS_READ_ONLY_ROLES.some((UR) => user.role === UR)
      ? [
          {
            locked: true,
            isSystem: true,
            label: "Actions",
            cell: renderCellActions(user),
          },
        ]
      : []),
    {
      props: { className: "w-[200px]" },
      field: "id.keyword",
      label: "Waiver Number",
      locked: true,
      transform: (data) => data.id,
      cell: (data) => <CellDetailsLink record={data} />,
    },
    {
      field: "state.keyword",
      label: "State",
      transform: (data) => data.state ?? BLANK_VALUE,
      cell: (data) => data.state,
    },
    {
      field: "authority.keyword",
      label: "Authority",
      transform: (data) => data.authority ?? BLANK_VALUE,
      cell: (data) =>
        data?.authority ? removeUnderscoresAndCapitalize(data.authority) : BLANK_VALUE,
    },
    {
      field: "actionType.keyword",
      label: "Action Type",
      transform: (data) => formatActionType(data.actionType),
      cell: (data) => formatActionType(data.actionType),
    },
    {
      field: isCms ? "cmsStatus.keyword" : "stateStatus.keyword",
      label: "Status",
      transform: (data) => {
        const status = (() => {
          if (!isCms) return data.stateStatus;
          Iif (user.role === UserRoles.HELPDESK) {
            return data.stateStatus;
          }
          return data.cmsStatus;
        })();
 
        const subStatusRAI = data.raiWithdrawEnabled
          ? " (Withdraw Formal RAI Response - Enabled)"
          : "";
 
        return `${status}${subStatusRAI}`;
      },
      cell: (data) => {
        const status = (() => {
          if (!isCms) return data.stateStatus;
          if (user.role === UserRoles.HELPDESK) return data.stateStatus;
          return data.cmsStatus;
        })();
 
        return (
          <>
            <p className={data.seatoolStatus === SEATOOL_STATUS.DRAFT ? "italic" : ""}>{status}</p>
            {data.raiWithdrawEnabled &&
              data.seatoolStatus !== SEATOOL_STATUS.PENDING_APPROVAL &&
              data.seatoolStatus !== SEATOOL_STATUS.PENDING_CONCURRENCE && (
                <p className="text-xs opacity-65">ยท Withdraw Formal RAI Response - Enabled</p>
              )}
          </>
        );
      },
    },
    {
      field: "submissionDate",
      label: "Initial Submission",
      transform: (data) =>
        data?.submissionDate
          ? formatDateToET(data.submissionDate, "MM/dd/yyyy", false)
          : BLANK_VALUE,
      cell: renderCellDate("submissionDate"),
    },
    {
      field: "finalDispositionDate",
      label: "Final Disposition",
      hidden: true,
      transform: (data) =>
        data?.finalDispositionDate
          ? formatDateToUTC(data.finalDispositionDate, "MM/dd/yyyy")
          : BLANK_VALUE,
      cell: (data) =>
        data?.finalDispositionDate
          ? formatDateToUTC(data.finalDispositionDate, "MM/dd/yyyy")
          : BLANK_VALUE,
    },
    {
      field: "makoChangedDate",
      label: "Latest Package Activity",
      transform: (data) =>
        data.makoChangedDate
          ? formatDateToET(data.makoChangedDate, "MM/dd/yyyy", false)
          : BLANK_VALUE,
      cell: renderCellDate("makoChangedDate"),
    },
    {
      field: "raiRequestedDate",
      label: "Formal RAI Requested",
      hidden: true,
      transform: (data) =>
        data?.raiRequestedDate ? formatDateToUTC(data.raiRequestedDate, "MM/dd/yyyy") : BLANK_VALUE,
      cell: (data) =>
        data?.raiRequestedDate ? formatDateToUTC(data.raiRequestedDate, "MM/dd/yyyy") : BLANK_VALUE,
    },
    {
      field: "raiReceivedDate",
      label: "Formal RAI Response",
      transform: (data) => {
        return data.raiReceivedDate
          ? formatDateToET(data.raiReceivedDate, "MM/dd/yyyy", false)
          : BLANK_VALUE;
      },
      cell: renderCellDate("raiReceivedDate"),
    },
    {
      field: "leadAnalystName.keyword",
      label: "CPOC Name",
      hidden: true,
      transform: (data) => data.leadAnalystName ?? BLANK_VALUE,
      cell: (data) => data.leadAnalystName,
    },
    {
      field: "submitterName.keyword",
      label: "Submitted By",
      transform: (data) => getDraftAwareSubmitterName(data),
      cell: (data) => getDraftAwareSubmitterName(data),
    },
  ];
};
 
export const WaiversList = ({ oneMacUser }: { oneMacUser: OneMacUser }) => {
  const columns = useMemo(() => getColumns(oneMacUser), [oneMacUser]);
  return <OsMainView columns={columns} />;
};