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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | 3x 6x 6x 12x 4x 334x 334x 334x 334x 334x 334x 334x 334x 334x 334x 334x 334x 334x 4x 334x 2x 334x 668x 668x 668x 668x 668x 668x 334x 29x 29x 29x 29x 334x 1x 1x 1x 1x 334x 1x 1x 1x 334x 29x 1x 28x 29x 29x 29x 29x 334x 28x 42x 334x 1x 1x 1x 1x 1x 334x 4x 4x 4x 5x 4x 4x 5x 8x 334x 2x 2x 2x 2x 2x 2x 2x 2x 334x 9x 3x 3x 9x 6x 2x 2x 6x 4x 4x 4x 334x 9x 4x 4x 4x 4x 4x 4x 334x 334x 36x 298x 60x 238x 238x 238x 334x 334x 25x 2x 2x 2x 2x 334x 305x 328x 372x 4x 2x 333x 448x 1x 4x 29x | import React, { useEffect, useState } from "react";
import "./DropDownMenuEditor.scss";
import {
Alert,
Box,
Button,
Card,
CardContent,
Checkbox,
Chip,
Collapse,
FormControlLabel,
IconButton,
LinearProgress,
Paper,
Stack,
Tooltip,
Typography,
} from "@mui/material";
import { useTheme } from "@mui/material/styles";
import ReadOnlyMathEditor from "@/utils/components/TinyMCETextEditorReadOnly";
import UnsavedChangesDialog from "@/utils/components/UnsavedChangesDialog";
import tinyMCEUtility from "@/utils/helpers/tinyMCEUtility";
// Icons
import AddIcon from "@mui/icons-material/Add";
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline";
import EditIcon from "@mui/icons-material/Edit";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import ExpandLessIcon from "@mui/icons-material/ExpandLess";
import SaveIcon from "@mui/icons-material/Save";
import CloseIcon from "@mui/icons-material/Close";
import HelpOutlineIcon from "@mui/icons-material/HelpOutline";
import ArrowDropDownCircleIcon from "@mui/icons-material/ArrowDropDownCircle";
import SettingsIcon from "@mui/icons-material/Settings";
import NoteAddIcon from "@mui/icons-material/NoteAdd";
import RestartAltIcon from "@mui/icons-material/RestartAlt";
import DropdownMenu from "./DropdownMenuV2";
import {
useQuestionForm,
TextEditorDialog,
QuestionSettings,
QuickTipsCard,
getClassificationProgress,
editorContainerSx,
editorHeaderSx,
cardHeaderHoverSx,
editorCardSx,
contentPreviewSx,
emptyStateSx,
neutralSurfaceSx,
tipsCardSx,
} from "../utils";
function convertDataChoicesFormat(arr) {
return arr.map((group) => ({
id: group.id,
items: group.items.map((answer, index) => ({
id: index,
text: answer,
})),
}));
}
function unnormalizeDataChoicesFormat(arr) {
return arr.map((group) => ({
id: group.id,
items: group.items.map((item) => item.text),
}));
}
const MainV2 = ({ role = "teacher" }) => {
const {
displayError,
setDisplayError,
editQuestion,
isEditMode,
setEditMode,
questionText,
setQuestionText,
questionTextEditor,
setQuestionTextEditor,
showQuestionTextEditor,
questionDetailsText,
setQuestionDetailsText,
questionDetailsTextEditor,
setQuestionDetailsTextEditor,
showQuestionDetailsTextEditor,
answerDetailsText,
setAnswerDetailsText,
answerDetailsTextEditor,
setAnswerDetailsTextEditor,
showAnswerDetailsTextEditor,
values,
touched,
errors,
handleChange,
handleBlur,
setFieldValue,
setFieldTouched,
handleCancel,
clickQuestionButton,
saveQuestion,
cancelQuestion,
clickQuestionDetailsButton,
saveQuestionDetails,
cancelQuestionDetails,
clickEditAnswerDetails,
saveAnswerDetails,
cancelEditAnswerDetails,
deleteAnswerDetails,
submitQuestion,
buildBasePayload,
loadEditData,
resetFields,
handleImageUpload,
SaveProgress,
navigationBlocker,
} = useQuestionForm(role);
const { dropDownMenuHTML, regexBlank, regexMenuHere } = tinyMCEUtility();
const theme = useTheme();
// Expandable sections
const [questionDetailsExpanded, setQuestionDetailsExpanded] = useState(false);
const [answerDetailsExpanded, setAnswerDetailsExpanded] = useState(false);
const [settingsExpanded, setSettingsExpanded] = useState(true);
// Drop-down menu specific state
const [isBlanks, setBlanks] = useState([]);
const [isChoices, setChoices] = useState([]);
const [isSelectedResponse, setSelectedResponse] = useState(null);
const [isResponseTextEditor, setResponseTextEditor] = useState("");
const [isShowResponseTextEditor, setShowResponseTextEditor] = useState(false);
// Grading order: by default each blank is checked against the answer authored
// FOR that specific blank (position-sensitive — see the backend's
// _POSITION_SENSITIVE_TYPES). This lets a teacher opt a question into
// unordered grading instead, where a correct answer counts wherever the
// student put it among the dropdowns.
const [isUnordered, setUnordered] = useState(false);
// Question conversion (specific to drop-down menu)
const dropDownMenuToString = (question) => {
return regexMenuHere ? question.replace(regexMenuHere, "__blank__") : question;
};
const stringToDropDownMenu = (question) => {
return regexBlank ? question.replace(regexBlank, dropDownMenuHTML) : question;
};
// Progress calculation
const getProgress = () => {
let progress = 0;
if (questionText) progress += 25;
if (isChoices.length > 0 && isChoices.every((c) => c.items.length > 0)) progress += 25;
if (isBlanks.length > 0 && isBlanks.some((b) => b.answer)) progress += 25;
progress += (getClassificationProgress(values) / 100) * 25;
return Math.round(progress);
};
// Response handlers
const clickAddResponse = (indexNum) => {
setShowResponseTextEditor(true);
setResponseTextEditor("");
setSelectedResponse({ index: indexNum });
setEditMode(false);
};
const clickEditResponse = (entry, indexNum, indexNum2) => {
setShowResponseTextEditor(true);
setResponseTextEditor(entry.text);
setSelectedResponse({ index1: indexNum, index2: indexNum2 });
setEditMode(true);
};
const cancelChoice = () => {
setResponseTextEditor("");
setShowResponseTextEditor(false);
setEditMode(false);
};
const saveChoice = () => {
if (isEditMode) {
updateSelectedResponse(isSelectedResponse.index1, isSelectedResponse.index2);
} else {
addChoice(isSelectedResponse.index, {
id: isChoices[isSelectedResponse.index].items.length,
text: isResponseTextEditor,
});
}
setResponseTextEditor("");
setSelectedResponse(null);
setShowResponseTextEditor(false);
setEditMode(false);
};
const addChoice = (index, newChoice) => {
setChoices((prevChoices) =>
prevChoices.map((item, idx) => (idx === index ? { ...item, items: [...item.items, newChoice] } : item))
);
};
const updateSelectedResponse = (isChoiceIndex, textIndex) => {
setChoices((prevChoices) => {
const updatedChoices = [...prevChoices];
updatedChoices[isChoiceIndex] = {
...updatedChoices[isChoiceIndex],
items: updatedChoices[isChoiceIndex].items.map((choice, index) =>
index === textIndex ? { ...choice, text: isResponseTextEditor } : choice
),
};
return updatedChoices;
});
};
const deleteResponse = (isChoiceIndex, textIndex) => {
// The blank stores the chosen response's raw HTML verbatim (DropdownMenuV2
// puts it there — same value the student's <option value> submits), so
// comparing directly against a response's own `text` finds it. Without this,
// deleting the chosen response left the question with a correct answer that
// is no longer among its choices.
const deletedAnswer = isChoices[isChoiceIndex].items[textIndex].text;
setBlanks((prevBlanks) =>
prevBlanks.map((item) =>
item.id === isChoiceIndex && item.answer === deletedAnswer ? { ...item, answer: "" } : item
)
);
setChoices((prevChoices) =>
prevChoices.map((choiceItem, index) =>
index === isChoiceIndex
? { ...choiceItem, items: choiceItem.items.filter((_, index2) => index2 !== textIndex) }
: choiceItem
)
);
};
// Reset all values
const handleReset = () => {
setQuestionText("");
setQuestionDetailsText("");
setAnswerDetailsText("");
setBlanks([]);
setChoices([]);
setUnordered(false);
setDisplayError({ status: false, message: "" });
resetFields();
};
// Validation
const hasValidChoices = () => {
if (isChoices.length === 0) {
setDisplayError({ status: true, message: "Please add at least one dropdown menu in the question." });
return false;
}
const dropdownWithTooFewOptions = isChoices.findIndex((choice) => choice.items.length < 2);
if (dropdownWithTooFewOptions !== -1) {
setDisplayError({
status: true,
message: `Dropdown ${dropdownWithTooFewOptions + 1} needs at least two response options.`,
});
return false;
}
const hasEmptyResponses = isChoices.some((choice) => choice.items.length === 0);
Iif (hasEmptyResponses) {
setDisplayError({ status: true, message: "Please add at least one response for each dropdown menu." });
return false;
}
setDisplayError({ status: false, message: "" });
return true;
};
// Submit handler - SAME PAYLOAD STRUCTURE
const createNewQuestion = async () => {
if (!hasValidChoices()) return;
const basePayload = buildBasePayload("Drop-down-Menu", [...isBlanks]);
const payload = {
...basePayload,
question: dropDownMenuToString(questionText),
choices: unnormalizeDataChoicesFormat([...isChoices]),
correctAnswer: {
...basePayload.correctAnswer,
unordered: isUnordered,
},
};
await submitQuestion(payload, () => {
setBlanks([]);
setChoices([]);
setUnordered(false);
});
};
// Dialog management
const getActiveDialog = () => {
if (showQuestionTextEditor)
return {
type: "question",
content: questionTextEditor,
setContent: setQuestionTextEditor,
save: saveQuestion,
cancel: cancelQuestion,
questionTypes: ["dropDownMenu"],
};
if (isShowResponseTextEditor)
return {
type: "choice",
content: isResponseTextEditor,
setContent: setResponseTextEditor,
save: saveChoice,
cancel: cancelChoice,
questionTypes: [],
disabledToolbarButtons: ["matheditor", "graph2d", "insertimage", "inserttable"],
};
Iif (showAnswerDetailsTextEditor)
return {
type: "answerDetails",
content: answerDetailsTextEditor,
setContent: setAnswerDetailsTextEditor,
save: saveAnswerDetails,
cancel: cancelEditAnswerDetails,
questionTypes: [],
};
Iif (showQuestionDetailsTextEditor)
return {
type: "questionDetails",
content: questionDetailsTextEditor,
setContent: setQuestionDetailsTextEditor,
save: saveQuestionDetails,
cancel: cancelQuestionDetails,
questionTypes: [],
};
return null;
};
const activeDialog = getActiveDialog();
// Load edit data
useEffect(() => {
loadEditData((data) => {
setQuestionText(stringToDropDownMenu(data.question));
setBlanks([...data.correctAnswer.answers]);
setChoices(convertDataChoicesFormat([...data.choices]));
setUnordered(Boolean(data.correctAnswer?.unordered));
});
}, []);
return (
<Box className="dropdown-v2-container" sx={editorContainerSx()}>
<SaveProgress />
<UnsavedChangesDialog blocker={navigationBlocker} />
{/* Dialog */}
{activeDialog && (
<TextEditorDialog
open={true}
editorType={activeDialog.type}
isEditMode={isEditMode}
editContent={activeDialog.content}
setEditContent={activeDialog.setContent}
onSave={activeDialog.save}
onCancel={activeDialog.cancel}
questionTypes={activeDialog.questionTypes}
onImageUpload={handleImageUpload}
disabledToolbarButtons={activeDialog.disabledToolbarButtons ?? []}
/>
)}
{/* Header */}
<Paper className="dropdown-v2-header" elevation={0} sx={editorHeaderSx()}>
<Box className="dropdown-v2-header-content">
<Box className="dropdown-v2-header-left">
<ArrowDropDownCircleIcon sx={{ fontSize: 28, color: "primary.main" }} />
<Box>
<Typography variant="h5" fontWeight={600}>
{editQuestion ? "Edit Question" : "Create Drop-down Menu Question"}
</Typography>
<Typography variant="body2" color="text.secondary">
{editQuestion
? "Update your question details"
: "Build an interactive drop-down menu question"}
</Typography>
</Box>
</Box>
<Box className="dropdown-v2-header-actions">
<Button variant="outlined" color="inherit" onClick={handleCancel} startIcon={<CloseIcon />}>
Cancel
</Button>
<Button variant="outlined" color="warning" onClick={handleReset} startIcon={<RestartAltIcon />}>
Reset
</Button>
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
<Button
variant="contained"
color="primary"
onClick={createNewQuestion}
startIcon={<SaveIcon />}
>
{editQuestion ? "Update" : "Save Question"}
</Button>
<Tooltip
title={
<Box sx={{ p: 1 }}>
<Typography variant="subtitle2" sx={{ fontWeight: 600, mb: 1 }}>
Required Fields:
</Typography>
<Stack spacing={0.5}>
<Typography
variant="caption"
sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
>
{questionText ? (
<CheckCircleIcon fontSize="small" color="success" />
) : (
<CheckCircleOutlineIcon fontSize="small" />
)}
Question with dropdown placeholders
</Typography>
<Typography
variant="caption"
sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
>
{isChoices.length > 0 && isChoices.every((c) => c.items.length >= 2) ? (
<CheckCircleIcon fontSize="small" color="success" />
) : (
<CheckCircleOutlineIcon fontSize="small" />
)}
Responses for each dropdown
</Typography>
<Typography
variant="caption"
sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
>
{isBlanks.length > 0 && isBlanks.some((b) => b.answer) ? (
<CheckCircleIcon fontSize="small" color="success" />
) : (
<CheckCircleOutlineIcon fontSize="small" />
)}
Correct answers selected
</Typography>
<Typography
variant="caption"
sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
>
{values.assignmentType ? (
<CheckCircleIcon fontSize="small" color="success" />
) : (
<CheckCircleOutlineIcon fontSize="small" />
)}
Assignment type
</Typography>
<Typography
variant="caption"
sx={{ display: "flex", alignItems: "center", gap: 0.5 }}
>
{values.questionPoints ? (
<CheckCircleIcon fontSize="small" color="success" />
) : (
<CheckCircleOutlineIcon fontSize="small" />
)}
Question points
</Typography>
</Stack>
</Box>
}
arrow
placement="bottom-end"
>
<IconButton size="small" sx={{ color: "primary.main" }}>
<HelpOutlineIcon fontSize="small" />
</IconButton>
</Tooltip>
</Box>
</Box>
</Box>
{/* Progress bar */}
<Box className="dropdown-v2-progress">
<LinearProgress
variant="determinate"
value={getProgress()}
color="success"
sx={{ height: 6, borderRadius: 3 }}
/>
<Typography variant="caption" color="text.secondary" sx={{ mt: 0.5 }}>
{getProgress()}% complete
</Typography>
</Box>
</Paper>
{/* Error Alert */}
{displayError.status && (
<Alert
severity="error"
sx={{ mx: 3, mt: 2 }}
onClose={() => setDisplayError({ status: false, message: "" })}
>
{displayError.message}
</Alert>
)}
{/* Question Settings Validation Errors */}
{Object.keys(errors).some((key) => touched[key]) && (
<Alert severity="error" sx={{ mx: 3, mt: 2 }}>
<Typography variant="body2" fontWeight={600} sx={{ mb: 0.5 }}>
Please complete the required question settings:
</Typography>
<Stack spacing={0.25}>
{Object.entries(errors).map(([key, message]) =>
touched[key] ? (
<Typography key={key} variant="caption">
• {message}
</Typography>
) : null
)}
</Stack>
</Alert>
)}
{/* Main Content */}
<Box className="dropdown-v2-main">
{/* Left Panel - Question & Responses */}
<Box className="dropdown-v2-left-panel">
{/* Question Card */}
<Card className="dropdown-v2-card" sx={editorCardSx(theme)}>
<CardContent>
<Box className="dropdown-v2-card-header">
<Box className="dropdown-v2-card-title">
<HelpOutlineIcon color="primary" />
<Typography variant="h6">Question</Typography>
{questionText && <CheckCircleIcon color="success" fontSize="small" />}
</Box>
<Button
variant={questionText ? "outlined" : "contained"}
size="small"
startIcon={questionText ? <EditIcon /> : <AddIcon />}
onClick={clickQuestionButton}
>
{questionText ? "Edit" : "Add Question"}
</Button>
</Box>
{questionText ? (
<Paper
variant="outlined"
className="dropdown-v2-content-preview"
sx={contentPreviewSx()}
>
<DropdownMenu
isQuestionText={questionText}
isChoices={isChoices}
setChoices={setChoices}
isBlanks={isBlanks}
setBlanks={setBlanks}
/>
</Paper>
) : (
<Box className="dropdown-v2-empty-state" sx={emptyStateSx(theme)}>
<NoteAddIcon sx={{ fontSize: 48, color: "action.disabled" }} />
<Typography color="text.secondary">
Click "Add Question" to write your question with dropdown menus
</Typography>
<Typography variant="caption" color="text.secondary">
Use the dropdown menu button in the editor to add placeholders
</Typography>
</Box>
)}
{/* Question Details - Collapsible */}
<Box sx={{ mt: 2 }}>
<Button
size="small"
onClick={() => setQuestionDetailsExpanded(!questionDetailsExpanded)}
endIcon={questionDetailsExpanded ? <ExpandLessIcon /> : <ExpandMoreIcon />}
sx={{ textTransform: "none" }}
>
Question Details (Optional)
{questionDetailsText && (
<CheckCircleIcon color="success" fontSize="small" sx={{ ml: 1 }} />
)}
</Button>
<Collapse in={questionDetailsExpanded}>
<Box sx={{ mt: 1 }}>
{questionDetailsText ? (
<Paper
variant="outlined"
className="dropdown-v2-content-preview"
sx={contentPreviewSx()}
>
<ReadOnlyMathEditor content={questionDetailsText} />
<IconButton
size="small"
onClick={clickQuestionDetailsButton}
sx={{ position: "absolute", top: 8, right: 8 }}
>
<EditIcon fontSize="small" />
</IconButton>
</Paper>
) : (
<Button
variant="text"
size="small"
startIcon={<AddIcon />}
onClick={clickQuestionDetailsButton}
>
Add details or hints
</Button>
)}
</Box>
</Collapse>
</Box>
</CardContent>
</Card>
{/* Responses Card */}
{isChoices.length > 0 && (
<Card className="dropdown-v2-card" sx={editorCardSx(theme)}>
<CardContent>
<Box className="dropdown-v2-card-header">
<Box className="dropdown-v2-card-title">
<ArrowDropDownCircleIcon color="primary" />
<Typography variant="h6">Dropdown Responses</Typography>
<Chip
size="small"
label={`${isChoices.length} dropdown${isChoices.length > 1 ? "s" : ""}`}
color="primary"
variant="filled"
sx={{ fontWeight: 500 }}
/>
</Box>
</Box>
{isChoices.length > 1 && (
<Box sx={{ mb: 2 }}>
<FormControlLabel
control={
<Checkbox
id="dropdown-menu-unordered-grading"
data-testid="dropdown-menu-unordered-checkbox"
checked={isUnordered}
onChange={(e) => setUnordered(e.target.checked)}
/>
}
label="Grade dropdowns unordered"
/>
<Typography variant="caption" color="text.secondary" sx={{ display: "block" }}>
{isUnordered
? "A correct answer counts in ANY dropdown, not just the one it was assigned to."
: "Each dropdown is checked against the answer assigned to that specific dropdown."}
</Typography>
</Box>
)}
<Box className="dropdown-v2-responses-grid">
{isChoices.map((choice, index) => (
<Box
key={index}
className="dropdown-v2-response-group"
sx={neutralSurfaceSx(theme)}
>
<Box className="dropdown-v2-response-header">
<Typography variant="subtitle2" fontWeight={600}>
Dropdown {index + 1}
</Typography>
<Chip
size="small"
label={`${choice.items?.length || 0} options`}
color={choice.items?.length > 0 ? "success" : "default"}
variant={choice.items?.length > 0 ? "filled" : "outlined"}
sx={{
color: choice.items?.length > 0 ? "white" : "text.primary",
}}
/>
</Box>
<Box className="dropdown-v2-response-items">
{choice.items?.map((entry, index2) => (
<Paper
key={index2}
variant="outlined"
className="dropdown-v2-response-item"
sx={contentPreviewSx()}
>
<Box sx={{ flex: 1, minWidth: 0 }}>
<ReadOnlyMathEditor content={entry.text} />
</Box>
<Box className="dropdown-v2-response-actions">
<IconButton
size="small"
onClick={() => clickEditResponse(entry, index, index2)}
>
<EditIcon fontSize="small" />
</IconButton>
<IconButton
size="small"
onClick={() => deleteResponse(index, index2)}
color="error"
>
<DeleteOutlineIcon fontSize="small" />
</IconButton>
</Box>
</Paper>
))}
</Box>
<Button
size="small"
variant="outlined"
startIcon={<AddIcon />}
onClick={() => clickAddResponse(index)}
fullWidth
>
Add Response
</Button>
</Box>
))}
</Box>
</CardContent>
</Card>
)}
{/* Answer Details Card - Collapsible */}
<Card className="dropdown-v2-card" sx={editorCardSx(theme)}>
<CardContent>
<Box
className="dropdown-v2-card-header clickable"
onClick={() => setAnswerDetailsExpanded(!answerDetailsExpanded)}
sx={cardHeaderHoverSx(theme)}
>
<Box className="dropdown-v2-card-title">
<NoteAddIcon color="primary" />
<Typography variant="h6">Answer Explanation (Optional)</Typography>
{answerDetailsText && <CheckCircleIcon color="success" fontSize="small" />}
</Box>
{answerDetailsExpanded ? <ExpandLessIcon /> : <ExpandMoreIcon />}
</Box>
<Collapse in={answerDetailsExpanded}>
<Box sx={{ mt: 2 }}>
{answerDetailsText ? (
<Paper
variant="outlined"
className="dropdown-v2-content-preview"
sx={{ position: "relative", ...contentPreviewSx() }}
>
<ReadOnlyMathEditor content={answerDetailsText} />
<Box
sx={{
position: "absolute",
top: 8,
right: 8,
display: "flex",
gap: 0.5,
}}
>
<IconButton
size="small"
onClick={() => clickEditAnswerDetails(answerDetailsText)}
>
<EditIcon fontSize="small" />
</IconButton>
<IconButton size="small" onClick={deleteAnswerDetails} color="error">
<DeleteOutlineIcon fontSize="small" />
</IconButton>
</Box>
</Paper>
) : (
<Button
variant="outlined"
startIcon={<AddIcon />}
onClick={() => clickEditAnswerDetails("")}
fullWidth
>
Add Answer Explanation
</Button>
)}
</Box>
</Collapse>
</CardContent>
</Card>
</Box>
{/* Right Panel - Tips + Settings */}
<Box className="dropdown-v2-right-panel">
<QuickTipsCard
className="dropdown-v2-card dropdown-v2-tips-card"
sx={{ ...editorCardSx(theme), ...tipsCardSx(theme) }}
tips={[
"Use the dropdown menu button in the editor to add placeholders",
"Add multiple response options for each dropdown",
"Select the correct answer from each dropdown",
"Each dropdown can have different options",
]}
/>
<Card className="dropdown-v2-card dropdown-v2-settings-card" sx={editorCardSx(theme)}>
<CardContent>
<Box
className="dropdown-v2-card-header clickable"
onClick={() => setSettingsExpanded(!settingsExpanded)}
sx={cardHeaderHoverSx(theme)}
>
<Box className="dropdown-v2-card-title">
<SettingsIcon color="primary" />
<Typography variant="h6">Question Settings</Typography>
</Box>
{settingsExpanded ? <ExpandLessIcon /> : <ExpandMoreIcon />}
</Box>
<Collapse in={settingsExpanded}>
<Box sx={{ mt: 2 }}>
<QuestionSettings
values={values}
touched={touched}
errors={errors}
handleChange={handleChange}
handleBlur={handleBlur}
setFieldValue={setFieldValue}
setFieldTouched={setFieldTouched}
/>
</Box>
</Collapse>
</CardContent>
</Card>
</Box>
</Box>
</Box>
);
};
export default MainV2;
|