Skip to content

Commit 4717f84

Browse files
committed
refactor code
1 parent 93c8eb1 commit 4717f84

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

site/src/api/api.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,25 @@ describe("api.ts", () => {
114114
})
115115
})
116116

117-
describe("getURLWithSearchParams", () => {
118-
it.each<[string, TypesGen.WorkspaceFilter | TypesGen.UsersRequest | undefined, string]>([
117+
describe("getURLWithSearchParams - workspaces", () => {
118+
it.each<[string, TypesGen.WorkspaceFilter | undefined, string]>([
119119
["/api/v2/workspaces", undefined, "/api/v2/workspaces"],
120120

121121
["/api/v2/workspaces", { q: "" }, "/api/v2/workspaces"],
122122
["/api/v2/workspaces", { q: "owner:1" }, "/api/v2/workspaces?q=owner%3A1"],
123123

124124
["/api/v2/workspaces", { q: "owner:me" }, "/api/v2/workspaces?q=owner%3Ame"],
125+
])(`Workspaces - getURLWithSearchParams(%p, %p) returns %p`, (basePath, filter, expected) => {
126+
expect(getURLWithSearchParams(basePath, filter)).toBe(expected)
127+
})
128+
})
125129

130+
describe("getURLWithSearchParams - users", () => {
131+
it.each<[string, TypesGen.UsersRequest | undefined, string]>([
132+
["/api/v2/users", undefined, "/api/v2/users"],
126133
["/api/v2/users", { q: "status:active" }, "/api/v2/users?q=status%3Aactive"],
127134
["/api/v2/users", { q: "" }, "/api/v2/users"],
128-
])(`getURLWithSearchParams(%p) returns %p`, (basePath, filter, expected) => {
135+
])(`Users - getURLWithSearchParams(%p, %p) returns %p`, (basePath, filter, expected) => {
129136
expect(getURLWithSearchParams(basePath, filter)).toBe(expected)
130137
})
131138
})

site/src/api/errors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ export const getErrorMessage = (
7272
? error.message
7373
: defaultMessage
7474

75+
/**
76+
*
77+
* @param error
78+
* @returns a combined validation error message if the error is an ApiError
79+
* and contains validation messages for different form fields.
80+
*/
7581
export const getValidationErrorMessage = (error: Error | ApiError | unknown): string => {
7682
const validationErrors =
7783
isApiError(error) && error.response.data.validations ? error.response.data.validations : []

site/src/pages/UsersPage/UsersPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const UsersPage: React.FC = () => {
5050
// Fetch users on component mount
5151
useEffect(() => {
5252
const filter = searchParams.get("filter")
53-
const query = filter !== null ? filter : userFilterQuery.active
53+
const query = filter ?? userFilterQuery.active
5454
usersSend({
5555
type: "GET_USERS",
5656
query,

site/src/pages/WorkspacesPage/WorkspacesPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const WorkspacesPage: FC = () => {
1414

1515
useEffect(() => {
1616
const filter = searchParams.get("filter")
17-
const query = filter !== null ? filter : workspaceFilterQuery.me
17+
const query = filter ?? workspaceFilterQuery.me
1818

1919
send({
2020
type: "GET_WORKSPACES",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy