Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3362085
D11208.id38199.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D11208.id38199.diff
View Options
diff --git a/lib/utils/role-utils.js b/lib/utils/role-utils.js
--- a/lib/utils/role-utils.js
+++ b/lib/utils/role-utils.js
@@ -38,26 +38,6 @@
return message;
}
-type RoleDeletableAndEditableStatus = {
- +isDeletable: boolean,
- +isEditable: boolean,
-};
-function useRoleDeletableAndEditableStatus(
- roleName: string,
- defaultRoleID: string,
- existingRoleID: string,
-): RoleDeletableAndEditableStatus {
- return React.useMemo(() => {
- const canDelete = roleName !== 'Admins' && defaultRoleID !== existingRoleID;
- const canEdit = roleName !== 'Admins';
-
- return {
- isDeletable: canDelete,
- isEditable: canEdit,
- };
- }, [roleName, defaultRoleID, existingRoleID]);
-}
-
function useRolesFromCommunityThreadInfo(
threadInfo: ThreadInfo,
memberInfos: $ReadOnlyArray<RelativeMemberInfo>,
@@ -154,7 +134,6 @@
export {
constructRoleDeletionMessagePrompt,
- useRoleDeletableAndEditableStatus,
useRolesFromCommunityThreadInfo,
toggleUserSurfacedPermission,
useMembersGroupedByRole,
diff --git a/web/roles/role-actions-menu.react.js b/web/roles/role-actions-menu.react.js
--- a/web/roles/role-actions-menu.react.js
+++ b/web/roles/role-actions-menu.react.js
@@ -6,6 +6,7 @@
import { useModalContext } from 'lib/components/modal-provider.react.js';
import SWMansionIcon from 'lib/components/swmansion-icon.react.js';
import {
+ roleIsAdminRole,
roleIsDefaultRole,
useRoleUserSurfacedPermissions,
} from 'lib/shared/thread-utils.js';
@@ -14,7 +15,6 @@
ThreadInfo,
} from 'lib/types/minimally-encoded-thread-permissions-types.js';
import { values } from 'lib/utils/objects.js';
-import { useRoleDeletableAndEditableStatus } from 'lib/utils/role-utils.js';
import CreateRolesModal from './create-roles-modal.react.js';
import DeleteRoleModal from './delete-role-modal.react.js';
@@ -43,12 +43,6 @@
);
invariant(existingRole, 'existing role should exist');
- const roleOptions = useRoleDeletableAndEditableStatus(
- roleName,
- defaultRoleID,
- existingRole.id,
- );
-
const roleNamesToUserSurfacedPermissions =
useRoleUserSurfacedPermissions(threadInfo);
@@ -83,9 +77,8 @@
const menuItems = React.useMemo(() => {
const availableOptions = [];
- const { isDeletable, isEditable } = roleOptions;
- if (isEditable) {
+ if (!roleIsAdminRole(existingRole)) {
availableOptions.push(
<MenuItem
key="Edit role"
@@ -97,7 +90,7 @@
);
}
- if (isDeletable) {
+ if (!roleIsAdminRole(existingRole) && !roleIsDefaultRole(existingRole)) {
availableOptions.push(
<MenuItem
key="Delete role"
@@ -110,7 +103,7 @@
}
return availableOptions;
- }, [roleOptions, openDeleteRoleModal, openEditRoleModal]);
+ }, [existingRole, openEditRoleModal, openDeleteRoleModal]);
return (
<div className={css.menuContainer}>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 9:21 PM (20 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2581006
Default Alt Text
D11208.id38199.diff (2 KB)
Attached To
Mode
D11208: [lib] Deprecate `useRoleDeletableAndEditableStatus` and determine `is[Editable/Deletable]` directly in `RoleActionsMenu`
Attached
Detach File
Event Timeline
Log In to Comment