Skip to content

Commit

Permalink
(refactor) Use one component export syntax for consistency (openmrs#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen authored and usamaidrsk committed Apr 29, 2024
1 parent 87fb909 commit 2b05e49
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 53 deletions.
4 changes: 3 additions & 1 deletion src/components/encounter/encounter-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface EncounterFormProps {
setIsSubmitting?: Dispatch<SetStateAction<boolean>>;
}

export const EncounterForm: React.FC<EncounterFormProps> = ({
const EncounterForm: React.FC<EncounterFormProps> = ({
formJson,
patient,
formSessionDate,
Expand Down Expand Up @@ -878,3 +878,5 @@ export const EncounterForm: React.FC<EncounterFormProps> = ({
</FormContext.Provider>
);
};

export default EncounterForm;
8 changes: 5 additions & 3 deletions src/components/group/obs-group.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { useField } from 'formik';
import { FormContext } from '../../form-context';
import { type FormFieldProps } from '../../types';
import { getFieldControlWithFallback, isUnspecifiedSupported } from '../section/helpers';
import { UnspecifiedField } from '../inputs/unspecified/unspecified.component';
import { Tooltip } from '../inputs/tooltip/tooltip.component';
import Tooltip from '../inputs/tooltip/tooltip.component';
import UnspecifiedField from '../inputs/unspecified/unspecified.component';
import styles from '../section/form-section.scss';

export interface ObsGroupProps extends FormFieldProps {
deleteControl?: any;
}

export const ObsGroup: React.FC<ObsGroupProps> = ({ question, onChange, deleteControl }) => {
const ObsGroup: React.FC<ObsGroupProps> = ({ question, onChange, deleteControl }) => {
const [groupMembersControlMap, setGroupMembersControlMap] = useState([]);
const { formFieldHandlers } = useContext(FormContext);

Expand Down Expand Up @@ -89,3 +89,5 @@ export const ObsGroup: React.FC<ObsGroupProps> = ({ question, onChange, deleteCo

return <div className={styles.flexRow}>{groupContent}</div>;
};

export default ObsGroup;
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import classNames from 'classnames';
import { FormGroup, ContentSwitcher as CdsContentSwitcher, Switch } from '@carbon/react';
import { useField } from 'formik';
import { isInlineView } from '../../../utils/form-helper';
import { isEmpty } from '../../../validators/form-validator';
import { isTrue } from '../../../utils/boolean-utils';
import { FieldValueView } from '../../value/view/field-value-view.component';
import { FormContext } from '../../../form-context';
import { type FormFieldProps } from '../../../types';
import FieldValueView from '../../value/view/field-value-view.component';
import styles from './content-switcher.scss';
import { useTranslation } from 'react-i18next';

export const ContentSwitcher: React.FC<FormFieldProps> = ({ question, onChange, handler, previousValue }) => {
const ContentSwitcher: React.FC<FormFieldProps> = ({ question, onChange, handler, previousValue }) => {
const { t } = useTranslation();
const [field, meta] = useField(question.id);
const { setFieldValue, encounterContext, layoutType, workspaceLayout } = React.useContext(FormContext);
Expand Down Expand Up @@ -87,3 +87,5 @@ export const ContentSwitcher: React.FC<FormFieldProps> = ({ question, onChange,
)
);
};

export default ContentSwitcher;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render, fireEvent, screen, cleanup, act, waitFor } from '@testing-library/react';
import { Formik } from 'formik';
import { ContentSwitcher } from './content-switcher.component';
import ContentSwitcher from './content-switcher.component';
import { type EncounterContext, FormContext } from '../../../form-context';
import { type FormField } from '../../../types';
import { ObsSubmissionHandler } from '../../../submission-handlers/base-handlers';
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/date/date.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { formatDate } from '@openmrs/esm-framework';
import { isTrue } from '../../../utils/boolean-utils';
import { type FormFieldProps } from '../../../types';
import { isInlineView } from '../../../utils/form-helper';
import { FieldValueView } from '../../value/view/field-value-view.component';
import { fieldRequiredErrCode, isEmpty } from '../../../validators/form-validator';
import { FormContext } from '../../../form-context';
import FieldValueView from '../../value/view/field-value-view.component';
import RequiredFieldLabel from '../../required-field-label/required-field-label.component';
import styles from './date.scss';

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 @@ -3,17 +3,17 @@ import { FilterableMultiSelect, Layer, Tag } from '@carbon/react';
import classNames from 'classnames';
import { useField } from 'formik';
import { useTranslation } from 'react-i18next';
import { FieldValueView } from '../../value/view/field-value-view.component';
import { FormContext } from '../../../form-context';
import { type FormFieldProps } from '../../../types';
import { ValueEmpty } from '../../value/value.component';
import { fieldRequiredErrCode, isEmpty } from '../../../validators/form-validator';
import { isInlineView } from '../../../utils/form-helper';
import { isTrue } from '../../../utils/boolean-utils';
import FieldValueView from '../../value/view/field-value-view.component';
import RequiredFieldLabel from '../../required-field-label/required-field-label.component';
import styles from './multi-select.scss';

export const MultiSelect: React.FC<FormFieldProps> = ({ question, onChange, handler, previousValue }) => {
const MultiSelect: React.FC<FormFieldProps> = ({ question, onChange, handler, previousValue }) => {
const { t } = useTranslation();
const [field, meta] = useField(question.id);
const { setFieldValue, encounterContext, layoutType, workspaceLayout } = React.useContext(FormContext);
Expand Down Expand Up @@ -138,3 +138,5 @@ export const MultiSelect: React.FC<FormFieldProps> = ({ question, onChange, hand
)
);
};

export default MultiSelect;
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 @@ -5,7 +5,7 @@ import { useField } from 'formik';
import { isTrue } from '../../../utils/boolean-utils';
import { fieldRequiredErrCode, isEmpty } from '../../../validators/form-validator';
import { isInlineView } from '../../../utils/form-helper';
import { FieldValueView } from '../../value/view/field-value-view.component';
import FieldValueView from '../../value/view/field-value-view.component';
import { type FormFieldProps } from '../../../types';
import { FormContext } from '../../../form-context';
import RequiredFieldLabel from '../../required-field-label/required-field-label.component';
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/radio/radio.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FormContext } from '../../../form-context';
import { isTrue } from '../../../utils/boolean-utils';
import { isInlineView } from '../../../utils/form-helper';
import { fieldRequiredErrCode, isEmpty } from '../../../validators/form-validator';
import { FieldValueView } from '../../value/view/field-value-view.component';
import FieldValueView from '../../value/view/field-value-view.component';
import RequiredFieldLabel from '../../required-field-label/required-field-label.component';
import styles from './radio.scss';

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 @@ -6,9 +6,9 @@ import { useField } from 'formik';
import { fieldRequiredErrCode, isEmpty } from '../../../validators/form-validator';
import { isInlineView } from '../../../utils/form-helper';
import { isTrue } from '../../../utils/boolean-utils';
import { FieldValueView } from '../../value/view/field-value-view.component';
import { FormContext } from '../../../form-context';
import { type FormFieldProps } from '../../../types';
import FieldValueView from '../../value/view/field-value-view.component';
import RequiredFieldLabel from '../../required-field-label/required-field-label.component';
import styles from './dropdown.scss';

Expand Down
4 changes: 2 additions & 2 deletions src/components/inputs/text-area/text-area.component.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React, { useEffect, useMemo, useState } from 'react';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Layer, TextArea as TextAreaInput } from '@carbon/react';
import { useField } from 'formik';
import { fieldRequiredErrCode, isEmpty } from '../../../validators/form-validator';
import { isInlineView } from '../../../utils/form-helper';
import { isTrue } from '../../../utils/boolean-utils';
import { FieldValueView } from '../../value/view/field-value-view.component';
import { FormContext } from '../../../form-context';
import { type FormFieldProps } from '../../../types';
import FieldValueView from '../../value/view/field-value-view.component';
import RequiredFieldLabel from '../../required-field-label/required-field-label.component';
import styles from './text-area.scss';
import { useTranslation } from 'react-i18next';

const TextArea: React.FC<FormFieldProps> = ({ question, onChange, handler, previousValue: previousValueProp }) => {
const { t } = useTranslation();
Expand Down
4 changes: 2 additions & 2 deletions src/components/inputs/text/text.component.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, { useEffect, useMemo, useState } from 'react';
import classNames from 'classnames';
import isEmpty from 'lodash-es/isEmpty';
import { useTranslation } from 'react-i18next';
import { Layer, TextInput } from '@carbon/react';
import { useField } from 'formik';
import { type FormFieldProps } from '../../../types';
import { FormContext } from '../../../form-context';
import { fieldRequiredErrCode } from '../../../validators/form-validator';
import { isTrue } from '../../../utils/boolean-utils';
import { isInlineView } from '../../../utils/form-helper';
import { FieldValueView } from '../../value/view/field-value-view.component';
import FieldValueView from '../../value/view/field-value-view.component';
import RequiredFieldLabel from '../../required-field-label/required-field-label.component';
import styles from './text.scss';
import { useTranslation } from 'react-i18next';

const TextField: React.FC<FormFieldProps> = ({ question, onChange, handler, previousValue }) => {
const { t } = useTranslation();
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 @@ -5,7 +5,7 @@ import { useField } from 'formik';
import { FormContext } from '../../../form-context';
import { isTrue } from '../../../utils/boolean-utils';
import { isInlineView } from '../../../utils/form-helper';
import { FieldValueView } from '../../value/view/field-value-view.component';
import FieldValueView from '../../value/view/field-value-view.component';
import { isEmpty } from '../../../validators/form-validator';
import { booleanConceptToBoolean } from '../../../utils/common-expression-helpers';
import styles from './toggle.scss';
Expand Down
4 changes: 3 additions & 1 deletion src/components/inputs/tooltip/tooltip.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface TooltipProps {
field: FormField;
}

export const Tooltip: React.FC<TooltipProps> = ({ field }) => {
const Tooltip: React.FC<TooltipProps> = ({ field }) => {
const { t } = useTranslation();
return (
<CarbonTooltip align="top" label={t(field.questionInfo)} description={t(field.questionInfo)}>
Expand All @@ -19,3 +19,5 @@ export const Tooltip: React.FC<TooltipProps> = ({ field }) => {
</CarbonTooltip>
);
};

export default Tooltip;
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import classNames from 'classnames';
import debounce from 'lodash-es/debounce';
import { ComboBox, InlineLoading, Layer } from '@carbon/react';
import { useField } from 'formik';
import { FieldValueView } from '../../value/view/field-value-view.component';
import { isTrue } from '../../../utils/boolean-utils';
import { useTranslation } from 'react-i18next';
import { getRegisteredDataSource } from '../../../registry/registry';
import { getControlTemplate } from '../../../registry/inbuilt-components/control-templates';
import { FormContext } from '../../../form-context';
import { type FormFieldProps } from '../../../types';
import { fieldRequiredErrCode, isEmpty } from '../../../validators/form-validator';
import FieldValueView from '../../value/view/field-value-view.component';
import { isInlineView } from '../../../utils/form-helper';
import RequiredFieldLabel from '../../required-field-label/required-field-label.component';
import styles from './ui-select-extended.scss';
Expand Down
4 changes: 3 additions & 1 deletion src/components/inputs/unspecified/unspecified.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { type FormFieldProps } from '../../../types';
import { isTrue } from '../../../utils/boolean-utils';
import styles from './unspecified.scss';

export const UnspecifiedField: React.FC<FormFieldProps> = ({ question, onChange, handler }) => {
const UnspecifiedField: React.FC<FormFieldProps> = ({ question, onChange, handler }) => {
const { t } = useTranslation();
const [field, meta] = useField(`${question.id}-unspecified`);
const { setFieldValue, encounterContext, fields } = React.useContext(FormContext);
Expand Down Expand Up @@ -82,3 +82,5 @@ export const UnspecifiedField: React.FC<FormFieldProps> = ({ question, onChange,
)
);
};

export default UnspecifiedField;
2 changes: 1 addition & 1 deletion src/components/inputs/unspecified/unspecified.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { fireEvent, render, screen } from '@testing-library/react';
import { Formik } from 'formik';
import { type FormField, type EncounterContext, FormContext } from '../../..';
import { ObsSubmissionHandler } from '../../../submission-handlers/base-handlers';
import { UnspecifiedField } from './unspecified.component';
import { findTextOrDateInput } from '../../../utils/test-utils';
import DateField from '../date/date.component';
import UnspecifiedField from './unspecified.component';

const question: FormField = {
label: 'Visit Date',
Expand Down
4 changes: 3 additions & 1 deletion src/components/label/label.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type LabelProps = {
tooltipText?: string;
};

export const LabelField: React.FC<LabelProps> = ({ value, tooltipText }) => {
const LabelField: React.FC<LabelProps> = ({ value, tooltipText }) => {
return (
<div className={styles.label}>
<DefinitionTooltip direction="bottom" tabIndex={0} tooltipText={tooltipText}>
Expand All @@ -16,3 +16,5 @@ export const LabelField: React.FC<LabelProps> = ({ value, tooltipText }) => {
</div>
);
};

export default LabelField;
7 changes: 3 additions & 4 deletions src/components/patient-banner/patient-banner.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import React from 'react';
import { ExtensionSlot } from '@openmrs/esm-framework';
import styles from './patient-banner.scss';

export const PatientBanner: React.FC<{ patient: any; hideActionsOverflow?: any }> = ({
patient,
hideActionsOverflow,
}) => {
const PatientBanner: React.FC<{ patient: any; hideActionsOverflow?: any }> = ({ patient, hideActionsOverflow }) => {
return (
<div className={styles.patientBannerContainer}>
<ExtensionSlot
Expand All @@ -19,3 +16,5 @@ export const PatientBanner: React.FC<{ patient: any; hideActionsOverflow?: any }
</div>
);
};

export default PatientBanner;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {
hideHeader?: boolean;
};

export const PreviousValueReview: React.FC<Props> = ({ previousValue, displayText, setValue, field, hideHeader }) => {
const PreviousValueReview: React.FC<Props> = ({ previousValue, displayText, setValue, field, hideHeader }) => {
const { t } = useTranslation();

return (
Expand Down Expand Up @@ -40,3 +40,5 @@ export const PreviousValueReview: React.FC<Props> = ({ previousValue, displayTex
</div>
);
};

export default PreviousValueReview;
2 changes: 1 addition & 1 deletion src/components/repeat/repeat.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useFormikContext } from 'formik';
import { useTranslation } from 'react-i18next';
import { type FormField, type FormFieldProps } from '../../types';
import { evaluateAsyncExpression, evaluateExpression } from '../../utils/expression-runner';
import { ObsGroup } from '../group/obs-group.component';
import ObsGroup from '../group/obs-group.component';
import { isEmpty } from '../../validators/form-validator';
import styles from './repeat.scss';
import { cloneObsGroup } from './helpers';
Expand Down
6 changes: 3 additions & 3 deletions src/components/section/form-section.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { ToastNotification } from '@carbon/react';
import { formatPreviousValueDisplayText, getFieldControlWithFallback, isUnspecifiedSupported } from './helpers';
import { getRegisteredFieldSubmissionHandler } from '../../registry/registry';
import { isTrue } from '../../utils/boolean-utils';
import { UnspecifiedField } from '../inputs/unspecified/unspecified.component';
import { FormContext } from '../../form-context';
import { PreviousValueReview } from '../previous-value-review/previous-value-review.component';
import { Tooltip } from '../inputs/tooltip/tooltip.component';
import PreviousValueReview from '../previous-value-review/previous-value-review.component';
import Tooltip from '../inputs/tooltip/tooltip.component';
import UnspecifiedField from '../inputs/unspecified/unspecified.component';
import styles from './form-section.scss';

interface FieldComponentMap {
Expand Down
7 changes: 5 additions & 2 deletions src/components/value/view/field-value-view.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { LabelField } from '../../label/label.component';
import LabelField from '../../label/label.component';
import { ValueDisplay, ValueEmpty } from '../value.component';
import styles from './field-value-view.scss';

Expand All @@ -9,7 +9,8 @@ interface FieldValueViewProps {
value: any;
conceptName: string;
}
export const FieldValueView: React.FC<FieldValueViewProps> = ({ label, conceptName, value, isInline }) => (

const FieldValueView: React.FC<FieldValueViewProps> = ({ label, conceptName, value, isInline }) => (
<>
{isInline ? (
<div className={styles.inlineFlexRow}>
Expand All @@ -28,3 +29,5 @@ export const FieldValueView: React.FC<FieldValueViewProps> = ({ label, conceptNa
)}
</>
);

export default FieldValueView;
12 changes: 6 additions & 6 deletions src/form-engine.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Form, Formik } from 'formik';
import { Formik, Form } from 'formik';
import classNames from 'classnames';
import { Button, ButtonSet, InlineLoading } from '@carbon/react';
import { I18nextProvider, useTranslation } from 'react-i18next';
Expand All @@ -9,19 +9,19 @@ import LinearLoader from './components/loaders/linear-loader.component';
import LoadingIcon from './components/loaders/loading.component';
import Sidebar from './components/sidebar/sidebar.component';
import { init, teardown } from './lifecycle';
import type { FormPage as FormPageProps, FormSchema, SessionMode } from './types';
import { PatientBanner } from './components/patient-banner/patient-banner.component';
import type { FormSchema, SessionMode, FormPage as FormPageProps } from './types';
import { extractErrorMessagesFromResponse, reportError } from './utils/error-utils';
import { useFormJson } from './hooks/useFormJson';
import { usePostSubmissionAction } from './hooks/usePostSubmissionAction';
import { useWorkspaceLayout } from './hooks/useWorkspaceLayout';
import { usePatientData } from './hooks/usePatientData';
import { evaluatePostSubmissionExpression } from './utils/post-submission-action-helper';
import MarkdownWrapper from './components/inputs/markdown/markdown-wrapper.component';
import styles from './form-engine.scss';
import { EncounterForm } from './components/encounter/encounter-form.component';
import { moduleName } from './globals';
import { useFormCollapse } from './hooks/useFormCollapse';
import EncounterForm from './components/encounter/encounter-form.component';
import PatientBanner from './components/patient-banner/patient-banner.component';
import MarkdownWrapper from './components/inputs/markdown/markdown-wrapper.component';
import styles from './form-engine.scss';

interface FormProps {
patientUUID: string;
Expand Down
Loading

0 comments on commit 2b05e49

Please sign in to comment.