-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load Teacher Tools Catalog from Docs, Store in State (#9829)
This change includes the following: 1. Loading the catalog from docs files. (Shared and target-specific files are possible, with "live" and "test" files in each. Test catalog entries are only loaded if the URL contains testcatalog=1 or tc=1.) 2. Storing catalog in state once loaded 3. Selecting catalog criteria items to add to your rubric 4. Storing selected criteria instances in state 5. Basic UI for selecting criteria & displaying selected criteria 6. A few new types needed to read/parse criteria json Notably, it does not include: 1. Any linking between the selected criteria and what gets sent to the editor for validation 2. Generating validator plans from the selected criteria (would be a prerequisite to sending to the editor) 3. Any target-specific catalogs (those will need to be checked into their respective pxt-target repos)
- Loading branch information
Showing
23 changed files
with
523 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"criteria": [ | ||
{ | ||
"id": "7AE7EA2A-3AC8-42DC-89DB-65E3AE157156", | ||
"use": "check_for_comments", | ||
"template": "At least ${count} comments", | ||
"description": "The project contains at least the specified number of comments.", | ||
"docPath": "/teachertool", | ||
"params": [ | ||
{ | ||
"name": "count", | ||
"type": "number", | ||
"default": 1, | ||
"path": "checks[0].count" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"criteria": [ | ||
{ | ||
"id": "A7C78825-51B5-45B0-9E42-2AAC767D4E02", | ||
"use": "processes_and_displays_array_in_loop", | ||
"template": "One kind of loop to process/display the information in an array", | ||
"docPath": "/teachertool" | ||
}, | ||
{ | ||
"id": "59AAC5BA-B0B3-4389-AA90-1E767EFA8563", | ||
"use": "block_used_n_times", | ||
"template": "${block_id} used ${count} times", | ||
"description": "This block was used the specified number of times in your project.", | ||
"docPath": "/teachertool", | ||
"params": [ | ||
{ | ||
"name": "block_id", | ||
"type": "block_id", | ||
"path": "checks[0].blocks[:clear&:append]" | ||
}, | ||
{ | ||
"name": "count", | ||
"type": "number", | ||
"default": 1, | ||
"path": "checks[0].count" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/// <reference path="../../../built/pxtblocks.d.ts"/> | ||
|
||
import { useContext } from "react"; | ||
import { AppStateContext } from "../state/appStateContext"; | ||
import { getCatalogCriteriaWithId } from "../state/helpers"; | ||
import { Button } from "react-common/components/controls/Button"; | ||
import { removeCriteriaFromRubric } from "../transforms/removeCriteriaFromRubric"; | ||
import { showCatalogModal } from "../transforms/showCatalogModal"; | ||
|
||
|
||
interface IProps {} | ||
|
||
const ActiveRubricDisplay: React.FC<IProps> = ({}) => { | ||
const { state: teacherTool, dispatch } = useContext(AppStateContext); | ||
|
||
return ( | ||
<div className="rubric-display"> | ||
<h3>{lf("Rubric")}</h3> | ||
{teacherTool.selectedCriteria?.map(criteriaInstance => { | ||
if (!criteriaInstance) return null; | ||
|
||
const catalogCriteria = getCatalogCriteriaWithId(criteriaInstance.catalogCriteriaId); | ||
return criteriaInstance.catalogCriteriaId && ( | ||
<div className="criteria-instance-display" key={criteriaInstance.instanceId}> | ||
{catalogCriteria?.template} | ||
<Button | ||
className="criteria-btn-remove" | ||
label={lf("X")} | ||
onClick={() => removeCriteriaFromRubric(criteriaInstance)} | ||
title={lf("Remove")} /> | ||
</div> | ||
); | ||
})} | ||
<Button className="add-criteria secondary" label={lf("+ Add Criteria")} onClick={showCatalogModal} title={lf("Add Criteria")} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ActiveRubricDisplay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/// <reference path="../../../built/pxtblocks.d.ts"/> | ||
|
||
import { useContext, useState } from "react"; | ||
import { AppStateContext } from "../state/appStateContext"; | ||
import { Checkbox } from "react-common/components/controls/Checkbox"; | ||
import { Modal } from "react-common/components/controls/Modal"; | ||
import { hideModal } from "../transforms/hideModal"; | ||
import { addCriteriaToRubric } from "../transforms/addCriteriaToRubric"; | ||
import { CatalogCriteria } from "../types/criteria"; | ||
|
||
interface IProps {} | ||
|
||
const CatalogModal: React.FC<IProps> = ({}) => { | ||
const { state: teacherTool } = useContext(AppStateContext); | ||
const [ checkedCriteriaIds, setCheckedCriteria ] = useState<Set<string>>(new Set<string>()); | ||
|
||
function handleCriteriaSelectedChange(criteria: CatalogCriteria, newValue: boolean) { | ||
const newSet = new Set(checkedCriteriaIds); | ||
if (newValue) { | ||
newSet.add(criteria.id); | ||
} else { | ||
newSet.delete(criteria.id); // Returns false if criteria.id is not in the set, can be safely ignored. | ||
} | ||
setCheckedCriteria(newSet); | ||
} | ||
|
||
function isCriteriaSelected(criteriaId: string): boolean { | ||
return checkedCriteriaIds.has(criteriaId); | ||
} | ||
|
||
function handleAddSelectedClicked() { | ||
addCriteriaToRubric([...checkedCriteriaIds]); | ||
closeModal(); | ||
} | ||
|
||
function closeModal() { | ||
hideModal("catalog-display"); | ||
|
||
// Clear for next open. | ||
setCheckedCriteria(new Set<string>()); | ||
} | ||
|
||
const modalActions = [ | ||
{ | ||
label: lf("Cancel"), | ||
className: "secondary", | ||
onClick: closeModal, | ||
}, | ||
{ | ||
label: lf("Add Selected"), | ||
className: "primary", | ||
onClick: handleAddSelectedClicked, | ||
}, | ||
] | ||
|
||
return teacherTool.modal === "catalog-display" ? ( | ||
<Modal className="catalog-modal" title={lf("Select the criteria you'd like to include")} onClose={closeModal} actions={modalActions}> | ||
{teacherTool.catalog?.map(criteria => { | ||
return criteria?.template && ( | ||
<Checkbox | ||
id={`checkbox_${criteria.id}`} | ||
key={criteria.id} | ||
className="catalog-item" | ||
label={criteria.template} | ||
onChange={(newValue) => handleCriteriaSelectedChange(criteria, newValue)} | ||
isChecked={isCriteriaSelected(criteria.id)} /> | ||
); | ||
})} | ||
</Modal> | ||
) : null; | ||
}; | ||
|
||
export default CatalogModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.