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

When adding a data point to a test set, there is never a default set selected #1698

Merged
merged 3 commits into from
May 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -91,7 +91,6 @@ const AddToTestSetDrawer: React.FC<Props> = ({params, isChatVariant, ...props})
const {appTheme} = useAppTheme()
const classes = useStyles({themeMode: appTheme} as StyleProps)
const [form] = Form.useForm()
const [selectedTestset, setSelectedTestset] = useState<string>()
const [newTesetModalOpen, setNewTestsetModalOpen] = useState(false)
const [loading, setLoading] = useState(false)
const [turnModeChat, setTurnModeChat] = useState<
Expand All @@ -101,9 +100,24 @@ const AddToTestSetDrawer: React.FC<Props> = ({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 storedValue = localStorage.getItem(`selectedTestset_${appId}`)?.replace(/"/g, "")
const [selectedTestset, setSelectedTestset] = useLocalStorage<string>(
`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: [],
correct_answer: "",
Expand Down
Loading