Skip to content

Commit

Permalink
feat: Batch export logs frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfarias committed Sep 25, 2023
1 parent fcb7bfb commit ce61ea3
Show file tree
Hide file tree
Showing 5 changed files with 637 additions and 203 deletions.
72 changes: 72 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import posthog from 'posthog-js'
import {
ActionType,
BatchExportLogEntry,
CohortType,
DashboardCollaboratorType,
DashboardTemplateEditorType,
Expand Down Expand Up @@ -537,6 +538,10 @@ class ApiRequest {
return this.batchExports(teamId).addPathComponent(id)
}

public batchExportLogs(id: BatchExportConfiguration['id'], teamId?: TeamType['id']): ApiRequest {
return this.batchExport(id, teamId).addPathComponent('logs')
}

public batchExportRuns(id: BatchExportConfiguration['id'], teamId?: TeamType['id']): ApiRequest {
return this.batchExports(teamId).addPathComponent(id).addPathComponent('runs')
}
Expand All @@ -549,6 +554,14 @@ class ApiRequest {
return this.batchExportRuns(id, teamId).addPathComponent(runId)
}

public batchExportRunLogs(
id: BatchExportConfiguration['id'],
runId: BatchExportRun['id'],
teamId?: TeamType['id']
): ApiRequest {
return this.batchExportRun(id, runId, teamId).addPathComponent('logs')
}

// Request finalization
public async get(options?: ApiMethodOptions): Promise<any> {
return await api.get(this.assembleFullUrl(), options)
Expand Down Expand Up @@ -1186,6 +1199,65 @@ const api = {
},
},

batchExportLogs: {
async search(
batchExportId: string,
currentTeamId: number | null,
searchTerm: string | null = null,
typeFilters: CheckboxValueType[] = [],
trailingEntry: BatchExportLogEntry | null = null,
leadingEntry: BatchExportLogEntry | null = null
): Promise<BatchExportLogEntry[]> {
const params = toParams(
{
limit: LOGS_PORTION_LIMIT,
type_filter: typeFilters,
search: searchTerm || undefined,
before: trailingEntry?.timestamp,
after: leadingEntry?.timestamp,
},
true
)

const response = await new ApiRequest()
.batchExportLogs(batchExportId, currentTeamId || undefined)
.withQueryString(params)
.get()

return response.results
},
},

batchExportRunLogs: {
async search(
batchExportId: string,
batchExportRunId: string,
currentTeamId: number | null,
searchTerm: string | null = null,
typeFilters: CheckboxValueType[] = [],
trailingEntry: BatchExportLogEntry | null = null,
leadingEntry: BatchExportLogEntry | null = null
): Promise<BatchExportLogEntry[]> {
const params = toParams(
{
limit: LOGS_PORTION_LIMIT,
type_filter: typeFilters,
search: searchTerm || undefined,
before: trailingEntry?.timestamp,
after: leadingEntry?.timestamp,
},
true
)

const response = await new ApiRequest()
.batchExportRunLogs(batchExportId, batchExportRunId, currentTeamId || undefined)
.withQueryString(params)
.get()

return response.results
},
},

annotations: {
async get(annotationId: RawAnnotationType['id']): Promise<RawAnnotationType> {
return await new ApiRequest().annotation(annotationId).get()
Expand Down
Loading

0 comments on commit ce61ea3

Please sign in to comment.