Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Landscape/Group membership list #153

Merged
merged 24 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b3bd48c
chore: Upgrade backend version
josebui Oct 10, 2023
9e7e6d8
chore: Upgrade backend version
josebui Oct 10, 2023
3a0ed14
fix: Added enrollMethod and membership type to membership list extract
josebui Oct 11, 2023
0720e1f
chore: Updated backend version
josebui Oct 27, 2023
59cb4a6
chore: Updated backend version
josebui Oct 30, 2023
024fa61
chore: Updated backend version
josebui Oct 31, 2023
f4bdbfa
chore: Update backend version
josebui Nov 1, 2023
c8df684
chore: Updated backend version
josebui Nov 1, 2023
cb8ecfe
chore: Updated backend version
josebui Nov 10, 2023
75d3ee3
chore: Updated backend version
josebui Nov 16, 2023
0151821
fix: Removed deprecated membership code
josebui Nov 16, 2023
443230d
fix: Added membership types
josebui Nov 16, 2023
6cb1deb
fix: Added membership types
josebui Nov 16, 2023
c52c324
fix: Fixed memberships list name
josebui Nov 17, 2023
62219aa
fix: Added separate field for user in membership
josebui Nov 17, 2023
34191ed
fix: Added separate field for user in membership
josebui Nov 17, 2023
1078dfe
fix: Added separate field for user in membership
josebui Nov 17, 2023
8106109
fix: Added userRole to membership
josebui Nov 17, 2023
175b8f5
fix: Added types for membership utils
josebui Nov 20, 2023
bfff88d
fix: Fixed type name
josebui Nov 21, 2023
ba9332f
chore: Updated backend version
josebui Nov 22, 2023
2d858d4
fix: Fixed error in type
josebui Nov 22, 2023
6ce3d64
chore: Updated backend version
josebui Nov 29, 2023
46f1876
chore: Updateed backend version
josebui Dec 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
josebui marked this conversation as resolved.
Show resolved Hide resolved
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