Skip to content

Commit

Permalink
Filter criteria you've already included in your rubric
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Feb 5, 2024
1 parent 5937787 commit 4c88c7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion teachertool/src/components/CatalogModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Modal } from "react-common/components/controls/Modal";
import { hideModal } from "../transforms/hideModal";
import { addCriteriaToRubric } from "../transforms/addCriteriaToRubric";
import { CatalogCriteria } from "../types/criteria";
import { getSelectableCatalogCriteria } from "../state/helpers";

interface IProps {}

Expand Down Expand Up @@ -53,14 +54,16 @@ export const CatalogModal: React.FC<IProps> = ({}) => {
},
];

const selectableCatalogCriteria = getSelectableCatalogCriteria();

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 => {
{selectableCatalogCriteria.map(criteria => {
return (
criteria?.template && (
<Checkbox
Expand Down
16 changes: 16 additions & 0 deletions teachertool/src/state/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ export function verifyRubricIntegrity(rubric: Rubric): {
}
return { valid: invalidCriteria.length === 0, validCriteria, invalidCriteria };
}

export function getSelectableCatalogCriteria(): CatalogCriteria[] {
const { state } = stateAndDispatch();

const usedCriteria = state.rubric.criteria.map(c => c.catalogCriteriaId) ?? [];

// 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 (
state.catalog?.filter(
catalogCriteria =>
(catalogCriteria.parameters && catalogCriteria.parameters.length > 0) ||
!usedCriteria.includes(catalogCriteria.id)
) ?? []
);
}

0 comments on commit 4c88c7d

Please sign in to comment.