(props: {
open: boolean;
close: () => void;
userMessage: UIMessageData | undefined;
answer: UIAnswerType;
variables: ApprovalVariable[];
setUserMessage: (message: Record<string, any>) => void;
})
| 390 | } |
| 391 | |
| 392 | export function EditUserMessageModal(props: { |
| 393 | open: boolean; |
| 394 | close: () => void; |
| 395 | userMessage: UIMessageData | undefined; |
| 396 | answer: UIAnswerType; |
| 397 | variables: ApprovalVariable[]; |
| 398 | setUserMessage: (message: Record<string, any>) => void; |
| 399 | }) { |
| 400 | const supabase = useSupabaseClient<Database>(); |
| 401 | const [localVariables, setLocalVariables] = useState<Record<string, any>>({}); |
| 402 | const [isValid, setIsValid] = useState<boolean[]>([]); |
| 403 | useEffect(() => { |
| 404 | try { |
| 405 | const parsedVariables = JSON.parse(props.userMessage?.raw_text ?? "{}"); |
| 406 | setLocalVariables( |
| 407 | Object.entries(parsedVariables).reduce((acc, [k, v]) => { |
| 408 | if (Array.isArray(v) || typeof v === "object") { |
| 409 | acc[k] = JSON.stringify(v); |
| 410 | } else { |
| 411 | acc[k] = v; |
| 412 | } |
| 413 | return acc; |
| 414 | }, {} as Record<string, any>), |
| 415 | ); |
| 416 | setIsValid(Object.keys(parsedVariables).map(() => true)); |
| 417 | } catch (e) { |
| 418 | console.error(e); |
| 419 | } |
| 420 | }, [props.userMessage]); |
| 421 | return ( |
| 422 | <Modal |
| 423 | open={Boolean(props.open)} |
| 424 | setOpen={() => props.close()} |
| 425 | classNames={"max-w-3xl overflow-visible"} |
| 426 | > |
| 427 | <div className="w-full flex-col mb-4"> |
| 428 | <h1 className="text-xl text-gray-300">Edit Parameters Values</h1> |
| 429 | </div> |
| 430 | {Object.keys(localVariables).length > 0 ? ( |
| 431 | <div className="flex flex-col"> |
| 432 | {Object.entries(localVariables).map(([key, val], idx) => { |
| 433 | const relevantVariable = props.variables.find( |
| 434 | (v) => v.name === key, |
| 435 | ); |
| 436 | if (!relevantVariable) return null; |
| 437 | return ( |
| 438 | <div |
| 439 | key={idx} |
| 440 | className="relative grid grid-cols-6 gap-x-2 border-t first:border-t-0 border-t-gray-600 py-1.5" |
| 441 | > |
| 442 | <div className="col-span-2 flex place-items-center h-full"> |
| 443 | <p className={"text-lg text-gray-300 align-text-bottom"}> |
| 444 | {key} |
| 445 | </p> |
| 446 | <div className="relative"> |
| 447 | <QuestionMarkCircleIcon |
| 448 | className={ |
| 449 | "ml-3 h-6 w-6 peer text-gray-400 hover:bg-gray-700 transition p-0.5 rounded-full" |
nothing calls this directly
no test coverage detected