From fa267d4e3ffcc9141a061d9de87ff9636af2c336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Thu, 14 Nov 2024 17:09:55 +0100 Subject: [PATCH] Document logs history parameters tab in Playground (#592) --- .../Variables/hooks/useVariablesData.tsx | 6 +- .../editor/_components/Playground/index.tsx | 6 +- .../DocumentParams/DatasetParams/index.tsx | 65 ++------- .../DocumentParams/HistoryLogParams/index.tsx | 96 ++++++++++++- .../HistoryLogParams/useLogHistoryParams.ts | 129 ++++++++++++++++++ .../HistoryLogParams/useSelectedRow.ts | 36 +++++ .../Playground/DocumentParams/Input/index.tsx | 2 +- .../DocumentParams/PaginationNav/index.tsx | 58 ++++++++ .../Playground/DocumentParams/index.tsx | 8 +- .../EvaluationResultsTable.tsx | 4 +- .../logs/_components/DocumentLogs/index.tsx | 43 +++++- .../documents/[documentUuid]/logs/page.tsx | 10 +- .../uuids/[uuid]/with-position/route.ts | 35 +++++ .../[documentUuid]/documentLogs/route.ts | 5 +- .../src/hooks/useDocumentParameters/index.ts | 7 +- .../hooks/useGenerateDocumentLogDetailUrl.ts | 27 ++++ apps/web/src/services/routes/api.ts | 10 +- apps/web/src/stores/datasetPreviews.ts | 4 +- .../web/src/stores/documentLogWithMetadata.ts | 32 ++--- .../documentLogWithPaginationPosition.ts | 43 ++++++ apps/web/src/stores/documentLogs.ts | 33 +++-- packages/core/src/constants.ts | 2 + .../src/lib/pagination/buildPagination.ts | 3 +- .../computeDocumentLogsWithMetadata.ts | 4 +- .../fetchDocumentLogWithPosition.ts | 40 ++++++ .../core/src/services/documentLogs/index.ts | 1 + .../web-ui/src/lib/hooks/useLocalStorage.ts | 1 + 27 files changed, 596 insertions(+), 114 deletions(-) create mode 100644 apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/HistoryLogParams/useLogHistoryParams.ts create mode 100644 apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/HistoryLogParams/useSelectedRow.ts create mode 100644 apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/PaginationNav/index.tsx create mode 100644 apps/web/src/app/api/documentLogs/uuids/[uuid]/with-position/route.ts create mode 100644 apps/web/src/hooks/useGenerateDocumentLogDetailUrl.ts create mode 100644 apps/web/src/stores/documentLogWithPaginationPosition.ts create mode 100644 packages/core/src/services/documentLogs/fetchDocumentLogWithPosition.ts diff --git a/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/editor/_components/Playground/Variables/hooks/useVariablesData.tsx b/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/editor/_components/Playground/Variables/hooks/useVariablesData.tsx index 506f01fc2..8a766688e 100644 --- a/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/editor/_components/Playground/Variables/hooks/useVariablesData.tsx +++ b/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/editor/_components/Playground/Variables/hooks/useVariablesData.tsx @@ -13,9 +13,9 @@ import { PinnedDocumentation } from '../components/PinnedDocumentation' export const useVariablesData = (providerLog: ProviderLogDto) => { const [config, setConfig] = useState() - const { data: documentLogWithMetadata } = useDocumentLogWithMetadata( - providerLog.documentLogUuid, - ) + const { data: documentLogWithMetadata } = useDocumentLogWithMetadata({ + documentLogUuid: providerLog.documentLogUuid, + }) const [isMessagesPinned, setIsMessagesPinned] = useState(false) const [isPopoverOpen, setIsPopoverOpen] = useState(false) diff --git a/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/editor/_components/Playground/index.tsx b/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/editor/_components/Playground/index.tsx index e7159df44..e25df5f92 100644 --- a/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/editor/_components/Playground/index.tsx +++ b/apps/web/src/app/(private)/evaluations/(evaluation)/[evaluationUuid]/editor/_components/Playground/index.tsx @@ -49,9 +49,9 @@ export default function Playground({ const { data: providerLog } = useProviderLog( providerLogId ? Number(providerLogId) : undefined, ) - const { data: documentLogWithMetadata } = useDocumentLogWithMetadata( - providerLog?.documentLogUuid, - ) + const { data: documentLogWithMetadata } = useDocumentLogWithMetadata({ + documentLogUuid: providerLog?.documentLogUuid, + }) const parameters = useMemo(() => { if (!providerLog || !documentLogWithMetadata) { return { diff --git a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/DatasetParams/index.tsx b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/DatasetParams/index.tsx index ef6d7c8a1..7db45de3b 100644 --- a/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/DatasetParams/index.tsx +++ b/apps/web/src/app/(private)/projects/[projectId]/versions/[commitUuid]/documents/[documentUuid]/_components/DocumentEditor/Editor/Playground/DocumentParams/DatasetParams/index.tsx @@ -1,61 +1,11 @@ -import { - Button, - cn, - ReactStateDispatch, - Select, - Text, -} from '@latitude-data/web-ui' +import { cn, ReactStateDispatch, Select } from '@latitude-data/web-ui' import { PlaygroundInputs } from '$/hooks/useDocumentParameters' import { ParamsSource } from '../index' +import { ParametersPaginationNav } from '../PaginationNav' import { InputMapper } from './InputsMapper' import { type UseSelectDataset } from './useSelectDataset' -const INDEX_ZERO_LIST = 1 -function DatasetRowsPagination({ - currentIndex, - totalCount, - onRowChange, -}: { - currentIndex: number | undefined - totalCount: number | undefined - onRowChange: (index: number) => void -}) { - if (currentIndex === undefined || totalCount === undefined) return null - - return ( -
-
- ) -} - export function DatasetParams({ inputs, datasetInfo: data, @@ -68,9 +18,11 @@ export function DatasetParams({ const selectedId = data.selectedDataset?.id ? String(data.selectedDataset.id) : undefined + const onPrevPage = (page: number) => data.onRowChange(page - 1) + const onNextPage = (page: number) => data.onRowChange(page + 1) return (
-
+