Fix guest badge not appearing on member list (#7197)

* Fix guest badge not appearing on member list

* Improve performance on role change
This commit is contained in:
Daniel Espino García 2023-03-13 21:39:29 +01:00 committed by GitHub
parent ee3edbecfc
commit 8ff732a9d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 23 deletions

View file

@ -61,30 +61,30 @@ const sectionRoleKeyExtractor = (cAdmin: boolean) => {
return cAdmin ? messages.admins : messages.members;
};
export function createProfilesSections(intl: IntlShape, profiles: UserProfile[], members?: ChannelMember[]) {
export function createProfilesSections(intl: IntlShape, profiles: UserProfile[], members?: ChannelMembership[]) {
if (!profiles.length) {
return [];
}
const sections = new Map();
const sections = new Map<string, UserProfile[]>();
if (members?.length) {
// when channel members are provided, build the sections by admins and members
const membersDictionary = new Map();
const membersSections = new Map();
const membersDictionary = new Map<string, ChannelMembership>();
const membersSections = new Map<string, UserProfile[]>();
const {formatMessage} = intl;
members.forEach((m) => membersDictionary.set(m.user_id, m));
profiles.forEach((p) => {
const member = membersDictionary.get(p.id);
const sectionKey = sectionRoleKeyExtractor(member.scheme_admin!);
const sectionValue = membersSections.get(sectionKey) || [];
// combine UserProfile and ChannelMember objects so can get channel member scheme_admin permission
const section = [...sectionValue, {...p, ...member}];
membersSections.set(sectionKey, section);
if (member) {
const sectionKey = sectionRoleKeyExtractor(member.scheme_admin!).id;
const section = membersSections.get(sectionKey) || [];
section.push(p);
membersSections.set(sectionKey, section);
}
});
sections.set(formatMessage(messages.admins), membersSections.get(messages.admins));
sections.set(formatMessage(messages.members), membersSections.get(messages.members));
sections.set(formatMessage(messages.admins), membersSections.get(messages.admins.id) || []);
sections.set(formatMessage(messages.members), membersSections.get(messages.members.id) || []);
} else {
// when channel members are not provided, build the sections alphabetically
profiles.forEach((p) => {
@ -98,13 +98,11 @@ export function createProfilesSections(intl: IntlShape, profiles: UserProfile[],
const results = [];
let index = 0;
for (const [k, v] of sections) {
if (v) {
results.push({
first: index === 0,
id: k,
data: v,
});
}
results.push({
first: index === 0,
id: k,
data: v,
});
index++;
}
return results;
@ -147,11 +145,11 @@ const getStyleFromTheme = makeStyleSheetFromTheme((theme) => {
type Props = {
profiles: UserProfile[];
channelMembers?: ChannelMember[];
channelMembers?: ChannelMembership[];
currentUserId: string;
teammateNameDisplay: string;
handleSelectProfile: (user: UserProfile) => void;
fetchMore: () => void;
fetchMore?: () => void;
loading: boolean;
manageMode?: boolean;
showManageMode?: boolean;
@ -332,4 +330,3 @@ export default function UserList({
}
return renderSectionList(data as Array<SectionListData<UserProfile>>);
}

View file

@ -218,6 +218,7 @@ export default function ManageChannelMembers({
useEffect(() => {
mounted.current = true;
getProfiles();
return () => {
mounted.current = false;
};
@ -262,7 +263,6 @@ export default function ManageChannelMembers({
{/* fix flashing No Results page when results are present */}
<UserList
currentUserId={currentUserId}
fetchMore={getProfiles}
handleSelectProfile={handleSelectProfile}
loading={loading}
manageMode={true} // default true to change row select icon to a dropdown