2021-05-24 12:13:24 +00:00
|
|
|
import React from "react"
|
2021-05-07 15:30:10 +00:00
|
|
|
import BoxFull from "../base/BoxFull"
|
|
|
|
import FormLabelled from "../base/FormLabelled"
|
|
|
|
import FormLabel from "../base/formparts/FormLabel"
|
|
|
|
import InputWithIcon from "../base/InputWithIcon"
|
2021-05-11 16:05:01 +00:00
|
|
|
import { faBackward, faFolder, faPencilAlt, faPlus } from "@fortawesome/free-solid-svg-icons"
|
2021-05-07 15:30:10 +00:00
|
|
|
import Radio from "../base/Radio"
|
|
|
|
import Button from "../base/Button"
|
|
|
|
import useRepositoryEditor from "../../hooks/useRepositoryEditor"
|
2021-05-07 23:40:49 +00:00
|
|
|
import FormAlert from "../base/formparts/FormAlert"
|
2021-05-10 15:24:32 +00:00
|
|
|
import { useHistory } from "react-router"
|
2021-05-24 12:13:24 +00:00
|
|
|
import useStrings from "../../hooks/useStrings"
|
2021-05-07 15:30:10 +00:00
|
|
|
|
|
|
|
|
2021-05-10 13:22:07 +00:00
|
|
|
/**
|
|
|
|
* A {@link BoxFull} allowing the user to save the changes made in the current {@link RepositoryEditor}.
|
|
|
|
*
|
2021-05-25 02:39:48 +00:00
|
|
|
* @param id - The id of the repository.
|
|
|
|
* @param name - The current name of the repository.
|
|
|
|
* @param setName - Function to change the name of the repository.
|
|
|
|
* @param evaluationMode - The current evaluation mode of the repository.
|
|
|
|
* @param setEvaluationMode - Function to change the current evaluation mode of the repository.
|
2021-05-17 14:11:58 +00:00
|
|
|
* @param running - If a request is running, disabling the buttons.
|
2021-05-25 02:39:48 +00:00
|
|
|
* @param error - If a request error occoured, the error.
|
|
|
|
* @param revert - Function to cancel the changes made to the repository.
|
|
|
|
* @param save - Function to apply the changes made to the repository.
|
2021-05-17 14:11:58 +00:00
|
|
|
* @param props - Additional props to pass to the box.
|
2021-05-10 13:22:07 +00:00
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2021-05-25 02:39:48 +00:00
|
|
|
export default function BoxRepositoryCreate(
|
|
|
|
{
|
2021-05-10 13:22:07 +00:00
|
|
|
id,
|
2021-05-07 15:30:10 +00:00
|
|
|
name,
|
|
|
|
setName,
|
2021-05-25 02:39:48 +00:00
|
|
|
evaluationMode,
|
|
|
|
setEvaluationMode,
|
|
|
|
running,
|
2021-05-07 23:40:49 +00:00
|
|
|
error,
|
2021-05-25 02:39:48 +00:00
|
|
|
revert,
|
|
|
|
save,
|
|
|
|
...props
|
|
|
|
}) {
|
2021-05-07 15:30:10 +00:00
|
|
|
|
2021-05-24 12:13:24 +00:00
|
|
|
const strings = useStrings()
|
2021-05-10 15:24:32 +00:00
|
|
|
|
2021-05-07 15:30:10 +00:00
|
|
|
return (
|
2021-05-18 00:04:06 +00:00
|
|
|
<BoxFull header={strings.createRepo} {...props}>
|
2021-05-11 14:37:15 +00:00
|
|
|
<FormLabelled
|
|
|
|
onSubmit={e => {
|
|
|
|
e.preventDefault()
|
|
|
|
save()
|
|
|
|
}}
|
|
|
|
>
|
2021-05-18 00:04:06 +00:00
|
|
|
<FormLabel htmlFor={"repo-name"} text={strings.repoName}>
|
2021-05-07 15:30:10 +00:00
|
|
|
<InputWithIcon
|
|
|
|
id={"repo-name"}
|
|
|
|
icon={faFolder}
|
|
|
|
value={name}
|
|
|
|
onChange={e => setName(e.target.value)}
|
|
|
|
/>
|
|
|
|
</FormLabel>
|
2021-05-18 00:04:06 +00:00
|
|
|
<FormLabel htmlFor={"filter-mode"} text={strings.request}>
|
2021-05-07 15:30:10 +00:00
|
|
|
<label>
|
|
|
|
<Radio
|
|
|
|
name={"filter-mode"}
|
2021-05-10 12:13:45 +00:00
|
|
|
onChange={() => setEvaluationMode(0)}
|
2021-05-07 15:30:10 +00:00
|
|
|
checked={evaluationMode === 0}
|
|
|
|
/>
|
2021-05-18 00:04:06 +00:00
|
|
|
{strings.filterOR}
|
2021-05-07 15:30:10 +00:00
|
|
|
</label>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
<Radio
|
|
|
|
name={"filter-mode"}
|
2021-05-10 12:13:45 +00:00
|
|
|
onChange={() => setEvaluationMode(1)}
|
2021-05-07 15:30:10 +00:00
|
|
|
checked={evaluationMode === 1}
|
|
|
|
/>
|
2021-05-18 00:04:06 +00:00
|
|
|
{strings.filterAND}
|
2021-05-07 15:30:10 +00:00
|
|
|
</label>
|
|
|
|
</FormLabel>
|
2021-05-07 23:40:49 +00:00
|
|
|
{error ?
|
2021-05-11 14:37:15 +00:00
|
|
|
<FormAlert color={"Red"}>
|
2021-05-24 03:02:07 +00:00
|
|
|
{strings[error.data.code]}
|
2021-05-11 14:37:15 +00:00
|
|
|
</FormAlert>
|
|
|
|
: null}
|
2021-05-10 13:22:07 +00:00
|
|
|
{id ?
|
2021-05-11 16:05:01 +00:00
|
|
|
<>
|
|
|
|
<Button
|
|
|
|
style={{ "gridColumn": "1" }}
|
|
|
|
icon={faBackward}
|
|
|
|
color={"Red"}
|
2021-05-11 16:05:18 +00:00
|
|
|
onClick={() => revert()}
|
2021-05-17 13:58:24 +00:00
|
|
|
disabled={running}
|
2021-05-11 16:05:01 +00:00
|
|
|
>
|
2021-05-18 00:04:06 +00:00
|
|
|
{strings.rollback}
|
2021-05-11 16:05:01 +00:00
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
style={{ "gridColumn": "2" }}
|
|
|
|
icon={faPencilAlt}
|
|
|
|
color={"Green"}
|
2021-05-24 03:02:07 +00:00
|
|
|
onClick={save}
|
2021-05-17 13:58:24 +00:00
|
|
|
disabled={running}
|
2021-05-11 16:05:01 +00:00
|
|
|
>
|
2021-05-18 00:04:06 +00:00
|
|
|
{strings.save}
|
2021-05-11 16:05:01 +00:00
|
|
|
</Button>
|
|
|
|
</>
|
2021-05-11 14:37:15 +00:00
|
|
|
:
|
|
|
|
<Button
|
|
|
|
style={{ "gridColumn": "1 / 3" }}
|
|
|
|
icon={faPlus}
|
|
|
|
color={"Green"}
|
2021-05-24 03:02:07 +00:00
|
|
|
onClick={save}
|
2021-05-17 13:58:24 +00:00
|
|
|
disabled={running}
|
2021-05-11 14:37:15 +00:00
|
|
|
>
|
2021-05-18 00:04:06 +00:00
|
|
|
{strings.createRepo}
|
2021-05-11 14:37:15 +00:00
|
|
|
</Button>
|
2021-05-10 13:22:07 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 15:30:10 +00:00
|
|
|
</FormLabelled>
|
|
|
|
</BoxFull>
|
|
|
|
)
|
|
|
|
}
|