-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
815 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useRef } from "react"; | ||
import { ExistingAttribute, FakeAttribute } from "../../domain"; | ||
import Dialog from "../ui/Dialog"; | ||
import Form, { FormValues } from "./Form"; | ||
|
||
export type SuiteDialogProps = { | ||
onCancel: VoidFunction; | ||
onSubmit: (values: FormValues) => void; | ||
attributes: (FakeAttribute | ExistingAttribute)[]; | ||
}; | ||
|
||
const TestCaseDialog = ({ onCancel, onSubmit, attributes, ...other }: SuiteDialogProps) => { | ||
const firstElementRef = useRef<HTMLInputElement>(null); | ||
const initialValues: FormValues = { | ||
attributes: [], | ||
name: "", | ||
description: "", | ||
}; | ||
return ( | ||
<Dialog open onClose={onCancel} className="max-w-xl w-full" onOverlayClick={onCancel} {...other}> | ||
<Dialog.Close onClick={onCancel} /> | ||
<Form | ||
initialValues={initialValues} | ||
onSubmit={onSubmit} | ||
onCancel={onCancel} | ||
className="p-8" | ||
initialFocus={firstElementRef} | ||
attributes={attributes} | ||
/> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default TestCaseDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Formik } from "formik"; | ||
import { OKCancelFooter } from "../ui/Dialog"; | ||
import TextInput from "../ui/TextInput"; | ||
import * as Yup from "yup"; | ||
import FieldError from "../ui/FieldError"; | ||
import clsx from "clsx"; | ||
import { captionClasses } from "../ui/typography"; | ||
import { FormHTMLAttributes, Ref } from "react"; | ||
import { ExistingAttribute, FakeAttribute } from "../../domain"; | ||
import Attributes from "../ui/Attributes"; | ||
import { FilterValue } from "../ui/Attribute"; | ||
const schema = Yup.object().shape({ | ||
name: Yup.string().required("Please give this test case a name"), | ||
}); | ||
|
||
export type FormValues = { | ||
name: string; | ||
description: string; | ||
attributes: FilterValue[]; | ||
}; | ||
|
||
export type FormProps = Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit"> & { | ||
initialValues: FormValues; | ||
initialFocus?: Ref<HTMLInputElement>; | ||
onSubmit: (values: FormValues) => void; | ||
onCancel: VoidFunction; | ||
attributes: (ExistingAttribute | FakeAttribute)[]; | ||
}; | ||
|
||
const Form = ({ initialValues, initialFocus, onSubmit, onCancel, attributes, ...other }: FormProps) => ( | ||
<Formik initialValues={initialValues} validationSchema={schema} onSubmit={onSubmit}> | ||
{({ values, errors, handleSubmit, handleChange, handleBlur, setFieldValue }) => ( | ||
<form onSubmit={handleSubmit} {...other}> | ||
<h3 className="uppercase font-medium text-base text-neutral-fade2 mt-3 mb-5">Create a new test case</h3> | ||
<label htmlFor="name" className={clsx("block mb-2 font-medium", captionClasses)}> | ||
Test case name | ||
</label> | ||
<TextInput | ||
ref={initialFocus} | ||
name="name" | ||
className="block w-full" | ||
placeholder="Suite name" | ||
value={values.name} | ||
onChange={handleChange} | ||
/> | ||
<FieldError>{errors.name}</FieldError> | ||
<label htmlFor="description" className={clsx("block mb-2 font-medium mt-8", captionClasses)}> | ||
Description | ||
</label> | ||
<TextInput | ||
name="description" | ||
className="block w-full" | ||
placeholder="Description" | ||
value={values.description} | ||
onChange={handleChange} | ||
/> | ||
<label className={clsx("block mb-2 font-medium mt-8", captionClasses)}>Attributes</label> | ||
<Attributes | ||
attributes={attributes} | ||
value={values.attributes} | ||
onChange={value => setFieldValue("attributes", value)} | ||
addLinkContent="Add attribute" | ||
className="flex-col" | ||
/> | ||
<OKCancelFooter OKText="Save" OKType="submit" onCancelClick={onCancel} className="pt-8" /> | ||
</form> | ||
)} | ||
</Formik> | ||
); | ||
|
||
export default Form; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const captionClasses = "uppercase text-sm font-medium text-neutral-fade2"; | ||
export const captionClasses = "uppercase text-sm font-normal text-neutral-fade2 tracking-wider"; |
Oops, something went wrong.