All files / components/Concept SubConceptTable.jsx

83.33% Statements 10/12
47.91% Branches 23/48
50% Functions 2/4
83.33% Lines 10/12

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                53x                                                                               53x 27x 3x     24x 2x     22x       22x 22x           53x        
import OurTable, { ButtonColumn } from "main/components/Common/OurTable";
 
export default function SubConceptTable({
  subConcepts = [],
  editCallback = () => {},
  deleteCallback = () => {},
  testId = "SubConceptTable",
}) {
  const columns = [
    {
      header: "id",
      accessorKey: "id",
      id: "id",
    },
    {
      header: "label",
      accessorKey: "label",
      id: "label",
    },
    {
      header: "parentId",
      accessorKey: "parentId",
      id: "parentId",
    },
    {
      header: "parentLabel",
      accessorKey: "parentLabel",
      id: "parentLabel",
    },
    {
      header: "parentLevel",
      accessorKey: "parentLevel",
      id: "parentLevel",
    },
    {
      header: "parentX",
      accessorKey: "parentX",
      id: "parentX",
    },
    {
      header: "sortOrder",
      accessorKey: "sortOrder",
      id: "sortOrder",
    },
    ButtonColumn("Edit", "primary", editCallback, testId),
    ButtonColumn("Delete", "danger", deleteCallback, testId),
  ];
 
  const sortedSubConcepts = [...subConcepts].sort((a, b) => {
    if ((a.parentLevel ?? 0) !== (b.parentLevel ?? 0)) {
      return (a.parentLevel ?? 0) - (b.parentLevel ?? 0);
    }
 
    if ((a.parentX ?? 0) !== (b.parentX ?? 0)) {
      return (a.parentX ?? 0) - (b.parentX ?? 0);
    }
 
    Iif ((a.parentLabel ?? "") !== (b.parentLabel ?? "")) {
      return (a.parentLabel ?? "").localeCompare(b.parentLabel ?? "");
    }
 
    Eif ((a.sortOrder ?? 0) !== (b.sortOrder ?? 0)) {
      return (a.sortOrder ?? 0) - (b.sortOrder ?? 0);
    }
 
    return (a.id ?? 0) - (b.id ?? 0);
  });
 
  return (
    <OurTable data={sortedSubConcepts} columns={columns} testid={testId} />
  );
}