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

(test) Fix warnings raised when running tests #204

Merged
merged 1 commit into from
Apr 23, 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
6 changes: 5 additions & 1 deletion src/components/group/ohri-obs-group.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export const OHRIObsGroup: React.FC<ObsGroupProps> = ({ question, onChange, dele
});
}
}, [question.questions]);

const groupContent = groupMembersControlMap
.filter((groupMemberMapItem) => !!groupMemberMapItem && !groupMemberMapItem.field.isHidden)
.map((groupMemberMapItem, index) => {
const keyId = groupMemberMapItem.field.id + '-' + index;
const { control, field } = groupMemberMapItem;
if (control) {
const questionFragment = React.createElement(control, {
Expand All @@ -41,7 +43,7 @@ export const OHRIObsGroup: React.FC<ObsGroupProps> = ({ question, onChange, dele
});

return (
<div className={classNames(styles.flexColumn, styles.obsGroupColumn)}>
<div className={classNames(styles.flexColumn, styles.obsGroupColumn)} key={keyId}>
<div className={styles.parentResizer}>
{questionFragment}
<div
Expand All @@ -59,8 +61,10 @@ export const OHRIObsGroup: React.FC<ObsGroupProps> = ({ question, onChange, dele
);
}
});

if (groupContent && deleteControl) {
groupContent.push(deleteControl);
}

return <div className={styles.flexRow}>{groupContent}</div>;
};
4 changes: 2 additions & 2 deletions src/components/inputs/number/ohri-number.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ const OHRINumber: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler,
invalid={!isFieldRequiredError && errors.length > 0}
invalidText={errors[0]?.message}
label={question.label}
max={question.questionOptions.max || undefined}
min={question.questionOptions.min || undefined}
max={Number(question.questionOptions.max) || undefined}
min={Number(question.questionOptions.min) || undefined}
name={question.id}
value={field.value || ''}
allowEmpty={true}
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/radio/ohri-radio.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const OHRIRadio: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler,
return (
<RadioButton
id={`${question.id}-${answer.label}`}
labelText={answer.label}
labelText={answer.label ?? ''}
value={answer.concept}
key={index}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/select/ohri-dropdown.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const OHRIDropdown: React.FC<OHRIFormFieldProps> = ({ question, onChange, handle
invalid={!isFieldRequiredError && errors.length > 0}
invalidText={errors.length && errors[0].message}
warn={warnings.length > 0}
warnText={warnings.length && warnings[0].message}
warnText={warnings.length ? warnings[0].message : ''}
/>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/text/ohri-text.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const OHRIText: React.FC<OHRIFormFieldProps> = ({ question, onChange, handler, p
name={question.id}
value={field.value || ''}
disabled={question.disabled}
readOnly={question.readonly}
readOnly={Boolean(question.readonly)}
invalid={!isFieldRequiredError && errors.length > 0}
invalidText={errors.length && errors[0].message}
warn={warnings.length > 0}
Expand Down
37 changes: 21 additions & 16 deletions src/components/repeat/ohri-repeat.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useId, useState } from 'react';
import { FormGroup, Button } from '@carbon/react';
import { Add, TrashCan } from '@carbon/react/icons';
import { useFormikContext } from 'formik';
Expand All @@ -16,8 +16,10 @@ export const showAddButton = (limit: string | number, counter: number) => {
return !Number.isNaN(repeatLimit) && repeatLimit > 0 ? counter < repeatLimit : true;
};

export const OHRIRepeat: React.FC<OHRIFormFieldProps> = ({ question, onChange }) => {
const OHRIRepeat: React.FC<OHRIFormFieldProps> = ({ question, onChange }) => {
const { t } = useTranslation();
const id = useId();

const {
fields: allFormFields,
encounterContext,
Expand Down Expand Up @@ -105,25 +107,25 @@ export const OHRIRepeat: React.FC<OHRIFormFieldProps> = ({ question, onChange })
};

const nodes = obsGroups.map((question, index) => {
const keyId = question.id + '-' + index;
const deleteControl =
obsGroups.length > 1 && encounterContext.sessionMode !== 'view' ? (
<div>
<div className={styles.removeButton}>
<Button
renderIcon={() => <TrashCan size={16} />}
kind="danger--tertiary"
onClick={() => removeNthRow(question)}
hasIconOnly
/>
</div>
<div key={keyId} className={styles.removeButton}>
<Button
className={styles.button}
renderIcon={() => <TrashCan size={16} />}
kind="danger--tertiary"
onClick={() => removeNthRow(question)}>
<span>{t('removeGroup', 'Remove group')}</span>
</Button>
</div>
) : null;

return (
<>
<div key={keyId}>
{index !== 0 && (
<div>
<hr className={styles.separator} />
<hr className={styles.divider} />
</div>
)}
<div className={styles.obsGroupContainer}>
Expand All @@ -134,17 +136,18 @@ export const OHRIRepeat: React.FC<OHRIFormFieldProps> = ({ question, onChange })
deleteControl={index !== 0 ? deleteControl : null}
/>
</div>
</>
</div>
);
});

encounterContext.sessionMode != 'view' &&
nodes.push(
<div>
<div key={id}>
{showAddButton(question.questionOptions.repeatOptions?.limit, counter) && (
<Button
className={styles.button}
iconDescription={t('add', 'Add')}
renderIcon={() => <Add size={16} />}
className={styles.repeatButton}
kind="tertiary"
onClick={() => {
const nextCount = counter + 1;
Expand All @@ -167,3 +170,5 @@ export const OHRIRepeat: React.FC<OHRIFormFieldProps> = ({ question, onChange })
)
);
};

export default OHRIRepeat;
16 changes: 12 additions & 4 deletions src/components/repeat/ohri-repeat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@
margin-left: 0.5rem;
}

.obsGroupContainer {
margin: 1rem 0rem;
.button {
svg {
margin-left: 1rem;
}
}

.separator {
margin-bottom: 1rem;
.obsGroupContainer {
margin: 1rem 0rem 2rem;
}

.container {
margin-top: 0.65rem;
margin-bottom: 2rem;
}

.divider {
border: 1.5px solid #e0e0e0;
border-bottom: none;
margin: 2rem 0;
}
5 changes: 5 additions & 0 deletions src/components/section/ohri-form-section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@
.controlWidthConstrained {
max-width: 18rem;
}

.flexColumn {
display: flex;
flex-direction: column;
}
4 changes: 2 additions & 2 deletions src/ohri-form.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ describe('OHRI Forms:', () => {
});
});

describe('Calcuated values', () => {
describe('Calculated values', () => {
afterEach(() => {
cleanup();
});
Expand Down Expand Up @@ -641,7 +641,7 @@ describe('OHRI Forms:', () => {
//Add repeat group
await act(async () => fireEvent.click(addButton));

const deleteButton = await screen.findByRole('button', { name: 'danger' });
const deleteButton = await screen.findByRole('button', { name: /remove group/i });
femaleRadios = await findAllRadioGroupMembers(screen, 'Female');
maleRadios = await findAllRadioGroupMembers(screen, 'Male');
birthDateFields = await findAllTextOrDateInputs(screen, 'Date of Birth');
Expand Down
4 changes: 3 additions & 1 deletion src/ohri-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ const OHRIForm: React.FC<OHRIFormProps> = ({
setSubmitting(false);
}}>
{(props) => {
setIsFormTouched(props.dirty);
useEffect(() => {
setIsFormTouched(props.dirty);
}, [props.dirty]);

return (
<Form className={classNames('cds--form', 'no-padding', styles.ohriForm)} ref={ref}>
Expand Down
2 changes: 1 addition & 1 deletion src/registry/inbuilt-components/inbuiltControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import OHRIDropdown from '../../components/inputs/select/ohri-dropdown.component
import OHRITextArea from '../../components/inputs/text-area/ohri-text-area.component';
import OHRIText from '../../components/inputs/text/ohri-text.component';
import OHRIToggle from '../../components/inputs/toggle/ohri-toggle.component';
import { OHRIRepeat } from '../../components/repeat/ohri-repeat.component';
import OHRIRepeat from '../../components/repeat/ohri-repeat.component';
import File from '../../components/inputs/file/file.component';
import { RegistryItem } from '../registry';
import { controlTemplates } from './control-templates';
Expand Down
6 changes: 3 additions & 3 deletions src/utils/common-expression-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export class CommonExpressionHelpers {
return o === lastReferenceValue;
});
const SDValue = refObjectKeys[lastValueIndex];
formattedSDValue = SDValue.replace('SD', '');
formattedSDValue = SDValue?.replace('SD', '');
if (formattedSDValue.includes('neg')) {
formattedSDValue = formattedSDValue.substring(1, 0);
formattedSDValue = '-' + formattedSDValue;
Expand Down Expand Up @@ -353,7 +353,7 @@ export class CommonExpressionHelpers {
return o === lastReferenceValue;
});
const SDValue = refObjectKeys[lastValueIndex];
formattedSDValue = SDValue.replace('SD', '');
formattedSDValue = SDValue?.replace('SD', '');
if (formattedSDValue.includes('neg')) {
formattedSDValue = formattedSDValue.substring(1, 0);
formattedSDValue = '-' + formattedSDValue;
Expand Down Expand Up @@ -398,7 +398,7 @@ export class CommonExpressionHelpers {
return o === lastReferenceValue;
});
const SDValue = refObjectKeys[lastValueIndex];
formattedSDValue = SDValue.replace('SD', '');
formattedSDValue = SDValue?.replace('SD', '');
if (formattedSDValue.includes('neg')) {
formattedSDValue = formattedSDValue.substring(1, 0);
formattedSDValue = '-' + formattedSDValue;
Expand Down
Loading