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

fix(prompts): fix regex validation logic so it shows up in the form #6228

Merged
merged 1 commit into from
Feb 3, 2025
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
2 changes: 2 additions & 0 deletions app/src/components/combobox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ export function ComboBox<T extends object>({
width,
stopPropagation,
renderEmptyState,
isInvalid,
...props
}: ComboBoxProps<T>) {
return (
<AriaComboBox
{...props}
css={css(fieldBaseCSS, comboBoxCSS)}
data-size={size}
isInvalid={isInvalid || Boolean(errorMessage)}
style={{
width,
}}
Expand Down
7 changes: 5 additions & 2 deletions app/src/components/field/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ export const fieldBaseCSS = css`
vertical-align: middle;

&[data-focused] {
// TODO: figure out focus ring behavior. For now the color is enough
outline: none;
}
&[data-focused]:not([data-invalid]) {
border: 1px solid var(--ac-global-input-field-border-color-active);
}
&[data-hovered]:not([data-disabled]) {
&[data-hovered]:not([data-disabled]):not([data-invalid]) {
border: 1px solid var(--ac-global-input-field-border-color-active);
}
&[data-disabled] {
opacity: var(--ac-global-opacity-disabled);
}
&[data-invalid]:not([data-focused]) {
&[data-invalid] {
border-color: var(--ac-global-color-danger);
}
&::placeholder {
Expand Down
18 changes: 11 additions & 7 deletions app/src/pages/playground/SavePromptForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { Form, TextArea } from "@arizeai/components";
import { Button, Flex, View } from "@phoenix/components";
import { SavePromptFormQuery } from "@phoenix/pages/playground/__generated__/SavePromptFormQuery.graphql";
import { PromptComboBox } from "@phoenix/pages/playground/PromptComboBox";

import { identifierPattern } from "../../utils/identifierUtils";
import { identifierPattern } from "@phoenix/utils/identifierUtils";

export type SavePromptSubmitHandler = (params: SavePromptFormParams) => void;

Expand Down Expand Up @@ -62,7 +61,8 @@ export function SavePromptForm({
const {
control,
handleSubmit,
formState: { isDirty, isValid, errors },
formState: { isDirty, isValid },
trigger,
} = useForm<SavePromptFormParams>({
values: {
promptId: selectedPromptId ?? undefined,
Expand Down Expand Up @@ -104,20 +104,24 @@ export function SavePromptForm({
},
pattern: identifierPattern,
}}
render={({ field: { onBlur, onChange } }) => (
render={({ field: { onBlur, onChange }, fieldState }) => (
<PromptComboBox
label="Prompt"
description="The prompt to update, or prompt name to create"
placeholder="Select a prompt, or enter a new prompt name"
placeholder="Select or enter new prompt name"
isRequired
onBlur={onBlur}
defaultInputValue={promptInputValue}
onInputChange={setPromptInputValue}
onInputChange={(value) => {
setPromptInputValue(value);
onChange(value);
trigger("name");
}}
// this seems... not great. not sure how else to get a stable element reference that doesn't use a ref
// https://react-spectrum.adobe.com/react-aria/Popover.html#props
// eslint-disable-next-line react-compiler/react-compiler
container={flexContainer.current ?? undefined}
errorMessage={errors.name?.message}
errorMessage={fieldState.error?.message}
allowsCustomValue
onChange={(promptId) => {
onChange(promptId);
Expand Down