Skip to content

Commit 609d471

Browse files
committed
Review changes
1 parent dd0f625 commit 609d471

File tree

6 files changed

+29
-28
lines changed

6 files changed

+29
-28
lines changed

webui/src/lib/components/auth/forms.jsx

+4-12
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,8 @@ import {SearchIcon} from "@primer/octicons-react";
99
import {useAPI} from "../../hooks/api";
1010
import {Checkbox, DataTable, DebouncedFormControl, AlertError, Loading} from "../controls";
1111

12-
export const ResolveEntityDisplayName = (ent) => {
13-
// for users
14-
if (ent?.email?.length) return ent.email;
15-
if (ent?.friendly_name?.length) return ent.friendly_name;
16-
// for groups
17-
if (ent?.name?.length) return ent.name;
18-
return ent.id;
19-
}
20-
21-
export const AttachModal = ({ show, searchFn, onAttach, onHide, addText = "Add",
12+
13+
export const AttachModal = ({ show, searchFn, onAttach, onHide, resolveEntityFN = (ent => ent.id), addText = "Add",
2214
emptyState = 'No matches', modalTitle = 'Add', headers = ['Select', 'ID'],
2315
filterPlaceholder = 'Filter...'}) => {
2416
const search = useRef(null);
@@ -50,7 +42,7 @@ export const AttachModal = ({ show, searchFn, onAttach, onHide, addText = "Add",
5042
onAdd={() => setSelected([...selected, ent])}
5143
onRemove={() => setSelected(selected.filter(selectedEnt => selectedEnt.id !== ent.id))}
5244
name={'selected'}/>,
53-
<strong>{ResolveEntityDisplayName(ent)}</strong>
45+
<strong>{resolveEntityFN(ent)}</strong>
5446
]}/>
5547

5648
<div className="mt-3">
@@ -59,7 +51,7 @@ export const AttachModal = ({ show, searchFn, onAttach, onHide, addText = "Add",
5951
<strong>Selected: </strong>
6052
{(selected.map(item => (
6153
<Badge key={item.id} pill variant="primary" className="me-1">
62-
{ResolveEntityDisplayName(item)}
54+
{resolveEntityFN(item)}
6355
</Badge>
6456
)))}
6557
</p>

webui/src/lib/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface User {
44
friendly_name: string;
55
}
66

7-
export const resolveDisplayName = (user: User): string => {
7+
export const resolveUserDisplayName = (user: User): string => {
88
if (!user) return "";
99
if (user?.email?.length) return user.email;
1010
if (user?.friendly_name?.length) return user.friendly_name;

webui/src/pages/auth/credentials.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {auth} from "../../lib/api";
1212
import {useState} from "react";
1313
import {CredentialsShowModal, CredentialsTable} from "../../lib/components/auth/credentials";
1414
import {useRouter} from "../../lib/hooks/router";
15-
import {resolveDisplayName} from "../../lib/utils";
15+
import {resolveUserDisplayName} from "../../lib/utils";
1616

1717
const CredentialsContainer = () => {
1818
const router = useRouter();
@@ -40,7 +40,7 @@ const CredentialsContainer = () => {
4040
<ConfirmationButton
4141
variant="success"
4242
modalVariant="success"
43-
msg={<span>Create a new Access Key for user <strong>{resolveDisplayName(user)}</strong>?</span>}
43+
msg={<span>Create a new Access Key for user <strong>{resolveUserDisplayName(user)}</strong>?</span>}
4444
onConfirm={hide => {
4545
createKey()
4646
.then(key => { setCreatedKey(key) })

webui/src/pages/auth/groups/group/members.jsx

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {GroupHeader} from "../../../../lib/components/auth/nav";
66
import {useAPIWithPagination} from "../../../../lib/hooks/api";
77
import {auth, MAX_LISTING_AMOUNT} from "../../../../lib/api";
88
import {Paginator} from "../../../../lib/components/pagination";
9-
import {AttachModal, ResolveEntityDisplayName} from "../../../../lib/components/auth/forms";
9+
import {AttachModal} from "../../../../lib/components/auth/forms";
1010
import {ConfirmationButton} from "../../../../lib/components/modals";
1111
import {
1212
ActionGroup,
@@ -19,7 +19,7 @@ import {
1919
} from "../../../../lib/components/controls";
2020
import {useRouter} from "../../../../lib/hooks/router";
2121
import {Link} from "../../../../lib/components/nav";
22-
import {resolveDisplayName} from "../../../../lib/utils";
22+
import {resolveUserDisplayName} from "../../../../lib/utils";
2323

2424

2525
const GroupMemberList = ({ groupId, after, onPaginate }) => {
@@ -34,7 +34,7 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => {
3434
setAttachError(null);
3535
}, [refresh]);
3636

37-
const setAllUsersFromLakeFS = async () => {
37+
const allUsersFromLakeFS = async (resolveUserDisplayNameFN = (user => user.id)) => {
3838
if (allUsers.length > 0) {
3939
return allUsers
4040
}
@@ -48,17 +48,17 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => {
4848
after = results.pagination.next_offset;
4949
hasMore = results.pagination.has_more;
5050
} while (hasMore);
51-
usersList.sort((a, b) => ResolveEntityDisplayName(a).localeCompare(ResolveEntityDisplayName(b)));
51+
usersList.sort((a, b) => resolveUserDisplayNameFN(a).localeCompare(resolveUserDisplayNameFN(b)));
5252
setAllUsers(usersList);
5353
return usersList;
5454
} catch (error) {
5555
console.error("Error fetching users:", error);
5656
return [];
5757
}
5858
}
59-
const searchUsers = async (prefix, maxResults) => {
60-
let allUsersList = await setAllUsersFromLakeFS()
61-
let filteredUsers = allUsersList.filter(user => ResolveEntityDisplayName(user).startsWith(prefix));
59+
const searchUsers = async (prefix, maxResults, resolveUserDisplayNameFN = (user => user.id)) => {
60+
let allUsersList = await allUsersFromLakeFS(resolveUserDisplayNameFN)
61+
let filteredUsers = allUsersList.filter(user => resolveUserDisplayNameFN(user).startsWith(prefix));
6262
return filteredUsers.slice(0, maxResults);
6363
};
6464
let content;
@@ -71,7 +71,7 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => {
7171
<DataTable
7272
keyFn={user => user.id}
7373
rowFn={user => [
74-
<Link href={{pathname: '/auth/users/:userId', params: {userId: user.id}}}>{resolveDisplayName(user)}</Link>,
74+
<Link href={{pathname: '/auth/users/:userId', params: {userId: user.id}}}>{resolveUserDisplayName(user)}</Link>,
7575
<FormattedDate dateValue={user.creation_date}/>
7676
]}
7777
headers={['User ID', 'Created At']}
@@ -80,7 +80,7 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => {
8080
buttonFn: user => <ConfirmationButton
8181
size="sm"
8282
variant="outline-danger"
83-
msg={<span>Are you sure you{'\''}d like to remove user <strong>{resolveDisplayName(user)}</strong> from group <strong>{groupId}</strong>?</span>}
83+
msg={<span>Are you sure you{'\''}d like to remove user <strong>{resolveUserDisplayName(user)}</strong> from group <strong>{groupId}</strong>?</span>}
8484
onConfirm={() => {
8585
auth.removeUserFromGroup(user.id, groupId)
8686
.catch(error => alert(error))
@@ -101,7 +101,8 @@ const GroupMemberList = ({ groupId, after, onPaginate }) => {
101101
filterPlaceholder={'Find User...'}
102102
modalTitle={'Add to Group'}
103103
addText={'Add to Group'}
104-
searchFn={prefix => searchUsers(prefix, 5).then(res => res)}
104+
resolveEntityFN={resolveUserDisplayName}
105+
searchFn={prefix => searchUsers(prefix, 5, resolveUserDisplayName).then(res => res)}
105106
onHide={() => setShowAddModal(false)}
106107
onAttach={(selected) => {
107108
Promise.all(selected.map(user => auth.addUserToGroup(user.id, groupId)))

webui/src/pages/auth/users/index.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from "../../../lib/components/controls";
2525
import validator from "validator/es";
2626
import { disallowPercentSign, INVALID_USER_NAME_ERROR_MESSAGE } from "../validation";
27-
import { resolveDisplayName } from "../../../lib/utils";
27+
import { resolveUserDisplayName } from "../../../lib/utils";
2828

2929
const USER_NOT_FOUND = "unknown";
3030
export const GetUserEmailByIdContext = createContext();
@@ -119,7 +119,7 @@ const UsersContainer = ({nextPage, refresh, setRefresh, error, loading, userList
119119
onRemove={() => setSelected(selected.filter(u => u !== user))}
120120
/>,
121121
<Link href={{pathname: '/auth/users/:userId', params: {userId: user.id}}}>
122-
{ resolveDisplayName(user) }
122+
{ resolveUserDisplayName(user) }
123123
</Link>,
124124
<FormattedDate dateValue={user.creation_date}/>
125125
]}/>

webui/src/pages/auth/users/user/groups.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ import { ConfirmationButton } from "../../../../lib/components/modals";
2121
import { useRouter } from "../../../../lib/hooks/router";
2222
import { Link } from "../../../../lib/components/nav";
2323

24+
const resolveGroupDisplayName = (group) => {
25+
if(!group) return "";
26+
if (group?.name?.length) return group.name;
27+
return group.id;
28+
}
29+
2430
const UserGroupsList = ({ userId, after, onPaginate }) => {
2531
const [refresh, setRefresh] = useState(false);
2632
const [showAddModal, setShowAddModal] = useState(false);
@@ -97,6 +103,7 @@ const UserGroupsList = ({ userId, after, onPaginate }) => {
97103
searchFn={(prefix) =>
98104
auth.listGroups(prefix, "", 5).then((res) => res.results)
99105
}
106+
resolveEntityFN={resolveGroupDisplayName}
100107
onHide={() => setShowAddModal(false)}
101108
onAttach={(selected) => {
102109
Promise.all(
@@ -112,7 +119,8 @@ const UserGroupsList = ({ userId, after, onPaginate }) => {
112119
.finally(() => {
113120
setShowAddModal(false);
114121
});
115-
}}
122+
}
123+
}
116124
/>
117125
)}
118126
</>

0 commit comments

Comments
 (0)