Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

MAT-7854 Quantity value should be a number #748

Merged
merged 2 commits into from
Oct 29, 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
8 changes: 4 additions & 4 deletions src/components/common/quantityInput/QuantityInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ describe("QuantityInput Component", () => {
expect(quantityFieldInput.value).toBe("");
expect(onQuantityChange).toBeCalled();
userEvent.type(quantityFieldInput, "-1-");
await expect(onQuantityChange).toHaveBeenNthCalledWith(2, {
expect(onQuantityChange).toHaveBeenNthCalledWith(2, {
unit: "mg",
value: "-1",
value: -1,
});
userEvent.type(quantityFieldInput, "2.5/...-");
await expect(onQuantityChange).toHaveBeenNthCalledWith(6, {
expect(onQuantityChange).toHaveBeenNthCalledWith(6, {
unit: "mg",
value: "2.5",
value: 2.5,
});
});
});
2 changes: 1 addition & 1 deletion src/components/common/quantityInput/QuantityInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
const unitCodes = ucum.UnitTables.getInstance().unitCodes_;
setUcumUnits(unitCodes);
}
}, [ucum, ucumUnits]);

Check warning on line 59 in src/components/common/quantityInput/QuantityInput.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage

React Hook useEffect has an unnecessary dependency: 'ucum'. Either exclude it or remove the dependency array. Outer scope values like 'ucum' aren't valid dependencies because mutating them doesn't re-render the component

const valueFn = (value: any) => {
let result: string;
Expand All @@ -80,7 +80,7 @@
} else {
onQuantityChange(null);
}
}, [currentQuantity]);

Check warning on line 83 in src/components/common/quantityInput/QuantityInput.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage

React Hook useEffect has a missing dependency: 'onQuantityChange'. Either include it or remove the dependency array. If 'onQuantityChange' changes too often, find the parent component that defines it and wrap that definition in useCallback

const findUnitOptionFromCQLQuantity = (value) => {
const option: ucum = ucumOptions?.find((option) => option.code === value);
Expand All @@ -101,11 +101,11 @@
setCurrentUnit(unit);
}
}
}, [ucumOptions]);

Check warning on line 104 in src/components/common/quantityInput/QuantityInput.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage

React Hook useEffect has missing dependencies: 'currentQuantity' and 'findUnitOptionFromCQLQuantity'. Either include them or remove the dependency array

const handleQuantityValueChange = (newValue) => {
const newQuantity: CQL.Quantity = {
value: newValue,
value: Number(newValue),
unit: currentQuantity.unit,
};
setCurrentQuantity(newQuantity);
Expand Down
Loading