From 61d2e8704958fa39ccd57fa43ad66496a05a9160 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bulot=20Fran=C3=A7ois?= <f_bulot@hotmail.com>
Date: Tue, 17 Oct 2023 13:19:26 +0200
Subject: [PATCH] reduce code smells

---
 .../components/component-new-edit.jsx         | 33 ++++++++++++-------
 .../component-new-edit-container.js           |  5 ++-
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/widgets/component-new-edit/components/component-new-edit.jsx b/src/widgets/component-new-edit/components/component-new-edit.jsx
index ef9d1f87d..3a1af34ac 100644
--- a/src/widgets/component-new-edit/components/component-new-edit.jsx
+++ b/src/widgets/component-new-edit/components/component-new-edit.jsx
@@ -1,6 +1,5 @@
 import React, { useRef, useEffect, useState } from 'react';
-import { connect } from 'react-redux';
-import { formValueSelector, formPropTypes, Field } from 'redux-form';
+import { formPropTypes, Field } from 'redux-form';
 import ReactModal from 'react-modal';
 import PropTypes from 'prop-types';
 
@@ -53,6 +52,17 @@ export const propTypes = {
   componentsStore: PropTypes.object,
   addSubformValidationErrors: PropTypes.func.isRequired,
   clearSubformValidationErrors: PropTypes.func.isRequired,
+  onCancel: PropTypes.func.isRequired,
+  deleteComponent: PropTypes.func,
+  onSubmit: PropTypes.func.isRequired,
+  activeQuestionnaire: PropTypes.object.isRequired,
+  updateComponent: PropTypes.func.isRequired,
+  externalLoopsStore: PropTypes.arrayOf(
+    PropTypes.shape({
+      id: PropTypes.string.isRequired,
+      name: PropTypes.string.isRequired,
+    }),
+  ).isRequired,
 };
 
 export const defaultProps = {
@@ -60,6 +70,7 @@ export const defaultProps = {
   submitErrors: {},
   componentsStore: {},
   codesListsStoreStore: {},
+  deleteComponent: undefined,
 };
 
 const ComponentNewEdit = props => {
@@ -80,6 +91,7 @@ const ComponentNewEdit = props => {
     clearSubformValidationErrors,
     externalLoopsStore,
     InitialMember,
+    updateComponent,
   } = props;
   const [showNewNestedFilter, setShowNewNestedFilter] = useState(false);
   const [showPopup, setShowPopup] = useState(false);
@@ -527,7 +539,7 @@ const ComponentNewEdit = props => {
                   <GenericOption key="selectFinalMember" value="">
                     {Dictionary.selectFinalMembre}
                   </GenericOption>
-                  {InitialMember && getFinalOptions(componentsStore)}
+                  {getFinalOptions(componentsStore)}
                 </Field>
               </>
             )}
@@ -627,7 +639,7 @@ const ComponentNewEdit = props => {
               handleCloseNestedFilter1={handleCloseNestedFilter}
               componentType={NESTEDFILTRE}
               handleDeleteNestedFilter={handleDeleteNestedFilter}
-              updateComponent={props.updateComponent}
+              updateComponent={updateComponent}
               initialMemberFilter={InitialMember}
             />
           </div>
@@ -672,11 +684,8 @@ const ComponentNewEdit = props => {
     </div>
   );
 };
-const mapStateToProps = state => {
-  const selector = formValueSelector('component');
-  return {
-    InitialMember: selector(state, 'initialMember'),
-    filterImbriquer: selector(state, 'filterImbriquer'),
-  };
-};
-export default connect(mapStateToProps)(ComponentNewEdit);
+
+ComponentNewEdit.propTypes = propTypes;
+ComponentNewEdit.defaultProps = defaultProps;
+
+export default ComponentNewEdit;
diff --git a/src/widgets/component-new-edit/containers/component-new-edit-container.js b/src/widgets/component-new-edit/containers/component-new-edit-container.js
index 13e102e79..4f2317010 100644
--- a/src/widgets/component-new-edit/containers/component-new-edit-container.js
+++ b/src/widgets/component-new-edit/containers/component-new-edit-container.js
@@ -1,6 +1,6 @@
 import { connect } from 'react-redux';
 import PropTypes from 'prop-types';
-import { formPropTypes } from 'redux-form';
+import { formValueSelector, formPropTypes } from 'redux-form';
 
 import ComponentNewEdit from '../components/component-new-edit';
 import {
@@ -58,7 +58,10 @@ const mapStateToProps = (state, { componentId }) => {
   const externalLoopsWanted = Object.keys(externalLoopsAvailable)
     .filter(key => externalQuestionnnairesId.includes(key))
     .reduce((acc, key) => [...acc, ...externalLoopsAvailable[key].loops], []);
+  const selector = formValueSelector('component');
   return {
+    InitialMember: selector(state, 'initialMember'),
+    filterImbriquer: selector(state, 'filterImbriquer'),
     errorsIntegrityByTab: getErrorsIntegrityByTab(errorsIntegrity),
     componentsStore: state.appState.activeComponentsById,
     externalLoopsStore: externalLoopsWanted,