EN · DE · RU · FR · ES

#2646 : ValidationManager.jsx

projectforge-webapp/src/components/design/input/ValidationManager.jsx Composant React, projectforge-webapp/src/components/design/input/ValidationManager.jsx 68 lignes · 53 code · 6 commentaires · 9 vides
Objectif : Application web React : ValidationManager.jsx. ValidationManager.jsx fait partie de l'application open-source de gestion de projet ProjectForge.

Source (100 premières lignes)

import PropTypes from 'prop-types';
import React from 'react';

// Valide automatiquement les champs de saisie imbriqués à l'intérieur. (Uniquement le premier niveau)
function ValidationManager({ children, customValidation }) {
    const extraLabel = null;

    return (
        <>
            {React.Children.map(children, (child) => {
                if (!child) {
                    return child;
                }
                const { props: childProps } = child;
                const {
                    checked,
                    required,
                    maxLength,
                    value,
                } = childProps;

                let valid = true;
                let { additionalLabel } = childProps;

                // Valider required et maxLength
                if (
                    (required && !(value || checked))
                    || (maxLength && value && value.length > maxLength)
                ) {
                    valid = false;
                }

                // Vérifier une validation personnalisée.
                if (customValidation) {
                    valid = false;

                    if (additionalLabel) {
                        // Ajouter le message de validation au label supplémentaire s'il existe
                        additionalLabel += ` - ${customValidation.message}`;
                    } else {
                        // ou alors définir le label supplémentaire comme message de validation.
                        additionalLabel = customValidation.message;
                    }
                }

                return {
                    ...child,
                    // Manipulation des props de l'enfant.
                    props: {
                        ...child.props,
                        additionalLabel,
                        color: valid ? childProps.color : 'danger',
                    },
                };
            })}
            {extraLabel}
        </>
    );
}

ValidationManager.propTypes = {
    children: PropTypes.node.isRequired,
    customValidation: PropTypes.shape({
        message: PropTypes.string,
    }),
};

export default ValidationManager;

Historique Git

f867698d3 wip : mise à jour des versions des packages
3685edd6c mise à jour vers React 18 wip
a73905c14 Correction de fautes de frappe dans les répertoires projectforge*/ Trouvé via codespell Voir c3b0602a893
253b9f38b mise à jour de certaines dépendances et correction des erreurs eslint
bbd81edc3 es-lint, nouvelles versions js.

f867698d3

wip : mise à jour des versions des packages
f867698d30e539955cc1dd9aacc4986234ff36f2
diff --git a/projectforge-webapp/src/components/design/input/ValidationManager.jsx b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
index ce75b3494..dbf154867 100644
--- a/projectforge-webapp/src/components/design/input/ValidationManager.jsx
+++ b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
@@ -1,11 +1,9 @@
 import PropTypes from 'prop-types';
 import React from 'react';
-import DayPickerInput from 'react-day-picker/DayPickerInput';
-import AdditionalLabel from './AdditionalLabel';
 
 // Automatically validate the input fields nested inside. (Only first level)
 function ValidationManager({ children, customValidation }) {
-    let extraLabel = null;
+    const extraLabel = null;
 
     return (
         <>
@@ -13,7 +11,7 @@ function ValidationManager({ children, customValidation }) {
                 if (!child) {
                     return child;
                 }
-                const { props: childProps, type } = child;
+                const { props: childProps } = child;
                 const {
                     checked,
                     required,
@@ -43,10 +41,6 @@ function ValidationManager({ children, customValidation }) {
                         // or else set the additional label to the validation message.
                         additionalLabel = customValidation.message;
                     }
-
-                    if (type === DayPickerInput) {
-                        extraLabel = <AdditionalLabel title={additionalLabel} />;
-                    }
                 }
 
                 return {

3685edd6c

mise à jour vers React 18 wip
3685edd6c9f0dfd4582dbeb01c05491c254ccb84
diff --git a/projectforge-webapp/src/components/design/input/ValidationManager.jsx b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
index 2fbb670c5..ce75b3494 100644
--- a/projectforge-webapp/src/components/design/input/ValidationManager.jsx
+++ b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
@@ -71,8 +71,4 @@ ValidationManager.propTypes = {
     }),
 };
 
-ValidationManager.defaultProps = {
-    customValidation: undefined,
-};
-
 export default ValidationManager;

a73905c14

Correction de fautes de frappe dans les répertoires projectforge*/ Trouvé via codespell Voir c3b0602a893
a73905c1490c145f5212a29b752628e259cd2d58
diff --git a/projectforge-webapp/src/components/design/input/ValidationManager.jsx b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
index aac26aaf7..2fbb670c5 100644
--- a/projectforge-webapp/src/components/design/input/ValidationManager.jsx
+++ b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
@@ -51,7 +51,7 @@ function ValidationManager({ children, customValidation }) {
 
                 return {
                     ...child,
-                    // Manupulating the props of the child.
+                    // Manipulating the props of the child.
                     props: {
                         ...child.props,
                         additionalLabel,

253b9f38b

mise à jour de certaines dépendances et correction des erreurs eslint
253b9f38b25268fbe922dbe9e4ddca94b13b98aa
diff --git a/projectforge-webapp/src/components/design/input/ValidationManager.jsx b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
index 1ae5dd5f2..aac26aaf7 100644
--- a/projectforge-webapp/src/components/design/input/ValidationManager.jsx
+++ b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
@@ -5,7 +5,7 @@ import AdditionalLabel from './AdditionalLabel';
 
 // Automatically validate the input fields nested inside. (Only first level)
 function ValidationManager({ children, customValidation }) {
-    let extraLabel = <></>;
+    let extraLabel = null;
 
     return (
         <>

bbd81edc3

es-lint, nouvelles versions js.
bbd81edc3f6b2fd975756421148651d4d75eaf33
diff --git a/projectforge-webapp/src/components/design/input/ValidationManager.jsx b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
index b94e142da..1ae5dd5f2 100644
--- a/projectforge-webapp/src/components/design/input/ValidationManager.jsx
+++ b/projectforge-webapp/src/components/design/input/ValidationManager.jsx
@@ -5,10 +5,10 @@ import AdditionalLabel from './AdditionalLabel';
 
 // Automatically validate the input fields nested inside. (Only first level)
 function ValidationManager({ children, customValidation }) {
-    let extraLabel = <React.Fragment />;
+    let extraLabel = <></>;
 
     return (
-        <React.Fragment>
+        <>
             {React.Children.map(children, (child) => {
                 if (!child) {
                     return child;
@@ -60,7 +60,7 @@ function ValidationManager({ children, customValidation }) {
                 };
             })}
             {extraLabel}
-        </React.Fragment>
+        </>
     );
 }