-
Notifications
You must be signed in to change notification settings - Fork 361
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
Changes from 5 commits
2a3693a
2331a7b
8892f3c
9aa365d
dd0f625
609d471
6083e4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ import Button from "react-bootstrap/Button"; | |
|
||
import {GroupHeader} from "../../../../lib/components/auth/nav"; | ||
import {useAPIWithPagination} from "../../../../lib/hooks/api"; | ||
import {auth} from "../../../../lib/api"; | ||
import {auth, MAX_LISTING_AMOUNT} from "../../../../lib/api"; | ||
import {Paginator} from "../../../../lib/components/pagination"; | ||
import {AttachModal} from "../../../../lib/components/auth/forms"; | ||
import {AttachModal, ResolveEntityDisplayName} from "../../../../lib/components/auth/forms"; | ||
import {ConfirmationButton} from "../../../../lib/components/modals"; | ||
import { | ||
ActionGroup, | ||
|
@@ -26,15 +26,41 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => { | |
const [refresh, setRefresh] = useState(false); | ||
const [showAddModal, setShowAddModal] = useState(false); | ||
const [attachError, setAttachError] = useState(null); | ||
|
||
const [allUsers, setAllUsers] = useState([]); | ||
const {results, loading, error, nextPage} = useAPIWithPagination(() => { | ||
return auth.listGroupMembers(groupId, after); | ||
}, [groupId, after, refresh]); | ||
|
||
useEffect(() => { | ||
setAttachError(null); | ||
}, [refresh]); | ||
|
||
const setAllUsersFromLakeFS = async () => { | ||
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. This is not only setting the users, but mainly fetching them. So please rename to |
||
if (allUsers.length > 0) { | ||
return allUsers | ||
} | ||
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. @itaigilo, isn't there some better way to force only one load, with 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. Probably - |
||
after = "" | ||
let hasMore = true | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. What happens after 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 commentThe 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 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. Check out 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 don't think it's the same case. |
||
usersList = usersList.concat(results.results); | ||
after = results.pagination.next_offset; | ||
hasMore = results.pagination.has_more; | ||
} while (hasMore); | ||
usersList.sort((a, b) => ResolveEntityDisplayName(a).localeCompare(ResolveEntityDisplayName(b))); | ||
setAllUsers(usersList); | ||
return usersList; | ||
} catch (error) { | ||
console.error("Error fetching users:", error); | ||
return []; | ||
} | ||
} | ||
const searchUsers = async (prefix, maxResults) => { | ||
let allUsersList = await setAllUsersFromLakeFS() | ||
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. If I get it right, it fetches all the search results from the API for every prefix change? No caching? 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. No, only on the first time we load the "add member" pop-up |
||
let filteredUsers = allUsersList.filter(user => ResolveEntityDisplayName(user).startsWith(prefix)); | ||
return filteredUsers.slice(0, maxResults); | ||
}; | ||
let content; | ||
if (loading) content = <Loading/>; | ||
else if (error) content= <AlertError error={error}/>; | ||
|
@@ -75,7 +101,7 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => { | |
filterPlaceholder={'Find User...'} | ||
modalTitle={'Add to Group'} | ||
addText={'Add to Group'} | ||
searchFn={prefix => auth.listUsers(prefix, "", 5).then(res => res.results)} | ||
searchFn={prefix => searchUsers(prefix, 5).then(res => res)} | ||
onHide={() => setShowAddModal(false)} | ||
onAttach={(selected) => { | ||
Promise.all(selected.map(user => auth.addUserToGroup(user.id, groupId))) | ||
|
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 aresolveDisplayName
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.