-
Notifications
You must be signed in to change notification settings - Fork 360
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
Add friendly name to list group members response #8413
Conversation
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.
spoke offline, please test and ask re-review when done :)
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.
@idanovo thanks for jumping into some UI stuff -
The code is very clear and easy to understand.
Blocking mainly for possible performance issues, since if we're indeed fetching all users, we should make sure we do it only when necessary, to prevent from extra loads.
@@ -9,9 +9,10 @@ import {SearchIcon} from "@primer/octicons-react"; | |||
import {useAPI} from "../../hooks/api"; | |||
import {Checkbox, DataTable, DebouncedFormControl, AlertError, Loading} from "../controls"; | |||
|
|||
const resolveEntityDisplayName = (ent) => { | |||
export const ResolveEntityDisplayName = (ent) => { |
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.
In our JS code (and in React in general), capitalize React components, while functions should be camelCased -
No matter if they are private or public.
(So this one should remain resolveEntityDisplayName
.)
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.
More important:
Now that this func is exported, it seemed to me that it should reside in some utils
file.
Well, apparently, there's already utils.ts
, containing a resolveDisplayName
func 😄
Please unify these.
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.
@itaigilo, I talked with Idan F2F, and mentioned that this resolver method should be provided by the caller, given the fact that this form isn't aware of the caller and that it already mixes between groups and users
WDYT
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.
Not sure this is in the context of this PR...
We can chat about it f2f if you'd like to.
useEffect(() => { | ||
setAttachError(null); | ||
}, [refresh]); | ||
|
||
const setAllUsersFromLakeFS = async () => { |
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.
This is not only setting the users, but mainly fetching them.
This is important, since when I'm calling this function, it should be clear that it gets data from the API.
So please rename to AllUsersFromLakeFS
, or something else that will make it clear that this is about API calls.
let usersList = [] | ||
try { | ||
do { | ||
const results = await auth.listUsers("", after, MAX_LISTING_AMOUNT); |
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.
What happens after MAX_LISTING_AMOUNT
?
Shouldn't we detect this scenario, and at least warn the user in some way?
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.
I run do-while in order to list all the users with pagination
} | ||
} | ||
const searchUsers = async (prefix, maxResults) => { | ||
let allUsersList = await setAllUsersFromLakeFS() |
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.
If I get it right, it fetches all the search results from the API for every prefix change? No caching?
What will happen (performance-wise) in case of 1000 users, for example?
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.
No, only on the first time we load the "add member" pop-up
I load all the objects to the allUsers
which is part of the state of this page
BTW, I've tested my PR with 10K users org and it ran pretty fast
And if I'm taking this up one level, I'm not sure that fetching all the users in the client is the best approach here. |
try { | ||
do { | ||
const results = await auth.listUsers("", after, MAX_LISTING_AMOUNT); |
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.
Check out useAPIWithPagination
I think it reduce a bit of code
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.
I don't think it's the same case.
Here, I need to load all the users, not just a specific page.
The useAPIWithPagination load each time a different page to the state which is not what I need
if (allUsers.length > 0) { | ||
return allUsers | ||
} |
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.
@itaigilo, isn't there some better way to force only one load, with useEffect
or something?
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.
Probably -
But I think that if some caching will be added here, it'll change the flow. Not sure though.
@itaigilo We do it intentionally on the UI, the alternative for this was to change listUsers to not list users by ID (which is the key we use to save the users in the the KV). |
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.
Looking good 😄
Approving to unblock, but please check out my code-style comments.
|
||
export const AttachModal = ({ show, searchFn, onAttach, onHide, addText = "Add", | ||
|
||
export const AttachModal = ({ show, searchFn, onAttach, onHide, resolveEntityFN = (ent => ent.id), addText = "Add", |
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.
Nit:
Should be resolveEntityFN
(since we have searchFn
).
I would also put but Fn params next to each other.
useEffect(() => { | ||
setAttachError(null); | ||
}, [refresh]); | ||
|
||
const allUsersFromLakeFS = async (resolveUserDisplayNameFN = (user => user.id)) => { |
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.
I think this is too much business logic to be in this file -
Well might be useful somewhere else.
How about extracting this?
Even into a file of its own, under components/auth
, for example?
@@ -21,6 +21,12 @@ import { ConfirmationButton } from "../../../../lib/components/modals"; | |||
import { useRouter } from "../../../../lib/hooks/router"; | |||
import { Link } from "../../../../lib/components/nav"; | |||
|
|||
const resolveGroupDisplayName = (group) => { |
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.
🔥
No description provided.