Skip to content

Commit

Permalink
Fetch only logs without errors on playground parameters (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon authored Nov 18, 2024
1 parent 6702a60 commit 93bca98
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 83 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@intercom/messenger-js-sdk": "^0.0.14",
"@latitude-data/constants": "workspace:*",
"@latitude-data/compiler": "workspace:^",
"@latitude-data/core": "workspace:*",
"@latitude-data/env": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DocumentVersion } from '@latitude-data/core/browser'
import { DocumentLogWithMetadataAndError } from '@latitude-data/core/repositories'
import { Badge, cn, Icon, Skeleton, Text, Tooltip } from '@latitude-data/web-ui'
import { DocumentLog, DocumentVersion } from '@latitude-data/core/browser'
import { Badge, cn, Icon, Skeleton, Text } from '@latitude-data/web-ui'
import { useDocumentParameters } from '$/hooks/useDocumentParameters'
import { useGenerateDocumentLogDetailUrl } from '$/hooks/useGenerateDocumentLogDetailUrl'
import { format } from 'date-fns'
Expand All @@ -15,7 +14,7 @@ function usePaginatedDocumentLogUrl({
selectedLog,
isLoading,
}: {
selectedLog: DocumentLogWithMetadataAndError | undefined
selectedLog: DocumentLog | undefined
page: number | undefined
isLoading: boolean
}) {
Expand All @@ -33,7 +32,6 @@ function usePaginatedDocumentLogUrl({
url,
shortCode,
createdAt,
hasError: !!selectedLog.error.message,
}
}

Expand Down Expand Up @@ -80,18 +78,7 @@ export function HistoryLogParams({
<Text.H5 ellipsis noWrap>
{urlData.createdAt}
</Text.H5>
{urlData.hasError ? (
<Tooltip
variant='destructive'
trigger={
<Badge variant='destructive'>{urlData.shortCode}</Badge>
}
>
This log has an error
</Tooltip>
) : (
<Badge variant='accent'>{urlData.shortCode}</Badge>
)}
<Badge variant='accent'>{urlData.shortCode}</Badge>
<Icon
name='externalLink'
color='foregroundMuted'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function useLogHistoryParams({
documentUuid: document.documentUuid,
page: '1', // Not used really. This is only for the counter.
pageSize: ONLY_ONE_PAGE,
excludeErrors: true,
})

const [position, setPosition] = useState<LogWithPosition | undefined>(
Expand All @@ -71,8 +72,12 @@ export function useLogHistoryParams({
)
const { isLoading: isLoadingPosition } = useDocumentLogWithPaginationPosition(
{
projectId: project.id,
commitUuid: commit.uuid,
document,
documentLogUuid: logUuid,
onFetched: onFetchCurrentLog,
excludeErrors: true,
},
)

Expand All @@ -82,6 +87,7 @@ export function useLogHistoryParams({
projectId: project.id,
page: position === undefined ? undefined : String(position.position),
pageSize: ONLY_ONE_PAGE,
excludeErrors: true,
onFetched: (logs) => {
const log = logs[0]
if (!log) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function ParametersPaginationNav({
onClick={() => onPrevPage(currentIndex)}
/>
<div className='flex flex-row justify-center items-center flex-grow min-w-0'>
<Text.H5M color='foregroundMuted' ellipsis noWrap>
<Text.H5M userSelect={false} color='foregroundMuted' ellipsis noWrap>
{zeroIndex ? currentIndex + INDEX_ZERO_LIST : currentIndex} of{' '}
{totalCount} {label}
</Text.H5M>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { DocumentLogsTable } from './DocumentLogsTable'

const useDocumentLogSocket = (
documentUuid: string,
mutate: ReturnType<typeof useDocumentLogs>['mutate'],
mutate: ReturnType<typeof useDocumentLogs<false>>['mutate'],
) => {
const onMessage = useCallback(
(args: EventArgs<'documentLogCreated'>) => {
Expand Down Expand Up @@ -95,6 +95,7 @@ export function DocumentLogs({
projectId: project.id,
page,
pageSize,
excludeErrors: false,
},
{
fallbackData: serverDocumentLogs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DocumentLogs } from './_components/DocumentLogs'

async function fetchDocumentLogPage({
workspace,
commit: _c, // TODO: Add when other PRs are merged
commit,
documentLogUuid,
}: {
commit: Commit
Expand All @@ -25,7 +25,7 @@ async function fetchDocumentLogPage({

const result = await fetchDocumentLogWithPosition({
workspace,
// commit, TODO: Add when other PRs are merged
commit,
documentLogUuid,
})

Expand Down Expand Up @@ -66,13 +66,14 @@ export default async function DocumentPage({

const rows = await computeDocumentLogsWithMetadataQuery({
workspaceId: workspace.id,
documentUuid: params.documentUuid,
documentUuid,
draft: commit,
page,
pageSize: searchParams.pageSize as string | undefined,
})

const selectedLog = rows.find((r) => r.uuid === documentLogUuid)

return (
<div className='flex flex-grow min-h-0 flex-col w-full p-6 gap-2 min-w-0'>
{!rows.length ? (
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Workspace } from '@latitude-data/core/browser'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { fetchDocumentLogWithPosition } from '@latitude-data/core/services/documentLogs/fetchDocumentLogWithPosition'
import { authHandler } from '$/middlewares/authHandler'
import { errorHandler } from '$/middlewares/errorHandler'
import { NextRequest, NextResponse } from 'next/server'

export const GET = errorHandler(
authHandler(
async (
req: NextRequest,
{
params: { projectId, commitUuid, documentLogUuid },
workspace,
}: {
params: {
projectId: string
commitUuid: string
documentUuid: string
documentLogUuid: string
}
workspace: Workspace
},
) => {
const commitsScope = new CommitsRepository(workspace.id)
const searchParams = req.nextUrl.searchParams
const excludeErrors = searchParams.get('excludeErrors') === 'true'
const commit = await commitsScope
.getCommitByUuid({ uuid: commitUuid, projectId: Number(projectId) })
.then((r) => r.unwrap())
const result = await fetchDocumentLogWithPosition({
workspace,
commit,
documentLogUuid,
excludeErrors,
})

if (result.error) {
return NextResponse.json(
{ message: `Document Log not found with uuid: ${documentLogUuid}` },
{ status: 404 },
)
}

return NextResponse.json(result.value, { status: 200 })
},
),
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Workspace } from '@latitude-data/core/browser'
import { buildPagination } from '@latitude-data/core/lib/pagination/buildPagination'
import { CommitsRepository } from '@latitude-data/core/repositories'
import { computeDocumentLogsCount } from '@latitude-data/core/services/documentLogs/computeDocumentLogs'
import { computeDocumentLogsWithMetadataCount } from '@latitude-data/core/services/documentLogs/computeDocumentLogsWithMetadata'
import { authHandler } from '$/middlewares/authHandler'
import { errorHandler } from '$/middlewares/errorHandler'
Expand Down Expand Up @@ -37,13 +38,17 @@ export const GET = errorHandler(
) => {
const searchParams = req.nextUrl.searchParams
const commitsScope = new CommitsRepository(workspace.id)
const excludeErrors = searchParams.get('excludeErrors') === 'true'
const commit = await commitsScope
.getCommitByUuid({
uuid: params.commitUuid,
projectId: params.projectId,
})
.then((r) => r.unwrap())
const count = await computeDocumentLogsWithMetadataCount({
const queryFn = excludeErrors
? computeDocumentLogsCount
: computeDocumentLogsWithMetadataCount
const count = await queryFn({
workspaceId: workspace.id,
documentUuid: params.documentUuid,
draft: commit,
Expand Down
Loading

0 comments on commit 93bca98

Please sign in to comment.