88 Spinner ,
99 Bullseye ,
1010} from '@patternfly/react-core' ;
11- import { Link , Navigate , useLocation } from 'react-router-dom' ;
11+ import { Link , Navigate , useLocation , useNavigate } from 'react-router-dom' ;
1212import {
1313 PermissionsContextProvider ,
1414 usePermissionsContext ,
@@ -17,19 +17,24 @@ import ApplicationsPage from '#~/pages/ApplicationsPage';
1717import { ProjectDetailsContext } from '#~/pages/projects/ProjectDetailsContext' ;
1818import { useAccessReview } from '#~/api/useAccessReview.ts' ;
1919import { getDisplayNameFromK8sResource } from '#~/concepts/k8s/utils.ts' ;
20+ import { RBAC_SUBJECT_KIND_USER , RBAC_SUBJECT_KIND_GROUP } from '#~/concepts/permissions/const' ;
21+ import type { SupportedSubjectKind } from '#~/concepts/permissions/types' ;
2022import AssignRolesFooterActions from './manageRoles/AssignRolesFooterActions' ;
2123import AssignRolesSubjectSection from './manageRoles/AssignRolesSubjectSection' ;
2224import ManageRolesTable from './manageRoles/ManageRolesTable' ;
2325import RoleAssignmentChangesModal from './manageRoles/confirmModal/RoleAssignmentChangesModal' ;
2426import useManageRolesData from './manageRoles/useManageRolesData' ;
2527import { useRoleAssignmentData } from './useRoleAssignmentData' ;
28+ import { applyRoleAssignmentChanges } from './roleBindingMutations' ;
2629
2730const ProjectPermissionsAssignRolesForm : React . FC = ( ) => {
28- const { error } = usePermissionsContext ( ) ;
31+ const { error, roleBindings } = usePermissionsContext ( ) ;
2932 const { currentProject } = React . useContext ( ProjectDetailsContext ) ;
3033 const { state } : { state ?: { subjectKind ?: 'user' | 'group' ; subjectName ?: string } } =
3134 useLocation ( ) ;
35+ const navigate = useNavigate ( ) ;
3236 const isManageMode = ! ! state ;
37+ const namespace = currentProject . metadata . name ;
3338
3439 const [ subjectKind , setSubjectKind ] = React . useState < 'user' | 'group' > (
3540 state ?. subjectKind ?? 'user' ,
@@ -41,6 +46,33 @@ const ProjectPermissionsAssignRolesForm: React.FC = () => {
4146 const { rows, selections, toggleSelection, trimmedSubjectName, changes, hasChanges } =
4247 useManageRolesData ( subjectKind , subjectName , existingSubjectNames ) ;
4348
49+ const handleSave = React . useCallback ( async ( ) : Promise < void > => {
50+ const rbacSubjectKind : SupportedSubjectKind =
51+ subjectKind === 'user' ? RBAC_SUBJECT_KIND_USER : RBAC_SUBJECT_KIND_GROUP ;
52+
53+ const result = await applyRoleAssignmentChanges ( {
54+ roleBindings : roleBindings . data ,
55+ namespace,
56+ subjectKind : rbacSubjectKind ,
57+ subjectName : trimmedSubjectName ,
58+ changes,
59+ } ) ;
60+
61+ if ( ! result . success ) {
62+ // Build a descriptive error message
63+ const errorMessages = result . errors . map ( ( e ) => e . message ) . join ( '; ' ) ;
64+ throw new Error (
65+ `${ result . failedCount } of ${ result . totalOperations } operations failed: ${ errorMessages } ` ,
66+ ) ;
67+ }
68+
69+ // Refresh roleBindings after successful save
70+ await roleBindings . refresh ( ) ;
71+
72+ // Navigate back to permissions tab
73+ navigate ( `/projects/${ namespace } ?section=permissions` ) ;
74+ } , [ subjectKind , trimmedSubjectName , changes , roleBindings , namespace , navigate ] ) ;
75+
4476 return (
4577 < ApplicationsPage
4678 title = { isManageMode ? 'Manage roles' : 'Assign roles' }
@@ -114,7 +146,7 @@ const ProjectPermissionsAssignRolesForm: React.FC = () => {
114146 subjectName = { trimmedSubjectName }
115147 changes = { changes }
116148 onClose = { ( ) => setIsConfirmOpen ( false ) }
117- onConfirm = { ( ) => setIsConfirmOpen ( false ) }
149+ onConfirm = { handleSave }
118150 />
119151 ) }
120152 </ ApplicationsPage >
0 commit comments