Skip to content

Commit

Permalink
fix(frontend): moved testset into project scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ashrafchowdury committed Oct 9, 2024
1 parent c88dd73 commit 2e35c46
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 168 deletions.
19 changes: 9 additions & 10 deletions agenta-web/src/components/Sidebar/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ export const useSidebarConfig = () => {

const sidebarConfig: SidebarConfig[] = [
{
key: "app-management-link",
title: "App Management",
key: "application-link",
title: "Applications",
tooltip: "Create new applications or switch between your existing projects.",
link: "/apps",
icon: <AppstoreOutlined />,
},
{
key: "app-testsets-link",
title: "Test Sets",
tooltip: "Create and manage testsets for evaluation purposes.",
link: `/apps/testsets`,
icon: <DatabaseOutlined />,
divider: true,
},
{
Expand All @@ -84,14 +91,6 @@ export const useSidebarConfig = () => {
icon: <RocketOutlined />,
isHidden: !appId && !recentlyVisitedAppId,
},
{
key: "app-testsets-link",
title: "Test Sets",
tooltip: "Create and manage testsets for evaluation purposes.",
link: `/apps/${appId || recentlyVisitedAppId}/testsets`,
icon: <DatabaseOutlined />,
isHidden: !appId && !recentlyVisitedAppId,
},
{
key: "app-evaluations-link",
title: "Evaluations",
Expand Down
11 changes: 10 additions & 1 deletion agenta-web/src/components/TestSetTable/TestsetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {NoticeType} from "antd/es/message/interface"
import {GenericObject, KeyValuePair} from "@/lib/Types"
import TableCellsRenderer from "./TableCellsRenderer"
import TableHeaderComponent from "./TableHeaderComponent"
import {useAppsData} from "@/contexts/app.context"

type TestsetTableProps = {
mode: "create" | "edit"
Expand Down Expand Up @@ -93,8 +94,9 @@ const TestsetTable: React.FC<TestsetTableProps> = ({mode}) => {
const classes = useStylesTestset()
const router = useRouter()
const {appTheme} = useAppTheme()
const {apps, isLoading: isAppsLoading} = useAppsData()

const appId = router.query.app_id as string
const appId = apps[0]?.app_id
const {testset_id} = router.query

useBlockNavigation(unSavedChanges, {
Expand All @@ -115,6 +117,13 @@ const TestsetTable: React.FC<TestsetTableProps> = ({mode}) => {
}
}, [rowData, testsetName, columnDefs, inputValues])

useEffect(() => {
if ((apps.length === 0 || !apps) && !isAppsLoading) {
message.warning("To view the test set, you first need to create an app.")
router.push("/apps")
}
}, [isAppsLoading])

useEffect(() => {
async function applyColData(colData: {field: string}[] = []) {
const newColDefs = createNewColDefs(colData)
Expand Down
9 changes: 8 additions & 1 deletion agenta-web/src/lib/helpers/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,14 @@ export const getVotesPercentage = (record: HumanEvaluationListTableDataType, ind
export const checkIfResourceValidForDeletion = async (
data: Omit<Parameters<typeof fetchEvaluatonIdsByResource>[0], "appId">,
) => {
const appId = getAppValues().currentApp?.app_id
let appId

if (data.resourceType === "testset") {
appId = getAppValues().apps[0]?.app_id
} else {
appId = getAppValues().currentApp?.app_id
}

if (!appId) return false

const response = await fetchEvaluatonIdsByResource({...data, appId})
Expand Down
128 changes: 0 additions & 128 deletions agenta-web/src/pages/apps/[app_id]/testsets/new/endpoint/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Button, Table, Space} from "antd"
import {Button, Table, Space, message} from "antd"
import Link from "next/link"
import {useRouter} from "next/router"
import {ColumnsType} from "antd/es/table"
Expand All @@ -8,8 +8,9 @@ import {DeleteOutlined} from "@ant-design/icons"
import {deleteTestsets, useLoadTestsetsList} from "@/services/testsets/api"
import {createUseStyles} from "react-jss"
import {testset} from "@/lib/Types"
import {isDemo} from "@/lib/helpers/utils"
import {checkIfResourceValidForDeletion} from "@/lib/helpers/evaluate"
import {useAppsData} from "@/contexts/app.context"
import {useUpdateEffect} from "usehooks-ts"

const useStyles = createUseStyles({
container: {
Expand Down Expand Up @@ -42,10 +43,18 @@ const useStyles = createUseStyles({
export default function Testsets() {
const classes = useStyles()
const router = useRouter()
const appId = router.query.app_id as string
const {apps, isLoading: isAppsLoading} = useAppsData()
const appId = apps[0]?.app_id
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([])
const {testsets, isTestsetsLoading, mutate} = useLoadTestsetsList(appId)

useUpdateEffect(() => {
if ((apps.length === 0 || !apps) && !isAppsLoading) {
message.warning("To view the test set, you first need to create an app.")
router.push("/apps")
}
}, [isAppsLoading])

const columns: ColumnsType<testset> = [
{
title: "Name",
Expand Down Expand Up @@ -80,6 +89,7 @@ export default function Testsets() {
}))
)
return

await deleteTestsets(testsetsIds)
mutate()
setSelectedRowKeys([])
Expand All @@ -91,29 +101,15 @@ export default function Testsets() {
<div className={classes.container}>
<div className={classes.btnContainer}>
<div className={classes.linksContainer}>
<Link
data-cy="testset-new-upload-link"
href={`/apps/${appId}/testsets/new/upload`}
>
<Link data-cy="testset-new-upload-link" href={`/apps/testsets/new/upload`}>
<Button type="primary">Upload Test Set</Button>
</Link>
<Link
data-cy="testset-new-manual-link"
href={`/apps/${appId}/testsets/new/manual`}
>
<Link data-cy="testset-new-manual-link" href={`/apps/testsets/new/manual`}>
<Button>Create Test Set in UI</Button>
</Link>
<Link
data-cy="testset-new-api-link"
href={`/apps/${appId}/testsets/new/api`}
>
<Link data-cy="testset-new-api-link" href={`/apps/testsets/new/api`}>
<Button>Create a test set with API</Button>
</Link>
{!isDemo() && (
<Link href={`/apps/${appId}/testsets/new/endpoint`}>
<Button>Import from Endpoint</Button>
</Link>
)}
</div>

{testsets.length > 0 && (
Expand Down Expand Up @@ -155,10 +151,10 @@ export default function Testsets() {
columns={columns}
dataSource={testsets}
rowKey="_id"
loading={isTestsetsLoading}
loading={isTestsetsLoading || isAppsLoading}
onRow={(record) => {
return {
onClick: () => router.push(`/apps/${appId}/testsets/${record._id}`),
onClick: () => router.push(`/apps/testsets/${record._id}`),
}
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import pythonCodeUpload from "@/code_snippets/testsets/create_with_upload/python
import cURLCodeUpload from "@/code_snippets/testsets/create_with_upload/curl"
import tsCodeUpload from "@/code_snippets/testsets/create_with_upload/typescript"
import {Typography} from "antd"
import {useRouter} from "next/router"
import {createUseStyles} from "react-jss"
import {getAgentaApiUrl} from "@/lib/helpers/utils"
import { useAppsData } from "@/contexts/app.context"

const useStyles = createUseStyles({
title: {
Expand All @@ -20,8 +20,8 @@ const useStyles = createUseStyles({

export default function NewTestsetWithAPI() {
const classes = useStyles()
const router = useRouter()
const appId = router.query.app_id as string
const {apps} = useAppsData()
const appId = apps[0]?.app_id

const uploadURI = `${getAgentaApiUrl()}/api/testsets/upload`
const jsonURI = `${getAgentaApiUrl()}/api/testsets/${appId}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {isValidCSVFile, isValidJSONFile} from "@/lib/helpers/fileManipulations"
import {GenericObject} from "@/lib/Types"
import {globalErrorHandler} from "@/lib/helpers/errorHandler"
import {getAgentaApiUrl} from "@/lib/helpers/utils"
import {useAppsData} from "@/contexts/app.context"

const useStyles = createUseStyles({
fileFormatBtn: {
Expand All @@ -29,12 +30,17 @@ const useStyles = createUseStyles({
export default function AddANewTestset() {
const classes = useStyles()
const router = useRouter()
const appId = router.query.app_id as string
const {apps} = useAppsData()
const appId = apps[0]?.app_id
const [form] = Form.useForm()
const [uploadLoading, setUploadLoading] = useState(false)
const [uploadType, setUploadType] = useState<"JSON" | "CSV" | undefined>("CSV")

const onFinish = async (values: any) => {
if (!appId) {
message.warning("To view the test set, you first need to create an app.")
}

const {file} = values
const fileObj = file[0].originFileObj
const malformedFileError = `The file you uploaded is either malformed or is not a valid ${uploadType} file`
Expand Down Expand Up @@ -67,7 +73,7 @@ export default function AddANewTestset() {
_ignoreError: true,
})
form.resetFields()
router.push(`/apps/${appId}/testsets`)
router.push(`/apps/testsets`)
} catch (e: any) {
if (
e?.response?.data?.detail?.find((item: GenericObject) =>
Expand Down
2 changes: 1 addition & 1 deletion agenta-web/src/services/testsets/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {axiosFetcher} from "@/services/api"

export const useLoadTestsetsList = (appId: string) => {
const {data, error, mutate, isLoading} = useSWR(
`${getAgentaApiUrl()}/api/testsets/?app_id=${appId}`,
() => (appId ? `${getAgentaApiUrl()}/api/testsets/?app_id=${appId}` : null),
axiosFetcher,
{revalidateOnFocus: false, shouldRetryOnError: false},
)
Expand Down

0 comments on commit 2e35c46

Please sign in to comment.