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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | 5x 44x 44x 12x 176x 12x | import { useForm } from "react-hook-form";
import { Button, Form, OverlayTrigger, Tooltip } from "react-bootstrap";
import { BsInfoCircle } from "react-icons/bs";
import {
DEFAULT_TEAM_REGEX,
PERMISSION_LABELS,
} from "main/utils/newAssignmentsUtils";
const testIdPrefix = "NewTeamAssignmentForm";
export default function NewTeamAssignmentForm({
initialContents,
submitAction,
buttonLabel = "Create",
}) {
// Stryker disable all
const {
register,
formState: { errors },
handleSubmit,
} = useForm({
defaultValues: {
isPrivate: false,
permission: "MAINTAIN",
requireSignedCommit: false,
restrictPrsToContributors: false,
teamRegex: DEFAULT_TEAM_REGEX,
...initialContents,
},
});
// Stryker restore all
return (
<Form onSubmit={handleSubmit(submitAction)} data-testid={testIdPrefix}>
<Form.Group className="mb-3">
<Form.Label htmlFor="repoPrefix">Team Repository Prefix</Form.Label>
<Form.Control
id="repoPrefix"
type="text"
isInvalid={Boolean(errors.repoPrefix)}
data-testid={`${testIdPrefix}-repoPrefix`}
{...register("repoPrefix", {
validate: (value) =>
value.trim().length > 0 || "Team Repository Prefix is required.",
})}
/>
<Form.Control.Feedback type="invalid">
{errors.repoPrefix?.message}
</Form.Control.Feedback>
</Form.Group>
<Form.Group className="mb-3">
<Form.Check
id="isPrivate"
type="switch"
label="Private Repositories?"
data-testid={`${testIdPrefix}-isPrivate`}
{...register("isPrivate")}
/>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label htmlFor="permission">Team Permissions</Form.Label>
<Form.Select
id="permission"
data-testid={`${testIdPrefix}-permission`}
{...register("permission")}
>
{Object.entries(PERMISSION_LABELS).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</Form.Select>
</Form.Group>
<Form.Group className="mb-3">
<Form.Check
id="requireSignedCommit"
type="switch"
label="Require Signed Commits?"
data-testid={`${testIdPrefix}-requireSignedCommit`}
{...register("requireSignedCommit")}
/>
<Form.Text
muted
data-testid={`${testIdPrefix}-requireSignedCommit-help`}
>
Repositories get a ruleset that requires signed commits on every
branch except gh-pages. When this is off, that ruleset is removed from
them.
</Form.Text>
</Form.Group>
<Form.Group className="mb-3">
<Form.Check id="restrictPrsToContributors" type="checkbox">
<Form.Check.Input
type="checkbox"
data-testid={`${testIdPrefix}-restrictPrsToContributors`}
{...register("restrictPrsToContributors")}
/>
<Form.Check.Label>
{"Restrict PRs to Contibutors "}
<OverlayTrigger
placement="right"
overlay={
<Tooltip id="restrictPrsToContributors-tooltip">
When repos are open source, this ensures that PRs only come
from users with Write access to the repo. In practice, this
typically restricts it to the students from your course and
your course staff.
</Tooltip>
}
>
<span
data-testid={`${testIdPrefix}-restrictPrsToContributors-info`}
>
<BsInfoCircle />
</span>
</OverlayTrigger>
</Form.Check.Label>
</Form.Check>
</Form.Group>
<Form.Group className="mb-3">
<Form.Label htmlFor="teamRegex">
{"Team Regex "}
<OverlayTrigger
placement="right"
overlay={
<Tooltip id="teamRegex-tooltip">
Only teams whose names match this regular expression will have
repositories created. The default, {DEFAULT_TEAM_REGEX}, matches
every team.
</Tooltip>
}
>
<BsInfoCircle />
</OverlayTrigger>
</Form.Label>
<Form.Control
id="teamRegex"
type="text"
isInvalid={Boolean(errors.teamRegex)}
data-testid={`${testIdPrefix}-teamRegex`}
{...register("teamRegex", {
validate: (value) =>
value.trim().length > 0 || "Team Regex is required.",
})}
/>
<Form.Control.Feedback type="invalid">
{errors.teamRegex?.message}
</Form.Control.Feedback>
</Form.Group>
<Button type="submit" data-testid={`${testIdPrefix}-submit`}>
{buttonLabel}
</Button>
</Form>
);
}
|