-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teacher Tool: Improve Customizable Criteria UI (#9915)
This change puts parameters into a clear error-state when they're empty, updates the results view to box in parameters per the design, and contains a few other minor tweaks throughout. The boxes around parameter values in the results view seemed very similar to the boxes in the catalog view, so I refactored that into a shareable component. The main difference between the two is whether or not you show the parameter name vs the parameter value, which is indicated by whether or not you pass a criteria instance or just a catalog criteria.
- Loading branch information
Showing
11 changed files
with
219 additions
and
134 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useContext, useMemo } from "react"; | ||
import { CatalogCriteria, CriteriaInstance } from "../types/criteria"; | ||
import { splitCriteriaTemplate } from "../utils"; | ||
import { CriteriaTemplateSegment } from "../types"; | ||
import { getParameterValue } from "../state/helpers"; | ||
import { AppStateContext } from "../state/appStateContext"; | ||
import css from "./styling/ReadonlyCriteriaDisplay.module.scss"; | ||
|
||
export interface ReadOnlyCriteriaDisplayProps { | ||
catalogCriteria: CatalogCriteria; | ||
criteriaInstance?: CriteriaInstance; // If defined, show parameter values in the display. Else, show parameter names. | ||
showDescription?: boolean; | ||
} | ||
|
||
export const ReadOnlyCriteriaDisplay: React.FC<ReadOnlyCriteriaDisplayProps> = ({ | ||
catalogCriteria, | ||
criteriaInstance, | ||
showDescription, | ||
}) => { | ||
const { state: teacherTool } = useContext(AppStateContext); | ||
|
||
function getSegmentDisplayText(segment: CriteriaTemplateSegment): string { | ||
if (!criteriaInstance || segment.type === "plain-text") { | ||
return segment.content; | ||
} | ||
|
||
return getParameterValue(teacherTool, criteriaInstance.instanceId, segment.content) ?? ""; | ||
} | ||
|
||
const segments = useMemo(() => splitCriteriaTemplate(catalogCriteria.template), [catalogCriteria.template]); | ||
return ( | ||
<div className={css["criteria-display"]}> | ||
{catalogCriteria.template && ( | ||
<div className={css["criteria-template"]}> | ||
{segments.map((segment, index) => { | ||
return ( | ||
<span key={index} className={css[`${segment.type}-segment`]}> | ||
{getSegmentDisplayText(segment)} | ||
</span> | ||
); | ||
})} | ||
</div> | ||
)} | ||
{showDescription && catalogCriteria.description && ( | ||
<div className={css["criteria-description"]}>{catalogCriteria.description}</div> | ||
)} | ||
</div> | ||
); | ||
}; |
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
22 changes: 22 additions & 0 deletions
22
teachertool/src/components/styling/ReadonlyCriteriaDisplay.module.scss
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,22 @@ | ||
.criteria-display { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
|
||
.criteria-template { | ||
.plain-text-segment { | ||
margin-right: 0.3rem; | ||
} | ||
|
||
.param-segment { | ||
border-radius: 0.5rem; | ||
border: 1px solid var(--pxt-page-foreground); | ||
padding: 0.2rem 0.5rem; | ||
margin-right: 0.3rem; | ||
} | ||
} | ||
|
||
.criteria-description { | ||
color: var(--pxt-page-foreground-light); | ||
} | ||
} |
Oops, something went wrong.