Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/ O3-2253:Marking a field as readonly should render the field control as opposed to switching to view mode #114

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/inputs/date/ohri-date.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const OHRIDate: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler })
}
}, [field.value, time]);

return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<OHRIFieldValueView
label={question.label}
value={field.value instanceof Date ? getDisplay(field.value, question.questionOptions.rendering) : field.value}
Expand Down Expand Up @@ -170,6 +170,7 @@ const OHRIDate: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler })
invalidText={errors[0]?.message}
warn={warnings.length > 0}
warnText={warnings[0]?.message}
readOnly={question.readonly}
/>
</DatePicker>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const OHRIEncounterLocationPicker: React.FC<{ question: OHRIFormField; on
});
}, [conceptName]);

return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<div className={styles.formField}>
<OHRIFieldValueView
label={question.label}
Expand All @@ -59,6 +59,7 @@ export const OHRIEncounterLocationPicker: React.FC<{ question: OHRIFormField; on
setFieldValue(question.id, selectedItem);
setEncounterLocation(selectedItem);
}}
readOnly={question.readonly}
disabled={question.disabled}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const OHRIMultiSelect: React.FC<OHRIFormFieldProps> = ({ question, onChan
return false;
}, [encounterContext.sessionMode, question.readonly, question.inlineRendering, layoutType, workspaceLayout]);

return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<div className={styles.formField}>
<OHRIFieldValueView
label={question.label}
Expand Down Expand Up @@ -111,6 +111,7 @@ export const OHRIMultiSelect: React.FC<OHRIFormFieldProps> = ({ question, onChan
invalidText={errors[0]?.message}
warn={warnings.length > 0}
warnText={warnings[0]?.message}
readOnly={question.readonly}
/>
</div>
<div className={styles.formField} style={{ marginTop: '0.125rem' }}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/inputs/number/ohri-number.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const OHRINumber: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler
return false;
}, [encounterContext.sessionMode, question.readonly, question.inlineRendering, layoutType, workspaceLayout]);

return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<div className={styles.formField}>
<OHRIFieldValueView
label={question.label}
Expand Down Expand Up @@ -99,6 +99,7 @@ const OHRINumber: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler
hideSteppers={true}
onWheel={e => e.target.blur()}
disabled={question.disabled}
readOnly={question.readonly}
className={isFieldRequiredError ? styles.errorLabel : ''}
warn={warnings.length > 0}
warnText={warnings[0]?.message}
Expand Down
3 changes: 2 additions & 1 deletion src/components/inputs/select/ohri-dropdown.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const OHRIDropdown: React.FC<OHRIFormFieldProps> = ({ question, onChange, handle
return false;
}, [encounterContext.sessionMode, question.readonly, question.inlineRendering, layoutType, workspaceLayout]);

return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<OHRIFieldValueView
label={question.label}
value={field.value ? handler?.getDisplayValue(question, field.value) : field.value}
Expand All @@ -87,6 +87,7 @@ const OHRIDropdown: React.FC<OHRIFormFieldProps> = ({ question, onChange, handle
selectedItem={field.value}
onChange={({ selectedItem }) => handleChange(selectedItem)}
disabled={question.disabled}
readOnly={question.readonly}
invalid={!isFieldRequiredError && errors.length > 0}
invalidText={errors.length && errors[0].message}
warn={warnings.length > 0}
Expand Down
3 changes: 2 additions & 1 deletion src/components/inputs/text-area/ohri-text-area.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const OHRITextArea: React.FC<OHRIFormFieldProps> = ({ question, onChange, handle
return false;
}, [encounterContext.sessionMode, question.readonly, question.inlineRendering, layoutType, workspaceLayout]);

return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<div className={styles.formField}>
<OHRIFieldValueView label={question.label} value={field.value} conceptName={conceptName} isInline={isInline} />
</div>
Expand All @@ -68,6 +68,7 @@ const OHRITextArea: React.FC<OHRIFormFieldProps> = ({ question, onChange, handle
onFocus={() => setPreviousValue(field.value)}
rows={question.questionOptions.rows || 4}
disabled={question.disabled}
readOnly={question.readonly}
invalid={!isFieldRequiredError && errors.length > 0}
invalidText={errors.length && errors[0].message}
warn={warnings.length > 0}
Expand Down
3 changes: 2 additions & 1 deletion src/components/inputs/text/ohri-text.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const OHRIText: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler })
return false;
}, [encounterContext.sessionMode, question.readonly, question.inlineRendering, layoutType, workspaceLayout]);

return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<div className={styles.formField}>
<OHRIFieldValueView label={question.label} value={field.value} conceptName={conceptName} isInline={isInline} />
</div>
Expand All @@ -86,6 +86,7 @@ const OHRIText: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler })
value={field.value || ''}
onFocus={() => setPreviousValue(field.value)}
disabled={question.disabled}
readOnly={question.readonly}
invalid={!isFieldRequiredError && errors.length > 0}
invalidText={errors.length && errors[0].message}
warn={warnings.length > 0}
Expand Down
3 changes: 2 additions & 1 deletion src/components/inputs/toggle/ohri-toggle.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const OHRIToggle: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler
return false;
}, [encounterContext.sessionMode, question.readonly, question.inlineRendering, layoutType, workspaceLayout]);

return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<div className={styles.formField}>
<OHRIFieldValueView
label={question.label}
Expand All @@ -60,6 +60,7 @@ const OHRIToggle: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler
onToggle={handleChange}
toggled={!!field.value}
disabled={question.disabled}
readOnly={question.readonly}
/>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const UISelectExtended: React.FC<OHRIFormFieldProps> = ({ question, handl
}
return changes;
};
return encounterContext.sessionMode == 'view' || isTrue(question.readonly) ? (
return encounterContext.sessionMode == 'view' ? (
<div className={styles.formField}>
<OHRIFieldValueView
label={question.label}
Expand Down Expand Up @@ -130,6 +130,7 @@ export const UISelectExtended: React.FC<OHRIFormFieldProps> = ({ question, handl
}}
onChange={({ selectedItem }) => handleChange(selectedItem?.uuid)}
disabled={question.disabled}
readOnly={question.readonly}
onInputChange={value => {
inputValue.current = value;
if (question.questionOptions['isSearchable']) {
Expand Down
Loading