Skip to content

Commit

Permalink
Log filters UI (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
csansoon authored Dec 10, 2024
1 parent 7019e8c commit 0dafc01
Show file tree
Hide file tree
Showing 49 changed files with 1,470 additions and 563 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
import { useCallback, useState } from 'react'

import { DocumentVersion } from '@latitude-data/core/browser'
import { useCurrentCommit, useCurrentProject } from '@latitude-data/web-ui'
import { useCurrentProject } from '@latitude-data/web-ui'
import { useDocumentParameters } from '$/hooks/useDocumentParameters'
import useDocumentLogs from '$/stores/documentLogs'
import useDocumentLogWithPaginationPosition, {
LogWithPosition,
} from '$/stores/documentLogWithPaginationPosition'
import useDocumentLogsPagination from '$/stores/useDocumentLogsPagination'
import { useFilterOptions } from '$/hooks/useLogFilterOptions'

const ONLY_ONE_PAGE = '1'

export function useLogHistoryParams({
document,
commitVersionUuid,
}: {
document: DocumentVersion
commitVersionUuid: string
}) {
const { project } = useCurrentProject()
const {
mapDocParametersToInputs,
history: { setHistoryLog, logUuid },
} = useDocumentParameters({
documentVersionUuid: document.documentUuid,
commitVersionUuid,
})
const { project } = useCurrentProject()
const { commit } = useCurrentCommit()

const filterOptions = useFilterOptions()
const { data: pagination, isLoading: isLoadingCounter } =
useDocumentLogsPagination({
projectId: project.id,
commitUuid: commit.uuid,
documentUuid: document.documentUuid,
projectId: project.id,
filterOptions,
page: '1', // Not used really. This is only for the counter.
pageSize: ONLY_ONE_PAGE,
excludeErrors: true,
Expand All @@ -47,18 +50,18 @@ export function useLogHistoryParams({
)
const { isLoading: isLoadingPosition } = useDocumentLogWithPaginationPosition(
{
projectId: project.id,
commitUuid: commit.uuid,
document,
documentLogUuid: logUuid,
document,
projectId: project.id,
filterOptions,
onFetched: onFetchCurrentLog,
excludeErrors: true,
},
)

const { data: logs, isLoading: isLoadingLog } = useDocumentLogs({
documentUuid: position === undefined ? undefined : document.documentUuid,
commitUuid: commit.uuid,
filterOptions,
projectId: project.id,
page: position === undefined ? undefined : String(position.position),
pageSize: ONLY_ONE_PAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { ReactNode, useContext } from 'react'

import { Button, Icon, useCurrentCommit } from '@latitude-data/web-ui'
import { Button, useCurrentCommit } from '@latitude-data/web-ui'

import { DocumentationContext } from '../DocumentationModal'
import { ShareDocument } from './ShareDocument'
Expand All @@ -29,8 +29,12 @@ export default function DocumentTabs({
documentUuid={params.documentUuid}
/>
<div className='flex flex-row items-center gap-x-4'>
<Button variant='ghost' onClick={toggleDocumentation}>
Deploy this prompt <Icon name='code2' />
<Button
variant='ghost'
onClick={toggleDocumentation}
iconProps={{ name: 'code2', placement: 'right' }}
>
Deploy this prompt
</Button>
<ShareDocument
document={document}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { useSearchParams } from 'next/navigation'

import { DocumentLogWithMetadataAndErrorAndEvaluationResult } from '..'
import { ResultCellContent } from '../../EvaluationResults/EvaluationResultsTable'
import { useCommits } from '$/stores/commitsStore'
import { useFilterOptions } from '$/hooks/useLogFilterOptions'

const countLabel = (selected: number) => (count: number) => {
return selected ? `${selected} of ${count} logs selected` : `${count} logs`
Expand Down Expand Up @@ -63,13 +65,15 @@ export const DocumentLogsTable = forwardRef<HTMLTableElement, Props>(
const searchParams = useSearchParams()
const page = searchParams.get('page') ?? '1'
const pageSize = searchParams.get('pageSize') ?? '25'
const { commit } = useCurrentCommit()
const { project } = useCurrentProject()
const { commit } = useCurrentCommit()
const { document } = useCurrentDocument()
const { data: commits } = useCommits()
const filterOptions = useFilterOptions()
const { data: pagination, isLoading } = useDocumentLogsPagination({
documentUuid: commits ? document.documentUuid : undefined,
projectId: project.id,
commitUuid: commit.uuid,
documentUuid: document.documentUuid,
filterOptions,
page,
pageSize,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import { Commit } from '@latitude-data/core/browser'
import { Button, Text } from '@latitude-data/web-ui'
import { getDocumentByUuidCached } from '$/app/(private)/_data-access'
import {
Button,
Text,
useCurrentCommit,
useCurrentProject,
} from '@latitude-data/web-ui'
import { useCurrentDocument } from '$/app/providers/DocumentProvider'
import { ROUTES } from '$/services/routes'
import Link from 'next/link'

import { DocumentBlankSlateLayout } from '../../../../../_components/DocumentBlankSlateLayout'
import { DocumentsClient } from '../../../../../_components/DocumentsClient'

export async function DocumentLogBlankSlate({
commit,
projectId,
documentUuid,
}: {
commit: Commit
documentUuid: string
projectId: number
}) {
const document = await getDocumentByUuidCached({
documentUuid,
projectId,
commitUuid: commit.uuid,
})
export function DocumentLogBlankSlate() {
const { project } = useCurrentProject()
const { commit } = useCurrentCommit()
const { document } = useCurrentDocument()

return (
<DocumentBlankSlateLayout>
<div className='flex flex-col gap-4 items-center'>
Expand All @@ -31,9 +26,9 @@ export async function DocumentLogBlankSlate({
<Link
href={
ROUTES.projects
.detail({ id: projectId })
.detail({ id: project.id })
.commits.detail({ uuid: commit.uuid })
.documents.detail({ uuid: documentUuid }).logs.upload
.documents.detail({ uuid: document.documentUuid }).logs.upload
}
>
<Button fullWidth variant='outline'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { forwardRef } from 'react'
import { capitalize } from 'lodash-es'

import { EvaluationResultableType } from '@latitude-data/core/browser'
import {
DocumentLogFilterOptions,
EvaluationResultableType,
} from '@latitude-data/core/browser'
import { buildPagination } from '@latitude-data/core/lib/pagination/buildPagination'
import {
DocumentLogWithMetadataAndError,
Expand Down Expand Up @@ -95,6 +98,7 @@ function EvaluationsColumn({

type Props = {
documentLogs: DocumentLogRow[]
documentLogFilterOptions: DocumentLogFilterOptions
evaluationResults: Record<number, ResultWithEvaluation[]>
selectedLog: DocumentLogWithMetadataAndError | undefined
setSelectedLog: (log: DocumentLogWithMetadataAndError | undefined) => void
Expand All @@ -105,6 +109,7 @@ export const DocumentLogsTable = forwardRef<HTMLTableElement, Props>(
function DocumentLogsTable(
{
documentLogs,
documentLogFilterOptions,
evaluationResults,
selectedLog,
setSelectedLog,
Expand All @@ -128,11 +133,12 @@ export const DocumentLogsTable = forwardRef<HTMLTableElement, Props>(
const { data: pagination, isLoading: isPaginationLoading } =
useDocumentLogsPagination({
projectId: project.id,
commitUuid: commit.uuid,
filterOptions: documentLogFilterOptions,
documentUuid: document.documentUuid,
page,
pageSize,
})
const queryParams = window.location.search
return (
<Table
ref={ref}
Expand All @@ -150,6 +156,7 @@ export const DocumentLogsTable = forwardRef<HTMLTableElement, Props>(
.documents.detail({ uuid: document.documentUuid }).logs
.root,
count: pagination.count,
queryParams,
page: Number(page),
pageSize: Number(pageSize),
})
Expand Down

This file was deleted.

Loading

0 comments on commit 0dafc01

Please sign in to comment.