|
1 | 1 | import { createColumnHelper, Row } from "@tanstack/react-table";
|
2 |
| -import { Button } from "react-bootstrap"; |
3 |
| -import { BsPencilFill, BsPersonXFill } from "react-icons/bs"; |
4 |
| -import { MdContentCopy, MdDelete } from "react-icons/md"; |
| 2 | +import { Button, Tooltip, OverlayTrigger, Badge } from "react-bootstrap"; |
5 | 3 | import { ICourseResponse as ICourse } from "../../utils/interfaces";
|
6 | 4 |
|
7 | 5 | /**
|
8 |
| - * @author Atharva Thorve, on December, 2023 |
9 |
| - * @author Mrityunjay Joshi on December, 2023 |
10 |
| - */ |
| 6 | + * Author: Suraj Raghu Kumar on October 27, 2023 |
| 7 | + Author: Yuktasree Muppala on October 27, 2023 |
| 8 | + Author: Harvardhan Patil on October 27, 2023 |
| 9 | + */ |
11 | 10 |
|
12 |
| -// Course Columns Configuration: Defines the columns for the courses table |
13 | 11 | type Fn = (row: Row<ICourse>) => void;
|
| 12 | + |
14 | 13 | const columnHelper = createColumnHelper<ICourse>();
|
15 |
| -export const courseColumns = (handleEdit: Fn, handleDelete: Fn, handleTA: Fn, handleCopy: Fn) => [ |
16 |
| - // Column for the course name |
| 14 | + |
| 15 | +export const courseColumns = ( |
| 16 | + handleEdit: Fn, |
| 17 | + handleDelete: Fn, |
| 18 | + handleTA: Fn, |
| 19 | + handleCopy: Fn, |
| 20 | + |
| 21 | +) => [ |
17 | 22 | columnHelper.accessor("name", {
|
18 | 23 | id: "name",
|
19 |
| - header: "Name", |
| 24 | + header: () => <span style={{ fontWeight: 'bold', color: '#000000', fontSize: '1.17em' }}>Course Name</span>, |
| 25 | + cell: (info) => ( |
| 26 | + <div className="d-flex justify-content-start align-items-center" style={{ fontSize: '1.1em', padding: '8px 0' }}> |
| 27 | + <span style={{ color: '#000000' }}>{info.getValue()}</span> |
| 28 | + </div> |
| 29 | + ), |
20 | 30 | enableSorting: true,
|
21 | 31 | enableColumnFilter: true,
|
22 | 32 | enableGlobalFilter: false,
|
23 | 33 | }),
|
| 34 | + |
24 | 35 |
|
25 |
| - // Column for the institution name |
26 | 36 | columnHelper.accessor("institution.name", {
|
27 | 37 | id: "institution",
|
28 |
| - header: "Institution", |
| 38 | + header: () => <span style={{ fontWeight: 'bold', color: '#000000', fontSize: '1.17em' }}>Institution</span>, |
29 | 39 | enableSorting: true,
|
30 | 40 | enableMultiSort: true,
|
31 | 41 | enableGlobalFilter: false,
|
| 42 | + cell: (info) => ( |
| 43 | + <div className="d-flex justify-content-start align-items-center" style={{ fontSize: '1.17em', padding: '8px 0' }}> |
| 44 | + <span>{info.getValue() || <Badge bg="secondary">Not Available</Badge>}</span> |
| 45 | + </div> |
| 46 | + ), |
32 | 47 | }),
|
33 | 48 |
|
34 |
| - // Column for the creation date |
35 |
| - columnHelper.accessor("created_at", { |
36 |
| - header: "Creation Date", |
| 49 | + columnHelper.accessor("instructor.name", { |
| 50 | + id: "instructor", |
| 51 | + header: () => <span style={{ fontWeight: 'bold', color: '#000000', fontSize: '1.17em' }}>Instructor</span>, |
37 | 52 | enableSorting: true,
|
38 |
| - enableColumnFilter: false, |
| 53 | + enableColumnFilter: true, |
39 | 54 | enableGlobalFilter: false,
|
| 55 | + cell: ({ row }) => { |
| 56 | + const instructor = row.original.instructor; |
| 57 | + return ( |
| 58 | + <div className="d-flex justify-content-start align-items-center" style={{ fontSize: '1.17em', |
| 59 | + padding: '8px 0' }}> |
| 60 | + <span> |
| 61 | + {instructor && instructor.name ? ( |
| 62 | + instructor.name |
| 63 | + ) : ( |
| 64 | + <Badge bg="danger">Unassigned</Badge> |
| 65 | + )} |
| 66 | + </span> |
| 67 | + </div> |
| 68 | + ); |
| 69 | + }, |
| 70 | + }), |
| 71 | + |
| 72 | + columnHelper.accessor("created_at", { |
| 73 | + header: () => <span style={{ fontWeight: 'bold', color: '#000000', fontSize: '1.17em' }}>Creation Date</span>, |
| 74 | + enableSorting: true, |
| 75 | + enableColumnFilter: true, |
| 76 | + enableGlobalFilter: true, |
| 77 | + cell: (info) => ( |
| 78 | + <div className="d-flex justify-content-start align-items-center" style={{ fontSize: '1.17em', padding: '8px 0' }}> |
| 79 | + <span>{new Date(info.getValue()).toLocaleDateString() || <Badge bg="secondary">N/A</Badge>}</span> |
| 80 | + </div> |
| 81 | + ), |
40 | 82 | }),
|
41 | 83 |
|
42 |
| - // Column for the last updated date |
43 | 84 | columnHelper.accessor("updated_at", {
|
44 |
| - header: "Updated Date", |
| 85 | + header: () => <span style={{ fontWeight: 'bold', color: '#000000', fontSize: '1.17em' }}>Updated Date</span>, |
45 | 86 | enableSorting: true,
|
46 |
| - enableColumnFilter: false, |
47 |
| - enableGlobalFilter: false, |
| 87 | + enableColumnFilter: true, |
| 88 | + enableGlobalFilter: true, |
| 89 | + cell: (info) => ( |
| 90 | + <div className="d-flex justify-content-start align-items-center" style={{ fontSize: '1.17em', padding: '8px 0' }}> |
| 91 | + <span>{new Date(info.getValue()).toLocaleDateString() || <Badge bg="secondary">N/A</Badge>}</span> |
| 92 | + </div> |
| 93 | + ), |
48 | 94 | }),
|
49 | 95 |
|
50 |
| - // Actions column with edit, delete, TA, and copy buttons |
51 | 96 | columnHelper.display({
|
52 | 97 | id: "actions",
|
53 |
| - header: "Actions", |
| 98 | + header: () => <span style={{ fontWeight: 'bold', color: '#000000', fontSize: '1.17em' }}>Actions</span>, |
54 | 99 | cell: ({ row }) => (
|
55 |
| - <> |
56 |
| - <Button variant="outline-warning" size="sm" onClick={() => handleEdit(row)}> |
57 |
| - <BsPencilFill /> |
58 |
| - </Button> |
59 |
| - <Button |
60 |
| - variant="outline-danger" |
61 |
| - size="sm" |
62 |
| - className="ms-sm-2" |
63 |
| - onClick={() => handleDelete(row)} |
64 |
| - > |
65 |
| - <MdDelete /> |
66 |
| - </Button> |
67 |
| - <Button variant="outline-info" size="sm" className="ms-sm-2" onClick={() => handleTA(row)}> |
68 |
| - <BsPersonXFill /> |
69 |
| - </Button> |
70 |
| - <Button |
71 |
| - variant="outline-primary" |
72 |
| - size="sm" |
73 |
| - className="ms-sm-2" |
74 |
| - onClick={() => handleCopy(row)} |
75 |
| - > |
76 |
| - <MdContentCopy /> |
77 |
| - </Button> |
78 |
| - </> |
| 100 | + <div className="d-flex justify-content-around" style={{ fontSize: '1.17em', padding: '8px 0' }}> |
| 101 | + <OverlayTrigger overlay={<Tooltip>Edit Course</Tooltip>}> |
| 102 | + <Button |
| 103 | + variant="link" |
| 104 | + onClick={() => handleEdit(row)} |
| 105 | + aria-label="Edit Course" |
| 106 | + style={{ padding: '0', margin: '0 8px' }} // Add margin for spacing |
| 107 | + > |
| 108 | + <img src={process.env.PUBLIC_URL + '/assets/images/pencil.png'} alt="Edit" style={{ width: '25px', height: '20px' }} /> |
| 109 | + </Button> |
| 110 | + </OverlayTrigger> |
| 111 | + |
| 112 | + <OverlayTrigger overlay={<Tooltip>Delete Course</Tooltip>}> |
| 113 | + <Button |
| 114 | + variant="link" |
| 115 | + onClick={() => handleDelete(row)} |
| 116 | + aria-label="Delete Course" |
| 117 | + style={{ padding: '0', margin: '0 8px' }} |
| 118 | + > |
| 119 | + <img src={process.env.PUBLIC_URL + '/assets/images/remove.png'} alt="Delete" style={{ width: '25px', height: '20px' }} /> |
| 120 | + </Button> |
| 121 | + </OverlayTrigger> |
| 122 | + |
| 123 | + <OverlayTrigger overlay={<Tooltip>Assign TA</Tooltip>}> |
| 124 | + <Button |
| 125 | + variant="link" |
| 126 | + onClick={() => handleTA(row)} |
| 127 | + aria-label="Assign TA" |
| 128 | + style={{ padding: '0', margin: '0 8px' }} |
| 129 | + > |
| 130 | + <img src={process.env.PUBLIC_URL + '/assets/images/assign.png'} alt="Assign TA" style={{ width: '35px', height: '25px' }} /> |
| 131 | + </Button> |
| 132 | + </OverlayTrigger> |
| 133 | + |
| 134 | + <OverlayTrigger overlay={<Tooltip>Copy Course</Tooltip>}> |
| 135 | + <Button |
| 136 | + variant="link" |
| 137 | + onClick={() => handleCopy(row)} |
| 138 | + aria-label="Copy Course" |
| 139 | + style={{ padding: '0', margin: '0 8px' }} |
| 140 | + > |
| 141 | + <img src={'/assets/images/paste.png'} alt="Copy" style={{ width: '35px', height: '25px' }} /> |
| 142 | + </Button> |
| 143 | + </OverlayTrigger> |
| 144 | + </div> |
79 | 145 | ),
|
80 | 146 | }),
|
81 | 147 | ];
|
0 commit comments