Skip to content

Commit

Permalink
Allow checks (Occurrence / Whole) for roundabouts (#854)
Browse files Browse the repository at this point in the history
* Allow checks (Occurrence / Whole) for roundabouts

* fix test

* fix : required = isRoundabout for roundabout component
  • Loading branch information
BulotF authored Oct 30, 2024
1 parent b765303 commit bb4828e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/constants/dictionary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,14 @@ const dictionary = {
en: 'Array',
fr: 'Tableau',
},
ROUNDABOUT: {
en: 'Roundabout',
fr: 'Rond-point',
},
OCCURRENCE: {
en: 'Occurrence',
fr: 'Occurrence',
},
responseFormatSimple: {
fr: 'Réponse simple',
en: 'Simple response',
Expand Down
5 changes: 3 additions & 2 deletions src/model/transformations/control.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function remoteToState(remote = []) {
criticity,
during_collect,
post_collect,
scope: scope === 'line' ? 'LINE' : 'DYNAMIC_ARRAY',
scope:
scope === 'line' || scope === 'occurrence' ? 'OCCURRENCE' : 'WHOLE',
},
};
}, {});
Expand All @@ -50,7 +51,7 @@ export function stateToRemote(state) {
criticity,
during_collect,
post_collect,
scope: scope === 'LINE' && 'line',
scope: scope === 'OCCURRENCE' && 'occurrence',
};
});
}
6 changes: 3 additions & 3 deletions src/model/transformations/control.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('control tramsformation', () => {
criticity: 'criticity 2',
during_collect: 'during_collect 2',
post_collect: 'post_collect 2',
scope: 'line',
scope: 'occurrence',
},
];
const state = {
Expand All @@ -33,7 +33,7 @@ describe('control tramsformation', () => {
criticity: 'criticity 1',
during_collect: 'during_collect 1',
post_collect: 'post_collect 1',
scope: 'DYNAMIC_ARRAY',
scope: 'WHOLE',
},
2: {
id: '2',
Expand All @@ -43,7 +43,7 @@ describe('control tramsformation', () => {
criticity: 'criticity 2',
during_collect: 'during_collect 2',
post_collect: 'post_collect 2',
scope: 'LINE',
scope: 'OCCURRENCE',
},
};
describe('remoteToState', () => {
Expand Down
36 changes: 22 additions & 14 deletions src/widgets/component-new-edit/components/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Controls = ({
errors,
addErrors,
isDynamicArray,
isRoundabout,
}) => {
const [disableValidation, setDisableValidation] = useState(false);
return (
Expand Down Expand Up @@ -91,26 +92,30 @@ const Controls = ({
label={Dictionary.control_scope}
required={isDynamicArray}
>
<GenericOption key="DYNAMIC_ARRAY" value="DYNAMIC_ARRAY">
<GenericOption key="WHOLE" value="WHOLE">
{Dictionary.DYNAMIC_ARRAY}
</GenericOption>
<GenericOption key="LINE" value="LINE">
<GenericOption key="OCCURRENCE" value="OCCURRENCE">
{Dictionary.LINE}
</GenericOption>
</Field>
)}
{/* <Field */}
{/* name="during_collect" */}
{/* id="control_during_collect" */}
{/* component={Checkbox} */}
{/* label={Dictionary.control_during_collect} */}
{/* /> */}
{/* <Field */}
{/* name="post_collect" */}
{/* id="control_post_collect" */}
{/* component={Checkbox} */}
{/* label={Dictionary.control_post_collect} */}
{/* /> */}
{isRoundabout && (
<Field
name="scope"
id="control_scope"
component={Select}
label={Dictionary.control_scope}
required={isRoundabout}
>
<GenericOption key="WHOLE" value="WHOLE">
{Dictionary.ROUNDABOUT}
</GenericOption>
<GenericOption key="OCCURRENCE" value="OCCURRENCE">
{Dictionary.OCCURRENCE}
</GenericOption>
</Field>
)}
</ListWithInputPanel>
</FormSection>
);
Expand All @@ -127,6 +132,7 @@ const mapStateToProps = (state, { formName }) => {
state,
`${TABS_PATHS.RESPONSE_FORMAT}.${QUESTION_TYPE_ENUM.TABLE}.${DIMENSION_TYPE.PRIMARY}.type`,
) === DIMENSION_FORMATS.LIST,
isRoundabout: selector(state, `locked`) !== undefined,
};
};

Expand All @@ -136,12 +142,14 @@ Controls.propTypes = {
errors: PropTypes.array,
addErrors: PropTypes.func.isRequired,
isDynamicArray: PropTypes.bool,
isRoundabout: PropTypes.bool,
};
Controls.defaultProps = {
formName: DEFAULT_FORM_NAME,
selectorPath: TABS_PATHS.CONTROLS,
errors: [],
isDynamicArray: false,
isRoundabout: false,
};

export default connect(mapStateToProps)(Controls);
10 changes: 10 additions & 0 deletions src/widgets/component-new-edit/components/sequence-new-edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export const SequenceNewEdit = ({
addErrors={addSubformValidationErrors}
/>
</Tab>
<Tab
label={Dictionary.controls}
path={TABS_PATHS.CONTROLS}
key={TABS_PATHS.CONTROLS}
>
<Controls
errors={errorsIntegrityByTab[TABS_PATHS.CONTROLS]}
addErrors={addSubformValidationErrors}
/>
</Tab>
</Tabs>
)}
{componentType !== ROUNDABOUT && (
Expand Down

0 comments on commit bb4828e

Please sign in to comment.