From 50707ee5039724b40def53193b64a6b5578e427e Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 11 Sep 2024 10:36:45 +0200 Subject: [PATCH] feature: fixes evaluations filtering in documentuuid view (#163) Also reorders routes to make place for the evaluation detail view --- .../src/actions/evaluations/runBatch.test.ts | 20 ++--- .../ConnectedDocumentsTable/index.tsx | 2 +- .../evaluations/_components/Layout.tsx | 15 ---- .../_components/BatchEvaluationsTable.tsx | 76 +++++++++++++++++++ .../dashboard/_components/Layout.tsx | 54 +++++++++++++ .../EvaluationEditor.tsx | 0 .../EvaluationList.tsx | 0 .../ConnectToEvaluationStep/index.tsx | 0 .../MapPromptDataToDatasetStep/index.tsx | 0 .../{ => dashboard}/connect/page.tsx | 0 .../evaluations/{ => dashboard}/layout.tsx | 24 +----- .../evaluations/dashboard/page.tsx | 3 + .../[documentUuid]/evaluations/page.tsx | 16 +++- .../documents/[documentUuid]/layout.tsx | 17 +++-- apps/web/src/services/routes.ts | 19 +++-- .../core/src/tests/factories/evaluations.ts | 2 +- .../web-ui/src/providers/DocumentProvider.tsx | 33 ++++++++ packages/web-ui/src/providers/index.ts | 1 + 18 files changed, 215 insertions(+), 67 deletions(-) delete mode 100644 apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/_components/Layout.tsx create mode 100644 apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/_components/BatchEvaluationsTable.tsx create mode 100644 apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/_components/Layout.tsx rename apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/{ => dashboard}/connect/_components/ConnectToEvaluationStep/EvaluationEditor.tsx (100%) rename apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/{ => dashboard}/connect/_components/ConnectToEvaluationStep/EvaluationList.tsx (100%) rename apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/{ => dashboard}/connect/_components/ConnectToEvaluationStep/index.tsx (100%) rename apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/{ => dashboard}/connect/_components/MapPromptDataToDatasetStep/index.tsx (100%) rename apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/{ => dashboard}/connect/page.tsx (100%) rename apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/{ => dashboard}/layout.tsx (52%) create mode 100644 apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/page.tsx create mode 100644 packages/web-ui/src/providers/DocumentProvider.tsx diff --git a/apps/web/src/actions/evaluations/runBatch.test.ts b/apps/web/src/actions/evaluations/runBatch.test.ts index 0ff6838a7..c4241fe6c 100644 --- a/apps/web/src/actions/evaluations/runBatch.test.ts +++ b/apps/web/src/actions/evaluations/runBatch.test.ts @@ -4,8 +4,6 @@ import { DocumentVersion, EvaluationDto, Project, - ProviderApiKey, - Providers, User, Workspace, } from '@latitude-data/core/browser' @@ -63,8 +61,7 @@ describe('runBatchAction', () => { document: DocumentVersion, commit: Commit, dataset: Dataset, - evaluation: EvaluationDto, - provider: ProviderApiKey + evaluation: EvaluationDto beforeEach(async () => { vi.clearAllMocks() @@ -78,13 +75,6 @@ describe('runBatchAction', () => { document = setup.documents[0]! commit = setup.commit - provider = await factories.createProviderApiKey({ - workspace, - type: Providers.OpenAI, - name: 'Test Provider', - user, - }) - dataset = await factories .createDataset({ name: 'Test Dataset', @@ -93,8 +83,8 @@ describe('runBatchAction', () => { }) .then((result) => result.dataset) - evaluation = await factories.createEvaluation({ - provider, + evaluation = await factories.createLlmAsJudgeEvaluation({ + workspace, name: 'Test Evaluation', }) @@ -181,8 +171,8 @@ describe('runBatchAction', () => { }) it('enqueues multiple evaluation jobs for multiple evaluationIds', async () => { - const evaluation2 = await factories.createEvaluation({ - provider, + const evaluation2 = await factories.createLlmAsJudgeEvaluation({ + workspace, name: 'Test Evaluation 2', }) diff --git a/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/dashboard/_components/ConnectedDocumentsTable/index.tsx b/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/dashboard/_components/ConnectedDocumentsTable/index.tsx index a683c0c0e..54957b189 100644 --- a/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/dashboard/_components/ConnectedDocumentsTable/index.tsx +++ b/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/dashboard/_components/ConnectedDocumentsTable/index.tsx @@ -136,7 +136,7 @@ export default function ConnectedDocumentsTable({ .detail({ id: document.projectId }) .commits.detail({ uuid: HEAD_COMMIT }) .documents.detail({ uuid: document.documentUuid }) - .evaluations.detail({ uuid: document.evaluationUuid }).root, + .evaluations.detail(document.evaluationUuid).root, ) } /> diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/_components/Layout.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/_components/Layout.tsx deleted file mode 100644 index 00f7b12fe..000000000 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/_components/Layout.tsx +++ /dev/null @@ -1,15 +0,0 @@ -'use client' - -import { EvaluationDto } from '@latitude-data/core/browser' -import ActiveEvaluationsTable from '$/app/(private)/evaluations/_components/ActiveEvaluations/Table' -import useEvaluations from '$/stores/evaluations' - -export default function Layout({ - evaluations: fallbackData, -}: { - evaluations: EvaluationDto[] -}) { - const { data: evaluations } = useEvaluations({ fallbackData }) - - return -} diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/_components/BatchEvaluationsTable.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/_components/BatchEvaluationsTable.tsx new file mode 100644 index 000000000..8ec6f6232 --- /dev/null +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/_components/BatchEvaluationsTable.tsx @@ -0,0 +1,76 @@ +import { EvaluationDto } from '@latitude-data/core/browser' +import { + Icon, + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, + Text, + useCurrentCommit, + useCurrentDocument, + useCurrentProject, +} from '@latitude-data/web-ui' +import { useNavigate } from '$/hooks/useNavigate' +import { ROUTES } from '$/services/routes' +import Link from 'next/link' + +export default function BatchEvaluationsTable({ + evaluations, +}: { + evaluations: EvaluationDto[] +}) { + const navigate = useNavigate() + const { project } = useCurrentProject() + const { commit } = useCurrentCommit() + const document = useCurrentDocument() + return ( + + + + Name + Description + Actions + + + + {evaluations.map((evaluation) => ( + + navigate.push( + ROUTES.projects + .detail({ id: project.id }) + .commits.detail({ uuid: commit.uuid }) + .documents.detail({ uuid: document.documentUuid }) + .evaluations.detail(evaluation.uuid).dashboard.root, + ) + } + > + + {evaluation.name} + + + {evaluation.description} + + e.stopPropagation()}> + + + + + + ))} + +
+ ) +} diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/_components/Layout.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/_components/Layout.tsx new file mode 100644 index 000000000..59947a309 --- /dev/null +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/_components/Layout.tsx @@ -0,0 +1,54 @@ +'use client' + +import { EvaluationDto } from '@latitude-data/core/browser' +import { + TableBlankSlate, + useCurrentCommit, + useCurrentDocument, + useCurrentProject, +} from '@latitude-data/web-ui' +import { ROUTES } from '$/services/routes' +import useEvaluations from '$/stores/evaluations' +import Link from 'next/link' + +import BatchEvaluationsTable from './BatchEvaluationsTable' + +export default function EvaluationsLayoutClient({ + evaluations: fallbackData, +}: { + evaluations: EvaluationDto[] +}) { + const { project } = useCurrentProject() + const { commit } = useCurrentCommit() + const document = useCurrentDocument() + const { data: evaluations } = useEvaluations({ + fallbackData, + params: { documentUuid: document.documentUuid }, + }) + + const href = ROUTES.projects + .detail({ id: project.id }) + .commits.detail({ uuid: commit.uuid }) + .documents.detail({ uuid: document.documentUuid }).evaluations.dashboard + .connect.root + + return ( + <> + {evaluations.length > 0 && ( + + )} + {evaluations.length === 0 && ( + + + Connect your first evaluation + + + } + /> + )} + + ) +} diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/_components/ConnectToEvaluationStep/EvaluationEditor.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/_components/ConnectToEvaluationStep/EvaluationEditor.tsx similarity index 100% rename from apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/_components/ConnectToEvaluationStep/EvaluationEditor.tsx rename to apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/_components/ConnectToEvaluationStep/EvaluationEditor.tsx diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/_components/ConnectToEvaluationStep/EvaluationList.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/_components/ConnectToEvaluationStep/EvaluationList.tsx similarity index 100% rename from apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/_components/ConnectToEvaluationStep/EvaluationList.tsx rename to apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/_components/ConnectToEvaluationStep/EvaluationList.tsx diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/_components/ConnectToEvaluationStep/index.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/_components/ConnectToEvaluationStep/index.tsx similarity index 100% rename from apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/_components/ConnectToEvaluationStep/index.tsx rename to apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/_components/ConnectToEvaluationStep/index.tsx diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/_components/MapPromptDataToDatasetStep/index.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/_components/MapPromptDataToDatasetStep/index.tsx similarity index 100% rename from apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/_components/MapPromptDataToDatasetStep/index.tsx rename to apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/_components/MapPromptDataToDatasetStep/index.tsx diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/page.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/page.tsx similarity index 100% rename from apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/connect/page.tsx rename to apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/connect/page.tsx diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/layout.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/layout.tsx similarity index 52% rename from apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/layout.tsx rename to apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/layout.tsx index 0263423d3..36cb43917 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/layout.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/layout.tsx @@ -1,11 +1,11 @@ import { ReactNode } from 'react' -import { TableBlankSlate, TableWithHeader } from '@latitude-data/web-ui' +import { TableWithHeader } from '@latitude-data/web-ui' import { getEvaluationsByDocumentUuidCached } from '$/app/(private)/_data-access' import { ROUTES } from '$/services/routes' import Link from 'next/link' -import Layout from './_components/Layout' +import EvaluationsLayoutClient from './_components/Layout' export default async function EvaluationsLayout({ children, @@ -18,7 +18,7 @@ export default async function EvaluationsLayout({ const href = ROUTES.projects .detail({ id: Number(projectId) }) .commits.detail({ uuid: commitUuid }) - .documents.detail({ uuid: documentUuid }).evaluations.connect.root + .documents.detail({ uuid: documentUuid }).evaluations.dashboard.connect.root return (
@@ -30,23 +30,7 @@ export default async function EvaluationsLayout({ Connect evaluation } - table={ - <> - {evaluations.length > 0 && } - {evaluations.length === 0 && ( - - - Connect your first evaluation - - - } - /> - )} - - } + table={} />
) diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/page.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/page.tsx new file mode 100644 index 000000000..d6c2af518 --- /dev/null +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/dashboard/page.tsx @@ -0,0 +1,3 @@ +export default function EvaluationsDashboardPage() { + return null // --> layout.tsx +} diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/page.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/page.tsx index 29ce4aba4..0886f6cc0 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/page.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/evaluations/page.tsx @@ -1,3 +1,15 @@ -export default function EvaluationsPage() { - return null // --> layout.tsx +import { ROUTES } from '$/services/routes' +import { redirect } from 'next/navigation' + +export default function EvaluationsPage({ + params: { projectId, documentUuid, commitUuid }, +}: { + params: { projectId: string; documentUuid: string; commitUuid: string } +}) { + redirect( + ROUTES.projects + .detail({ id: Number(projectId) }) + .commits.detail({ uuid: commitUuid }) + .documents.detail({ uuid: documentUuid }).evaluations.dashboard.root, + ) } diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/layout.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/layout.tsx index 71198125f..cbbe6ec22 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/layout.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/layout.tsx @@ -1,5 +1,6 @@ import { ReactNode } from 'react' +import { DocumentVersionProvider } from '@latitude-data/web-ui' import { getDocumentByUuidCached } from '$/app/(private)/_data-access' import env from '$/env' import { ROUTES } from '$/services/routes' @@ -26,13 +27,15 @@ export default async function DocumentPage({ }) return ( - - {children} - + + + {children} + + ) } catch (error) { // TODO: Show a 404 page within the documents layout, while still showing diff --git a/apps/web/src/services/routes.ts b/apps/web/src/services/routes.ts index 7926fd90f..79479a9f7 100644 --- a/apps/web/src/services/routes.ts +++ b/apps/web/src/services/routes.ts @@ -81,19 +81,26 @@ export const ROUTES = { root: rootDocuments, detail: ({ uuid }: { uuid: string }) => { const root = `${rootDocuments}/${uuid}` - const rootEvaluations = `${root}/evaluations` + const evaluationsRoot: string = `${root}/evaluations` return { root, [DocumentRoutes.editor]: { root }, [DocumentRoutes.evaluations]: { - root: rootEvaluations, - connect: { - root: `${rootEvaluations}/connect`, + root: evaluationsRoot, + dashboard: { + root: `${evaluationsRoot}/dashboard`, + connect: { + root: `${evaluationsRoot}/dashboard/connect`, + }, }, - detail: ({ uuid }: { uuid: string }) => { - const root = `${rootEvaluations}/${uuid}` + detail: (uuid: string) => { + const detailRoot = `${evaluationsRoot}/${uuid}` return { root, + dashboard: { + root: `${detailRoot}/dashboard`, + destroy: `${detailRoot}/dashboard/destroy`, + }, } }, }, diff --git a/packages/core/src/tests/factories/evaluations.ts b/packages/core/src/tests/factories/evaluations.ts index 58041c23d..91d548a75 100644 --- a/packages/core/src/tests/factories/evaluations.ts +++ b/packages/core/src/tests/factories/evaluations.ts @@ -18,7 +18,7 @@ export async function createLlmAsJudgeEvaluation({ }: IEvaluationData) { const evaluationResult = await createEvaluationService({ workspace, - metadata: { prompt }, + metadata: { prompt: prompt ?? faker.lorem.sentence() }, type: EvaluationMetadataType.LlmAsJudge, name: name ?? faker.company.catchPhrase(), description: description ?? faker.lorem.sentence(), diff --git a/packages/web-ui/src/providers/DocumentProvider.tsx b/packages/web-ui/src/providers/DocumentProvider.tsx new file mode 100644 index 000000000..a0656e75e --- /dev/null +++ b/packages/web-ui/src/providers/DocumentProvider.tsx @@ -0,0 +1,33 @@ +'use client' + +import { createContext, ReactNode, useContext } from 'react' + +import { DocumentVersion } from '@latitude-data/core/browser' + +const DocumentContext = createContext(undefined) + +const DocumentVersionProvider = ({ + children, + document, +}: { + children: ReactNode + document: DocumentVersion +}) => { + return ( + + {children} + + ) +} + +const useCurrentDocument = () => { + const context = useContext(DocumentContext) + if (!context) { + throw new Error( + 'useCurrentDocument must be used within a DocumentVersionProvider', + ) + } + return context +} + +export { DocumentVersionProvider, useCurrentDocument } diff --git a/packages/web-ui/src/providers/index.ts b/packages/web-ui/src/providers/index.ts index f5b6a4854..aec83c1f6 100644 --- a/packages/web-ui/src/providers/index.ts +++ b/packages/web-ui/src/providers/index.ts @@ -1,3 +1,4 @@ export * from './CommitProvider' export * from './ProjectProvider' export * from './SessionProvider' +export * from './DocumentProvider'