Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Dec 11, 2024
1 parent dc28990 commit 1d1ed7f
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { capitalize } from 'lodash-es'
import {
DocumentLogFilterOptions,
EvaluationResultableType,
LOG_FILTERS_ENCODED_PARAMS,
} from '@latitude-data/core/browser'
import { buildPagination } from '@latitude-data/core/lib/pagination/buildPagination'
import {
Expand Down Expand Up @@ -40,7 +41,6 @@ import useDocumentLogsPagination from '$/stores/useDocumentLogsPagination'
import { useSearchParams } from 'next/navigation'

import { ResultCellContent } from '../../../evaluations/[evaluationId]/_components/EvaluationResults/EvaluationResultsTable'
import { LOG_FILTERS_ENCODED_PARAMS } from '$/hooks/logFilters/useProcessLogFilters'

const countLabel = (selected: number) => (count: number) => {
return selected ? `${selected} of ${count} logs selected` : `${count} logs`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { LogSources, Workspace } from '@latitude-data/core/browser'
import { Workspace } from '@latitude-data/core/browser'
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'
import { decodeParameters } from '$/services/helpers'
import { parseApiDocumentLogParams } from '@latitude-data/core/services/documentLogs/index'

export const GET = errorHandler(
authHandler(
Expand All @@ -23,20 +23,12 @@ export const GET = errorHandler(
},
) => {
const searchParams = req.nextUrl.searchParams
const excludeErrors = searchParams.get('excludeErrors') === 'true'
const { commitIds, logSources } = decodeParameters(req.nextUrl.search)
const filterOptions = {
commitIds: Array.isArray(commitIds) ? commitIds.map(Number) : [],
logSources: (Array.isArray(logSources)
? logSources
: []) as LogSources[],
}

const queryParams = parseApiDocumentLogParams({ searchParams })
const result = await fetchDocumentLogWithPosition({
workspace,
filterOptions,
documentLogUuid,
excludeErrors,
filterOptions: queryParams.filterOptions,
excludeErrors: queryParams.excludeErrors,
})

if (result.error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { LogSources, Workspace } from '@latitude-data/core/browser'
import { Workspace } from '@latitude-data/core/browser'
import { computeDocumentLogsAggregations } from '@latitude-data/core/services/documentLogs/computeDocumentLogsAggregations'
import { authHandler } from '$/middlewares/authHandler'
import { errorHandler } from '$/middlewares/errorHandler'
import { NextRequest, NextResponse } from 'next/server'
import { decodeParameters } from '$/services/helpers'
import { parseApiDocumentLogParams } from '@latitude-data/core/services/documentLogs/index'

export const GET = errorHandler(
authHandler(
Expand All @@ -22,18 +22,12 @@ export const GET = errorHandler(
},
) => {
const { documentUuid } = params
const { commitIds, logSources } = decodeParameters(req.nextUrl.search)
const filterOptions = {
commitIds: Array.isArray(commitIds) ? commitIds.map(Number) : [],
logSources: (Array.isArray(logSources)
? logSources
: []) as LogSources[],
}

const searchParams = req.nextUrl.searchParams
const queryParams = parseApiDocumentLogParams({ searchParams })
const result = await computeDocumentLogsAggregations({
workspace,
documentUuid,
filterOptions,
filterOptions: queryParams.filterOptions,
})

return NextResponse.json(result, { status: 200 })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { LogSources, Workspace } from '@latitude-data/core/browser'
import { Workspace } from '@latitude-data/core/browser'
import { computeDocumentLogsDailyCount } from '@latitude-data/core/services/documentLogs/computeDocumentLogsDailyCount'
import { authHandler } from '$/middlewares/authHandler'
import { errorHandler } from '$/middlewares/errorHandler'
import { NextRequest, NextResponse } from 'next/server'
import { decodeParameters } from '$/services/helpers'
import { parseApiDocumentLogParams } from '@latitude-data/core/services/documentLogs/index'

export const GET = errorHandler(
authHandler(
Expand All @@ -23,21 +23,14 @@ export const GET = errorHandler(
) => {
const { documentUuid } = params
const searchParams = req.nextUrl.searchParams
const queryParams = parseApiDocumentLogParams({ searchParams })
const days = searchParams.get('days')
? parseInt(searchParams.get('days')!, 10)
: undefined
const { commitIds, logSources } = decodeParameters(req.nextUrl.search)
const filterOptions = {
commitIds: Array.isArray(commitIds) ? commitIds.map(Number) : [],
logSources: (Array.isArray(logSources)
? logSources
: []) as LogSources[],
}

const result = await computeDocumentLogsDailyCount({
workspace,
documentUuid,
filterOptions,
filterOptions: queryParams.filterOptions,
days,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LogSources, Workspace } from '@latitude-data/core/browser'
import { Workspace } from '@latitude-data/core/browser'
import { buildPagination } from '@latitude-data/core/lib/pagination/buildPagination'
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'
import { ROUTES } from '$/services/routes'
import { NextRequest, NextResponse } from 'next/server'
import { decodeParameters } from '$/services/helpers'
import { parseApiDocumentLogParams } from '@latitude-data/core/services/documentLogs/index'

function pageUrl(params: {
projectId: string
Expand Down Expand Up @@ -37,23 +37,16 @@ export const GET = errorHandler(
},
) => {
const searchParams = req.nextUrl.searchParams
const queryParams = parseApiDocumentLogParams({ searchParams })
const excludeErrors = searchParams.get('excludeErrors') === 'true'
const { commitIds, logSources } = decodeParameters(req.nextUrl.search)
const filterOptions = {
commitIds: Array.isArray(commitIds) ? commitIds.map(Number) : [],
logSources: (Array.isArray(logSources)
? logSources
: []) as LogSources[],
}

const queryFn = excludeErrors
? computeDocumentLogsCount
: computeDocumentLogsWithMetadataCount

const count = await queryFn({
workspaceId: workspace.id,
documentUuid: params.documentUuid,
filterOptions,
filterOptions: queryParams.filterOptions,
})

const pagination = buildPagination({
Expand All @@ -63,12 +56,8 @@ export const GET = errorHandler(
documentUuid: params.documentUuid,
}),
count,
page: searchParams.get('page')
? parseInt(searchParams.get('page') as string)
: 1,
pageSize: searchParams.get('pageSize')
? parseInt(searchParams.get('pageSize') as string)
: 25,
page: +queryParams.page,
pageSize: +queryParams.pageSize,
})

return NextResponse.json(pagination, { status: 200 })
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/hooks/logFilters/useProcessLogFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { useCallback, useMemo } from 'react'
import { usePathname, useRouter } from 'next/navigation'
import {
DocumentLogFilterOptions,
LOG_FILTERS_ENCODED_PARAMS,
LOG_SOURCES,
LogSources,
} from '@latitude-data/core/browser'
import { ReactStateDispatch } from '@latitude-data/web-ui'
import { paramsToString } from '@latitude-data/core/lib/pagination/buildPaginatedUrl'

export const LOG_FILTERS_ENCODED_PARAMS = ['customIdentifier']

function useEditableSearchParams() {
const router = useRouter()
const pathname = usePathname()
Expand Down
25 changes: 0 additions & 25 deletions apps/web/src/services/helpers.ts

This file was deleted.

60 changes: 34 additions & 26 deletions apps/web/src/services/routes/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DocumentLogFilterOptions } from '@latitude-data/core/browser'

import { addParameters } from '../helpers'
import { generateDocumentLogsApiRouteWithParams } from '@latitude-data/core/services/documentLogs/index'

type PaginationParameters = { page: number; pageSize: number }

Expand Down Expand Up @@ -91,13 +90,15 @@ export const _API_ROUTES = {
excludeErrors?: boolean
filterOptions: DocumentLogFilterOptions
}) =>
addParameters(`${documentRoot}/logs`, {
page,
pageSize,
excludeErrors,
...filterOptions,
generateDocumentLogsApiRouteWithParams({
path: `${documentRoot}/logs`,
params: {
page,
pageSize,
excludeErrors,
filterOptions,
},
}),

pagination: ({
page,
pageSize,
Expand All @@ -107,28 +108,35 @@ export const _API_ROUTES = {
excludeErrors?: boolean
filterOptions: DocumentLogFilterOptions
}) =>
addParameters(`${documentRoot}/logs/pagination`, {
page,
pageSize,
excludeErrors,
...filterOptions,
generateDocumentLogsApiRouteWithParams({
path: `${documentRoot}/logs/pagination`,
params: {
page,
pageSize,
excludeErrors,
filterOptions,
},
}),

aggregations: (filterOptions: DocumentLogFilterOptions) =>
addParameters(
`${documentRoot}/logs/aggregations`,
filterOptions,
),
generateDocumentLogsApiRouteWithParams({
path: `${documentRoot}/logs/aggregations`,
params: {
filterOptions,
},
}),
dailyCount: ({
filterOptions,
days,
}: {
filterOptions: DocumentLogFilterOptions
days?: number
}) =>
addParameters(`${documentRoot}/logs/daily-count`, {
days,
...filterOptions,
generateDocumentLogsApiRouteWithParams({
path: `${documentRoot}/logs/daily-count`,
params: {
days,
filterOptions,
},
}),
detail: (documentLogUuid: string) => {
return {
Expand All @@ -139,13 +147,13 @@ export const _API_ROUTES = {
excludeErrors?: boolean
filterOptions: DocumentLogFilterOptions
}) =>
addParameters(
`${documentRoot}/logs/${documentLogUuid}/position`,
{
generateDocumentLogsApiRouteWithParams({
path: `${documentRoot}/logs/${documentLogUuid}/position`,
params: {
excludeErrors,
...filterOptions,
filterOptions,
},
),
}),
}
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,4 @@ export const RELATIVE_DATES = {
} as const

export type RelativeDate = keyof typeof RELATIVE_DATES
export const LOG_FILTERS_ENCODED_PARAMS = ['customIdentifier']
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
DocumentLogFilterOptions,
LOG_FILTERS_ENCODED_PARAMS,
} from '../../../constants'

export function generateDocumentLogsApiRouteWithParams({
path: _path,
params: _params,
paramsToEncode: _pe = LOG_FILTERS_ENCODED_PARAMS,
}: {
path: string
paramsToEncode?: string[]
params: {
filterOptions?: DocumentLogFilterOptions
page?: number
pageSize?: number
excludeErrors?: boolean
days?: number | undefined
}
}) {
// TODO: Implement this function
return 'caca'
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './parseLogFilterParams'
export * from './parseApiLogFilterParams'
export * from './generateDocumentLogsApiRouteWithParams'

0 comments on commit 1d1ed7f

Please sign in to comment.