Skip to content

Commit 50c5825

Browse files
committed
Fix api helper
1 parent b68b46a commit 50c5825

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

site/src/api/api.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,22 @@ interface SearchParamOptions extends TypesGen.Pagination {
270270

271271
export const getURLWithSearchParams = (
272272
basePath: string,
273-
options: SearchParamOptions
273+
options?: SearchParamOptions
274274
): string => {
275-
const searchParams = new URLSearchParams()
276-
277-
const keys = Object.keys(options) as (keyof SearchParamOptions)[]
278-
keys.forEach((key) => {
279-
const value = options[key] ?? ""
280-
searchParams.append(key, value.toString())
281-
})
282-
283-
const searchString = searchParams.toString()
284-
285-
return searchString ? `${basePath}?${searchString}` : basePath
275+
if (options) {
276+
const searchParams = new URLSearchParams()
277+
const keys = Object.keys(options) as (keyof SearchParamOptions)[]
278+
keys.forEach((key) => {
279+
const value = options[key]
280+
if (value !== undefined && value !== "") {
281+
searchParams.append(key, value.toString())
282+
}
283+
})
284+
const searchString = searchParams.toString()
285+
return searchString ? `${basePath}?${searchString}` : basePath
286+
} else {
287+
return basePath
288+
}
286289
}
287290

288291
export const getWorkspaces = async (

0 commit comments

Comments
 (0)