From 7095a52a4e8446bdc5f91cfe46defc62ccbd0a90 Mon Sep 17 00:00:00 2001 From: Duane Nykamp Date: Fri, 28 Jul 2023 22:25:16 +0000 Subject: [PATCH 01/11] start DoenetML component error handling in activity tweak activity json format --- .../e2e/ActivityViewer/activityVariants.cy.js | 86 +-- .../e2e/ActivityViewer/compiledActivity.cy.js | 8 +- .../relationshipsAmongPages.cy.js | 22 +- .../DoenetML/variants/uniquevariants.cy.js | 2 +- doenet_docker/volumes/db_init/db_template.sql | 2 +- .../parseActivityDefinitionRenamePages.php | 4 +- src/Core/Core.js | 45 +- src/Core/components/ChoiceInput.js | 28 +- src/Core/components/Document.js | 2 +- src/Core/components/Map.js | 24 +- src/Core/components/Select.js | 55 +- src/Core/components/SelectFromSequence.js | 20 +- src/Core/components/SelectPrimeNumbers.js | 20 +- src/Core/components/Shuffle.js | 30 +- src/Core/components/abstract/BaseComponent.js | 39 +- .../abstract/SectioningComponent.js | 2 +- src/Core/utils/returnAllPossibleVariants.js | 23 +- src/Core/utils/serializedStateProcessing.js | 24 +- src/Core/utils/variants.js | 31 +- src/Parser/parser.js | 22 +- src/Tools/_framework/Menus/CreditAchieved.jsx | 21 +- src/Tools/_framework/Paths/Home.jsx | 93 +-- .../Paths/PortfolioActivityEditor.jsx | 43 +- .../Paths/PortfolioActivityViewer.jsx | 15 +- src/Tools/_framework/Paths/PublicEditor.jsx | 9 +- .../ToolPanels/AssignmentViewer.jsx | 41 +- .../ToolPanels/CollectionEditor.jsx | 4 +- .../ToolPanels/DraftAssignmentViewer.jsx | 27 +- .../_framework/ToolPanels/EditorViewer.jsx | 19 +- .../ToolPanels/GradebookStudentAssignment.jsx | 11 +- .../ToolPanels/GuestEditorViewer.jsx | 29 +- .../ToolPanels/PublicActivityViewer.jsx | 10 +- src/Tools/cypressTest/CypressTest.jsx | 132 +--- src/Tools/test/DoenetTest.jsx | 119 +-- src/Tools/test/testActivityDefinition.doenet | 14 - src/Viewer/ActivityViewer.jsx | 718 +++++++++--------- src/Viewer/DoenetML.css | 308 ++++++++ src/Viewer/DoenetML.jsx | 225 ++++++ src/Viewer/PageViewer.jsx | 517 ++++++------- src/Viewer/renderers/_error.jsx | 4 +- src/Viewer/renderers/alert.jsx | 4 +- src/Viewer/renderers/angle.jsx | 4 +- src/Viewer/renderers/answer.jsx | 5 +- src/Viewer/renderers/asList.jsx | 4 +- src/Viewer/renderers/boolean.jsx | 4 +- src/Viewer/renderers/booleanInput.jsx | 4 +- src/Viewer/renderers/button.jsx | 4 +- src/Viewer/renderers/c.jsx | 4 +- src/Viewer/renderers/cell.jsx | 4 +- src/Viewer/renderers/chart.jsx | 4 +- src/Viewer/renderers/choiceInput.jsx | 4 +- src/Viewer/renderers/circle.jsx | 4 +- src/Viewer/renderers/cobwebPolyline.jsx | 4 +- src/Viewer/renderers/containerInline.jsx | 4 +- src/Viewer/renderers/curve.jsx | 4 +- src/Viewer/renderers/ellipsis.jsx | 4 +- src/Viewer/renderers/em.jsx | 4 +- src/Viewer/renderers/embed.jsx | 4 +- src/Viewer/renderers/feedback.jsx | 5 +- src/Viewer/renderers/figure.jsx | 5 +- src/Viewer/renderers/footnote.jsx | 4 +- src/Viewer/renderers/graph.jsx | 5 +- src/Viewer/renderers/hint.jsx | 5 +- src/Viewer/renderers/image.jsx | 4 +- src/Viewer/renderers/label.jsx | 5 +- src/Viewer/renderers/legend.jsx | 4 +- src/Viewer/renderers/line.jsx | 4 +- src/Viewer/renderers/lineSegment.jsx | 4 +- src/Viewer/renderers/list.jsx | 5 +- src/Viewer/renderers/lq.jsx | 4 +- src/Viewer/renderers/lsq.jsx | 4 +- src/Viewer/renderers/math.jsx | 4 +- src/Viewer/renderers/mathInput.jsx | 4 +- src/Viewer/renderers/mathList.jsx | 4 +- src/Viewer/renderers/matrixInput.jsx | 5 +- src/Viewer/renderers/mdash.jsx | 4 +- src/Viewer/renderers/nbsp.jsx | 4 +- src/Viewer/renderers/ndash.jsx | 4 +- src/Viewer/renderers/number.jsx | 4 +- src/Viewer/renderers/numberList.jsx | 4 +- src/Viewer/renderers/paginatorControls.jsx | 4 +- src/Viewer/renderers/pegboard.jsx | 4 +- src/Viewer/renderers/point.jsx | 4 +- src/Viewer/renderers/polygon.jsx | 4 +- src/Viewer/renderers/polyline.jsx | 4 +- src/Viewer/renderers/q.jsx | 4 +- src/Viewer/renderers/ray.jsx | 4 +- src/Viewer/renderers/ref.jsx | 10 +- .../renderers/regionBetweenCurveXAxis.jsx | 4 +- src/Viewer/renderers/renderDoenetML.jsx | 6 +- src/Viewer/renderers/row.jsx | 4 +- src/Viewer/renderers/rq.jsx | 4 +- src/Viewer/renderers/rsq.jsx | 4 +- src/Viewer/renderers/section.jsx | 5 +- src/Viewer/renderers/sideBySide.jsx | 5 +- src/Viewer/renderers/slider.jsx | 4 +- src/Viewer/renderers/solution.jsx | 5 +- src/Viewer/renderers/spreadsheet.jsx | 4 +- src/Viewer/renderers/sq.jsx | 4 +- src/Viewer/renderers/subsetOfRealsInput.jsx | 4 +- src/Viewer/renderers/summaryStatistics.jsx | 5 +- src/Viewer/renderers/table.jsx | 5 +- src/Viewer/renderers/tabular.jsx | 5 +- src/Viewer/renderers/tag.jsx | 4 +- src/Viewer/renderers/text.jsx | 4 +- src/Viewer/renderers/textInput.jsx | 4 +- src/Viewer/renderers/textList.jsx | 4 +- src/Viewer/renderers/vector.jsx | 4 +- src/Viewer/renderers/video.jsx | 4 +- src/Viewer/useDoenetRenderer.jsx | 4 + src/_reactComponents/Course/CourseActions.jsx | 4 +- src/_sharedRecoil/PageViewerRecoil.jsx | 2 +- src/_utils/activityUtils.js | 615 +++++++++------ src/_utils/prerenderWorker.js | 20 +- 114 files changed, 2222 insertions(+), 1569 deletions(-) delete mode 100644 src/Tools/test/testActivityDefinition.doenet create mode 100644 src/Viewer/DoenetML.css create mode 100644 src/Viewer/DoenetML.jsx diff --git a/cypress/e2e/ActivityViewer/activityVariants.cy.js b/cypress/e2e/ActivityViewer/activityVariants.cy.js index b21e7b9529..4ce5799475 100644 --- a/cypress/e2e/ActivityViewer/activityVariants.cy.js +++ b/cypress/e2e/ActivityViewer/activityVariants.cy.js @@ -13,14 +13,14 @@ describe("Activity variants tests", function () { cy.wait(100); cy.get("#testRunner_toggleControls").click(); - let activityDefinition; + let doenetML; let attemptNumber = 0; for (let ind = 1; ind <= 200; ind += 97) { cy.window().then(async (win) => { attemptNumber++; - activityDefinition = ` + doenetML = ` @@ -33,7 +33,7 @@ describe("Activity variants tests", function () { `; win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, attemptNumber, }, @@ -82,7 +82,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, attemptNumber, }, @@ -121,7 +121,7 @@ describe("Activity variants tests", function () { cy.wait(100); cy.get("#testRunner_toggleControls").click(); - let activityDefinition = ` + let doenetML = ` @@ -152,7 +152,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -198,7 +198,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: 1, }, "*", @@ -237,7 +237,7 @@ describe("Activity variants tests", function () { cy.wait(100); cy.get("#testRunner_toggleControls").click(); - let activityDefinition = ` + let doenetML = ` @@ -270,7 +270,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -316,7 +316,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: 1, }, "*", @@ -350,7 +350,7 @@ describe("Activity variants tests", function () { }); it("Two pages few variants, page variants enumerated", () => { - let activityDefinition = ` + let doenetML = ` @@ -375,7 +375,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -422,13 +422,13 @@ describe("Activity variants tests", function () { } }); - it("Two pages, numberOfVariants not specified, defaults to 1000", () => { + it("Two pages, numVariants not specified, defaults to 1000", () => { cy.get("#testRunner_toggleControls").click(); cy.get("#testRunner_allowLocalState").click(); cy.wait(100); cy.get("#testRunner_toggleControls").click(); - let activityDefinition = ` + let doenetML = ` @@ -458,7 +458,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -551,7 +551,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: 1, }, "*", @@ -643,9 +643,9 @@ describe("Activity variants tests", function () { } }); - it("Two pages, specify numberOfVariants is 2", () => { - let activityDefinition = ` - + it("Two pages, specify numVariants is 2", () => { + let doenetML = ` + a @@ -673,7 +673,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -776,8 +776,8 @@ describe("Activity variants tests", function () { } }); - it("Shuffle and select orders, numberOfVariants not specified", () => { - let activityDefinition = ` + it("Shuffle and select orders, numVariants not specified", () => { + let doenetML = ` @@ -811,7 +811,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -893,7 +893,7 @@ describe("Activity variants tests", function () { }); it("Two pages, unique variants, variants to exclude", () => { - let activityDefinition = ` + let doenetML = ` @@ -918,7 +918,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -971,7 +971,7 @@ describe("Activity variants tests", function () { }); it("Two pages, unique variants, variants to include", () => { - let activityDefinition = ` + let doenetML = ` @@ -996,7 +996,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -1049,7 +1049,7 @@ describe("Activity variants tests", function () { }); it("Two pages, named variants, variants to exclude", () => { - let activityDefinition = ` + let doenetML = ` @@ -1088,7 +1088,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -1139,7 +1139,7 @@ describe("Activity variants tests", function () { }); it("Two pages, named variants, variants to include", () => { - let activityDefinition = ` + let doenetML = ` @@ -1178,7 +1178,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -1229,7 +1229,7 @@ describe("Activity variants tests", function () { }); it("Two pages, variants from problem, variant to exclude", () => { - let activityDefinition = ` + let doenetML = ` @@ -1264,7 +1264,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -1315,7 +1315,7 @@ describe("Activity variants tests", function () { }); it("Two pages, variants from problem, variant to include", () => { - let activityDefinition = ` + let doenetML = ` @@ -1350,7 +1350,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -1401,7 +1401,7 @@ describe("Activity variants tests", function () { }); it("Two pages, variants from document and problem, variants to exclude in problem", () => { - let activityDefinition = ` + let doenetML = ` @@ -1438,7 +1438,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -1489,7 +1489,7 @@ describe("Activity variants tests", function () { }); it("Two pages, variants from document and problem, variants to include in problem", () => { - let activityDefinition = ` + let doenetML = ` @@ -1526,7 +1526,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -1577,7 +1577,7 @@ describe("Activity variants tests", function () { }); it("Two pages, variants from document and problem, variant to exclude in document and problem", () => { - let activityDefinition = ` + let doenetML = ` @@ -1614,7 +1614,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", @@ -1673,7 +1673,7 @@ describe("Activity variants tests", function () { }); it("Two pages, variants from document and problem, variant to include in document and problem", () => { - let activityDefinition = ` + let doenetML = ` @@ -1710,7 +1710,7 @@ describe("Activity variants tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, requestedVariantIndex: ind, }, "*", diff --git a/cypress/e2e/ActivityViewer/compiledActivity.cy.js b/cypress/e2e/ActivityViewer/compiledActivity.cy.js index 96cc42ef82..c861bbfd21 100644 --- a/cypress/e2e/ActivityViewer/compiledActivity.cy.js +++ b/cypress/e2e/ActivityViewer/compiledActivity.cy.js @@ -13,7 +13,7 @@ describe("Compiled activity tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition: ` + doenetML: ` hi @@ -33,7 +33,7 @@ describe("Compiled activity tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition: ` + doenetML: ` hi @@ -55,7 +55,7 @@ describe("Compiled activity tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition: ` + doenetML: ` hi `, }, @@ -70,7 +70,7 @@ describe("Compiled activity tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition: ` + doenetML: ` hi `, }, diff --git a/cypress/e2e/ActivityViewer/relationshipsAmongPages.cy.js b/cypress/e2e/ActivityViewer/relationshipsAmongPages.cy.js index 301c628acf..107c81b8ee 100644 --- a/cypress/e2e/ActivityViewer/relationshipsAmongPages.cy.js +++ b/cypress/e2e/ActivityViewer/relationshipsAmongPages.cy.js @@ -7,7 +7,7 @@ describe("Relationships among pages tests", function () { }); it("Problem numbering continues across pages", () => { - let activityDefinition = ` + let doenetML = ` @@ -49,7 +49,7 @@ describe("Relationships among pages tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, }, "*", ); @@ -160,7 +160,7 @@ describe("Relationships among pages tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, }, "*", ); @@ -194,7 +194,7 @@ describe("Relationships among pages tests", function () { }); it("Section numbering continues across pages", () => { - let activityDefinition = ` + let doenetML = ` @@ -254,7 +254,7 @@ describe("Relationships among pages tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, }, "*", ); @@ -365,7 +365,7 @@ describe("Relationships among pages tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, }, "*", ); @@ -400,7 +400,7 @@ describe("Relationships among pages tests", function () { }); it("Links across pages", () => { - let activityDefinition = ` + let doenetML = ` @@ -456,7 +456,7 @@ describe("Relationships among pages tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, }, "*", ); @@ -543,7 +543,7 @@ describe("Relationships among pages tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, }, "*", ); @@ -596,7 +596,7 @@ describe("Relationships among pages tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, }, "*", ); @@ -637,7 +637,7 @@ describe("Relationships among pages tests", function () { cy.window().then(async (win) => { win.postMessage( { - activityDefinition, + doenetML, }, "*", ); diff --git a/cypress/e2e/DoenetML/variants/uniquevariants.cy.js b/cypress/e2e/DoenetML/variants/uniquevariants.cy.js index 4b15ec50bd..3ab7ed92ae 100644 --- a/cypress/e2e/DoenetML/variants/uniquevariants.cy.js +++ b/cypress/e2e/DoenetML/variants/uniquevariants.cy.js @@ -3529,7 +3529,7 @@ describe("Specifying unique variant tests", function () { it("no variant control, problem with 3 selects", () => { // Catch bug in enumerateCombinations - // where was indirectly overwriting numberOfVariantsByDescendant + // where was indirectly overwriting numVariantsByDescendant let values = [135, 246, 145, 236, 136, 245, 146, 235]; cy.log("get each value exactly one"); diff --git a/doenet_docker/volumes/db_init/db_template.sql b/doenet_docker/volumes/db_init/db_template.sql index 4b49e9bc15..48f7ebd76c 100644 --- a/doenet_docker/volumes/db_init/db_template.sql +++ b/doenet_docker/volumes/db_init/db_template.sql @@ -56,7 +56,7 @@ CREATE TABLE `activity_state` ( LOCK TABLES `activity_state` WRITE; /*!40000 ALTER TABLE `activity_state` DISABLE KEYS */; -INSERT INTO `activity_state` VALUES (1,'cyuserId','_Ga07DeeWjhH6Y4UpWlakE',1,'StbBhgrC0UT1kf31HTUzI','bafkreieszxhhjdhin3wbdvaudhiumb2ygqbnd6cfwyz4hqjdcbgrw6cebq','Salix caprea',379,'{\"orderWithCids\":[{\"type\":\"page\",\"cid\":\"bafkreiemblagflvpgbvw2zgurtswwcltj6mkolerhebcymztdmrsoabz6a\"}],\"variantsByPage\":[1],\"itemWeights\":[1],\"numberOfVariants\":1000}','{\"currentPage\":1}'); +INSERT INTO `activity_state` VALUES (1,'cyuserId','_Ga07DeeWjhH6Y4UpWlakE',1,'StbBhgrC0UT1kf31HTUzI','bafkreieszxhhjdhin3wbdvaudhiumb2ygqbnd6cfwyz4hqjdcbgrw6cebq','Salix caprea',379,'{\"orderWithCids\":[{\"type\":\"page\",\"cid\":\"bafkreiemblagflvpgbvw2zgurtswwcltj6mkolerhebcymztdmrsoabz6a\"}],\"variantsByPage\":[1],\"itemWeights\":[1],\"numVariants\":1000}','{\"currentPage\":1}'); /*!40000 ALTER TABLE `activity_state` ENABLE KEYS */; UNLOCK TABLES; diff --git a/public/api/parseActivityDefinitionRenamePages.php b/public/api/parseActivityDefinitionRenamePages.php index 609b65bb8a..52cf160bf2 100644 --- a/public/api/parseActivityDefinitionRenamePages.php +++ b/public/api/parseActivityDefinitionRenamePages.php @@ -46,8 +46,8 @@ function parse_activity_definition_rename_pages($activity_xml) { $activity_definition["shuffleItemWeights"] = true; } - if ($activity_object["numberOfVariants"]) { - $activity_definition["numberOfVariants"] = (string)$activity_object["itemWeights"]; + if ($activity_object["numVariants"]) { + $activity_definition["numVariants"] = (string)$activity_object["itemWeights"]; } diff --git a/src/Core/Core.js b/src/Core/Core.js index cd2f0a8bbb..85b1a95d24 100644 --- a/src/Core/Core.js +++ b/src/Core/Core.js @@ -25,7 +25,7 @@ import createComponentInfoObjects from "./utils/componentInfoObjects"; import { get as idb_get, set as idb_set } from "idb-keyval"; import { toastType } from "../Tools/_framework/ToastTypes"; import axios from "axios"; -import { gatherVariantComponents, getNumberOfVariants } from "./utils/variants"; +import { gatherVariantComponents, getNumVariants } from "./utils/variants"; import { assignDoenetMLRange, findAllNewlines, @@ -38,7 +38,9 @@ import { export default class Core { constructor({ doenetML, - doenetId, + preliminarySerializedComponents, + activityId, + cid, activityCid, pageNumber, attemptNumber = 1, @@ -58,13 +60,14 @@ export default class Core { // console.time('core'); this.coreId = coreId; - this.doenetId = doenetId; + this.activityId = activityId; this.activityCid = activityCid; this.pageNumber = pageNumber; this.attemptNumber = attemptNumber; this.itemNumber = itemNumber; this.activityVariantIndex = activityVariantIndex; this.doenetML = doenetML; + this.cid = cid; this.serverSaveId = serverSaveId; this.updateDataOnContentChange = updateDataOnContentChange; @@ -192,15 +195,13 @@ export default class Core { } }; - cidFromText(doenetML) - .then((cid) => - serializeFunctions.expandDoenetMLsToFullSerializedComponents({ - cids: [cid], - doenetMLs: [doenetML], - componentInfoObjects: this.componentInfoObjects, - flags: this.flags, - }), - ) + serializeFunctions + .expandDoenetMLsToFullSerializedComponents({ + doenetMLs: [doenetML], + preliminarySerializedComponents: [preliminarySerializedComponents], + componentInfoObjects: this.componentInfoObjects, + flags: this.flags, + }) .then(this.finishCoreConstruction) .catch((e) => { // throw e; @@ -213,13 +214,11 @@ export default class Core { } async finishCoreConstruction({ - cids, fullSerializedComponents, allDoenetMLs, errors, warnings, }) { - this.cid = cids[0]; this.allDoenetMLs = allDoenetMLs; this.doenetMLNewlines = findAllNewlines(allDoenetMLs[0]); @@ -321,10 +320,10 @@ export default class Core { // console.timeEnd('serialize doenetML'); - let numVariants = getNumberOfVariants({ + let numVariants = getNumVariants({ serializedComponent: serializedComponents[0], componentInfoObjects: this.componentInfoObjects, - }).numberOfVariants; + }).numVariants; if (!this.requestedVariant) { // don't have full variant, just requested variant index @@ -10296,7 +10295,7 @@ export default class Core { } const payload = { - doenetId: this.doenetId, + doenetId: this.activityId, activityCid: this.activityCid, pageCid: this.cid, pageNumber: this.pageNumber, @@ -11725,7 +11724,7 @@ export default class Core { if (this.flags.allowLocalState) { await idb_set( - `${this.doenetId}|${this.pageNumber}|${this.attemptNumber}|${this.cid}`, + `${this.activityId}|${this.pageNumber}|${this.attemptNumber}|${this.cid}`, { coreState: this.cumulativeStateVariableChanges, rendererState: this.rendererState, @@ -11757,7 +11756,7 @@ export default class Core { ), pageNumber: this.pageNumber, attemptNumber: this.attemptNumber, - doenetId: this.doenetId, + doenetId: this.activityId, saveId, serverSaveId: this.serverSaveId, updateDataOnContentChange: this.updateDataOnContentChange, @@ -11858,7 +11857,7 @@ export default class Core { if (this.flags.allowLocalState) { await idb_set( - `${this.doenetId}|${this.pageNumber}|${this.attemptNumber}|${this.cid}|ServerSaveId`, + `${this.activityId}|${this.pageNumber}|${this.attemptNumber}|${this.cid}|ServerSaveId`, data.saveId, ); } @@ -11872,7 +11871,7 @@ export default class Core { ) { if (this.flags.allowLocalState) { await idb_set( - `${this.doenetId}|${this.pageNumber}|${data.attemptNumber}|${data.cid}`, + `${this.activityId}|${this.pageNumber}|${data.attemptNumber}|${data.cid}`, { coreState: JSON.parse( data.coreState, @@ -11923,7 +11922,7 @@ export default class Core { } const payload = { - doenetId: this.doenetId, + doenetId: this.activityId, attemptNumber: this.attemptNumber, credit: pageCreditAchieved, itemNumber: this.itemNumber, @@ -12164,7 +12163,7 @@ export default class Core { try { const resp = await axios.post("/api/reportSolutionViewed.php", { - doenetId: this.doenetId, + doenetId: this.activityId, itemNumber: this.itemNumber, pageNumber: this.pageNumber, attemptNumber: this.attemptNumber, diff --git a/src/Core/components/ChoiceInput.js b/src/Core/components/ChoiceInput.js index d50bf2c77d..f14c664536 100644 --- a/src/Core/components/ChoiceInput.js +++ b/src/Core/components/ChoiceInput.js @@ -1446,19 +1446,18 @@ export default class Choiceinput extends Input { return { success: false }; } - let numberOfVariants = result.numberOfVariants * numberOfPermutations; + let numVariants = result.numVariants * numberOfPermutations; // adjust variants info added by call to super - serializedComponent.variants.numberOfVariants = numberOfVariants; + serializedComponent.variants.numVariants = numVariants; serializedComponent.variants.uniqueVariantData = { - numberOfVariantsByDescendant: - serializedComponent.variants.uniqueVariantData - .numberOfVariantsByDescendant, + numVariantsByDescendant: + serializedComponent.variants.uniqueVariantData.numVariantsByDescendant, numberOfPermutations, numChoices, }; - return { success: true, numberOfVariants }; + return { success: true, numVariants }; } static getUniqueVariant({ @@ -1466,15 +1465,15 @@ export default class Choiceinput extends Input { variantIndex, componentInfoObjects, }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; - if (numberOfVariants === undefined) { + let numVariants = serializedComponent.variants?.numVariants; + if (numVariants === undefined) { return { success: false }; } if ( !Number.isInteger(variantIndex) || variantIndex < 1 || - variantIndex > numberOfVariants + variantIndex > numVariants ) { return { success: false }; } @@ -1487,9 +1486,8 @@ export default class Choiceinput extends Input { }); } - let numberOfVariantsByDescendant = - serializedComponent.variants.uniqueVariantData - .numberOfVariantsByDescendant; + let numVariantsByDescendant = + serializedComponent.variants.uniqueVariantData.numVariantsByDescendant; let descendantVariantComponents = serializedComponent.variants.descendantVariantComponents; let numberOfPermutations = @@ -1497,7 +1495,7 @@ export default class Choiceinput extends Input { let numChoices = serializedComponent.variants.uniqueVariantData.numChoices; // treat permutations as another descendant variant component - let numbersOfOptions = [...numberOfVariantsByDescendant]; + let numbersOfOptions = [...numVariantsByDescendant]; numbersOfOptions.push(numberOfPermutations); let indicesForEachOption = enumerateCombinations({ @@ -1525,10 +1523,10 @@ export default class Choiceinput extends Input { for ( let descendantNum = 0; - descendantNum < numberOfVariantsByDescendant.length; + descendantNum < numVariantsByDescendant.length; descendantNum++ ) { - if (numberOfVariantsByDescendant[descendantNum] > 1) { + if (numVariantsByDescendant[descendantNum] > 1) { let descendant = descendantVariantComponents[descendantNum]; let compClass = componentInfoObjects.allComponentClasses[descendant.componentType]; diff --git a/src/Core/components/Document.js b/src/Core/components/Document.js index 8966a22c6c..fea84037ad 100644 --- a/src/Core/components/Document.js +++ b/src/Core/components/Document.js @@ -765,7 +765,7 @@ export default class Document extends BaseComponent { }) { // console.log("****Variant for document*****") - let numVariants = serializedComponent.variants.numberOfVariants; + let numVariants = serializedComponent.variants.numVariants; let variantIndex; // check if desiredVariant was specified diff --git a/src/Core/components/Map.js b/src/Core/components/Map.js index fb7e541d32..746db1a0b2 100644 --- a/src/Core/components/Map.js +++ b/src/Core/components/Map.js @@ -800,10 +800,10 @@ export default class Map extends CompositeComponent { serializedComponent, componentInfoObjects, }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; + let numVariants = serializedComponent.variants?.numVariants; - if (numberOfVariants !== undefined) { - return { success: true, numberOfVariants }; + if (numVariants !== undefined) { + return { success: true, numVariants }; } let descendantVariantComponents = gatherVariantComponents({ @@ -811,7 +811,7 @@ export default class Map extends CompositeComponent { componentInfoObjects, }); - let numberOfVariantsByDescendant = []; + let numVariantsByDescendant = []; for (let descendant of descendantVariantComponents) { let descendantClass = componentInfoObjects.allComponentClasses[descendant.componentType]; @@ -822,20 +822,20 @@ export default class Map extends CompositeComponent { if (!result.success) { return { success: false }; } - numberOfVariantsByDescendant.push(result.numberOfVariants); + numVariantsByDescendant.push(result.numVariants); } if ( - numberOfVariantsByDescendant.length === 1 && - numberOfVariantsByDescendant[0] === 1 + numVariantsByDescendant.length === 1 && + numVariantsByDescendant[0] === 1 ) { // just have a template with one variant // so will have a single variant even if don't know how many times the template is repeated - serializedComponent.variants.numberOfVariants = 1; + serializedComponent.variants.numVariants = 1; return { success: true, - numberOfVariants: 1, + numVariants: 1, }; } @@ -847,15 +847,15 @@ export default class Map extends CompositeComponent { variantIndex, componentInfoObjects, }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; - if (numberOfVariants === undefined) { + let numVariants = serializedComponent.variants?.numVariants; + if (numVariants === undefined) { return { success: false }; } if ( !Number.isInteger(variantIndex) || variantIndex < 1 || - variantIndex > numberOfVariants + variantIndex > numVariants ) { return { success: false }; } diff --git a/src/Core/components/Select.js b/src/Core/components/Select.js index eaac2ac3a4..553b4226e3 100644 --- a/src/Core/components/Select.js +++ b/src/Core/components/Select.js @@ -693,10 +693,10 @@ export default class Select extends CompositeComponent { serializedComponent, componentInfoObjects, }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; + let numVariants = serializedComponent.variants?.numVariants; - if (numberOfVariants !== undefined) { - return { success: true, numberOfVariants }; + if (numVariants !== undefined) { + return { success: true, numVariants }; } let numToSelect = 1, @@ -783,7 +783,7 @@ export default class Select extends CompositeComponent { serializedComponent.variants.descendantVariantComponents = descendantVariantComponents; - let numberOfVariantsByChild = []; + let numVariantsByChild = []; for (let descendant of descendantVariantComponents) { let descendantClass = componentInfoObjects.allComponentClasses[descendant.componentType]; @@ -794,31 +794,31 @@ export default class Select extends CompositeComponent { if (!result.success) { return { success: false }; } - numberOfVariantsByChild.push(result.numberOfVariants); + numVariantsByChild.push(result.numVariants); } let uniqueVariantData = { - numberOfVariantsByChild, + numVariantsByChild, numToSelect, withReplacement, }; - if (numberOfVariantsByChild.length === 0) { - numberOfVariants = 1; + if (numVariantsByChild.length === 0) { + numVariants = 1; } else if (withReplacement || numToSelect === 1) { - let numberOfOptionsPerSelection = numberOfVariantsByChild.reduce( + let numberOfOptionsPerSelection = numVariantsByChild.reduce( (a, c) => a + c, ); - numberOfVariants = Math.pow(numberOfOptionsPerSelection, numToSelect); + numVariants = Math.pow(numberOfOptionsPerSelection, numToSelect); } else { - let numChildren = numberOfVariantsByChild.length; + let numChildren = numVariantsByChild.length; if (numToSelect > numChildren) { return { success: false }; } - let firstNumber = numberOfVariantsByChild[0]; - let allSameNumber = numberOfVariantsByChild + let firstNumber = numVariantsByChild[0]; + let allSameNumber = numVariantsByChild .slice(1) .every((x) => x === firstNumber); @@ -827,25 +827,24 @@ export default class Select extends CompositeComponent { for (let n = numChildren - 1; n > numChildren - numToSelect; n--) { numberOfPermutations *= n; } - numberOfVariants = - numberOfPermutations * Math.pow(firstNumber, numToSelect); + numVariants = numberOfPermutations * Math.pow(firstNumber, numToSelect); } else { // have select without replacement where options have different numbers of variants - numberOfVariants = countOptions(numberOfVariantsByChild, numToSelect); + numVariants = countOptions(numVariantsByChild, numToSelect); } } - if (!(numberOfVariants > 0)) { + if (!(numVariants > 0)) { return { success: false }; } - serializedComponent.variants.numberOfVariants = numberOfVariants; + serializedComponent.variants.numVariants = numVariants; serializedComponent.variants.uniqueVariants = true; serializedComponent.variants.uniqueVariantData = uniqueVariantData; return { success: true, - numberOfVariants, + numVariants, }; } @@ -854,27 +853,27 @@ export default class Select extends CompositeComponent { variantIndex, componentInfoObjects, }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; - if (numberOfVariants === undefined) { + let numVariants = serializedComponent.variants?.numVariants; + if (numVariants === undefined) { return { success: false }; } if ( !Number.isInteger(variantIndex) || variantIndex < 1 || - variantIndex > numberOfVariants + variantIndex > numVariants ) { return { success: false }; } let uniqueVariantData = serializedComponent.variants.uniqueVariantData; - let numberOfVariantsByChild = uniqueVariantData.numberOfVariantsByChild; + let numVariantsByChild = uniqueVariantData.numVariantsByChild; let numToSelect = uniqueVariantData.numToSelect; let withReplacement = uniqueVariantData.withReplacement; let numChildren = serializedComponent.children.length; let childrenToSelect = serializedComponent.children; - if (numberOfVariantsByChild.length === 0) { + if (numVariantsByChild.length === 0) { return { success: true, desiredVariant: { indices: [] } }; } @@ -899,13 +898,13 @@ export default class Select extends CompositeComponent { let combinationsAvailable = combinations.map((x) => ({ combination: x, numberOfPossibilities: x.reduce( - (a, c) => a * numberOfVariantsByChild[c], + (a, c) => a * numVariantsByChild[c], 1, ), })); // console.log(combinationsAvailable); - // console.log(numberOfVariantsByChild); + // console.log(numVariantsByChild); // The variants, in order, will // select the first possibility from each combination @@ -958,7 +957,7 @@ export default class Select extends CompositeComponent { let indicesForEachChild = enumerateCombinations({ numberOfOptionsByIndex: selectedCombination.map( - (x) => numberOfVariantsByChild[x], + (x) => numVariantsByChild[x], ), maxNumber: variantIndexOfSelected, })[variantIndexOfSelected - 1].map((x) => x + 1); @@ -973,7 +972,7 @@ export default class Select extends CompositeComponent { let haveNontrivialSubvariants = false; for (let [ind, childNum] of selectedCombination.entries()) { - if (numberOfVariantsByChild[childNum] > 1) { + if (numVariantsByChild[childNum] > 1) { let child = childrenToSelect[childNum]; let compClass = componentInfoObjects.allComponentClasses[child.componentType]; diff --git a/src/Core/components/SelectFromSequence.js b/src/Core/components/SelectFromSequence.js index 6e42f7cb78..53bb5f35a2 100644 --- a/src/Core/components/SelectFromSequence.js +++ b/src/Core/components/SelectFromSequence.js @@ -657,39 +657,39 @@ export default class SelectFromSequence extends Sequence { serializedComponent.variants.uniqueVariantData = uniqueVariantData; - let numberOfVariants; + let numVariants; if (withReplacement || numToSelect === 1) { - numberOfVariants = Math.pow(nOptions, numToSelect); + numVariants = Math.pow(nOptions, numToSelect); } else { - numberOfVariants = nOptions; + numVariants = nOptions; for (let n = nOptions - 1; n > nOptions - numToSelect; n--) { - numberOfVariants *= n; + numVariants *= n; } } - if (!(numberOfVariants > 0)) { + if (!(numVariants > 0)) { return { success: false }; } - serializedComponent.variants.numberOfVariants = numberOfVariants; + serializedComponent.variants.numVariants = numVariants; return { success: true, - numberOfVariants: numberOfVariants, + numVariants: numVariants, }; } static getUniqueVariant({ serializedComponent, variantIndex }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; - if (numberOfVariants === undefined) { + let numVariants = serializedComponent.variants?.numVariants; + if (numVariants === undefined) { return { success: false }; } if ( !Number.isInteger(variantIndex) || variantIndex < 1 || - variantIndex > numberOfVariants + variantIndex > numVariants ) { return { success: false }; } diff --git a/src/Core/components/SelectPrimeNumbers.js b/src/Core/components/SelectPrimeNumbers.js index 2b4787612c..a8b0446d1b 100644 --- a/src/Core/components/SelectPrimeNumbers.js +++ b/src/Core/components/SelectPrimeNumbers.js @@ -447,39 +447,39 @@ export default class SelectPrimeNumbers extends CompositeComponent { serializedComponent.variants.uniqueVariantData = uniqueVariantData; - let numberOfVariants; + let numVariants; if (withReplacement || numToSelect === 1) { - numberOfVariants = Math.pow(primes.length, numToSelect); + numVariants = Math.pow(primes.length, numToSelect); } else { - numberOfVariants = primes.length; + numVariants = primes.length; for (let n = primes.length - 1; n > primes.length - numToSelect; n--) { - numberOfVariants *= n; + numVariants *= n; } } - if (!(numberOfVariants > 0)) { + if (!(numVariants > 0)) { return { success: false }; } - serializedComponent.variants.numberOfVariants = numberOfVariants; + serializedComponent.variants.numVariants = numVariants; return { success: true, - numberOfVariants: numberOfVariants, + numVariants: numVariants, }; } static getUniqueVariant({ serializedComponent, variantIndex }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; - if (numberOfVariants === undefined) { + let numVariants = serializedComponent.variants?.numVariants; + if (numVariants === undefined) { return { success: false }; } if ( !Number.isInteger(variantIndex) || variantIndex < 1 || - variantIndex > numberOfVariants + variantIndex > numVariants ) { return { success: false }; } diff --git a/src/Core/components/Shuffle.js b/src/Core/components/Shuffle.js index f36522359f..57073f4c72 100644 --- a/src/Core/components/Shuffle.js +++ b/src/Core/components/Shuffle.js @@ -390,23 +390,22 @@ export default class Shuffle extends CompositeComponent { return { success: false }; } - let numberOfVariants = result.numberOfVariants * numberOfPermutations; + let numVariants = result.numVariants * numberOfPermutations; - if (!(numberOfVariants > 0)) { + if (!(numVariants > 0)) { return { success: false }; } // adjust variants info added by call to super - serializedComponent.variants.numberOfVariants = numberOfVariants; + serializedComponent.variants.numVariants = numVariants; serializedComponent.variants.uniqueVariantData = { - numberOfVariantsByDescendant: - serializedComponent.variants.uniqueVariantData - .numberOfVariantsByDescendant, + numVariantsByDescendant: + serializedComponent.variants.uniqueVariantData.numVariantsByDescendant, numberOfPermutations, numComponents, }; - return { success: true, numberOfVariants }; + return { success: true, numVariants }; } static getUniqueVariant({ @@ -414,22 +413,21 @@ export default class Shuffle extends CompositeComponent { variantIndex, componentInfoObjects, }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; - if (numberOfVariants === undefined) { + let numVariants = serializedComponent.variants?.numVariants; + if (numVariants === undefined) { return { success: false }; } if ( !Number.isInteger(variantIndex) || variantIndex < 1 || - variantIndex > numberOfVariants + variantIndex > numVariants ) { return { success: false }; } - let numberOfVariantsByDescendant = - serializedComponent.variants.uniqueVariantData - .numberOfVariantsByDescendant; + let numVariantsByDescendant = + serializedComponent.variants.uniqueVariantData.numVariantsByDescendant; let descendantVariantComponents = serializedComponent.variants.descendantVariantComponents; let numberOfPermutations = @@ -438,7 +436,7 @@ export default class Shuffle extends CompositeComponent { serializedComponent.variants.uniqueVariantData.numComponents; // treat permutations as another descendant variant component - let numbersOfOptions = [...numberOfVariantsByDescendant]; + let numbersOfOptions = [...numVariantsByDescendant]; numbersOfOptions.push(numberOfPermutations); let indicesForEachOption = enumerateCombinations({ @@ -466,10 +464,10 @@ export default class Shuffle extends CompositeComponent { for ( let descendantNum = 0; - descendantNum < numberOfVariantsByDescendant.length; + descendantNum < numVariantsByDescendant.length; descendantNum++ ) { - if (numberOfVariantsByDescendant[descendantNum] > 1) { + if (numVariantsByDescendant[descendantNum] > 1) { let descendant = descendantVariantComponents[descendantNum]; let compClass = componentInfoObjects.allComponentClasses[descendant.componentType]; diff --git a/src/Core/components/abstract/BaseComponent.js b/src/Core/components/abstract/BaseComponent.js index b19305a031..ba18738dde 100644 --- a/src/Core/components/abstract/BaseComponent.js +++ b/src/Core/components/abstract/BaseComponent.js @@ -1414,10 +1414,10 @@ export default class BaseComponent { serializedComponent, componentInfoObjects, }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; + let numVariants = serializedComponent.variants?.numVariants; - if (numberOfVariants !== undefined) { - return { success: true, numberOfVariants }; + if (numVariants !== undefined) { + return { success: true, numVariants }; } let descendantVariantComponents = []; @@ -1438,9 +1438,9 @@ export default class BaseComponent { // number of variants is the product of // number of variants for each descendantVariantComponent - numberOfVariants = 1; + numVariants = 1; - let numberOfVariantsByDescendant = []; + let numVariantsByDescendant = []; for (let descendant of descendantVariantComponents) { let descendantClass = componentInfoObjects.allComponentClasses[descendant.componentType]; @@ -1451,20 +1451,20 @@ export default class BaseComponent { if (!result.success) { return { success: false }; } - numberOfVariantsByDescendant.push(result.numberOfVariants); - numberOfVariants *= result.numberOfVariants; + numVariantsByDescendant.push(result.numVariants); + numVariants *= result.numVariants; } - if (!(numberOfVariants > 0)) { + if (!(numVariants > 0)) { return { success: false }; } - serializedComponent.variants.numberOfVariants = numberOfVariants; + serializedComponent.variants.numVariants = numVariants; serializedComponent.variants.uniqueVariantData = { - numberOfVariantsByDescendant, + numVariantsByDescendant, }; - return { success: true, numberOfVariants }; + return { success: true, numVariants }; } static getUniqueVariant({ @@ -1472,24 +1472,23 @@ export default class BaseComponent { variantIndex, componentInfoObjects, }) { - let numberOfVariants = serializedComponent.variants?.numberOfVariants; - if (numberOfVariants === undefined) { + let numVariants = serializedComponent.variants?.numVariants; + if (numVariants === undefined) { return { success: false }; } if ( !Number.isInteger(variantIndex) || variantIndex < 1 || - variantIndex > numberOfVariants + variantIndex > numVariants ) { return { success: false }; } let haveNontrivialSubvariants = false; - let numberOfVariantsByDescendant = - serializedComponent.variants.uniqueVariantData - .numberOfVariantsByDescendant; + let numVariantsByDescendant = + serializedComponent.variants.uniqueVariantData.numVariantsByDescendant; let descendantVariantComponents = serializedComponent.variants.descendantVariantComponents; @@ -1497,7 +1496,7 @@ export default class BaseComponent { if (descendantVariantComponents.length > 0) { let indicesForEachDescendant = enumerateCombinations({ - numberOfOptionsByIndex: numberOfVariantsByDescendant, + numberOfOptionsByIndex: numVariantsByDescendant, maxNumber: variantIndex, })[variantIndex - 1].map((x) => x + 1); @@ -1506,10 +1505,10 @@ export default class BaseComponent { for ( let descendantNum = 0; - descendantNum < numberOfVariantsByDescendant.length; + descendantNum < numVariantsByDescendant.length; descendantNum++ ) { - if (numberOfVariantsByDescendant[descendantNum] > 1) { + if (numVariantsByDescendant[descendantNum] > 1) { let descendant = descendantVariantComponents[descendantNum]; let compClass = componentInfoObjects.allComponentClasses[descendant.componentType]; diff --git a/src/Core/components/abstract/SectioningComponent.js b/src/Core/components/abstract/SectioningComponent.js index 74484437d0..6935353a20 100644 --- a/src/Core/components/abstract/SectioningComponent.js +++ b/src/Core/components/abstract/SectioningComponent.js @@ -1007,7 +1007,7 @@ export class SectioningComponent extends BlockComponent { return; } - let numVariants = serializedComponent.variants.numberOfVariants; + let numVariants = serializedComponent.variants.numVariants; let variantIndex; // check if desiredVariant was specified diff --git a/src/Core/utils/returnAllPossibleVariants.js b/src/Core/utils/returnAllPossibleVariants.js index 6ea55b9790..9c4147e30a 100644 --- a/src/Core/utils/returnAllPossibleVariants.js +++ b/src/Core/utils/returnAllPossibleVariants.js @@ -1,23 +1,18 @@ import { numberToLetters } from "./sequence.js"; import * as serializeFunctions from "./serializedStateProcessing.js"; import createComponentInfoObjects from "./componentInfoObjects.js"; -import { retrieveTextFileForCid } from "./retrieveTextFile.js"; -import { cidFromText } from "./cid.js"; -import { getNumberOfVariants } from "./variants.js"; - -export async function returnAllPossibleVariants({ cid, doenetML }) { - if (doenetML === undefined) { - doenetML = await retrieveTextFileForCid(cid, "doenet"); - } else if (!cid) { - cid = await cidFromText(doenetML); - } +import { getNumVariants } from "./variants.js"; +export async function returnAllPossibleVariants({ + doenetML, + serializedComponents: preliminarySerializedComponents, +}) { let componentInfoObjects = createComponentInfoObjects(); let { fullSerializedComponents } = await serializeFunctions.expandDoenetMLsToFullSerializedComponents({ - contentIds: [cid], doenetMLs: [doenetML], + preliminarySerializedComponents: [preliminarySerializedComponents], componentInfoObjects, }); @@ -27,12 +22,12 @@ export async function returnAllPossibleVariants({ cid, doenetML }) { let document = serializedComponents[0]; - let results = getNumberOfVariants({ + let results = getNumVariants({ serializedComponent: document, componentInfoObjects, }); - let numVariants = results.numberOfVariants; + let numVariants = results.numVariants; let allPossibleVariants; @@ -65,7 +60,7 @@ export async function returnAllPossibleVariants({ cid, doenetML }) { ); } - return { allPossibleVariants, doenetML, cid }; + return allPossibleVariants; } function indexToLowercaseLetters(index) { diff --git a/src/Core/utils/serializedStateProcessing.js b/src/Core/utils/serializedStateProcessing.js index 3cf6424872..34477c70d9 100644 --- a/src/Core/utils/serializedStateProcessing.js +++ b/src/Core/utils/serializedStateProcessing.js @@ -9,8 +9,8 @@ import { retrieveTextFileForCid } from "./retrieveTextFile"; import { returnDeprecationMessage } from "./doenetMLversion"; export async function expandDoenetMLsToFullSerializedComponents({ - cids, doenetMLs, + preliminarySerializedComponents = [], componentInfoObjects, nPreviousDoenetMLs = 0, }) { @@ -23,11 +23,20 @@ export async function expandDoenetMLsToFullSerializedComponents({ for (let [ind, doenetML] of doenetMLs.entries()) { let errorsForDoenetML = []; let warningsForDoenetML = []; - - let result = parseAndCompile(doenetML); - let serializedComponents = result.components; - errorsForDoenetML.push(...result.errors); - warningsForDoenetML.push(...result.warnings); + let result; + + // if we happened to send in the parsed preliminary serialized components, + // then we don't need to parse the DoenetML again + let serializedComponents; + if (preliminarySerializedComponents[ind]) { + serializedComponents = JSON.parse( + JSON.stringify(preliminarySerializedComponents[ind]), + ); + } else { + result = parseAndCompile(doenetML); + serializedComponents = result.components; + errorsForDoenetML.push(...result.errors); + } serializedComponents = cleanIfHaveJustDocument(serializedComponents); @@ -147,7 +156,6 @@ export async function expandDoenetMLsToFullSerializedComponents({ warnings: additionalWarnings, } = await expandDoenetMLsToFullSerializedComponents({ doenetMLs: newDoenetMLs, - cids: newCids, componentInfoObjects, nPreviousDoenetMLs: nPreviousDoenetMLs + doenetMLs.length, }); @@ -237,7 +245,6 @@ export async function expandDoenetMLsToFullSerializedComponents({ } return { - cids, fullSerializedComponents: arrayOfSerializedComponents, allDoenetMLs, errors, @@ -2067,7 +2074,6 @@ function createAttributesFromString(componentAttributes, componentInfoObjects) { componentsForAttributes = result.components; errors.push(...result.errors); - warnings.push(...result.warnings); } catch (e) { errors.push({ message: "Error in macro", diff --git a/src/Core/utils/variants.js b/src/Core/utils/variants.js index 14ca5b9786..2a31fd6afa 100644 --- a/src/Core/utils/variants.js +++ b/src/Core/utils/variants.js @@ -13,12 +13,12 @@ export function getVariantsForDescendantsForUniqueVariants({ return { success: false }; } - let numberOfVariantsByDescendant = descendantVariantComponents.map( - (x) => x.variants.numberOfVariants, + let numVariantsByDescendant = descendantVariantComponents.map( + (x) => x.variants.numVariants, ); let indices = enumerateCombinations({ - numberOfOptionsByIndex: numberOfVariantsByDescendant, + numberOfOptionsByIndex: numVariantsByDescendant, maxNumber: variantIndex, })[variantIndex - 1]; @@ -172,10 +172,7 @@ export function gatherVariantComponents({ return variantComponents; } -export function getNumberOfVariants({ - serializedComponent, - componentInfoObjects, -}) { +export function getNumVariants({ serializedComponent, componentInfoObjects }) { // get number of variants from document (or other sectioning component) if (!serializedComponent.variants) { @@ -213,7 +210,7 @@ export function getNumberOfVariants({ ) { let sectionChild = nonBlankChildren[0]; - let results = getNumberOfVariants({ + let results = getNumVariants({ serializedComponent: sectionChild, componentInfoObjects, }); @@ -226,8 +223,8 @@ export function getNumberOfVariants({ }); serializedComponent.variants.uniqueVariants = true; - serializedComponent.variants.numberOfVariants = - sectionChild.variants.numberOfVariants; + serializedComponent.variants.numVariants = + sectionChild.variants.numVariants; serializedComponent.variants.allPossibleVariants = sectionChild.variants.allPossibleVariants; serializedComponent.variants.allVariantNames = @@ -432,11 +429,11 @@ export function determineVariantsForSection({ componentInfoObjects, }); - if (!uniqueResult.success || !(uniqueResult.numberOfVariants > 0)) { + if (!uniqueResult.success || !(uniqueResult.numVariants > 0)) { uniqueVariants = false; } else { uniqueVariants = - uniqueVariants || uniqueResult.numberOfVariants <= numVariantsSpecified; + uniqueVariants || uniqueResult.numVariants <= numVariantsSpecified; } } @@ -446,7 +443,7 @@ export function determineVariantsForSection({ if (uniqueVariants) { for (let [ind, num] of variantsToIncludeUniqueIndices.entries()) { - if (num <= uniqueResult.numberOfVariants) { + if (num <= uniqueResult.numVariants) { allPossibleVariantUniqueIndices.push(num); allPossibleVariants.push(variantsToInclude[ind]); allPossibleVariantSeeds.push(variantsToIncludeSeeds[ind]); @@ -458,15 +455,15 @@ export function determineVariantsForSection({ allPossibleVariantSeeds = variantsToIncludeSeeds; } - let numberOfVariants = allPossibleVariants.length; - if (numberOfVariants === 0) { + let numVariants = allPossibleVariants.length; + if (numVariants === 0) { throw Error( "No variants selected based on variantsToInclude, variantsToExclude, and the number of variants available", ); } serializedComponent.variants.uniqueVariants = uniqueVariants; - serializedComponent.variants.numberOfVariants = numberOfVariants; + serializedComponent.variants.numVariants = numVariants; serializedComponent.variants.allPossibleVariants = allPossibleVariants; serializedComponent.variants.allVariantNames = variantNames; serializedComponent.variants.allPossibleVariantUniqueIndices = @@ -476,7 +473,7 @@ export function determineVariantsForSection({ return { success: true, - numberOfVariants, + numVariants, }; } diff --git a/src/Parser/parser.js b/src/Parser/parser.js index 54b415ea2b..a7e55d1b84 100644 --- a/src/Parser/parser.js +++ b/src/Parser/parser.js @@ -15,7 +15,6 @@ export function parse(inText) { */ export function parseAndCompile(inText) { let errors = []; - let warnings = []; function compileElement(cursor) { if (cursor.name !== "Element") { @@ -88,6 +87,12 @@ export function parseAndCompile(inText) { adjustedTagName = "_error"; } else { attrs[attrName] = true; + attrRanges[attrName] = { + attrBegin: beginAttributeInd, + attrEnd: cursor.to, + begin: beginAttributeInd, + end: cursor.to, + }; } } else { cursor.nextSibling(); @@ -104,6 +109,8 @@ export function parseAndCompile(inText) { } else { attrs[attrName] = attrValue; attrRanges[attrName] = { + attrBegin: beginAttributeInd, + attrEnd: cursor.to, begin: cursor.from + 2, end: cursor.to - 1, }; @@ -325,7 +332,12 @@ export function parseAndCompile(inText) { //fuddling to ignore the quotes let attrValue = inText.substring(cursor.from + 1, cursor.to - 1); attrs[attrName] = attrValue; - attrRanges[attrName] = { begin: cursor.from + 1, end: cursor.to }; + attrRanges[attrName] = { + attrBegin: beginAttributeInd, + attrEnd: cursor.to, + begin: cursor.from + 2, + end: cursor.to - 1, + }; } } //move out of Attribute to maintain loop invariant @@ -417,12 +429,12 @@ export function parseAndCompile(inText) { } } if (!inText) { - return { components: [], errors, warnings }; + return { components: [], errors }; } let tc = parse(inText); let out = []; if (!tc.firstChild()) { - return { components: out, errors, warnings }; + return { components: out, errors }; } // console.log("intext",inText) // console.log("showCursor",showCursor(tc)); @@ -438,7 +450,7 @@ export function parseAndCompile(inText) { } } - return { components: out, errors, warnings }; + return { components: out, errors }; } /** diff --git a/src/Tools/_framework/Menus/CreditAchieved.jsx b/src/Tools/_framework/Menus/CreditAchieved.jsx index 8ff134b7df..5ec3e34c58 100644 --- a/src/Tools/_framework/Menus/CreditAchieved.jsx +++ b/src/Tools/_framework/Menus/CreditAchieved.jsx @@ -13,11 +13,11 @@ import { } from "../ToolPanels/AssignmentViewer"; import styled from "styled-components"; import { itemByDoenetId } from "../../../_reactComponents/Course/CourseActions"; -import { - activityAttemptNumberSetUpAtom, - currentPageAtom, - itemWeightsAtom, -} from "../../../Viewer/ActivityViewer"; +// import { +// activityAttemptNumberSetUpAtom, +// currentPageAtom, +// itemWeightsAtom, +// } from "../../../Viewer/ActivityViewer"; import { useLocation, useNavigate } from "react-router"; import { effectivePermissionsByCourseId } from "../../../_reactComponents/PanelHeaderComponents/RoleDropdown"; import Button from "../../../_reactComponents/PanelHeaderComponents/Button"; @@ -125,11 +125,12 @@ export default function CreditAchieved() { const recoilUserId = useRecoilValue(searchParamAtomFamily("userId")); const recoilTool = useRecoilValue(searchParamAtomFamily("tool")); const itemObj = useRecoilValue(itemByDoenetId(recoilDoenetId)); - const itemWeights = useRecoilValue(itemWeightsAtom); - const currentPage = useRecoilValue(currentPageAtom); - const activityAttemptNumberSetUp = useRecoilValue( - activityAttemptNumberSetUpAtom, - ); + const itemWeights = [];// useRecoilValue(itemWeightsAtom); + const currentPage = 1;//useRecoilValue(currentPageAtom); + const activityAttemptNumberSetUp = 1; + // useRecoilValue( + // activityAttemptNumberSetUpAtom, + // ); let { search } = useLocation(); let navigate = useNavigate(); diff --git a/src/Tools/_framework/Paths/Home.jsx b/src/Tools/_framework/Paths/Home.jsx index 6eedb21499..30ff455509 100644 --- a/src/Tools/_framework/Paths/Home.jsx +++ b/src/Tools/_framework/Paths/Home.jsx @@ -1,6 +1,6 @@ import React, { lazy, Suspense, useEffect } from "react"; -import { redirect, useLoaderData, useOutletContext } from "react-router"; -import PageViewer from "../../../Viewer/PageViewer"; +import { useLoaderData, useOutletContext } from "react-router"; +import { DoenetML } from "../../../Viewer/DoenetML"; import { pageVariantInfoAtom, pageVariantPanelAtom, @@ -247,26 +247,29 @@ export function Home() {
- - - Explore - - - Interact with our existing content - - -
+ + + Explore + + + Interact with{" "} + + our existing content + + + +
- - - Learn - - - Designed for the In-Person Classroom - - -
+ + + Learn + + + Designed for the In-Person Classroom + + + - diff --git a/src/Tools/_framework/Paths/PortfolioActivityEditor.jsx b/src/Tools/_framework/Paths/PortfolioActivityEditor.jsx index 4c1aa5cb5d..368f0f300e 100644 --- a/src/Tools/_framework/Paths/PortfolioActivityEditor.jsx +++ b/src/Tools/_framework/Paths/PortfolioActivityEditor.jsx @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from "react"; import { redirect, useLoaderData } from "react-router"; import CodeMirror from "../CodeMirror"; -import PageViewer from "../../../Viewer/PageViewer"; +import { DoenetML } from "../../../Viewer/DoenetML"; import Papa from "papaparse"; import { useSetRecoilState } from "recoil"; @@ -72,9 +72,9 @@ import { textEditorDoenetMLAtom } from "../../../_sharedRecoil/EditorViewerRecoi import { HiOutlineX, HiPlus } from "react-icons/hi"; // import Select from "react-select"; import { useCourse } from "../../../_reactComponents/Course/CourseActions"; -import VirtualKeyboard from "../Footers/VirtualKeyboard"; import VariantSelect from "../ChakraBasedComponents/VariantSelect"; import ErrorWarningPopovers from "../ChakraBasedComponents/ErrorWarningPopovers"; +import { useLocation, useNavigate } from "react-router"; export async function action({ params, request }) { const formData = await request.formData(); @@ -1317,6 +1317,9 @@ export function PortfolioActivityEditor() { let inTheMiddleOfSaving = useRef(false); let postponedSaving = useRef(false); + let navigate = useNavigate(); + let location = useLocation(); + const { saveDraft } = useSaveDraft(); const handleSaveDraft = useCallback(async () => { @@ -1408,15 +1411,18 @@ export function PortfolioActivityEditor() { }); // console.log("variants", variants); - function variantCallback(generatedVariantInfo, allPossibleVariants) { - // console.log(">>>variantCallback",generatedVariantInfo,allPossibleVariants) - const cleanGeneratedVariant = JSON.parse( - JSON.stringify(generatedVariantInfo), - ); - setVariants({ - index: cleanGeneratedVariant.index, - allPossibleVariants, - }); + function variantCallback({ pageVariant, activityVariant }) { + if (pageVariant) { + setVariants({ + index: Number(pageVariant.index), + allPossibleVariants: pageVariant.allPossibleVariants, + }); + } else if (activityVariant) { + setVariants({ + index: Number(activityVariant.variantIndex), + allPossibleVariants: activityVariant.allPossibleVariants, + }); + } } return ( @@ -1428,7 +1434,6 @@ export function PortfolioActivityEditor() { activityData={activityData} controlsTabsLastIndex={controlsTabsLastIndex} /> - <> - - @@ -1815,7 +1821,7 @@ export function PortfolioActivityEditor() { w="100%" > <> - - diff --git a/src/Tools/_framework/Paths/PortfolioActivityViewer.jsx b/src/Tools/_framework/Paths/PortfolioActivityViewer.jsx index e113c88ba7..cb546ce595 100644 --- a/src/Tools/_framework/Paths/PortfolioActivityViewer.jsx +++ b/src/Tools/_framework/Paths/PortfolioActivityViewer.jsx @@ -1,7 +1,12 @@ import React, { useEffect, useRef, useState } from "react"; -import { redirect, useLoaderData, useNavigate } from "react-router"; +import { + redirect, + useLoaderData, + useNavigate, + useLocation, +} from "react-router"; import styled from "styled-components"; -import PageViewer from "../../../Viewer/PageViewer"; +import { ActivityViewer } from "../../../Viewer/ActivityViewer"; import { useRecoilState } from "recoil"; import { checkIfUserClearedOut } from "../../../_utils/applicationUtils"; @@ -95,6 +100,7 @@ export function PortfolioActivityViewer() { } const navigate = useNavigate(); + const location = useLocation(); const [recoilPageToolView, setRecoilPageToolView] = useRecoilState(pageToolViewAtom); @@ -300,7 +306,7 @@ export function PortfolioActivityViewer() { width="100%" overflow="scroll" > - diff --git a/src/Tools/_framework/Paths/PublicEditor.jsx b/src/Tools/_framework/Paths/PublicEditor.jsx index 8f102dec1e..ab3228ffc1 100644 --- a/src/Tools/_framework/Paths/PublicEditor.jsx +++ b/src/Tools/_framework/Paths/PublicEditor.jsx @@ -3,11 +3,12 @@ import { redirect, useLoaderData, useNavigate, + useLocation, useOutletContext, } from "react-router"; import CodeMirror from "../CodeMirror"; -import PageViewer from "../../../Viewer/PageViewer"; +import { ActivityViewer } from "../../../Viewer/ActivityViewer"; import { Box, @@ -133,6 +134,7 @@ export function PublicEditor() { const { signedIn } = useOutletContext(); const navigate = useNavigate(); + const location = useLocation(); const [recoilPageToolView, setRecoilPageToolView] = useRecoilState(pageToolViewAtom); @@ -387,7 +389,7 @@ export function PublicEditor() { overflow="scroll" w="100%" > - diff --git a/src/Tools/_framework/ToolPanels/AssignmentViewer.jsx b/src/Tools/_framework/ToolPanels/AssignmentViewer.jsx index 276454dbae..bd433fd59f 100644 --- a/src/Tools/_framework/ToolPanels/AssignmentViewer.jsx +++ b/src/Tools/_framework/ToolPanels/AssignmentViewer.jsx @@ -1,6 +1,7 @@ import React, { useEffect, useRef, useState } from "react"; -import ActivityViewer, { - saveStateToDBTimerIdAtom, +import { + ActivityViewer, + // saveStateToDBTimerIdAtom, } from "../../../Viewer/ActivityViewer"; import { useRecoilValue, @@ -165,13 +166,13 @@ export default function AssignmentViewer() { let userId = useRef(null); let individualize = useRef(null); - const getValueOfTimeoutWithoutARefresh = useRecoilCallback( - ({ snapshot }) => - async () => { - return await snapshot.getPromise(saveStateToDBTimerIdAtom); - }, - [saveStateToDBTimerIdAtom], - ); + // const getValueOfTimeoutWithoutARefresh = useRecoilCallback( + // ({ snapshot }) => + // async () => { + // return await snapshot.getPromise(saveStateToDBTimerIdAtom); + // }, + // [saveStateToDBTimerIdAtom], + // ); useSetCourseIdFromDoenetId(recoilDoenetId); useInitCourseItems(courseId); @@ -183,7 +184,8 @@ export default function AssignmentViewer() { let [itemObj, setItemObj] = useRecoilState(itemByDoenetId(recoilDoenetId)); let label = itemObj.label; - let { search, hash } = useLocation(); + let location = useLocation(); + let { search, hash } = location; let navigate = useNavigate(); useEffect(() => { @@ -400,9 +402,9 @@ export default function AssignmentViewer() { return; } - allPossibleVariants.current = [ - ...Array(result.numberOfVariants).keys(), - ].map((x) => x + 1); + allPossibleVariants.current = [...Array(result.numVariants).keys()].map( + (x) => x + 1, + ); if (needNewVariant) { // determine if should individualize @@ -777,7 +779,7 @@ export default function AssignmentViewer() { setCidChanged(true)} setActivityAsCompleted={setActivityAsCompleted} @@ -815,10 +819,11 @@ async function returnNumberOfActivityVariants(cid) { return { success: false, message: "Could not retrieve file" }; } - let result = parseActivityDefinition(activityDefinitionDoenetML); + let result = await parseActivityDefinition(activityDefinitionDoenetML, cid); - if (!result.success) { - return result; + // TODO: handle communication of errors better + if (result.errors.length > 0) { + return { success: false, message: result.errors[0].message }; } try { @@ -827,5 +832,5 @@ async function returnNumberOfActivityVariants(cid) { return { success: false, message: e.message }; } - return { success: true, numberOfVariants: result.numberOfVariants }; + return { success: true, numVariants: result.numVariants }; } diff --git a/src/Tools/_framework/ToolPanels/CollectionEditor.jsx b/src/Tools/_framework/ToolPanels/CollectionEditor.jsx index 57906f6062..15f0c6396c 100644 --- a/src/Tools/_framework/ToolPanels/CollectionEditor.jsx +++ b/src/Tools/_framework/ToolPanels/CollectionEditor.jsx @@ -54,9 +54,11 @@ export default function CollectionEditor() { if (typeof response === "object") { response = response.data; } + + // TODO: returnAllPossibleVariants no longer has a callback argument returnAllPossibleVariants({ doenetML: response, - callback: ({ allPossibleVariants }) => { + callback: (allPossibleVariants) => { set(possibleVariantsByDoenetId(doenetId), allPossibleVariants); }, }); diff --git a/src/Tools/_framework/ToolPanels/DraftAssignmentViewer.jsx b/src/Tools/_framework/ToolPanels/DraftAssignmentViewer.jsx index 5b839ef6b0..aabc0be01b 100644 --- a/src/Tools/_framework/ToolPanels/DraftAssignmentViewer.jsx +++ b/src/Tools/_framework/ToolPanels/DraftAssignmentViewer.jsx @@ -1,5 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; -import ActivityViewer from "../../../Viewer/ActivityViewer"; +import { ActivityViewer } from "../../../Viewer/ActivityViewer"; import { useRecoilValue, atom, @@ -19,6 +19,7 @@ import { useSetCourseIdFromDoenetId, } from "../../../_reactComponents/Course/CourseActions"; import { activityVariantPanelAtom } from "../../../_sharedRecoil/PageViewerRecoil"; +import { useLocation, useNavigate } from "react-router"; export default function DraftAssignmentViewer() { // console.log(">>>===DraftAssignmentViewer") @@ -55,6 +56,9 @@ export default function DraftAssignmentViewer() { useSetCourseIdFromDoenetId(recoilDoenetId); useInitCourseItems(courseId); + let navigate = useNavigate(); + let location = useLocation(); + let itemObj = useRecoilValue(itemByDoenetId(recoilDoenetId)); let label = itemObj.label; @@ -77,11 +81,11 @@ export default function DraftAssignmentViewer() { // const loadProfile = useRecoilValueLoadable(profileAtom); // userId.current = loadProfile.contents.userId; - function variantCallback(variantIndex, numberOfVariants) { - // console.log(">>>variantCallback",variantIndex,numberOfVariants) + function variantCallback(variantIndex, numVariants) { + // console.log(">>>variantCallback",variantIndex,numVariants) setVariantPanel({ index: variantIndex, - numberOfVariants, + numVariants, }); } @@ -133,15 +137,16 @@ export default function DraftAssignmentViewer() { let result = await returnNumberOfActivityVariantsForCid(cid); - if (!result.success) { + // TODO: better display of errors + if (result.errors.length > 0) { setStage("Problem"); - setMessage(result.message); + setMessage(result.errors[0].message); return; } - allPossibleVariants.current = [ - ...Array(result.numberOfVariants).keys(), - ].map((x) => x + 1); + allPossibleVariants.current = [...Array(result.numVariants).keys()].map( + (x) => x + 1, + ); setLoad({ showCorrectness, @@ -182,7 +187,7 @@ export default function DraftAssignmentViewer() { ); diff --git a/src/Tools/_framework/ToolPanels/EditorViewer.jsx b/src/Tools/_framework/ToolPanels/EditorViewer.jsx index dd0a7a506b..3696477a4e 100644 --- a/src/Tools/_framework/ToolPanels/EditorViewer.jsx +++ b/src/Tools/_framework/ToolPanels/EditorViewer.jsx @@ -1,7 +1,8 @@ import React, { useEffect, useRef } from "react"; -import PageViewer, { - scrollableContainerAtom, -} from "../../../Viewer/PageViewer"; +import { + ActivityViewer, + // scrollableContainerAtom, +} from "../../../Viewer/ActivityViewer"; import useEventListener from "../../../_utils/hooks/useEventListener"; import { useRecoilValue, @@ -30,7 +31,7 @@ import { viewerDoenetMLAtom, } from "../../../_sharedRecoil/EditorViewerRecoil"; import axios from "axios"; -import { useLoaderData, useLocation } from "react-router"; +import { useLoaderData, useLocation, useNavigate } from "react-router"; import { pageVariantInfoAtom, pageVariantPanelAtom, @@ -88,8 +89,9 @@ export default function EditorViewer() { const { canUpload } = useRecoilValue(profileAtom); const updateViewer = useUpdateViewer(); - const setScrollableContainer = useSetRecoilState(scrollableContainerAtom); + // const setScrollableContainer = useSetRecoilState(scrollableContainerAtom); + let navigate = useNavigate(); let location = useLocation(); const previousLocations = useRef({}); @@ -266,7 +268,7 @@ export default function EditorViewer() { // console.log('>>>>variantInfo.index',variantInfo.index) return ( - ); } diff --git a/src/Tools/_framework/ToolPanels/GradebookStudentAssignment.jsx b/src/Tools/_framework/ToolPanels/GradebookStudentAssignment.jsx index ea3f61deca..fb3c61ae2a 100644 --- a/src/Tools/_framework/ToolPanels/GradebookStudentAssignment.jsx +++ b/src/Tools/_framework/ToolPanels/GradebookStudentAssignment.jsx @@ -22,10 +22,10 @@ import { import { serializedComponentsReviver } from "../../../Core/utils/serializedStateProcessing"; import axios from "axios"; import { currentAttemptNumber } from "../ToolPanels/AssignmentViewer"; -import PageViewer from "../../../Viewer/PageViewer"; import { effectivePermissionsByCourseId } from "../../../_reactComponents/PanelHeaderComponents/RoleDropdown"; -import ActivityViewer from "../../../Viewer/ActivityViewer"; +import { ActivityViewer } from "../../../Viewer/ActivityViewer"; import { coursePermissionsAndSettingsByCourseId } from "../../../_reactComponents/Course/CourseActions"; +import { useLocation, useNavigate } from "react-router"; // import { BreadcrumbProvider } from '../../../_reactComponents/Breadcrumb'; // import { DropTargetsProvider } from '../../../_reactComponents/DropTarget'; @@ -59,6 +59,9 @@ export default function GradebookStudentAssignmentView() { const setSuppressMenus = useSetRecoilState(suppressMenusAtom); let overview = useRecoilValueLoadable(overviewData); + let navigate = useNavigate(); + let location = useLocation(); + const totalPointsOrPercent = Number( assignments.contents[doenetId]?.totalPointsOrPercent, ); @@ -303,7 +306,7 @@ export default function GradebookStudentAssignmentView() { cid={cid} // cidChanged={cidChanged} // doenetML={doenetML} - doenetId={doenetId} + activityId={doenetId} userId={userId} forceDisable={true} forceShowCorrectness={true} @@ -332,6 +335,8 @@ export default function GradebookStudentAssignmentView() { // generatedVariantCallback={variantCallback} // pageChangedCallback={pageChanged} paginate={paginate} + location={location} + navigate={navigate} /> ); diff --git a/src/Tools/_framework/ToolPanels/GuestEditorViewer.jsx b/src/Tools/_framework/ToolPanels/GuestEditorViewer.jsx index f642acc26a..b7c192018b 100644 --- a/src/Tools/_framework/ToolPanels/GuestEditorViewer.jsx +++ b/src/Tools/_framework/ToolPanels/GuestEditorViewer.jsx @@ -1,7 +1,8 @@ import React, { useEffect, useRef, useState } from "react"; -import PageViewer, { - scrollableContainerAtom, -} from "../../../Viewer/PageViewer"; +import { + ActivityViewer, + // scrollableContainerAtom, +} from "../../../Viewer/ActivityViewer"; import useEventListener from "../../../_utils/hooks/useEventListener"; import { useRecoilValue, @@ -22,7 +23,7 @@ import { updateTextEditorDoenetMLAtom, viewerDoenetMLAtom, } from "../../../_sharedRecoil/EditorViewerRecoil"; -import { useLocation } from "react-router"; +import { useLocation, useNavigate } from "react-router"; import { pageVariantInfoAtom, pageVariantPanelAtom, @@ -46,6 +47,7 @@ export default function EditorViewer() { const setScrollableContainer = useSetRecoilState(scrollableContainerAtom); + let navigate = useNavigate(); let location = useLocation(); const previousLocations = useRef({}); @@ -92,9 +94,15 @@ export default function EditorViewer() { return; } - let parseResult = parseActivityDefinition(activityDefinition); - if (!parseResult.success) { - setErrMsg(`Invalid activity definition: ${parseResult.message}`); + let parseResult = await parseActivityDefinition( + activityDefinition, + activityCid, + ); + // TODO: handle diplsay of errors better + if (parseResult.errors.length > 0) { + setErrMsg( + `Invalid activity definition: ${parseResult.errors[0].message}`, + ); return; } @@ -219,7 +227,7 @@ export default function EditorViewer() { } return ( - ); } diff --git a/src/Tools/_framework/ToolPanels/PublicActivityViewer.jsx b/src/Tools/_framework/ToolPanels/PublicActivityViewer.jsx index 8bb8917cf5..f4cec9c048 100644 --- a/src/Tools/_framework/ToolPanels/PublicActivityViewer.jsx +++ b/src/Tools/_framework/ToolPanels/PublicActivityViewer.jsx @@ -1,7 +1,8 @@ import React, { useEffect, useRef, useState } from "react"; -import ActivityViewer from "../../../Viewer/ActivityViewer"; +import { ActivityViewer } from "../../../Viewer/ActivityViewer"; import { useRecoilValue } from "recoil"; import { searchParamAtomFamily } from "../NewToolRoot"; +import { useLocation, useNavigate } from "react-router"; import axios from "axios"; @@ -12,6 +13,9 @@ export default function Public(props) { const [errMsg, setErrMsg] = useState(null); + let navigate = useNavigate(); + let location = useLocation(); + useEffect(() => { const prevTitle = document.title; @@ -55,7 +59,7 @@ export default function Public(props) { ); diff --git a/src/Tools/cypressTest/CypressTest.jsx b/src/Tools/cypressTest/CypressTest.jsx index 54605e3bb4..995d2563e4 100644 --- a/src/Tools/cypressTest/CypressTest.jsx +++ b/src/Tools/cypressTest/CypressTest.jsx @@ -1,9 +1,9 @@ import React, { useState, useEffect, useRef } from "react"; -import PageViewer from "../../Viewer/PageViewer.jsx"; -import ActivityViewer from "../../Viewer/ActivityViewer.jsx"; +import { DoenetML } from "../../Viewer/DoenetML.jsx"; import { useRecoilState } from "recoil"; import { darkModeAtom } from "../_framework/DarkmodeController.jsx"; // import testCodeDoenetML from './testCode.doenet?raw'; +import { useLocation, useNavigate } from "react-router"; function Test() { // console.log("===Test") @@ -30,12 +30,10 @@ function Test() { localStorage.setItem("test settings", JSON.stringify(defaultTestSettings)); } - const [{ doenetML, activityDefinition, attemptNumber }, setBaseState] = - useState({ - doenetML: null, - activityDefinition: null, - attemptNumber: testSettings.attemptNumber, - }); + const [{ doenetMLstring, attemptNumber }, setBaseState] = useState({ + doenetMLstring: null, + attemptNumber: testSettings.attemptNumber, + }); const [updateNumber, setUpdateNumber] = useState(testSettings.updateNumber); const [controlsVisible, setControlsVisible] = useState( @@ -70,6 +68,9 @@ function Test() { const [_, setRefresh] = useState(0); const solutionDisplayMode = "button"; + let navigate = useNavigate(); + let location = useLocation(); + // requestedVariantIndex is undefined by default so that viewer // will use attemptNumber for variant // unless get a message (from cypress) to select a particular variant @@ -77,14 +78,11 @@ function Test() { //For Cypress Test Use window.onmessage = (e) => { - let newDoenetML = null, - newActivityDefinition = null, + let newDoenetMLstring = null, newAttemptNumber = attemptNumber; if (e.data.doenetML !== undefined) { - newDoenetML = e.data.doenetML; - } else if (e.data.activityDefinition !== undefined) { - newActivityDefinition = e.data.activityDefinition; + newDoenetMLstring = e.data.doenetML; } if (e.data.requestedVariantIndex !== undefined) { @@ -97,14 +95,9 @@ function Test() { } // don't do anything if receive a message from another source (like the youtube player) - if ( - newDoenetML || - newActivityDefinition || - newAttemptNumber !== attemptNumber - ) { + if (newDoenetMLstring || newAttemptNumber !== attemptNumber) { setBaseState({ - doenetML: newDoenetML, - activityDefinition: newActivityDefinition, + doenetMLstring: newDoenetMLstring, attemptNumber: newAttemptNumber, }); } @@ -411,67 +404,34 @@ function Test() { ); } - let viewer = null; - if (doenetML !== null) { - viewer = ( - - ); - } else if (activityDefinition !== null) { - viewer = ( - - ); - } + let viewer = ( + + ); return (
{ -// // Test = module.default; -// // console.log(">>>ACCEPT CALLED in test!!!!!!!!!",module.default) -// // console.log(">>>module",module) -// // } -// // ); -// } - export default Test; diff --git a/src/Tools/test/DoenetTest.jsx b/src/Tools/test/DoenetTest.jsx index 73901560ca..b90840cf1c 100644 --- a/src/Tools/test/DoenetTest.jsx +++ b/src/Tools/test/DoenetTest.jsx @@ -1,26 +1,24 @@ import React, { useState, useEffect, useRef } from "react"; -import ActivityViewer from "../../Viewer/ActivityViewer.jsx"; -import PageViewer from "../../Viewer/PageViewer.jsx"; -import testActivityDefinition from "./testActivityDefinition.doenet?raw"; +import { DoenetML } from "../../Viewer/DoenetML"; import testCodeDoenetML from "./testCode.doenet?raw"; import { MathJaxContext } from "better-react-mathjax"; import { mathjaxConfig } from "../../Core/utils/math.js"; import { useRecoilState } from "recoil"; import { darkModeAtom } from "../_framework/DarkmodeController.jsx"; +import { useLocation, useNavigate } from "react-router"; function Test() { // console.log("===Test") const [doenetML, setDoenetML] = useState(null); - const [activityDefinition, setActivityDefinition] = useState(null); + + let navigate = useNavigate(); + let location = useLocation(); //New ActivityViewer when code changes useEffect(() => { setDoenetML(testCodeDoenetML); }, [testCodeDoenetML]); - useEffect(() => { - setActivityDefinition(testActivityDefinition); - }, [testActivityDefinition]); const defaultTestSettings = { updateNumber: 0, @@ -36,7 +34,6 @@ function Test() { allowSaveSubmissions: false, allowSaveEvents: false, autoSubmit: false, - useTestCode: false, paginate: true, }; let testSettings = JSON.parse(localStorage.getItem("test settings")); @@ -77,7 +74,6 @@ function Test() { testSettings.allowSaveEvents, ); const [autoSubmit, setAutoSubmit] = useState(testSettings.autoSubmit); - const [useTestCode, setUseTestCode] = useState(testSettings.useTestCode); const [paginate, setPaginate] = useState(testSettings.paginate); const [_, setRefresh] = useState(0); const solutionDisplayMode = "button"; @@ -88,7 +84,7 @@ function Test() { let requestedVariantIndex = useRef(undefined); //Don't construct core until we have the doenetML defined - if (doenetML === null && activityDefinition === null) { + if (doenetML === null) { return null; } @@ -334,26 +330,6 @@ function Test() {

-
- -
-