1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00

🔧 Refactor ContextRepositoryEditor in ContextConditionEditor

This commit is contained in:
Steffo 2021-05-25 04:39:48 +02:00
parent 7a7dbc79b3
commit be989ed8e9
Signed by: steffo
GPG key ID: 6965406171929D01
6 changed files with 34 additions and 21 deletions

View file

@ -1,5 +1,5 @@
import React, { useContext } from "react"
import ContextRepositoryEditor from "../../contexts/ContextRepositoryEditor"
import ContextRepositoryEditor from "../../contexts/ContextConditionEditor"
import Badge from "../base/Badge"

View file

@ -15,24 +15,33 @@ import useStrings from "../../hooks/useStrings"
/**
* A {@link BoxFull} allowing the user to save the changes made in the current {@link RepositoryEditor}.
*
* @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.
* @param running - If a request is running, disabling the buttons.
* @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.
* @param props - Additional props to pass to the box.
* @returns {JSX.Element}
* @constructor
*/
export default function BoxRepositoryCreate({ running, ...props }) {
const {
export default function BoxRepositoryCreate(
{
id,
evaluationMode,
setEvaluationMode,
name,
setName,
save,
revert,
evaluationMode,
setEvaluationMode,
running,
error,
} = useRepositoryEditor()
revert,
save,
...props
}) {
const history = useHistory()
const strings = useStrings()
return (

View file

@ -1,5 +1,5 @@
import React, { useCallback, useContext, useState } from "react"
import ContextRepositoryEditor from "../../contexts/ContextRepositoryEditor"
import ContextConditionEditor from "../../contexts/ContextConditionEditor"
import useArrayState from "../../hooks/useArrayState"
import Style from "./RepositoryEditor.module.css"
import BoxConditionLocation from "../interactive/BoxConditionLocation"
@ -142,14 +142,9 @@ export default function RepositoryEditor({
}
return (
<ContextRepositoryEditor.Provider
<ContextConditionEditor.Provider
value={{
id,
name: _name, setName,
conditions: _conditions, addCondition, appendRawCondition, removeRawCondition, spliceRawCondition,
evaluationMode: _evaluationMode, setEvaluationMode,
error, running,
revert, save,
}}
>
<div className={classNames(Style.RepositoryEditor, className)}>
@ -158,8 +153,18 @@ export default function RepositoryEditor({
<BoxConditionUser className={Style.SearchByUser}/>
<BoxConditionDatetime className={Style.SearchByTimePeriod}/>
<BoxConditions className={Style.Conditions}/>
<BoxRepositoryCreate running={running} className={Style.CreateDialog}/>
<BoxRepositoryCreate
className={Style.CreateDialog}
name={name}
setName={setName}
evaluationMode={_evaluationMode}
setEvaluationMode={setEvaluationMode}
running={running}
error={error}
revert={revert}
save={save}
/>
</div>
</ContextRepositoryEditor.Provider>
</ContextConditionEditor.Provider>
)
}

View file

@ -2,7 +2,7 @@ import { createContext } from "react"
/**
* React Context representing containing all variables of a {@link RepositoryEditor}.
* React Context representing a list of {@link Condition}s as provided by {@link useArrayState}.
*
* It is `null` outside a RepositoryEditor.
*/

View file

@ -1,5 +1,5 @@
import { useContext } from "react"
import ContextRepositoryEditor from "../contexts/ContextRepositoryEditor"
import ContextRepositoryEditor from "../contexts/ContextConditionEditor"
/**

View file

@ -17,7 +17,6 @@ export default function PageRepositoryCreate() {
{makeIcon(faPlus)} {strings.dashboardTitle}
</BoxHeader>
}
{...props}
>
<RepositoryEditor/>
</PageWithHeader>