From 9a01814b109c7f07005194cedf96d9135c8be5bf Mon Sep 17 00:00:00 2001 From: pankhis Date: Sun, 21 Apr 2024 18:00:59 -0400 Subject: [PATCH] toggle question functionality --- src/pages/ViewTeamGrades/ReviewTable.tsx | 42 +++++++++++---------- src/pages/ViewTeamGrades/ReviewTableRow.tsx | 11 +++++- src/pages/ViewTeamGrades/grades.scss | 3 +- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/pages/ViewTeamGrades/ReviewTable.tsx b/src/pages/ViewTeamGrades/ReviewTable.tsx index 681994c..3105bd7 100644 --- a/src/pages/ViewTeamGrades/ReviewTable.tsx +++ b/src/pages/ViewTeamGrades/ReviewTable.tsx @@ -18,6 +18,7 @@ const ReviewTable: React.FC = () => { const [sortOrderRow, setSortOrderRow] = useState<'asc' | 'desc' | 'none'>('none'); // State for row sort order const [showWordCount10, setShowWordCount10] = useState(false); // State for showing reviews with more than 10 words const [showWordCount20, setShowWordCount20] = useState(false); // State for showing reviews with more than 20 words + const [showToggleQuestion, setShowToggleQuestion] = useState(false); // State for showing question column const [open, setOpen] = useState(false); const [showReviews, setShowReviews] = useState(false); @@ -55,19 +56,9 @@ const ReviewTable: React.FC = () => { setShowReviews(!showReviews); }; - // const renderQuestionReviews = () => { - // return dummyDataRounds[currentRound].map((question, index) => ( - //
- //

Question {question.questionNumber}: {question.questionText}

- // {question.reviews.map((review, reviewIndex) => ( - //
- //

Review {reviewIndex + 1}: Score: {review.score}

- // {('comment' in review) &&

Comment: {review.comment}

} - //
- // ))} - //
- // )); - // }; + const toggleShowQuestion = () => { + setShowToggleQuestion(!showToggleQuestion); + }; // JSX rendering of the ReviewTable component return ( @@ -137,23 +128,34 @@ const ReviewTable: React.FC = () => { onChange={(e) => setShowWordCount20(e.target.checked)} /> + +
- + + {showToggleQuestion && ( + + )} {Array.from({ length: currentRoundData[0].reviews.length }, (_, i) => ( - + ))} - - {showWordCount10 && } - {showWordCount20 && } + {showWordCount10 && } + {showWordCount20 && } @@ -163,10 +165,12 @@ const ReviewTable: React.FC = () => { row={row} showWordCount10={showWordCount10} showWordCount20={showWordCount20} + showToggleQuestion={showToggleQuestion} /> ))} - + {/* "Avg" header always in the first column */} + {showToggleQuestion && } {/* Add an empty cell if toggle question is shown */} {columnAverages.map((avg, index) => ( {/* Question Number */} @@ -25,6 +28,10 @@ const ReviewTableRow: React.FC = ({ row, showWordCount10, s + {showToggleQuestion && ( + + )} + {/* Review Cells */} {row.reviews.map((review, idx) => (
Question No.Question No.Question{`Review ${i + 1}`}{`Review ${i + 1}`} + Avg {sortOrderRow === "none" && ▲▼} {sortOrderRow === "asc" && } {sortOrderRow === "desc" && } 10+ Words20+ Words10+ Words20+ Words
AvgAvg {avg.toFixed(2)} diff --git a/src/pages/ViewTeamGrades/ReviewTableRow.tsx b/src/pages/ViewTeamGrades/ReviewTableRow.tsx index 78798ed..2d07040 100644 --- a/src/pages/ViewTeamGrades/ReviewTableRow.tsx +++ b/src/pages/ViewTeamGrades/ReviewTableRow.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { getColorClass, getWordCount10, getWordCount20 } from './utils'; // Importing utility functions import { ReviewData } from './App'; // Importing the ReviewData interface from App @@ -7,10 +7,13 @@ interface ReviewTableRowProps { row: ReviewData; // Data for the row showWordCount10: boolean; // Flag to show reviews with 10+ words showWordCount20: boolean; // Flag to show reviews with 20+ words + showToggleQuestion: boolean; // Flag to toggle the question column } // Functional component ReviewTableRow -const ReviewTableRow: React.FC = ({ row, showWordCount10, showWordCount20 }) => { +const ReviewTableRow: React.FC = ({ row, showWordCount10, showWordCount20, showToggleQuestion }) => { + const [toggleQuestion, setToggleQuestion] = useState(showToggleQuestion); + return (
{row.questionText}