All files / components/Reviews ReviewTable.js

100% Statements 9/9
75% Branches 12/16
33.33% Functions 2/6
100% Lines 9/9

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                      38x     79x             38x 21x     21x         38x 1x               1x         38x    
import OurTable, { ButtonColumn } from "main/components/OurTable";
 
export default function ReviewTable({
  data,
  userOptions,
  moderatorOptions,
  onEdit,
  onDelete,
  onApprove,
  onReject,
}) {
  const columns = [
    {
      Header: "Item ID",
      accessor: (row) => row.item?.id ?? row.item ?? row.itemId ?? "",
    },
    { Header: "Score", accessor: "itemsStars" },
    { Header: "Comments", accessor: "reviewerComments" },
    { Header: "Date Served", accessor: "dateItemServed" },
  ];
 
  if (userOptions) {
    columns.push(
      ButtonColumn("Edit", "primary", onEdit || (() => {}), "ReviewTable"),
    );
    columns.push(
      ButtonColumn("Delete", "danger", onDelete || (() => {}), "ReviewTable"),
    );
  }
 
  if (moderatorOptions) {
    columns.push(
      ButtonColumn(
        "Approve",
        "success",
        onApprove || (() => {}),
        "ReviewTable",
      ),
    );
    columns.push(
      ButtonColumn("Reject", "danger", onReject || (() => {}), "ReviewTable"),
    );
  }
 
  return <OurTable data={data} columns={columns} testid="ReviewTable" />;
}