Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

refactor: typing of AutoCompleteOption (#978)

Marc Klingen8ddcfa8136cc
diff --git a/src/features/prompts/components/auto-complete.tsx b/src/features/prompts/components/auto-complete.tsx
index 5aef944b7b..9555942a5d 100644
--- a/src/features/prompts/components/auto-complete.tsx
+++ b/src/features/prompts/components/auto-complete.tsx
@@ -12,12 +12,15 @@ import { useState, useRef, useCallback, type KeyboardEvent } from "react";
import { Check } from "lucide-react";
import { cn } from "@/src/utils/tailwind";
-export type Option = Record<"value" | "label", string> & Record<string, string>;
+export type AutoCompleteOption = {
+ value: string;
+ label: string;
+};
type AutoCompleteProps = {
- options: Option[];
- value: Option;
- onValueChange?: (value: Option) => void;
+ options: AutoCompleteOption[];
+ value: AutoCompleteOption;
+ onValueChange?: (value: AutoCompleteOption) => void;
disabled?: boolean;
placeholder?: string;
};
@@ -31,7 +34,7 @@ export const AutoComplete = ({
}: AutoCompleteProps) => {
const inputRef = useRef<HTMLInputElement>(null);
const [isOpen, setOpen] = useState(false);
- const [selected, setSelected] = useState<Option>(value);
+ const [selected, setSelected] = useState<AutoCompleteOption>(value);
const [inputValue, setInputValue] = useState<string>(value.label || "");
const handleKeyDown = useCallback(
@@ -70,7 +73,7 @@ export const AutoComplete = ({
}, [selected]);
const handleSelectOption = useCallback(
- (selectedOption: Option) => {
+ (selectedOption: AutoCompleteOption) => {
setInputValue(selectedOption.label);
setSelected(selectedOption);
@@ -152,7 +155,7 @@ const CommandItemCreate = ({
onMouseDown,
}: {
inputValue: string;
- options: Option[];
+ options: AutoCompleteOption[];
onSelect: () => void;
onMouseDown: (event: React.MouseEvent<HTMLElement>) => void;
}) => {
diff --git a/src/features/prompts/components/new-prompt-button.tsx b/src/features/prompts/components/new-prompt-button.tsx
index ab4f61446a..1a960e8bc0 100644
--- a/src/features/prompts/components/new-prompt-button.tsx
+++ b/src/features/prompts/components/new-prompt-button.tsx
@@ -28,7 +28,7 @@ import { extractVariables } from "@/src/utils/string";
import { Badge } from "@/src/components/ui/badge";
import router from "next/router";
import { AutoComplete } from "@/src/features/prompts/components/auto-complete";
-import { type Option } from "@/src/features/prompts/components/auto-complete";
+import { type AutoCompleteOption } from "@/src/features/prompts/components/auto-complete";
export const CreatePromptDialog = (props: {
projectId: string;
@@ -175,7 +175,7 @@ export const NewPromptForm = (props: {
control={form.control}
name="name"
render={({ field }) => {
- const setNameValue = (value: Option) => {
+ const setNameValue = (value: AutoCompleteOption) => {
field.onChange(value.value);
};