History

Extract stripDiffSearchParams helper to deduplicate diff param stripping logic

Consolidate the repeated pattern of destructuring and removing diff/diffTurnId/diffFilePath search params into a single stripDiffSearchParams() function in diffRouteSearch.ts. Replaces 5 identical destructuring blocks across 3 files with calls to the shared helper.

Cursor Agent committed 8 months ago

Commit f87f01f1 parent 891eb024 files · +35 −48Browse files

Showing the changes to apps/web/src/diffRouteSearch.ts (1 of 4 files). Show all

Unified · Split

apps/web/src/diffRouteSearch.ts+7−1
@@ -12,6 +12,13 @@ function normalizeSearchString(value: unknown): string | undefined { · 11 unmodified lines
12 return normalized.length > 0 ? normalized : undefined;12 return normalized.length > 0 ? normalized : undefined;
13}13}
14 14
15export function stripDiffSearchParams<T extends Record<string, unknown>>(
16 params: T,
17): Omit<T, "diff" | "diffTurnId" | "diffFilePath"> {
18 const { diff: _diff, diffTurnId: _diffTurnId, diffFilePath: _diffFilePath, ...rest } = params;
19 return rest as Omit<T, "diff" | "diffTurnId" | "diffFilePath">;
20}
21
15export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRouteSearch {22export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRouteSearch {
16 const diff = search.diff === "1" ? "1" : undefined;23 const diff = search.diff === "1" ? "1" : undefined;
17 const diffTurnId = diff ? normalizeSearchString(search.diffTurnId) : undefined;24 const diffTurnId = diff ? normalizeSearchString(search.diffTurnId) : undefined;
@@ -23,4 +30,3 @@ export function parseDiffRouteSearch(search: Record<string, unknown>): DiffRoute · 5 unmodified lines
23 ...(diffFilePath ? { diffFilePath } : {}),30 ...(diffFilePath ? { diffFilePath } : {}),
24 };31 };
25}32}
26