Fix: Show admin on channel members (#7472)
* feat: adding the scheme_admin info on the channel members user_list sections * feat: adding the scheme_admin info on channel members when there is a search in the textbox
This commit is contained in:
parent
8a32588507
commit
8bc1ec2dff
1 changed files with 28 additions and 6 deletions
|
|
@ -67,12 +67,12 @@ export function createProfilesSections(intl: IntlShape, profiles: UserProfile[],
|
|||
return [];
|
||||
}
|
||||
|
||||
const sections = new Map<string, UserProfile[]>();
|
||||
const sections = new Map<string, UserProfileWithChannelAdmin[]>();
|
||||
|
||||
if (members?.length) {
|
||||
// when channel members are provided, build the sections by admins and members
|
||||
const membersDictionary = new Map<string, ChannelMembership>();
|
||||
const membersSections = new Map<string, UserProfile[]>();
|
||||
const membersSections = new Map<string, UserProfileWithChannelAdmin[]>();
|
||||
const {formatMessage} = intl;
|
||||
members.forEach((m) => membersDictionary.set(m.user_id, m));
|
||||
profiles.forEach((p) => {
|
||||
|
|
@ -80,7 +80,7 @@ export function createProfilesSections(intl: IntlShape, profiles: UserProfile[],
|
|||
if (member) {
|
||||
const sectionKey = sectionRoleKeyExtractor(member.scheme_admin!).id;
|
||||
const section = membersSections.get(sectionKey) || [];
|
||||
section.push(p);
|
||||
section.push({...p, scheme_admin: member.scheme_admin});
|
||||
membersSections.set(sectionKey, section);
|
||||
}
|
||||
});
|
||||
|
|
@ -111,6 +111,28 @@ export function createProfilesSections(intl: IntlShape, profiles: UserProfile[],
|
|||
return results;
|
||||
}
|
||||
|
||||
function createProfiles(profiles: UserProfile[], members?: ChannelMembership[]): UserProfileWithChannelAdmin[] {
|
||||
if (!profiles.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const profileMap = new Map<string, UserProfileWithChannelAdmin>();
|
||||
profiles.forEach((profile) => {
|
||||
profileMap.set(profile.id, profile);
|
||||
});
|
||||
|
||||
if (members?.length) {
|
||||
members.forEach((m) => {
|
||||
const profileFound = profileMap.get(m.user_id);
|
||||
if (profileFound) {
|
||||
profileFound.scheme_admin = m.scheme_admin;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Array.from(profileMap.values());
|
||||
}
|
||||
|
||||
const getStyleFromTheme = makeStyleSheetFromTheme((theme) => {
|
||||
return {
|
||||
list: {
|
||||
|
|
@ -195,7 +217,7 @@ export default function UserList({
|
|||
}
|
||||
|
||||
if (term) {
|
||||
return profiles;
|
||||
return createProfiles(profiles, channelMembers);
|
||||
}
|
||||
|
||||
return createProfilesSections(intl, profiles, channelMembers);
|
||||
|
|
@ -337,7 +359,7 @@ export default function UserList({
|
|||
};
|
||||
|
||||
if (term) {
|
||||
return renderFlatList(data as UserProfile[]);
|
||||
return renderFlatList(data as UserProfileWithChannelAdmin[]);
|
||||
}
|
||||
return renderSectionList(data as Array<SectionListData<UserProfile>>);
|
||||
return renderSectionList(data as Array<SectionListData<UserProfileWithChannelAdmin>>);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue