From 325a5c52df453047146b6ddeebc0bacbfba79701 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Thu, 23 May 2024 23:07:07 +0100 Subject: [PATCH 1/3] set default testset when adding a data point --- .../Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx index 8df1d3f7d9..5abc33ef94 100644 --- a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx +++ b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx @@ -91,7 +91,6 @@ const AddToTestSetDrawer: React.FC = ({params, isChatVariant, ...props}) const {appTheme} = useAppTheme() const classes = useStyles({themeMode: appTheme} as StyleProps) const [form] = Form.useForm() - const [selectedTestset, setSelectedTestset] = useState() const [newTesetModalOpen, setNewTestsetModalOpen] = useState(false) const [loading, setLoading] = useState(false) const [turnModeChat, setTurnModeChat] = useState< @@ -101,9 +100,11 @@ const AddToTestSetDrawer: React.FC = ({params, isChatVariant, ...props}) const dirty = useRef(false) const router = useRouter() const appId = router.query.app_id as string - const isNew = selectedTestset === "-1" - const {testsets, mutate, isTestsetsLoading, isTestsetsLoadingError} = useLoadTestsetsList(appId) + const [selectedTestset, setSelectedTestset] = useState( + testsets.length ? testsets[0]._id : "-1", + ) + const isNew = selectedTestset === "-1" const chatParams = useRef<{chat: ChatMessage[]; correct_answer: ChatMessage | string}>({ chat: [], correct_answer: "", From f288b867a1a31e6505b34b459c532bd4cd3d5312 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Fri, 24 May 2024 00:09:55 +0100 Subject: [PATCH 2/3] Save the state of the last used option in a variant --- .../AddToTestSetDrawer/AddToTestSetDrawer.tsx | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx index 5abc33ef94..85764711f0 100644 --- a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx +++ b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx @@ -18,9 +18,9 @@ import { message, } from "antd" import {useRouter} from "next/router" -import React, {useCallback, useLayoutEffect, useRef, useState} from "react" +import React, {useCallback, useEffect, useLayoutEffect, useRef, useState} from "react" import {createUseStyles} from "react-jss" -import {useUpdateEffect} from "usehooks-ts" +import {useLocalStorage, useUpdateEffect} from "usehooks-ts" import ChatInputs from "@/components/ChatInputs/ChatInputs" import _ from "lodash" @@ -101,9 +101,22 @@ const AddToTestSetDrawer: React.FC = ({params, isChatVariant, ...props}) const router = useRouter() const appId = router.query.app_id as string const {testsets, mutate, isTestsetsLoading, isTestsetsLoadingError} = useLoadTestsetsList(appId) - const [selectedTestset, setSelectedTestset] = useState( - testsets.length ? testsets[0]._id : "-1", + const storedValue = JSON.parse(localStorage.getItem(`selectedTestset_${appId}`) || "") + const [selectedTestset, setSelectedTestset] = useLocalStorage( + `selectedTestset_${appId}`, + "", ) + + useEffect(() => { + if (storedValue && testsets.some((testset: testset) => testset._id === storedValue)) { + setSelectedTestset(storedValue) + } else if (testsets.length > 0) { + setSelectedTestset(testsets[0]._id) + } else { + setSelectedTestset("-1") + } + }, [testsets]) + const isNew = selectedTestset === "-1" const chatParams = useRef<{chat: ChatMessage[]; correct_answer: ChatMessage | string}>({ chat: [], From 1db198beaef6388af9c350a4f1a9123158b14684 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Fri, 24 May 2024 00:14:30 +0100 Subject: [PATCH 3/3] hot fix --- .../Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx index 85764711f0..177b24a16d 100644 --- a/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx +++ b/agenta-web/src/components/Playground/AddToTestSetDrawer/AddToTestSetDrawer.tsx @@ -101,7 +101,7 @@ const AddToTestSetDrawer: React.FC = ({params, isChatVariant, ...props}) const router = useRouter() const appId = router.query.app_id as string const {testsets, mutate, isTestsetsLoading, isTestsetsLoadingError} = useLoadTestsetsList(appId) - const storedValue = JSON.parse(localStorage.getItem(`selectedTestset_${appId}`) || "") + const storedValue = localStorage.getItem(`selectedTestset_${appId}`)?.replace(/"/g, "") const [selectedTestset, setSelectedTestset] = useLocalStorage( `selectedTestset_${appId}`, "",