Skip to content

Commit

Permalink
fix: do not allow arbitrary in table
Browse files Browse the repository at this point in the history
  • Loading branch information
QRuhier committed Jan 10, 2025
1 parent bc7067e commit 8aaf8b8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
15 changes: 2 additions & 13 deletions src/model/formToState/component-new-edit/response-format-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export const defaultMeasureState = {
cloneDeep(CodesListDefaultState),
{ id: uuid() },
),
allowArbitrary: false,
visHint: RADIO,
},
};
Expand All @@ -77,7 +76,6 @@ export const defaultMeasureForm = {
type: SIMPLE,
[SIMPLE]: defaultMeasureSimpleState,
[SINGLE_CHOICE]: {
allowArbitrary: false,
hasSpecialCode: false,
specialLabel: '',
specialCode: '',
Expand Down Expand Up @@ -174,17 +172,13 @@ export function formToStateMeasure(form, codesListMeasure) {
[simpleType]: { ...simpleForm },
};
} else {
const {
allowArbitrary,
visHint,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: codesListForm,
} = measureForm;
const { visHint, [DEFAULT_CODES_LIST_SELECTOR_PATH]: codesListForm } =
measureForm;
const codesList = codesListMeasure
? codesListMeasure.formToStateComponent(codesListForm)
: CodesListFactory().formToState(codesListForm);

state[SINGLE_CHOICE] = {
allowArbitrary,
visHint,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: codesList,
};
Expand Down Expand Up @@ -259,7 +253,6 @@ export function stateToFormMeasure(
type,
[SIMPLE]: simpleState,
[SINGLE_CHOICE]: {
allowArbitrary,
visHint,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: codesListState,
},
Expand All @@ -280,7 +273,6 @@ export function stateToFormMeasure(
type,
[SIMPLE]: simpleState,
[SINGLE_CHOICE]: {
allowArbitrary,
visHint,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: codesListForm,
},
Expand All @@ -290,7 +282,6 @@ export function stateToFormMeasure(
export function stateToFormMeasureList(currentState, codesListsStore) {
const {
[SINGLE_CHOICE]: {
allowArbitrary,
visHint,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: codesListState,
},
Expand All @@ -304,7 +295,6 @@ export function stateToFormMeasureList(currentState, codesListsStore) {
return {
...currentState,
[SINGLE_CHOICE]: {
allowArbitrary,
visHint,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: codesListForm,
},
Expand Down Expand Up @@ -387,7 +377,6 @@ const Factory = (initialState = {}, codesListsStore) => {
state[SINGLE_CHOICE] = {
[DEFAULT_CODES_LIST_SELECTOR_PATH]:
codesListsStore[measureState[DEFAULT_CODES_LIST_SELECTOR_PATH].id],
allowArbitrary: measureState.allowArbitrary,
visHint: measureState.visHint,
};
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/model/transformations/response-format-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ function stateToResponseState(state) {
} else {
const {
mandatory,
allowArbitrary,
visHint,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: { id: codesListId },
} = measureTypeState;
Expand All @@ -328,7 +327,6 @@ function stateToResponseState(state) {
typeName: TEXT,
maxLength: 1,
pattern: '',
allowArbitrary,
visHint,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function ResponseFormatSingle({
path,
formName,
allowPrecision,
disableSetArbitrary,
}) {
const selectorPath = responseFormatType;

Expand Down Expand Up @@ -170,19 +171,21 @@ function ResponseFormatSingle({
{visHint === SUGGESTER ? (
<>
<SuggesterLists selectorPathParent={selectorPathComposed} />
<Field
name="allowArbitrary"
component={ListRadios}
label={Dictionary.allowArbitraryResponse}
required
// Convert string "true"/"false" to boolean true/false when storing in Redux form
parse={(value) => value === 'true'}
// Convert true/false/undefined to string "true"/"false" when displaying the form
format={(value) => (value === true ? 'true' : 'false')}
>
<GenericOption value="true">{Dictionary.yes}</GenericOption>
<GenericOption value="false">{Dictionary.no}</GenericOption>
</Field>
{!disableSetArbitrary && (
<Field
name="allowArbitrary"
component={ListRadios}
label={Dictionary.allowArbitraryResponse}
required
// Convert string "true"/"false" to boolean true/false when storing in Redux form
parse={(value) => value === 'true'}
// Convert true/false/undefined to string "true"/"false" when displaying the form
format={(value) => (value === true ? 'true' : 'false')}
>
<GenericOption value="true">{Dictionary.yes}</GenericOption>
<GenericOption value="false">{Dictionary.no}</GenericOption>
</Field>
)}
</>
) : (
<CodesLists
Expand All @@ -204,6 +207,7 @@ ResponseFormatSingle.propTypes = {
path: PropTypes.string,
formName: PropTypes.string,
allowPrecision: PropTypes.bool,
disableSetArbitrary: PropTypes.bool,
};

ResponseFormatSingle.defaultProps = {
Expand All @@ -216,6 +220,7 @@ ResponseFormatSingle.defaultProps = {
path: SINGLE_CHOICE,
formName: DEFAULT_FORM_NAME,
allowPrecision: true,
disableSetArbitrary: false,
};

const mapStateToProps = (state, { selectorPathParent, responseFormatType }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function InputMeasure({ selectorPath }) {
selectorPathParent={selectorPath}
showMandatory={false}
allowPrecision={false}
disableSetArbitrary={true}
/>
</View>
</SelectorView>
Expand Down

0 comments on commit 8aaf8b8

Please sign in to comment.