Skip to content

feat: Add filter on Users page #2653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor code
  • Loading branch information
AbhineetJain committed Jun 28, 2022
commit bfbf72925e94222dcbc8b2fc27bf0ad36dd0f4ad
13 changes: 10 additions & 3 deletions site/src/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,25 @@ describe("api.ts", () => {
})
})

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

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

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

describe("getURLWithSearchParams - users", () => {
it.each<[string, TypesGen.UsersRequest | undefined, string]>([
["/api/v2/users", undefined, "/api/v2/users"],
["/api/v2/users", { q: "status:active" }, "/api/v2/users?q=status%3Aactive"],
["/api/v2/users", { q: "" }, "/api/v2/users"],
])(`getURLWithSearchParams(%p) returns %p`, (basePath, filter, expected) => {
])(`Users - getURLWithSearchParams(%p, %p) returns %p`, (basePath, filter, expected) => {
expect(getURLWithSearchParams(basePath, filter)).toBe(expected)
})
})
Expand Down
6 changes: 6 additions & 0 deletions site/src/api/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export const getErrorMessage = (
? error.message
: defaultMessage

/**
*
* @param error
* @returns a combined validation error message if the error is an ApiError
* and contains validation messages for different form fields.
*/
export const getValidationErrorMessage = (error: Error | ApiError | unknown): string => {
const validationErrors =
isApiError(error) && error.response.data.validations ? error.response.data.validations : []
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/UsersPage/UsersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const UsersPage: React.FC = () => {
// Fetch users on component mount
useEffect(() => {
const filter = searchParams.get("filter")
const query = filter !== null ? filter : userFilterQuery.active
const query = filter ?? userFilterQuery.active
usersSend({
type: "GET_USERS",
query,
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const WorkspacesPage: FC = () => {

useEffect(() => {
const filter = searchParams.get("filter")
const query = filter !== null ? filter : workspaceFilterQuery.me
const query = filter ?? workspaceFilterQuery.me

send({
type: "GET_WORKSPACES",
Expand Down