• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alkem-io / client-web / #9048

11 Oct 2024 01:42PM UTC coverage: 5.943%. First build
#9048

Pull #7022

travis-ci

Pull Request #7022: [v0.74.0] Roles API + Unauthenticated Explore page

202 of 10241 branches covered (1.97%)

Branch coverage included in aggregate %.

63 of 431 new or added lines in 60 files covered. (14.62%)

1468 of 17861 relevant lines covered (8.22%)

0.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/domain/community/community/utils/useCommunityMembersAsCardProps.ts
1
import { ContributorCardSquareProps } from '@/domain/community/contributor/ContributorCardSquare/ContributorCardSquare';
2
import { UserCardProps } from '@/domain/community/user/userCard/UserCard';
3
import { useMemo } from 'react';
4
import { COUNTRIES_BY_CODE } from '@/domain/common/location/countries.constants';
5
import { RoleSetContributorType } from '@/core/apollo/generated/graphql-schema';
6
import { ContributorViewModel } from './ContributorViewModel';
7
import { WithId } from '@/core/utils/WithId';
8

9
interface RoleSetMembers {
10
  memberUsers?: ContributorViewModel[];
11
  memberOrganizations?: ContributorViewModel[];
12
}
13

×
14
const DEFAULT_MEMBERS_LIMIT = 12;
15

16
type Options = {
17
  membersLimit?: number;
18
  memberUsersLimit?: number;
19
  memberOrganizationsLimit?: number;
20
  memberUsersCount?: number;
21
  memberOrganizationsCount?: number;
22
};
NEW
23

×
24
const mapUserToContributorCardProps = (user: ContributorViewModel): ContributorCardSquareProps => ({
25
  id: user.id,
26
  avatar: user.profile.avatar?.uri,
27
  displayName: user.profile.displayName,
28
  url: user.profile.url,
29
  tooltip: {
×
30
    tags: user.profile.tagsets?.flatMap(x => x.tags.map(t => t)) ?? [],
31
    city: user.profile.location?.city,
×
32
    country: user.profile.location?.country ? COUNTRIES_BY_CODE[user.profile.location.country] : undefined,
33
  },
34
  isContactable: user.isContactable,
35
  contributorType: RoleSetContributorType.User,
36
});
NEW
37

×
38
export const mapUserCardPropsToContributorCardProps = (user: UserCardProps): ContributorCardSquareProps => ({
×
39
  id: user.id ?? '',
40
  avatar: user.avatarSrc,
×
41
  displayName: user.displayName ?? '',
×
42
  url: user.url ?? '',
43
  tooltip: {
×
44
    tags: user.tags ?? [],
45
    city: user.city,
46
    country: user.country,
47
  },
×
48
  isContactable: user.isContactable ?? true,
49
  contributorType: RoleSetContributorType.User,
50
});
NEW
51

×
52
const mapOrganizationToContributorCardProps = (org: ContributorViewModel): ContributorCardSquareProps => ({
53
  id: org.id,
54
  avatar: org.profile.avatar?.uri,
55
  displayName: org.profile.displayName,
56
  url: org.profile.url,
57
  tooltip: {
×
58
    tags: org.profile.tagsets?.flatMap(x => x.tags.map(t => t)) ?? [],
59
  },
60
  isContactable: true,
61
  contributorType: RoleSetContributorType.Organization,
62
});
63

×
64
const applyLimit = <Item>(items: Item[] | undefined, limit?: number): Item[] | undefined =>
×
65
  limit && items ? items.slice(0, limit) : items;
66

×
67
export interface EntityDashboardContributors {
68
  memberUsers: WithId<ContributorCardSquareProps>[] | undefined;
×
69
  memberUsersCount: number | undefined;
70
  memberOrganizations: WithId<ContributorCardSquareProps>[] | undefined;
71
  memberOrganizationsCount: number | undefined;
×
72
}
×
73

×
74
const useCommunityMembersAsCardProps = (
×
75
  community: RoleSetMembers | undefined,
NEW
76
  options: Options = {}
×
77
): EntityDashboardContributors => {
×
78
  const {
79
    membersLimit = DEFAULT_MEMBERS_LIMIT,
80
    memberUsersLimit = membersLimit,
81
    memberOrganizationsLimit = membersLimit,
×
82
  } = options;
NEW
83

×
84
  const memberUsers: ContributorCardSquareProps[] | undefined = useMemo(
85
    () => applyLimit(community?.memberUsers, memberUsersLimit)?.map(mapUserToContributorCardProps),
×
86
    [community?.memberUsers, memberUsersLimit]
87
  );
88

89
  const memberUsersCount = options.memberUsersCount ?? community?.memberUsers?.length;
×
90

91
  const memberOrganizations: ContributorCardSquareProps[] | undefined = useMemo(
×
92
    () =>
93
      applyLimit(community?.memberOrganizations, memberOrganizationsLimit)?.map(mapOrganizationToContributorCardProps),
94
    [community?.memberOrganizations, memberOrganizationsLimit]
95
  );
96

97
  const memberOrganizationsCount = options.memberOrganizationsCount ?? community?.memberOrganizations?.length;
98

99
  return {
100
    memberUsers,
101
    memberUsersCount,
102
    memberOrganizations,
103
    memberOrganizationsCount,
104
  };
105
};
106

107
export default useCommunityMembersAsCardProps;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc