Skip to content

Commit

Permalink
Add rolesFetchError to state
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Sep 17, 2024
1 parent 89278c9 commit ebe0c6a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,18 @@ export const EditSpace: FC<PageProps> = ({
logger.error('Encountered error while getting list of roles for space!');
logger.error(error);
}
handleApiError(error, { logger, toasts: notifications.toasts });
dispatch({ type: 'fetch_roles_error', payload: true });
}
dispatch({ type: 'update_roles', payload: result });
});

setIsLoadingRoles(false);
};

if (!state.roles.size) {
// maybe we do not make this call if user can't view roles? 🤔
getRoles().catch((error) => handleApiError(error, { logger, toasts: notifications.toasts }));
if (!state.roles.size && !state.fetchRolesError) {
getRoles();
}
}, [dispatch, invokeClient, spaceId, state.roles, logger, notifications.toasts]);
}, [dispatch, invokeClient, spaceId, state.roles, state.fetchRolesError, logger]);

useEffect(() => {
const _getFeatures = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const EditSpaceProvider = ({

const initialStoreState = useRef<IEditSpaceStoreState>({
roles: new Map(),
fetchRolesError: false,
});

const { logger } = services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import type { Role } from '@kbn/security-plugin-types-common';

export type IDispatchAction =
| {
/** @description updates a single role record */
/** @description updates the records of roles for a space */
type: 'update_roles' | 'remove_roles';
payload: Role[];
}
| {
/** @description updates to true if user does not have privilege to view roles */
type: 'fetch_roles_error';
payload: boolean;
}
| {
type: 'string';
payload: unknown;
Expand All @@ -23,6 +28,8 @@ export type IDispatchAction =
export interface IEditSpaceStoreState {
/** roles assigned to current space */
roles: Map<string, Role>;
/** track if there was an error on the attempt to fetch roles **/
fetchRolesError: boolean;
}

export const createSpaceRolesReducer: Reducer<IEditSpaceStoreState, IDispatchAction> = (
Expand All @@ -48,6 +55,10 @@ export const createSpaceRolesReducer: Reducer<IEditSpaceStoreState, IDispatchAct

return clonedState;
}
case 'fetch_roles_error': {
clonedState.fetchRolesError = action.payload;
return clonedState;
}
default: {
return clonedState;
}
Expand Down

0 comments on commit ebe0c6a

Please sign in to comment.