Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 1x 1x 1x 1x 1x 1x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 1x | import { Form } from "react-bootstrap";
import { useBackend } from "main/utils/useBackend";
// A dropdown for selecting a School, backed by /api/course/schools, which
// only returns "active" schools (see the School enum on the backend). New
// schools become selectable here automatically once marked active there,
// with no frontend changes required (see issue #251).
function SchoolSelectDropdown({
initialValue,
register,
testIdPrefix = "SchoolSelectDropdown",
}) {
// Stryker disable all
const { data: schools } = useBackend(["/api/course/schools"], {
method: "GET",
url: "/api/course/schools",
});
// Stryker restore all
return (
<Form.Group className="mb-3">
<Form.Label htmlFor="school">School</Form.Label>
{schools && (
<Form.Select
data-testid={`${testIdPrefix}-school`}
id="school"
{...register("school", {
required: "School is required.",
})}
// Stryker disable next-line StringLiteral : there is no option
// with an empty value here, so any non-matching fallback string
// is behaviorally equivalent to "" (the browser just selects the
// first option either way).
defaultValue={initialValue ?? ""}
>
{schools.map((school) => (
<option
key={school.key}
value={school.key}
data-testid={`${testIdPrefix}-school-${school.key}`}
>
{school.displayName}
</option>
))}
</Form.Select>
)}
</Form.Group>
);
}
export default SchoolSelectDropdown;
|