|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useCallback } from 'react';
|
|
|
+import React, { useCallback, useMemo } from 'react';
|
|
|
|
|
|
import { GroupType } from '@growi/core';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
@@ -31,21 +31,29 @@ const SelectUserGroupModalSubstance: React.FC<Props> = (props: Props) => {
|
|
|
return selectedUserGroupIds.includes(targetUserGroup.item._id);
|
|
|
}, [selectedUserGroups]);
|
|
|
|
|
|
+ // Memoize user group list
|
|
|
+ const userGroupList = useMemo(() => {
|
|
|
+ if (userRelatedGroups == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return userRelatedGroups.map(userGroup => (
|
|
|
+ <button
|
|
|
+ className="btn btn-outline-primary d-flex justify-content-start mb-3 mx-4 align-items-center p-3"
|
|
|
+ type="button"
|
|
|
+ key={userGroup.item._id}
|
|
|
+ onClick={() => onSelect(userGroup)}
|
|
|
+ >
|
|
|
+ <input type="checkbox" checked={checked(userGroup)} onChange={() => {}} />
|
|
|
+ <p className="ms-3 mb-0">{userGroup.item.name}</p>
|
|
|
+ {userGroup.type === GroupType.externalUserGroup && <span className="ms-2 badge badge-pill badge-info">{userGroup.item.provider}</span>}
|
|
|
+ {/* TODO: Replace <div className="small">(TBD) List group members</div> */}
|
|
|
+ </button>
|
|
|
+ ));
|
|
|
+ }, [userRelatedGroups, onSelect, checked]);
|
|
|
+
|
|
|
return (
|
|
|
<ModalBody className="d-flex flex-column">
|
|
|
- {userRelatedGroups != null && userRelatedGroups.map(userGroup => (
|
|
|
- <button
|
|
|
- className="btn btn-outline-primary d-flex justify-content-start mb-3 mx-4 align-items-center p-3"
|
|
|
- type="button"
|
|
|
- key={userGroup.item._id}
|
|
|
- onClick={() => onSelect(userGroup)}
|
|
|
- >
|
|
|
- <input type="checkbox" checked={checked(userGroup)} onChange={() => {}} />
|
|
|
- <p className="ms-3 mb-0">{userGroup.item.name}</p>
|
|
|
- {userGroup.type === GroupType.externalUserGroup && <span className="ms-2 badge badge-pill badge-info">{userGroup.item.provider}</span>}
|
|
|
- {/* TODO: Replace <div className="small">(TBD) List group members</div> */}
|
|
|
- </button>
|
|
|
- ))}
|
|
|
+ {userGroupList}
|
|
|
<button
|
|
|
type="button"
|
|
|
className="btn btn-primary mt-2 mx-auto"
|
|
|
@@ -63,6 +71,11 @@ export const SelectUserGroupModal: React.FC<Props> = (props) => {
|
|
|
|
|
|
const { isOpen, closeModal } = props;
|
|
|
|
|
|
+ // Early return optimization
|
|
|
+ if (!isOpen) {
|
|
|
+ return <></>;
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<Modal isOpen={isOpen} toggle={closeModal}>
|
|
|
<ModalHeader toggle={closeModal}>
|