-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b09af83
commit dc28990
Showing
5 changed files
with
60 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core/src/services/documentLogs/logsFilterUtils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './parseLogFilterParams' | ||
export * from './parseApiLogFilterParams' |
48 changes: 48 additions & 0 deletions
48
packages/core/src/services/documentLogs/logsFilterUtils/parseApiLogFilterParams.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { DEFAULT_PAGINATION_SIZE, LogSources } from '../../../constants' | ||
import { parseSafeCreatedAtRange } from './parseLogFilterParams' | ||
|
||
function parsePage(page: string | null): string { | ||
if (!page) return '1' | ||
|
||
const parsed = parseInt(page, 10) | ||
if (isNaN(parsed)) return '1' | ||
|
||
return parsed < 1 ? '1' : parsed.toString() | ||
} | ||
|
||
function parseCommitIds(commitIds: string | undefined) { | ||
return commitIds?.split(',')?.map?.(Number) ?? [] | ||
} | ||
|
||
function parseLogSources(logSources: string | undefined) { | ||
return (logSources?.split?.(',') as LogSources[]) ?? [] | ||
} | ||
|
||
export function parseApiDocumentLogParams({ | ||
searchParams, | ||
}: { | ||
searchParams: URLSearchParams | ||
}) { | ||
const params = Object.fromEntries(searchParams.entries()) | ||
const commitIds = parseCommitIds(params.commitIds) | ||
const logSources = parseLogSources(params.logSources) | ||
const excludeErrors = searchParams.get('excludeErrors') === 'true' | ||
|
||
const filterOptions = { | ||
commitIds, | ||
logSources, | ||
createdAt: parseSafeCreatedAtRange(params.createdAt), | ||
} | ||
|
||
const isEmptyResponse = | ||
filterOptions.commitIds.length === 0 || | ||
filterOptions.logSources.length === 0 | ||
|
||
return { | ||
excludeErrors, | ||
isEmptyResponse, | ||
filterOptions, | ||
page: parsePage(searchParams.get('page')), | ||
pageSize: searchParams.get('pageSize') ?? String(DEFAULT_PAGINATION_SIZE), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters