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

bug/Disable the submit button when the variable name field is empty - #576 #578

Merged
merged 2 commits into from
Sep 11, 2023
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
21 changes: 18 additions & 3 deletions agenta-web/src/components/Playground/NewVariantModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Props {
addTab: () => void
variants: any[]
setNewVariantName: (value: string) => void
newVariantName: string
setTemplateVariantName: (value: string) => void
}

Expand All @@ -26,26 +27,40 @@ const NewVariantModal: React.FC<Props> = ({
addTab,
variants,
setNewVariantName,
newVariantName,
setTemplateVariantName,
}) => {
const classes = useStyles()
const [variantPlaceHolder, setVariantPlaceHolder] = useState("Source Variant")
const [isInputValid, setIsInputValid] = useState(false) // To check if the input is valid

const handleTemplateVariantChange = (value: string) => {
let newValue = value.includes(".") ? value.split(".")[0] : value
setTemplateVariantName(value)
setVariantPlaceHolder(`${newValue}`)
setIsInputValid(newVariantName.trim().length > 0 && value !== "Source Variant") // Update the validity of the input
}

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method name is too general. what input is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this context, input refers to the name of a variant. will make this clearer in the function name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may create an issue for it

const inputValue = e.target.value
setNewVariantName(inputValue)
setIsInputValid(inputValue.trim().length > 0 && variantPlaceHolder !== "Source Variant") // Update the validity of the input
}

return (
<Modal
title="Create a New Variant"
open={isModalOpen}
onOk={() => {
setIsModalOpen(false)
addTab()
if (isInputValid) {
// Check if the input is valid
setIsModalOpen(false)
addTab()
}
}}
onCancel={() => setIsModalOpen(false)}
centered
okButtonProps={{disabled: !isInputValid}} // Disable OK button if input is not valid
>
<Space direction="vertical" size={20}>
<div>
Expand All @@ -65,7 +80,7 @@ const NewVariantModal: React.FC<Props> = ({
<Text>Enter a unique name for the new variant:</Text>
<Input
addonBefore={variantPlaceHolder}
onChange={(e) => setNewVariantName(e.target.value)}
onChange={handleInputChange} // Modify this line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment might be not needed @yeokyeong-yanolja

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed this in a later commit. Thanks for noticing :)

/>
</div>
</Space>
Expand Down
1 change: 1 addition & 0 deletions agenta-web/src/components/Playground/VersionTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const VersionTabs: React.FC = () => {
}
variants={variants}
setNewVariantName={setNewVariantName}
newVariantName={newVariantName}
setTemplateVariantName={setTemplateVariantName}
/>
<VariantRemovalWarningModal
Expand Down
Loading