Skip to content

Commit

Permalink
MAT-7791: validation for argument name
Browse files Browse the repository at this point in the history
  • Loading branch information
chubert-sb committed Dec 6, 2024
1 parent e459882 commit aa68b85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useFormik } from "formik";
import Arguments from "./Arguments";
import { FunctionArgument } from "../../../model/CqlBuilderLookup";
import ConfirmationDialog from "../../common/ConfirmationDialog";
import { FunctionArgumentSchemaValidator } from "../../../validations/FunctionArgumentSchemaValidator";

interface ArgumentsProps {
functionArguments?: FunctionArgument[];
Expand Down Expand Up @@ -51,7 +52,7 @@ export default function ArgumentSection(props: ArgumentsProps) {
dataType: "",
other: "",
},
// validationSchema: FunctionSectionSchemaValidator,
validationSchema: FunctionArgumentSchemaValidator,
enableReinitialize: false,
onSubmit: () => {},
});
Expand Down Expand Up @@ -86,9 +87,9 @@ export default function ArgumentSection(props: ArgumentsProps) {
inputProps={{
"data-testid": "argument-name-input",
}}
{...formik.getFieldProps("argumentName")}
error={Boolean(formik.errors.argumentName)}
helperText={formik.errors.argumentName}
{...formik.getFieldProps("argumentName")}
/>
</div>
<div tw="flex-grow pl-5">
Expand Down
10 changes: 10 additions & 0 deletions src/validations/FunctionArgumentSchemaValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Yup from "yup";

export const FunctionArgumentSchemaValidator = Yup.object().shape({
argumentName: Yup.string().matches(
/^[a-zA-Z0-9_]*$/,
"No spaces or special characters besides underscore are allowed"
),
dataType: Yup.string(),
other: Yup.string(),
});

0 comments on commit aa68b85

Please sign in to comment.