-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prompts): Implement SavePromptForm for creating new prompts (#5751)
* feat(prompts): Implement SavePromptForm for creating new prompts * Rename button to 'save'
- Loading branch information
1 parent
38381d4
commit 4f4577e
Showing
4 changed files
with
223 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from "react"; | ||
import { Controller, useForm } from "react-hook-form"; | ||
|
||
import { | ||
Button, | ||
Flex, | ||
Form, | ||
TextArea, | ||
TextField, | ||
View, | ||
} from "@arizeai/components"; | ||
|
||
export type SavePromptSubmitHandler = (params: SavePromptFormParams) => void; | ||
|
||
export type SavePromptFormParams = { | ||
name: string; | ||
description?: string; | ||
}; | ||
|
||
export function SavePromptForm({ | ||
onSubmit, | ||
isSubmitting = false, | ||
submitButtonText = "Save", | ||
}: { | ||
onSubmit: SavePromptSubmitHandler; | ||
isSubmitting?: boolean; | ||
submitButtonText?: string; | ||
}) { | ||
const { | ||
control, | ||
handleSubmit, | ||
formState: { isDirty }, | ||
} = useForm<SavePromptFormParams>({ | ||
defaultValues: { | ||
name: "Prompt " + new Date().toISOString(), | ||
description: "", | ||
}, | ||
}); | ||
|
||
return ( | ||
<Form> | ||
<View padding="size-200"> | ||
<Controller | ||
name="name" | ||
control={control} | ||
rules={{ | ||
required: "Prompt name is required", | ||
}} | ||
render={({ | ||
field: { onChange, onBlur, value }, | ||
fieldState: { invalid, error }, | ||
}) => ( | ||
<TextField | ||
label="Prompt Name" | ||
description="The name of your saved prompt" | ||
errorMessage={error?.message} | ||
validationState={invalid ? "invalid" : "valid"} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={value} | ||
/> | ||
)} | ||
/> | ||
<Controller | ||
name="description" | ||
control={control} | ||
render={({ | ||
field: { onChange, onBlur, value }, | ||
fieldState: { invalid, error }, | ||
}) => ( | ||
<TextArea | ||
label="Description" | ||
description="A description of your prompt (optional)" | ||
isRequired={false} | ||
height={100} | ||
errorMessage={error?.message} | ||
validationState={invalid ? "invalid" : "valid"} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={value} | ||
/> | ||
)} | ||
/> | ||
</View> | ||
<View | ||
paddingEnd="size-200" | ||
paddingTop="size-100" | ||
paddingBottom="size-100" | ||
borderTopColor="light" | ||
borderTopWidth="thin" | ||
> | ||
<Flex direction="row" justifyContent="end"> | ||
<Button | ||
variant={isDirty ? "primary" : "default"} | ||
size="compact" | ||
loading={isSubmitting} | ||
onClick={handleSubmit(onSubmit)} | ||
> | ||
{submitButtonText} | ||
</Button> | ||
</Flex> | ||
</View> | ||
</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