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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | 50x 303x 229x 74x 50x 2x 2x 2x 50x 303x 42x 6x 6x 6x 6x 6x 6x 6x 6x 12x 12x 6x 6x 42x 50x 303x 303x 49x 254x 58x 58x 9x 196x 49x 2x 147x 49x 98x 49x 49x 50x | import OurTable from "main/components/OurTable";
import { Tooltip, OverlayTrigger, Button, Spinner } from "react-bootstrap";
import { Link } from "react-router";
const columns = (courseShowRoutePrefix, testId) => [
{
header: "id",
accessorKey: "id", // accessor is the "key" in the data
},
{
header: "Course Name",
id: "courseName",
cell: ({ cell }) => {
if (!courseShowRoutePrefix) {
return cell.row.original.courseName;
}
return (
<OverlayTrigger
placement="right"
overlay={
<Tooltip id={`tooltip-coursename-${cell.row.index}`}>
View course details
</Tooltip>
}
>
<Link
to={`${courseShowRoutePrefix}/${cell.row.original.id}`}
data-testid={`${testId}-cell-row-${cell.row.index}-col-${cell.column.id}-link`}
>
{cell.row.original.courseName}
</Link>
</OverlayTrigger>
);
},
},
{
header: "Term",
accessorKey: "term",
},
{
header: "School",
id: "school",
accessorKey: "school.displayName",
},
];
export default function CoursesTable({
courses,
testId,
joinCallback,
isLoading,
courseShowRoutePrefix,
}) {
const viewInviteCallback = (cell) => {
const organizationName = cell.row.original.orgName;
const gitInvite = `https://github.com/orgs/${organizationName}/invitation`;
window.open(gitInvite, "_blank");
};
const renderTooltip = (studentStatus) =>
function TooltipWrapper(props) {
let set_message;
switch (studentStatus) {
case "PENDING":
set_message =
"This course has not been completely set up by your instructor yet.";
break;
case "JOINCOURSE":
set_message =
"Clicking this button will generate an invitation to the GitHub organization associated with this course.";
break;
case "INVITED":
set_message =
"You have been invited to the GitHub organization associated with this course, but you still need to accept or decline the invitation. Please accept it if you plan to stay enrolled, and decline only if you plan to withdraw from the course.";
break;
case "OWNER":
set_message =
"You are an owner of the GitHub organization associated with this course.";
break;
case "MEMBER":
set_message =
"You are a member of the GitHub organization associated with this course.";
break;
default:
set_message = "Tooltip for illegal status that will never occur";
break;
}
return (
<Tooltip id={`${studentStatus.toLowerCase()}-tooltip`} {...props}>
{set_message}
</Tooltip>
);
};
const columnsWithStatus = [
...columns(courseShowRoutePrefix, testId),
{
header: "Status",
accessorKey: "studentStatus",
cell: ({ cell }) => {
const status = cell.row.original.studentStatus;
if (status === "PENDING") {
return (
<OverlayTrigger
placement="right"
overlay={renderTooltip("PENDING")}
>
<span className="text-warning">Pending</span>
</OverlayTrigger>
);
} else if (status === "JOINCOURSE") {
const cellIsLoading = isLoading(cell);
return (
<OverlayTrigger
placement="right"
overlay={renderTooltip("JOINCOURSE")}
>
<span>
<Button
variant={"primary"}
onClick={() => joinCallback(cell)}
data-testid={`${testId}-cell-row-${cell.row.index}-col-${cell.column.id}-button`}
disabled={cellIsLoading}
>
{cellIsLoading ? (
<>
<Spinner
as="span"
animation="grow"
size="sm"
role="status"
/>
Joining...
</>
) : (
<>Join Course</>
)}
</Button>
</span>
</OverlayTrigger>
);
} else if (status === "INVITED") {
return (
<OverlayTrigger
placement="right"
overlay={renderTooltip("INVITED")}
>
<span>
<Button
variant={"primary"}
onClick={() => viewInviteCallback(cell)}
data-testid={`${testId}-cell-row-${cell.row.index}-col-${cell.column.id}-button`}
>
View Invite
</Button>
</span>
</OverlayTrigger>
);
} else if (status === "OWNER") {
return (
<OverlayTrigger placement="right" overlay={renderTooltip("OWNER")}>
<span className="text-info">Owner</span>
</OverlayTrigger>
);
} else if (status === "MEMBER") {
return (
<OverlayTrigger placement="right" overlay={renderTooltip("MEMBER")}>
<span className="text-primary">Member</span>
</OverlayTrigger>
);
}
return (
<OverlayTrigger
placement="right"
overlay={renderTooltip(cell.row.original.studentStatus)}
>
<span>{status}</span>
</OverlayTrigger>
);
},
},
];
return (
<OurTable data={courses} columns={columnsWithStatus} testid={testId} />
);
}
|