Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
idanovo committed Dec 17, 2024
1 parent 609d471 commit 6083e4b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
6 changes: 3 additions & 3 deletions webui/src/lib/components/auth/forms.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {useAPI} from "../../hooks/api";
import {Checkbox, DataTable, DebouncedFormControl, AlertError, Loading} from "../controls";


export const AttachModal = ({ show, searchFn, onAttach, onHide, resolveEntityFN = (ent => ent.id), addText = "Add",
export const AttachModal = ({ show, searchFn, resolveEntityFn = (ent => ent.id), onAttach, onHide , addText = "Add",
emptyState = 'No matches', modalTitle = 'Add', headers = ['Select', 'ID'],
filterPlaceholder = 'Filter...'}) => {
const search = useRef(null);
Expand Down Expand Up @@ -42,7 +42,7 @@ export const AttachModal = ({ show, searchFn, onAttach, onHide, resolveEntityFN
onAdd={() => setSelected([...selected, ent])}
onRemove={() => setSelected(selected.filter(selectedEnt => selectedEnt.id !== ent.id))}
name={'selected'}/>,
<strong>{resolveEntityFN(ent)}</strong>
<strong>{resolveEntityFn(ent)}</strong>
]}/>

<div className="mt-3">
Expand All @@ -51,7 +51,7 @@ export const AttachModal = ({ show, searchFn, onAttach, onHide, resolveEntityFN
<strong>Selected: </strong>
{(selected.map(item => (
<Badge key={item.id} pill variant="primary" className="me-1">
{resolveEntityFN(item)}
{resolveEntityFn(item)}
</Badge>
)))}
</p>
Expand Down
20 changes: 20 additions & 0 deletions webui/src/lib/components/auth/users.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {auth, MAX_LISTING_AMOUNT} from "../../api";

export const allUsersFromLakeFS = async (resolveUserDisplayNameFN = (user => user.id)) => {
let after = ""
let hasMore = true
let usersList = []
try {
do {
const results = await auth.listUsers("", after, MAX_LISTING_AMOUNT);
usersList = usersList.concat(results.results);
after = results.pagination.next_offset;
hasMore = results.pagination.has_more;
} while (hasMore);
usersList.sort((a, b) => resolveUserDisplayNameFN(a).localeCompare(resolveUserDisplayNameFN(b)));
return usersList;
} catch (error) {
console.error("Error fetching users:", error);
return [];
}
}
34 changes: 9 additions & 25 deletions webui/src/pages/auth/groups/group/members.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Button from "react-bootstrap/Button";

import {GroupHeader} from "../../../../lib/components/auth/nav";
import {useAPIWithPagination} from "../../../../lib/hooks/api";
import {auth, MAX_LISTING_AMOUNT} from "../../../../lib/api";
import {auth} from "../../../../lib/api";
import {Paginator} from "../../../../lib/components/pagination";
import {AttachModal} from "../../../../lib/components/auth/forms";
import {ConfirmationButton} from "../../../../lib/components/modals";
Expand All @@ -20,6 +20,7 @@ import {
import {useRouter} from "../../../../lib/hooks/router";
import {Link} from "../../../../lib/components/nav";
import {resolveUserDisplayName} from "../../../../lib/utils";
import {allUsersFromLakeFS} from "../../../../lib/components/auth/users";


const GroupMemberList = ({ groupId, after, onPaginate }) => {
Expand All @@ -34,30 +35,13 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => {
setAttachError(null);
}, [refresh]);

const allUsersFromLakeFS = async (resolveUserDisplayNameFN = (user => user.id)) => {
if (allUsers.length > 0) {
return allUsers
}
after = ""
let hasMore = true
let usersList = []
try {
do {
const results = await auth.listUsers("", after, MAX_LISTING_AMOUNT);
usersList = usersList.concat(results.results);
after = results.pagination.next_offset;
hasMore = results.pagination.has_more;
} while (hasMore);
usersList.sort((a, b) => resolveUserDisplayNameFN(a).localeCompare(resolveUserDisplayNameFN(b)));
setAllUsers(usersList);
return usersList;
} catch (error) {
console.error("Error fetching users:", error);
return [];
}
}

const searchUsers = async (prefix, maxResults, resolveUserDisplayNameFN = (user => user.id)) => {
let allUsersList = await allUsersFromLakeFS(resolveUserDisplayNameFN)
let allUsersList = allUsers;
if (allUsersList.length == 0) {

Check warning on line 41 in webui/src/pages/auth/groups/group/members.jsx

View workflow job for this annotation

GitHub Actions / Analyze

Expected '===' and instead saw '=='

Check warning on line 41 in webui/src/pages/auth/groups/group/members.jsx

View workflow job for this annotation

GitHub Actions / Test React App

Expected '===' and instead saw '=='

Check warning on line 41 in webui/src/pages/auth/groups/group/members.jsx

View workflow job for this annotation

GitHub Actions / Run Linters and Checkers

Expected '===' and instead saw '=='

Check warning on line 41 in webui/src/pages/auth/groups/group/members.jsx

View workflow job for this annotation

GitHub Actions / Run Linters and Checkers

Expected '===' and instead saw '=='

Check warning on line 41 in webui/src/pages/auth/groups/group/members.jsx

View workflow job for this annotation

GitHub Actions / Generate code from latest lakeFS app

Expected '===' and instead saw '=='
allUsersList = await allUsersFromLakeFS(resolveUserDisplayNameFN)
setAllUsers(allUsersList)
}
let filteredUsers = allUsersList.filter(user => resolveUserDisplayNameFN(user).startsWith(prefix));
return filteredUsers.slice(0, maxResults);
};
Expand Down Expand Up @@ -101,7 +85,7 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => {
filterPlaceholder={'Find User...'}
modalTitle={'Add to Group'}
addText={'Add to Group'}
resolveEntityFN={resolveUserDisplayName}
resolveEntityFn={resolveUserDisplayName}
searchFn={prefix => searchUsers(prefix, 5, resolveUserDisplayName).then(res => res)}
onHide={() => setShowAddModal(false)}
onAttach={(selected) => {
Expand Down
2 changes: 1 addition & 1 deletion webui/src/pages/auth/users/user/groups.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const UserGroupsList = ({ userId, after, onPaginate }) => {
searchFn={(prefix) =>
auth.listGroups(prefix, "", 5).then((res) => res.results)
}
resolveEntityFN={resolveGroupDisplayName}
resolveEntityFn={resolveGroupDisplayName}
onHide={() => setShowAddModal(false)}
onAttach={(selected) => {
Promise.all(
Expand Down

0 comments on commit 6083e4b

Please sign in to comment.