- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
acbd54a
be7eaac
186425e
bfbf729
3f309aa
a7f7171
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import axios from "axios" | ||
import { getApiKey,getURLWithSearchParams, login, logout } from "./api" | ||
import * as TypesGen from "./typesGenerated" | ||
describe("api.ts", () => { | ||
@@ -114,16 +114,26 @@ describe("api.ts", () => { | ||
}) | ||
}) | ||
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"], | ||
])(`Users - getURLWithSearchParams(%p, %p) returns %p`, (basePath, filter, expected) => { | ||
expect(getURLWithSearchParams(basePath, filter)).toBe(expected) | ||
AbhineetJain marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {getValidationErrorMessage,isApiError, mapApiErrorToFieldErrors } from "./errors" | ||
describe("isApiError", () => { | ||
it("returns true when the object is an API Error", () => { | ||
@@ -36,3 +36,57 @@ describe("mapApiErrorToFieldErrors", () => { | ||
}) | ||
}) | ||
}) | ||
describe("getValidationErrorMessage", () => { | ||
it("returns multiple validation messages", () => { | ||
expect( | ||
getValidationErrorMessage({ | ||
response: { | ||
data: { | ||
message: "Invalid user search query.", | ||
validations: [ | ||
{ | ||
field: "status", | ||
detail: `Query param "status" has invalid value: "inactive" is not a valid user status`, | ||
}, | ||
{ | ||
field: "q", | ||
detail: `Query element "role:a:e" can only contain 1 ':'`, | ||
}, | ||
], | ||
}, | ||
}, | ||
isAxiosError: true, | ||
}), | ||
).toEqual( | ||
`Query param "status" has invalid value: "inactive" is not a valid user status\nQuery element "role:a:e" can only contain 1 ':'`, | ||
) | ||
}) | ||
it("non-API error returns empty validation message", () => { | ||
expect( | ||
getValidationErrorMessage({ | ||
response: { | ||
data: { | ||
error: "Invalid user search query.", | ||
}, | ||
}, | ||
isAxiosError: true, | ||
}), | ||
).toEqual("") | ||
}) | ||
it("no validations field returns empty validation message", () => { | ||
expect( | ||
getValidationErrorMessage({ | ||
response: { | ||
data: { | ||
message: "Invalid user search query.", | ||
detail: `Query element "role:a:e" can only contain 1 ':'`, | ||
}, | ||
}, | ||
isAxiosError: true, | ||
}), | ||
).toEqual("") | ||
Kira-Pilot marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -71,3 +71,15 @@ export const getErrorMessage = ( | ||
: error instanceof Error | ||
? 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 : [] | ||
return validationErrors.map((error) => error.detail).join("\n") | ||
} | ||
AbhineetJain marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -28,3 +28,13 @@ Empty.args = { | ||
users: [], | ||
roles: MockSiteRoles, | ||
} | ||
export const Loading = Template.bind({}) | ||
Loading.args = { | ||
users: [], | ||
roles: MockSiteRoles, | ||
isLoading: true, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I like this story since it tests a particular behavior of the component, but I am not sure if it is a good UI snapshot since the loader is spinning and the snapshot may change across different builds. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Good thought. I haven't read through this in detail, but could we pause the animation for the loader? Or introduce a slight delay?https://www.chromatic.com/docs/animations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Thanks for pointing to this, I used Loading.parameters={chromatic:{pauseAnimationAtEnd:true},} and it seems to be constant for at least 3 builds. | ||
Loading.parameters = { | ||
chromatic: { pauseAnimationAtEnd: true }, | ||
} |
Uh oh!
There was an error while loading.Please reload this page.