Directly load the group in OrganizerPickerWrapper if we have the group ID

Fixes #997

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-04-03 22:18:33 +02:00
parent a2bb0c0a4d
commit 84a5c6f893
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 40 additions and 15 deletions

View File

@ -148,7 +148,7 @@ import EmptyContent from "../Utils/EmptyContent.vue";
import {
CURRENT_ACTOR_CLIENT,
IDENTITIES,
LOGGED_USER_MEMBERSHIPS,
PERSON_GROUP_MEMBERSHIPS,
} from "../../graphql/actor";
import { Paginate } from "../../types/paginate";
import { GROUP_MEMBERS } from "@/graphql/member";
@ -184,15 +184,17 @@ const MEMBER_ROLES = [
},
},
currentActor: CURRENT_ACTOR_CLIENT,
userMemberships: {
query: LOGGED_USER_MEMBERSHIPS,
personMemberships: {
query: PERSON_GROUP_MEMBERSHIPS,
variables() {
return {
id: this.currentActor?.id,
page: 1,
limit: 10,
groupId: this.$route.query?.actorId,
};
},
update: (data) => data.loggedUser.memberships,
update: (data) => data.person.memberships,
},
identities: IDENTITIES,
},
@ -202,6 +204,9 @@ export default class OrganizerPickerWrapper extends Vue {
@Prop({ default: true, type: Boolean }) inline!: boolean;
@Prop({ type: Array, required: false, default: () => [] })
contacts!: IActor[];
currentActor!: IPerson;
identities!: IPerson[];
@ -212,13 +217,11 @@ export default class OrganizerPickerWrapper extends Vue {
usernameWithDomain = usernameWithDomain;
@Prop({ type: Array, required: false, default: () => [] })
contacts!: IActor[];
members: Paginate<IMember> = { elements: [], total: 0 };
membersPage = 1;
userMemberships: Paginate<IMember> = { elements: [], total: 0 };
personMemberships: Paginate<IMember> = { elements: [], total: 0 };
data(): Record<string, unknown> {
return {
@ -241,15 +244,13 @@ export default class OrganizerPickerWrapper extends Vue {
this.contactFilter = contactFilter;
}
@Watch("userMemberships")
@Watch("personMemberships")
setInitialActor(): void {
if (this.$route.query?.actorId) {
const actorId = this.$route.query?.actorId as string;
const actor = this.userMemberships.elements.find(
({ parent: { id }, role }) =>
actorId === id && MEMBER_ROLES.includes(role)
)?.parent as IActor;
this.selectedActor = actor;
if (
this.personMemberships?.elements[0]?.parent?.id ===
this.$route.query?.actorId
) {
this.selectedActor = this.personMemberships?.elements[0]?.parent;
}
}

View File

@ -351,6 +351,30 @@ export const PERSON_STATUS_GROUP = gql`
${ACTOR_FRAGMENT}
`;
export const PERSON_GROUP_MEMBERSHIPS = gql`
query PersonGroupMemberships($id: ID!, $groupId: ID!) {
person(id: $id) {
id
memberships(groupId: $groupId) {
total
elements {
id
role
parent {
...ActorFragment
}
invitedBy {
...ActorFragment
}
insertedAt
updatedAt
}
}
}
}
${ACTOR_FRAGMENT}
`;
export const GROUP_MEMBERSHIP_SUBSCRIPTION_CHANGED = gql`
subscription GroupMembershipSubscriptionChanged(
$actorId: ID!