Skip to content

Commit

Permalink
refactor: Landscape/Group membership list (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui authored Dec 4, 2023
1 parent 75d3405 commit a416b76
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 577 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-redux": "^8.1.3",
"terraso-backend": "github:techmatters/terraso-backend#2162f0e",
"terraso-backend": "github:techmatters/terraso-backend#abd145f",
"uuid": "^9.0.1"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/collaboration/membershipsFragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const collaborationMembershipsInfo = /* GraphQL */ `
fragment collaborationMembershipsInfo on CollaborationMembershipListNode {
membershipType
membershipsCount
enrollMethod
memberships(first: 5, membershipStatus: APPROVED) {
totalCount
edges {
Expand Down Expand Up @@ -71,6 +72,9 @@ export const accountCollaborationMembership = /* GraphQL */ `
id
userRole
membershipStatus
user {
...userFields
}
}
}
`;
43 changes: 37 additions & 6 deletions src/collaboration/membershipsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import _ from 'lodash/fp';
import { User } from 'terraso-client-shared/account/accountSlice';
import type {
AccountCollaborationMembershipFragment,
CollaborationMembershipFieldsFragment,
Expand All @@ -29,26 +30,54 @@ type MembershipQuery = Partial<
CollaborationMembershipsPendingFragment
>;

export type MembershipsInfo = {
totalCount?: number;
pendingCount?: number;
accountMembership?: Membership;
membershipsSample?: Membership[];
enrollMethod?: string;
membershipType?: string;
};

export type MembershipList = {
// TODO: massage membershipsUtils/Service so more of these can be required
membershipsInfo?: MembershipsInfo;
id: string;
slug: string;
membershipType: 'CLOSED' | 'OPEN';
};

export type Membership = {
membershipId: string;
userId?: string;
userRole?: string;
membershipStatus?: 'APPROVED' | 'PENDING';
user?: User;
};

export const extractMembershipsInfo = (
membershipList?: MembershipQuery | null,
) => ({
): MembershipsInfo => ({
totalCount:
membershipList?.membershipsCount ?? membershipList?.memberships?.totalCount,
pendingCount: membershipList?.pending?.totalCount,
accountMembership: extractAccountMembership(membershipList),
membershipsSample: extractMemberships(membershipList),
enrollMethod: membershipList?.enrollMethod,
membershipType: membershipList?.membershipType,
});

export const extractMembership = (
membership: Partial<CollaborationMembershipFieldsFragment>,
) => ({
...membership.user,
..._.omit('user', membership),
...membership,
membershipId: membership.id,
userId: membership.user?.id,
});

export const extractMemberships = (membershipList?: MembershipQuery | null) =>
export const extractMemberships = (
membershipList?: MembershipQuery | null,
): Membership[] =>
(
(
membershipList as
Expand All @@ -57,14 +86,16 @@ export const extractMemberships = (membershipList?: MembershipQuery | null) =>
| null
| undefined
)?.memberships?.edges || []
).map(edge => extractMembership(edge.node));
).map(edge => extractMembership(edge.node) as Membership);

export const extractAccountMembership = (
membershipList?: AccountCollaborationMembershipFragment | null,
) =>
): Membership | undefined =>
membershipList?.accountMembership
? {
..._.omit('id', membershipList.accountMembership),
membershipId: membershipList.accountMembership.id,
userId: membershipList.accountMembership.user?.id,
user: membershipList.accountMembership.user as User,
}
: undefined;
71 changes: 0 additions & 71 deletions src/memberships/membershipsFragments.ts

This file was deleted.

157 changes: 0 additions & 157 deletions src/memberships/membershipsService.ts

This file was deleted.

Loading

0 comments on commit a416b76

Please sign in to comment.