All files / utils sectionUtils.jsx

100% Statements 72/72
100% Branches 30/30
100% Functions 17/17
100% Lines 65/65

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        15x 2705x       15x 2703x 2703x 2703x 2692x 2692x 5x     2688x   15x         15x 2698x 2698x 2698x 2689x       2689x       5x     2683x   15x         15x 2703x 2703x 2703x 2692x       2692x 5x     2688x   15x         15x 2703x 2703x 2703x 2614x 2614x 4x     2688x   15x       15x 2x       15x 2688x 85x 2603x 1x 2602x 787x   1815x       15x 5461x   15x 4664x   2331x                           2331x                           2597x 2597x 2597x 2597x     1739x   15x 3x   15x 1736x     26237x       12455x    
import { hhmmTohhmma, convertToTimeRange } from "main/utils/timeUtils.jsx";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
 
export const convertToFraction = (en1, en2) => {
  return en1 != null && en2 != null ? `${en1}/${en2}` : "";
};
 
// Takes a time location array and returns the locations
export const formatLocation = (timeLocationArray) => {
  try {
    let res = "";
    for (let index = 0; index < timeLocationArray.length; index++) {
      res += `${timeLocationArray[index].building} ${timeLocationArray[index].room}`;
      if (index + 1 < timeLocationArray.length) {
        res += `, `;
      }
    }
    return res;
  } catch {
    return "";
  }
};
 
// Takes a time location array and returns the days
export const formatDays = (timeLocationArray) => {
  try {
    let res = "";
    for (let index = 0; index < timeLocationArray.length; index++) {
      res +=
        timeLocationArray[index].days !== null
          ? `${timeLocationArray[index].days}`
          : "";
      if (
        index + 1 < timeLocationArray.length &&
        timeLocationArray[index].days !== null
      ) {
        res += `, `;
      }
    }
    return res;
  } catch {
    return "";
  }
};
 
// Takes a time location array and returns the time range
export const formatTime = (timeLocationArray) => {
  try {
    let res = "";
    for (let index = 0; index < timeLocationArray.length; index++) {
      res += convertToTimeRange(
        hhmmTohhmma(timeLocationArray[index].beginTime),
        hhmmTohhmma(timeLocationArray[index].endTime),
      );
      if (index + 1 < timeLocationArray.length) {
        res += `, `;
      }
    }
    return res;
  } catch {
    return "";
  }
};
 
// Takes a instructors array and returns the instructors
export const formatInstructors = (instructorArray) => {
  try {
    let res = "";
    for (let index = 0; index < instructorArray.length; index++) {
      res += `${instructorArray[index].instructor}`;
      if (index + 1 < instructorArray.length) {
        res += `, `;
      }
    }
    return res;
  } catch {
    return "";
  }
};
 
export const isSection = (en1) => {
  return en1.substring(2) !== "00";
};
 
// returns the course status based on cancel, closed, or full
export const formatStatus = (section) => {
  if (section.courseCancelled) {
    return "Cancelled";
  } else if (section.classClosed === "Y") {
    return "Closed";
  } else if (section.enrolledTotal >= section.maxEnroll) {
    return "Full";
  } else {
    return "Open";
  }
};
 
export const getQuarter = (row) =>
  row.depth === 0 ? row.original.quarter : row.getParentRow().original.quarter;
 
export const formatInfoLink = (row) =>
  `/coursedetails/${getQuarter(row)}/${getSectionField(row, "enrollCode")}`;
 
export const renderInfoLink = (row, testid) => (
  <p className="text-center">
    <a
      href={formatInfoLink(row)}
      data-testid={`${testid}-row-${row.id}-col-info-link`}
      target={"_blank"}
      rel="noopener noreferrer"
      style={{ color: "black", backgroundColor: "inherit" }}
    >
      <FontAwesomeIcon icon={faInfoCircle} />
    </a>
  </p>
);
 
export const renderDetailPageLink = (row, testid) => (
  <p className="text-center">
    <a
      href={formatInfoLink(row)}
      data-testid={`${testid}-row-${row.id}-col-detail-link`}
      target={"_blank"}
      rel="noopener noreferrer"
    >
      {row.original.courseId}
    </a>
  </p>
);
 
export function enrollmentFraction(row) {
  const num = getSectionField(row, "enrolledTotal");
  const denom = getSectionField(row, "maxEnroll");
  const result = convertToFraction(num, denom);
  return result;
}
 
export const isPrimary = (row) => "primary" in row.original;
 
export const isLectureWithNoSections = (row) =>
  isPrimary(row) && row.original.subRows.length === 0;
 
export const shouldShowAddToScheduleLink = (row) =>
  !isPrimary(row) || row.original.subRows.length === 0;
 
export function getSection(row) {
  return "primary" in row.original ? row.original.primary : row.original;
}
 
export function getSectionField(row, key) {
  return getSection(row)[key];
}