Skip to content

Commit

Permalink
Add Max Count field for Catalog Criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Apr 24, 2024
1 parent 5a3bb20 commit 6d9d4b3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
12 changes: 9 additions & 3 deletions common-docs/teachertool/catalog-shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@
"use": "functions_have_comments",
"template": "All function definitions have comments",
"docPath": "/teachertool",
"description": "All user-defined functions in the program have comments attached to them."
"description": "All user-defined functions in the program have comments attached to them.",
"maxCount": 1
},
{
"id": "D21D76A2-D9FD-4F9B-B0AC-973CB870EA78",
"use": "variable_set",
"template": "At least one custom variable is set",
"docPath": "/teachertool",
"description": "At least one user-defined variable is set to a value."
"description": "At least one user-defined variable is set to a value.",
"maxCount": 1
},
{
"id": "0173898D-8A48-4266-AAB9-CE934471A734",
"use": "variable_accessed",
"template": "At least one variable is accessed",
"docPath": "/teachertool",
"description": "At least one variable's value is read."
"description": "At least one variable's value is read.",
"maxCount": 1
},
{
"id": "7AE7EA2A-3AC8-42DC-89DB-65E3AE157156",
"use": "block_comment_used",
"template": "At least ${count} comments",
"description": "The project contains at least the specified number of comments.",
"docPath": "/teachertool",
"maxCount": 1,
"params": [
{
"name": "count",
Expand Down Expand Up @@ -62,6 +66,7 @@
"template": "At least ${count} loops used",
"docPath": "/teachertool",
"description": "The program uses at least this many loops of any kind (for, repeat, while, or for-of).",
"maxCount": 1,
"params": [
{
"name": "count",
Expand All @@ -77,6 +82,7 @@
"template": "At least ${count} custom functions exist and get called",
"docPath": "/teachertool",
"description": "At least this many user-defined functions are created and called.",
"maxCount": 1,
"params": [
{
"name": "count",
Expand Down
1 change: 1 addition & 0 deletions common-docs/teachertool/test/catalog-shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"template": "Ask Copilot: ${question}",
"description": "Experimental: AI outputs may not be accurate. Use with caution and always review responses.",
"docPath": "/teachertool",
"maxCount": 10,
"params": [
{
"name": "question",
Expand Down
22 changes: 9 additions & 13 deletions teachertool/src/components/CatalogOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ const CatalogHeader: React.FC<CatalogHeaderProps> = ({ onClose }) => {

interface CatalogItemLabelProps {
catalogCriteria: CatalogCriteria;
allowsMultiple: boolean;
existingInstanceCount: number;
isMaxed: boolean;
recentlyAdded: boolean;
}
const CatalogItemLabel: React.FC<CatalogItemLabelProps> = ({
catalogCriteria,
allowsMultiple,
existingInstanceCount,
isMaxed,
recentlyAdded,
}) => {
const canAddMore = allowsMultiple || existingInstanceCount === 0;
const showRecentlyAddedIndicator = recentlyAdded && canAddMore;
const showRecentlyAddedIndicator = recentlyAdded && !isMaxed;
return (
<div className={css["catalog-item-label"]}>
<div className={css["action-indicators"]}>
{canAddMore ? (
{isMaxed ? (
<span className={css["max-label"]}>{Strings.Max}</span>
) : (
<>
<i
className={classList(
Expand All @@ -65,8 +64,6 @@ const CatalogItemLabel: React.FC<CatalogItemLabelProps> = ({
title={Strings.AddToChecklist}
/>
</>
) : (
<span className={css["max-label"]}>{Strings.Max}</span>
)}
</div>
<ReadOnlyCriteriaDisplay catalogCriteria={catalogCriteria} showDescription={true} />
Expand Down Expand Up @@ -116,10 +113,10 @@ const CatalogList: React.FC = () => {
return (
<div className={css["catalog-list"]}>
{criteria.map(c => {
const allowsMultiple = c.params !== undefined && c.params.length !== 0; // TODO add a json flag for this (MaxCount or AllowMultiple)
const existingInstanceCount = teacherTool.rubric.criteria.filter(
i => i.catalogCriteriaId === c.id
).length;
const isMaxed = c.maxCount !== undefined && existingInstanceCount >= c.maxCount;
return (
c.template && (
<Button
Expand All @@ -130,13 +127,12 @@ const CatalogList: React.FC = () => {
label={
<CatalogItemLabel
catalogCriteria={c}
allowsMultiple={allowsMultiple}
existingInstanceCount={existingInstanceCount}
isMaxed={isMaxed}
recentlyAdded={recentlyAddedIds[c.id] !== undefined}
/>
}
onClick={() => onItemClicked(c)}
disabled={!allowsMultiple && existingInstanceCount > 0}
disabled={isMaxed}
/>
)
);
Expand Down
9 changes: 0 additions & 9 deletions teachertool/src/state/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,3 @@ export function getSafeRubricName(state: AppState): string | undefined {
export function getCatalogCriteria(state: AppState): CatalogCriteria[] {
return state.catalog?.filter(c => !c.hideInCatalog) ?? [];
}

export function criteriaIsSelectable(state: AppState, catalogCriteria: CatalogCriteria): boolean {
// Return a criteria as selectable if it has parameters (so it can be used multiple times in a rubric)
// or if it has not yet been used in the active rubric.
return (
(catalogCriteria.params && catalogCriteria.params.length > 0) ||
!state.rubric.criteria.some(c => c.catalogCriteriaId === catalogCriteria.id)
);
}
1 change: 1 addition & 0 deletions teachertool/src/types/criteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface CatalogCriteria {
docPath: string | undefined; // Path to documentation
params: CriteriaParameter[] | undefined; // Any parameters that affect the criteria
hideInCatalog?: boolean; // Whether the criteria should be hidden in the user-facing catalog
maxCount?: number; // The maximum number of instances of this criteria that can be added to a rubric
}

// An instance of a criteria in a rubric.
Expand Down

0 comments on commit 6d9d4b3

Please sign in to comment.