Skip to content

Commit

Permalink
refactor: add more explicit variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Oct 14, 2024
1 parent ec6e53e commit 967cc14
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 2 additions & 5 deletions editor.planx.uk/src/@planx/components/NumberInput/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@ export default function NumberInputComponent(props: Props): FCReturn {
<FormControlLabel
control={
<Switch
checked={formik.values.onlyWholeNumbers}
checked={formik.values.isInteger}
onChange={() =>
formik.setFieldValue(
"onlyWholeNumbers",
!formik.values.onlyWholeNumbers,
)
formik.setFieldValue("isInteger", !formik.values.isInteger)
}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test("a clear error is shown if decimal value added when onlyWholeNumbers is tog
fn="fahrenheit"
title="What's the temperature?"
handleSubmit={handleSubmit}
onlyWholeNumbers={true}
isInteger={true}
/>,
);

Expand All @@ -117,7 +117,7 @@ test("allows only whole numbers to be submitted when toggled on by editor", asyn
fn="fahrenheit"
title="What's the temperature?"
handleSubmit={handleSubmit}
onlyWholeNumbers={true}
isInteger={true}
/>,
);

Expand Down
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/NumberInput/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface NumberInput extends BaseNodeData {
fn?: string;
units?: string;
allowNegatives?: boolean;
onlyWholeNumbers?: boolean;
isInteger?: boolean;
}

export type UserData = number;
Expand All @@ -29,7 +29,7 @@ export const parseNumberInput = (
fn: data?.fn || "",
units: data?.units,
allowNegatives: data?.allowNegatives || false,
onlyWholeNumbers: data?.onlyWholeNumbers || false,
isInteger: data?.isInteger || false,
...parseBaseNodeData(data),
});

Expand Down Expand Up @@ -62,7 +62,7 @@ export const numberInputValidationSchema = (input: NumberInput) =>
if (!value) {
return false;
}
if (input.onlyWholeNumbers && !Number.isInteger(Number(value))) {
if (input.isInteger && !Number.isInteger(Number(value))) {
return false;
}
return true;
Expand Down

0 comments on commit 967cc14

Please sign in to comment.