Skip to content

Commit f48c05b

Browse files
authored
chore: CollectionGroupMembership -> GroupMembership (outline#7269)
* chore: CollectionGroupMembership -> GroupMembership * Backwards compat * docs
1 parent f675a04 commit f48c05b

24 files changed

+256
-216
lines changed

app/components/GroupListItem.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { useTranslation } from "react-i18next";
55
import styled from "styled-components";
66
import { MAX_AVATAR_DISPLAY } from "@shared/constants";
77
import { s } from "@shared/styles";
8-
import CollectionGroupMembership from "~/models/CollectionGroupMembership";
98
import Group from "~/models/Group";
9+
import GroupMembership from "~/models/GroupMembership";
1010
import GroupMembers from "~/scenes/GroupMembers";
1111
import Facepile from "~/components/Facepile";
1212
import Flex from "~/components/Flex";
@@ -19,7 +19,7 @@ import NudeButton from "./NudeButton";
1919

2020
type Props = {
2121
group: Group;
22-
membership?: CollectionGroupMembership;
22+
membership?: GroupMembership;
2323
showFacepile?: boolean;
2424
showAvatar?: boolean;
2525
renderActions: (params: { openMembersModal: () => void }) => React.ReactNode;

app/components/Sharing/Collection/CollectionMemberList.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Props = {
2424
};
2525

2626
function CollectionMemberList({ collection, invitedInSession }: Props) {
27-
const { memberships, collectionGroupMemberships } = useStores();
27+
const { memberships, groupMemberships } = useStores();
2828
const can = usePolicy(collection);
2929
const { t } = useTranslation();
3030
const theme = useTheme();
@@ -39,8 +39,8 @@ function CollectionMemberList({ collection, invitedInSession }: Props) {
3939

4040
const { request: fetchGroupMemberships } = useRequest(
4141
React.useCallback(
42-
() => collectionGroupMemberships.fetchAll({ id: collectionId }),
43-
[collectionGroupMemberships, collectionId]
42+
() => groupMemberships.fetchAll({ id: collectionId }),
43+
[groupMemberships, collectionId]
4444
)
4545
);
4646

@@ -75,7 +75,7 @@ function CollectionMemberList({ collection, invitedInSession }: Props) {
7575

7676
return (
7777
<>
78-
{collectionGroupMemberships
78+
{groupMemberships
7979
.inCollection(collection.id)
8080
.sort((a, b) =>
8181
(
@@ -103,12 +103,12 @@ function CollectionMemberList({ collection, invitedInSession }: Props) {
103103
permission: CollectionPermission | typeof EmptySelectValue
104104
) => {
105105
if (permission === EmptySelectValue) {
106-
await collectionGroupMemberships.delete({
106+
await groupMemberships.delete({
107107
collectionId: collection.id,
108108
groupId: membership.groupId,
109109
});
110110
} else {
111-
await collectionGroupMemberships.create({
111+
await groupMemberships.create({
112112
collectionId: collection.id,
113113
groupId: membership.groupId,
114114
permission,

app/components/Sharing/Collection/SharePopover.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ type Props = {
4444
function SharePopover({ collection, visible, onRequestClose }: Props) {
4545
const theme = useTheme();
4646
const team = useCurrentTeam();
47-
const { collectionGroupMemberships, users, groups, memberships } =
48-
useStores();
47+
const { groupMemberships, users, groups, memberships } = useStores();
4948
const { t } = useTranslation();
5049
const can = usePolicy(collection);
5150
const [query, setQuery] = React.useState("");
@@ -206,7 +205,7 @@ function SharePopover({ collection, visible, onRequestClose }: Props) {
206205
}
207206

208207
if (group) {
209-
await collectionGroupMemberships.create({
208+
await groupMemberships.create({
210209
collectionId: collection.id,
211210
groupId: group.id,
212211
permission: CollectionPermission.Read,
@@ -268,7 +267,7 @@ function SharePopover({ collection, visible, onRequestClose }: Props) {
268267
}),
269268
[
270269
collection.id,
271-
collectionGroupMemberships,
270+
groupMemberships,
272271
groups,
273272
hidePicker,
274273
memberships,

app/components/Sharing/components/Suggestions.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export const Suggestions = observer(
122122
getSuggestionForEmail,
123123
users,
124124
users.orderedData,
125+
groups,
126+
groups.orderedData,
125127
document?.id,
126128
document?.members,
127129
collection?.id,

app/models/CollectionGroupMembership.ts

-27
This file was deleted.

app/models/GroupMembership.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { observable } from "mobx";
2+
import { CollectionPermission, DocumentPermission } from "@shared/types";
3+
import Collection from "./Collection";
4+
import Document from "./Document";
5+
import Group from "./Group";
6+
import Model from "./base/Model";
7+
import Relation from "./decorators/Relation";
8+
9+
/**
10+
* Represents a groups's membership to a collection or document.
11+
*/
12+
class GroupMembership extends Model {
13+
static modelName = "GroupMembership";
14+
15+
/** The group ID that this membership is granted to. */
16+
groupId: string;
17+
18+
/** The group that this membership is granted to. */
19+
@Relation(() => Group, { onDelete: "cascade" })
20+
group: Group;
21+
22+
/** The document ID that this membership grants the group access to. */
23+
documentId: string | undefined;
24+
25+
/** The document that this membership grants the group access to. */
26+
@Relation(() => Document, { onDelete: "cascade" })
27+
document: Document | undefined;
28+
29+
/** The collection ID that this membership grants the group access to. */
30+
collectionId: string | undefined;
31+
32+
/** The collection that this membership grants the group access to. */
33+
@Relation(() => Collection, { onDelete: "cascade" })
34+
collection: Collection | undefined;
35+
36+
/** The permission level granted to the group. */
37+
@observable
38+
permission: CollectionPermission | DocumentPermission;
39+
}
40+
41+
export default GroupMembership;

app/models/GroupUser.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,22 @@ import Model from "./base/Model";
44
import Relation from "./decorators/Relation";
55

66
/**
7-
* Represents a user's membership in a group.
7+
* Represents a user's membership to a group.
88
*/
99
class GroupUser extends Model {
1010
static modelName = "GroupUser";
1111

12-
/**
13-
* The ID of the user.
14-
*/
12+
/** The ID of the user. */
1513
userId: string;
1614

17-
/**
18-
* The user that belongs to the group.
19-
*/
15+
/** The user that belongs to the group. */
2016
@Relation(() => User, { onDelete: "cascade" })
2117
user: User;
2218

23-
/**
24-
* The ID of the group.
25-
*/
19+
/** The ID of the group. */
2620
groupId: string;
2721

28-
/**
29-
* The group that the user belongs to.
30-
*/
22+
/** The group that the user belongs to. */
3123
@Relation(() => Group, { onDelete: "cascade" })
3224
group: Group;
3325
}

app/models/UserMembership.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ class UserMembership extends Model {
1919
@observable
2020
permission: DocumentPermission;
2121

22-
/** The document ID that this permission grants the user access to. */
22+
/** The document ID that this membership grants the user access to. */
2323
documentId?: string;
2424

25-
/** The document that this permission grants the user access to. */
25+
/** The document that this membership grants the user access to. */
2626
@Relation(() => Document, { onDelete: "cascade" })
2727
document?: Document;
2828

29-
/** The source ID points to the root permission from which this permission inherits */
29+
/** The source ID points to the root membership from which this inherits */
3030
sourceId?: string;
3131

32-
/** The source points to the root permission from which this permission inherits */
32+
/** The source points to the root membership from which this inherits */
3333
@Relation(() => UserMembership, { onDelete: "cascade" })
3434
source?: UserMembership;
3535

36-
/** The user ID that this permission is granted to. */
36+
/** The user ID that this membership is granted to. */
3737
userId: string;
3838

39-
/** The user that this permission is granted to. */
39+
/** The user that this membership is granted to. */
4040
@Relation(() => User, { onDelete: "cascade" })
4141
user: User;
4242

43-
/** The user that created this permission. */
43+
/** The user that created this membership. */
4444
@Relation(() => User, { onDelete: "null" })
4545
createdBy: User;
4646

47-
/** The user ID that created this permission. */
47+
/** The user ID that created this membership. */
4848
createdById: string;
4949

5050
store: UserMembershipsStore;

app/scenes/Collection/components/MembershipPreview.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const MembershipPreview = ({ collection, limit = 8 }: Props) => {
2525
const [usersCount, setUsersCount] = React.useState(0);
2626
const [groupsCount, setGroupsCount] = React.useState(0);
2727
const { t } = useTranslation();
28-
const { memberships, collectionGroupMemberships, users } = useStores();
28+
const { memberships, groupMemberships, users } = useStores();
2929
const collectionUsers = users.inCollection(collection.id);
3030
const context = useActionContext();
3131
const isMobile = useMobile();
@@ -44,7 +44,7 @@ const MembershipPreview = ({ collection, limit = 8 }: Props) => {
4444
};
4545
const [users, groups] = await Promise.all([
4646
memberships.fetchPage(options),
47-
collectionGroupMemberships.fetchPage(options),
47+
groupMemberships.fetchPage(options),
4848
]);
4949
setUsersCount(users[PAGINATION_SYMBOL].total);
5050
setGroupsCount(groups[PAGINATION_SYMBOL].total);
@@ -58,7 +58,7 @@ const MembershipPreview = ({ collection, limit = 8 }: Props) => {
5858
isMobile,
5959
collection.permission,
6060
collection.id,
61-
collectionGroupMemberships,
61+
groupMemberships,
6262
memberships,
6363
limit,
6464
]);

app/stores/CollectionGroupMembershipsStore.ts

-82
This file was deleted.

0 commit comments

Comments
 (0)