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-3970 Re-enable readonly fields #397

Merged
merged 6 commits into from
Sep 30, 2024
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
1 change: 1 addition & 0 deletions src/components/inputs/date/date.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const DateField: React.FC<FormFieldInputProps> = ({ field, value: dateValue, err
disabled={field.datePickerFormat === 'timer' ? field.isDisabled : !dateValue ? true : false}
invalid={errors.length > 0}
invalidText={errors[0]?.message}
readOnly={isTrue(field.readonly)}
warning={warnings.length > 0}
warningText={warnings[0]?.message}
value={
Expand Down
6 changes: 4 additions & 2 deletions src/components/inputs/multi-select/multi-select.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const MultiSelect: React.FC<FormFieldInputProps> = ({ field, value, errors, warn
label: answer.label,
key: index,
disabled: answer.disable?.isDisabled,
readonly: isTrue(field.readonly),
}));

const initiallySelectedQuestionItems = useMemo(() => {
Expand Down Expand Up @@ -110,10 +111,10 @@ const MultiSelect: React.FC<FormFieldInputProps> = ({ field, value, errors, warn
invalidText={errors[0]?.message}
warn={warnings.length > 0}
warnText={warnings[0]?.message}
readOnly={field.readonly}
readOnly={isTrue(field.readonly)}
/>
) : (
<CheckboxGroup legendText={label} name={field.id}>
<CheckboxGroup legendText={label} name={field.id} readOnly={isTrue(field.readonly)}>
{field.questionOptions.answers?.map((value, index) => {
return (
<Checkbox
Expand All @@ -129,6 +130,7 @@ const MultiSelect: React.FC<FormFieldInputProps> = ({ field, value, errors, warn
checked={initiallyCheckedQuestionItems.some((item) => item === value.concept)}
onBlur={onblur}
disabled={value.disable?.isDisabled}
readOnly={isTrue(field.readonly)}
/>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/number/number.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const NumberField: React.FC<FormFieldInputProps> = ({ field, value, errors, warn
hideSteppers={true}
onWheel={(e) => e.target.blur()}
disabled={field.isDisabled}
readOnly={field.readonly}
readOnly={isTrue(field.readonly)}
className={classNames(styles.controlWidthConstrained, styles.boldedLabel)}
warn={warnings.length > 0}
warnText={warnings[0]?.message}
Expand Down
1 change: 1 addition & 0 deletions src/components/inputs/radio/radio.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const Radio: React.FC<FormFieldInputProps> = ({ field, value, errors, warnings,
name={field.id}
valueSelected={value}
onChange={handleChange}
readOnly={isTrue(field.readonly)}
orientation={field.questionOptions?.orientation || 'vertical'}>
{field.questionOptions.answers
.filter((answer) => !answer.isHidden)
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/select/dropdown.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Dropdown: React.FC<FormFieldInputProps> = ({ field, value, errors, warning
selectedItem={isEmpty(value) ? NullSelectOption : value}
onChange={handleChange}
disabled={field.isDisabled}
readOnly={field.readonly}
readOnly={isTrue(field.readonly)}
invalid={errors.length > 0}
invalidText={errors[0]?.message}
warn={warnings.length > 0}
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/text-area/text-area.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const TextArea: React.FC<FormFieldInputProps> = ({ field, value, errors, warning
value={value || ''}
rows={field.questionOptions.rows || 4}
disabled={field.isDisabled}
readOnly={field.readonly}
readOnly={isTrue(field.readonly)}
invalid={errors.length > 0}
invalidText={errors[0]?.message}
warn={warnings.length > 0}
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/toggle/toggle.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const Toggle: React.FC<FormFieldInputProps> = ({ field, value, errors, warnings,
onToggle={handleChange}
toggled={!!value}
disabled={field.isDisabled}
readOnly={field.readonly}
readOnly={isTrue(field.readonly)}
/>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const UiSelectExtended: React.FC<FormFieldInputProps> = ({ field, errors, warnin
setFieldValue(selectedItem?.uuid);
}}
disabled={field.isDisabled}
readOnly={field.readonly}
readOnly={isTrue(field.readonly)}
invalid={errors.length > 0}
invalidText={errors.length && errors[0].message}
onInputChange={(value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { showSnackbar } from '@openmrs/esm-framework';
import { useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib';
import { Button } from '@carbon/react';
import { type FormFieldInputProps } from '../../../types';
import { isTrue } from '../../../utils/boolean-utils';
import styles from './workspace-launcher.scss';

const WorkspaceLauncher: React.FC<FormFieldInputProps> = ({ field }) => {
Expand All @@ -27,7 +28,7 @@ const WorkspaceLauncher: React.FC<FormFieldInputProps> = ({ field }) => {
<div>
<div className={styles.label}>{t(field.label)}</div>
<div className={styles.workspaceButton}>
<Button onClick={handleLaunchWorkspace}>{field.questionOptions?.buttonLabel ?? t('launchWorkspace')}</Button>
<Button disabled={isTrue(field.readonly)} onClick={handleLaunchWorkspace}>{field.questionOptions?.buttonLabel ?? t('launchWorkspace')}</Button>
</div>
</div>
)
Expand Down