Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3383176
D11205.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D11205.diff
View Options
diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -34,6 +34,7 @@
threadPermissionsFromBitmaskHex,
} from '../permissions/minimally-encoded-thread-permissions.js';
import { specialRoles } from '../permissions/special-roles.js';
+import type { SpecialRole } from '../permissions/special-roles.js';
import {
permissionLookup,
getAllThreadPermissions,
@@ -121,7 +122,7 @@
type ThreadEntity,
type UserEntity,
} from '../utils/entity-text.js';
-import { entries } from '../utils/objects.js';
+import { entries, values } from '../utils/objects.js';
import {
useDispatchActionPromise,
type DispatchActionPromise,
@@ -1711,6 +1712,27 @@
}, [threadInfo.members, threadInfo.roles]);
}
+function useRoleNamesToSpecialRole(threadInfo: ThreadInfo): {
+ +[roleName: string]: ?SpecialRole,
+} {
+ return React.useMemo(() => {
+ const roleNamesToSpecialRole: { [roleName: string]: ?SpecialRole } = {};
+ values(threadInfo.roles).forEach(role => {
+ if (roleNamesToSpecialRole[role.name] !== undefined) {
+ return;
+ }
+ if (roleIsDefaultRole(role)) {
+ roleNamesToSpecialRole[role.name] = specialRoles.DEFAULT_ROLE;
+ } else if (roleIsAdminRole(role)) {
+ roleNamesToSpecialRole[role.name] = specialRoles.ADMIN_ROLE;
+ } else {
+ roleNamesToSpecialRole[role.name] = null;
+ }
+ });
+ return roleNamesToSpecialRole;
+ }, [threadInfo.roles]);
+}
+
type RoleUserSurfacedPermissions = {
+[roleName: string]: $ReadOnlySet<UserSurfacedPermission>,
};
@@ -1900,6 +1922,7 @@
patchThreadInfoToIncludeMentionedMembersOfParent,
threadInfoInsideCommunity,
useRoleMemberCountsForCommunity,
+ useRoleNamesToSpecialRole,
useRoleUserSurfacedPermissions,
getThreadsToDeleteText,
useUserProfileThreadInfo,
diff --git a/native/roles/community-roles-screen.react.js b/native/roles/community-roles-screen.react.js
--- a/native/roles/community-roles-screen.react.js
+++ b/native/roles/community-roles-screen.react.js
@@ -7,6 +7,7 @@
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js';
import {
useRoleMemberCountsForCommunity,
+ useRoleNamesToSpecialRole,
useRoleUserSurfacedPermissions,
} from 'lib/shared/thread-utils.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
@@ -51,6 +52,7 @@
const styles = useStyles(unboundStyles);
const roleNamesToMembers = useRoleMemberCountsForCommunity(threadInfo);
+ const roleNamesToSpecialRole = useRoleNamesToSpecialRole(threadInfo);
const roleNamesToUserSurfacedPermissions =
useRoleUserSurfacedPermissions(threadInfo);
@@ -65,6 +67,7 @@
navigation={props.navigation}
threadInfo={threadInfo}
roleName={roleName}
+ specialRole={roleNamesToSpecialRole[roleName]}
rolePermissions={roleNamesToUserSurfacedPermissions[roleName]}
memberCount={roleNamesToMembers[roleName]}
/>,
@@ -76,6 +79,7 @@
roleNamesToMembers,
props.navigation,
threadInfo,
+ roleNamesToSpecialRole,
roleNamesToUserSurfacedPermissions,
]);
diff --git a/native/roles/role-panel-entry.react.js b/native/roles/role-panel-entry.react.js
--- a/native/roles/role-panel-entry.react.js
+++ b/native/roles/role-panel-entry.react.js
@@ -6,6 +6,8 @@
import { Platform, Text, TouchableOpacity, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
+import type { SpecialRole } from 'lib/permissions/special-roles.js';
+import { specialRoles } from 'lib/permissions/special-roles.js';
import { roleIsDefaultRole } from 'lib/shared/thread-utils.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import type { UserSurfacedPermission } from 'lib/types/thread-permission-types.js';
@@ -22,13 +24,20 @@
+navigation: RolesNavigationProp<'CommunityRolesScreen'>,
+threadInfo: ThreadInfo,
+roleName: string,
+ +specialRole: ?SpecialRole,
+rolePermissions: $ReadOnlySet<UserSurfacedPermission>,
+memberCount: number,
};
function RolePanelEntry(props: RolePanelEntryProps): React.Node {
- const { navigation, threadInfo, roleName, rolePermissions, memberCount } =
- props;
+ const {
+ navigation,
+ threadInfo,
+ roleName,
+ specialRole,
+ rolePermissions,
+ memberCount,
+ } = props;
const styles = useStyles(unboundStyles);
const existingRoleID = React.useMemo(
@@ -128,7 +137,7 @@
]);
const menuButton = React.useMemo(() => {
- if (roleName === 'Admins') {
+ if (specialRole === specialRoles.ADMIN_ROLE) {
return <View style={styles.rolePanelEmptyMenuButton} />;
}
return (
@@ -141,10 +150,10 @@
</TouchableOpacity>
);
}, [
- roleName,
- styles.rolePanelEmptyMenuButton,
- styles.rolePanelMenuButton,
+ specialRole,
showActionSheet,
+ styles.rolePanelMenuButton,
+ styles.rolePanelEmptyMenuButton,
]);
return (
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 2:03 PM (21 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2597201
Default Alt Text
D11205.diff (4 KB)
Attached To
Mode
D11205: [lib][native] Introduce `useRoleNamesToSpecialRole` to remove `"Admins"` string check in `RolePanelEntry`
Attached
Detach File
Event Timeline
Log In to Comment