You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ya...@apache.org on 2026/10/18 03:04:27 UTC

(airavata-custos) 08/12: refresh project and allocation members together

This is an automated email from the ASF dual-hosted git repository.

yasithdev pushed a commit to branch stack-bugfixes
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git

commit 28a655ef6b2d08757ce8b661e7d81a10e25d544f
Author: Yasith Jayawardana <ya...@icloud.com>
AuthorDate: Sat Oct 17 22:53:12 2026 -0400

    refresh project and allocation members together
---
 .../components/AllocationMembersTab.tsx            |  9 ++-------
 web/src/features/core/allocations/queries.ts       | 22 +++++++++++++++++-----
 .../core/projects/components/ProjectMembersTab.tsx |  5 +----
 web/src/features/core/projects/queries.ts          |  6 +++++-
 4 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/web/src/features/core/allocations/components/AllocationMembersTab.tsx b/web/src/features/core/allocations/components/AllocationMembersTab.tsx
index 6b5c9dd36..3e9b793d1 100644
--- a/web/src/features/core/allocations/components/AllocationMembersTab.tsx
+++ b/web/src/features/core/allocations/components/AllocationMembersTab.tsx
@@ -78,7 +78,7 @@ export function AllocationMembersTab({
         if (role !== "MEMBER") {
           roleMutation.mutate(
             { userId: payload.user_id, payload: { role } },
-            { onSuccess: () => query.refetch(), onError: (err) => toast.error(err.message) },
+            { onError: (err) => toast.error(err.message) },
           );
         }
       },
@@ -212,12 +212,7 @@ export function AllocationMembersTab({
     if (!editing) return;
     roleMutation.mutate(
       { userId: editing.user_id, payload },
-      {
-        onSuccess: () => {
-          setEditing(null);
-          query.refetch();
-        },
-      },
+      { onSuccess: () => setEditing(null) },
     );
   }
 
diff --git a/web/src/features/core/allocations/queries.ts b/web/src/features/core/allocations/queries.ts
index 7894a5297..91df687c1 100644
--- a/web/src/features/core/allocations/queries.ts
+++ b/web/src/features/core/allocations/queries.ts
@@ -17,7 +17,14 @@
 
 "use client";
 
-import { skipToken, useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
+import {
+  type QueryClient,
+  skipToken,
+  useMutation,
+  useQueries,
+  useQuery,
+  useQueryClient,
+} from "@tanstack/react-query";
 import {
   addMember,
   approveChangeRequest,
@@ -61,6 +68,12 @@ export const allocationKeys = {
     [...allocationKeys.all, "change-requests", "events", id] as const,
 };
 
+// Project members are derived from allocation memberships; a key prefix avoids importing projects.
+function invalidateMembers(client: QueryClient, allocationId: string) {
+  client.invalidateQueries({ queryKey: allocationKeys.members(allocationId) });
+  client.invalidateQueries({ queryKey: ["projects", "members"] });
+}
+
 const DEFAULTS = {
   staleTime: 30_000,
   gcTime: 300_000,
@@ -140,7 +153,7 @@ export function useAddMember(allocationId: string) {
   const client = useQueryClient();
   return useMutation({
     mutationFn: (payload: CreateMembershipPayload) => addMember(payload),
-    onSuccess: () => client.invalidateQueries({ queryKey: allocationKeys.members(allocationId) }),
+    onSuccess: () => invalidateMembers(client, allocationId),
   });
 }
 
@@ -148,7 +161,7 @@ export function useRemoveMember(allocationId: string) {
   const client = useQueryClient();
   return useMutation({
     mutationFn: (id: string) => removeMember(id),
-    onSuccess: () => client.invalidateQueries({ queryKey: allocationKeys.members(allocationId) }),
+    onSuccess: () => invalidateMembers(client, allocationId),
   });
 }
 
@@ -192,8 +205,7 @@ export function useToggleAllocationAccess() {
             end_time: allocation.end_time,
             membership_status: "ACTIVE",
           }),
-    onSuccess: (_data, { allocation }) =>
-      client.invalidateQueries({ queryKey: allocationKeys.members(allocation.id) }),
+    onSuccess: (_data, { allocation }) => invalidateMembers(client, allocation.id),
   });
 }
 
diff --git a/web/src/features/core/projects/components/ProjectMembersTab.tsx b/web/src/features/core/projects/components/ProjectMembersTab.tsx
index b5ab9b504..67ab1502a 100644
--- a/web/src/features/core/projects/components/ProjectMembersTab.tsx
+++ b/web/src/features/core/projects/components/ProjectMembersTab.tsx
@@ -17,7 +17,6 @@
 
 "use client";
 
-import { useQueryClient } from "@tanstack/react-query";
 import { Check, Pencil, Plus } from "lucide-react";
 import Link from "next/link";
 import * as React from "react";
@@ -47,7 +46,7 @@ import { GuardedButton } from "@/shared/ui/GuardedButton";
 import { TableSkeleton } from "@/shared/ui/Loading";
 import { SuggestInput } from "@/shared/ui/SuggestInput";
 import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/shared/ui/table";
-import { projectKeys, useProjectMembers, useUpdateProjectMember } from "../queries";
+import { useProjectMembers, useUpdateProjectMember } from "../queries";
 import { type ProjectMemberRole, projectMemberRoleSchema } from "../schemas";
 
 export type ProjectMembersTabProps = {
@@ -175,7 +174,6 @@ export function ProjectMembersTab({
   canEditAccess,
   canSearchUsers,
 }: ProjectMembersTabProps) {
-  const client = useQueryClient();
   const membersQuery = useProjectMembers(projectId);
   const allocationsQuery = useAllocationsByProject(projectId);
   const allocations = allocationsQuery.data?.items ?? [];
@@ -293,7 +291,6 @@ export function ProjectMembersTab({
     } catch (err) {
       toast.error(err instanceof Error ? err.message : String(err));
     } finally {
-      await client.invalidateQueries({ queryKey: projectKeys.members(projectId) });
       setApplying(false);
       setReviewing(false);
       exitEditing();
diff --git a/web/src/features/core/projects/queries.ts b/web/src/features/core/projects/queries.ts
index 7a0a0b02c..445bf9cf3 100644
--- a/web/src/features/core/projects/queries.ts
+++ b/web/src/features/core/projects/queries.ts
@@ -107,6 +107,10 @@ export function useUpdateProjectMember(projectId: string) {
   return useMutation({
     mutationFn: ({ userId, payload }: { userId: string; payload: UpdateProjectMemberPayload }) =>
       updateProjectMember(projectId, userId, payload),
-    onSuccess: () => client.invalidateQueries({ queryKey: projectKeys.members(projectId) }),
+    onSuccess: () => {
+      client.invalidateQueries({ queryKey: projectKeys.members(projectId) });
+      // Allocation member rows show the project role; a key prefix avoids importing allocations.
+      client.invalidateQueries({ queryKey: ["allocations"] });
+    },
   });
 }