-
Notifications
You must be signed in to change notification settings - Fork 894
feat(site): add new filter to audit logs #7878
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bf39e76
Add basic filter for audit
BrunoQuaresma 5c47bdf
Add action filter
BrunoQuaresma 529ef8c
Add ilters
BrunoQuaresma de52a02
Remove machine
BrunoQuaresma de435b1
Merge branch 'main' into bq/add-filter-to-audit-logs
BrunoQuaresma 48cac76
Fix tests
BrunoQuaresma b86831f
Fix stories
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add basic filter for audit
- Loading branch information
commit bf39e76c677b25baa915738a2d3d1f6c842c59e6
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { useMe } from "hooks" | ||
import { BaseOption } from "./options" | ||
import { getUsers } from "api/api" | ||
import { UseFilterMenuOptions, useFilterMenu } from "./menu" | ||
import { FilterSearchMenu, OptionItem } from "./filter" | ||
import { UserAvatar } from "components/UserAvatar/UserAvatar" | ||
|
||
export type UserOption = BaseOption & { | ||
avatarUrl?: string | ||
} | ||
|
||
export const useUserFilterMenu = ({ | ||
value, | ||
onChange, | ||
enabled, | ||
}: Pick< | ||
UseFilterMenuOptions<UserOption>, | ||
"value" | "onChange" | "enabled" | ||
>) => { | ||
const me = useMe() | ||
|
||
const addMeAsFirstOption = (options: UserOption[]) => { | ||
options = options.filter((option) => option.value !== me.username) | ||
return [ | ||
{ label: me.username, value: me.username, avatarUrl: me.avatar_url }, | ||
...options, | ||
] | ||
} | ||
|
||
return useFilterMenu({ | ||
onChange, | ||
enabled, | ||
value, | ||
id: "owner", | ||
getSelectedOption: async () => { | ||
const usersRes = await getUsers({ q: value, limit: 1 }) | ||
const firstUser = usersRes.users.at(0) | ||
if (firstUser && firstUser.username === value) { | ||
return { | ||
label: firstUser.username, | ||
value: firstUser.username, | ||
avatarUrl: firstUser.avatar_url, | ||
} | ||
} | ||
return null | ||
}, | ||
getOptions: async (query) => { | ||
const usersRes = await getUsers({ q: query, limit: 25 }) | ||
let options: UserOption[] = usersRes.users.map((user) => ({ | ||
label: user.username, | ||
value: user.username, | ||
avatarUrl: user.avatar_url, | ||
})) | ||
options = addMeAsFirstOption(options) | ||
return options | ||
}, | ||
}) | ||
} | ||
|
||
export type UserFilterMenu = ReturnType<typeof useUserFilterMenu> | ||
|
||
export const UserMenu = (menu: UserFilterMenu) => { | ||
return ( | ||
<FilterSearchMenu | ||
id="users-menu" | ||
menu={menu} | ||
label={ | ||
menu.selectedOption ? ( | ||
<UserOptionItem option={menu.selectedOption} /> | ||
) : ( | ||
"All users" | ||
) | ||
} | ||
> | ||
{(itemProps) => <UserOptionItem {...itemProps} />} | ||
</FilterSearchMenu> | ||
) | ||
} | ||
|
||
const UserOptionItem = ({ | ||
option, | ||
isSelected, | ||
}: { | ||
option: UserOption | ||
isSelected?: boolean | ||
}) => { | ||
return ( | ||
<OptionItem | ||
option={option} | ||
isSelected={isSelected} | ||
left={ | ||
<UserAvatar | ||
username={option.label} | ||
avatarURL={option.avatarUrl} | ||
sx={{ width: 16, height: 16, fontSize: 8 }} | ||
/> | ||
} | ||
/> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { UserFilterMenu, UserMenu } from "components/Filter/UserFilter" | ||
import { | ||
Filter, | ||
MenuSkeleton, | ||
SearchFieldSkeleton, | ||
useFilter, | ||
} from "components/Filter/filter" | ||
|
||
export const AuditFilter = ({ | ||
filter, | ||
error, | ||
menus, | ||
}: { | ||
filter: ReturnType<typeof useFilter> | ||
error?: unknown | ||
menus: { | ||
user: UserFilterMenu | ||
} | ||
}) => { | ||
return ( | ||
<Filter | ||
isLoading={menus.user.isInitializing} | ||
filter={filter} | ||
error={error} | ||
options={<UserMenu {...menus.user} />} | ||
skeleton={ | ||
<> | ||
<SearchFieldSkeleton /> | ||
<MenuSkeleton /> | ||
</> | ||
} | ||
/> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call
getUsers
here, and also on line 48. Curious why we can't just make one call to grab all users and then filter on the user we want forgetSelectedOption
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, let's say we have a user called Wesley, Wesley is probably one of the last users to be queried in the database, so when we display the autocomplete options for the users, maybe Wesley is not shown because we only show the first 25 results. So making a separate query to get the selected value, in this case Wesley, is safer and we can be sure we are going to find it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, thanks for explaining!