Skip to content

Commit

Permalink
reduce code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
BulotF committed Oct 17, 2023
1 parent 1e62748 commit 61d2e87
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/widgets/component-new-edit/components/component-new-edit.jsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -53,13 +52,25 @@ 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 = {
errorsIntegrityByTab: {},
submitErrors: {},
componentsStore: {},
codesListsStoreStore: {},
deleteComponent: undefined,
};

const ComponentNewEdit = props => {
Expand All @@ -80,6 +91,7 @@ const ComponentNewEdit = props => {
clearSubformValidationErrors,
externalLoopsStore,
InitialMember,
updateComponent,
} = props;
const [showNewNestedFilter, setShowNewNestedFilter] = useState(false);
const [showPopup, setShowPopup] = useState(false);
Expand Down Expand Up @@ -527,7 +539,7 @@ const ComponentNewEdit = props => {
<GenericOption key="selectFinalMember" value="">
{Dictionary.selectFinalMembre}
</GenericOption>
{InitialMember && getFinalOptions(componentsStore)}
{getFinalOptions(componentsStore)}
</Field>
</>
)}
Expand Down Expand Up @@ -627,7 +639,7 @@ const ComponentNewEdit = props => {
handleCloseNestedFilter1={handleCloseNestedFilter}
componentType={NESTEDFILTRE}
handleDeleteNestedFilter={handleDeleteNestedFilter}
updateComponent={props.updateComponent}
updateComponent={updateComponent}
initialMemberFilter={InitialMember}
/>
</div>
Expand Down Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 61d2e87

Please sign in to comment.