fix: stop infinite rerender in move experiment modal
+import { useMemo } from 'react';
+
import { useStore } from 'contexts/Store';
import useFeature from 'hooks/useFeature';
import { V1PermissionType } from 'services/api-ts-sdk/api';
@@ -80,16 +82,21 @@ const usePermissions = (): PermissionsHook => {
const rbacEnabled = useFeature().isOn('rbac');
const rbacAllPermission = useFeature().isOn('mock_permissions_all');
const rbacReadPermission = useFeature().isOn('mock_permissions_read') || rbacAllPermission;
- const rbacOpts = {
+
+ const rbacOpts = useMemo(
+ () => ({
rbacAllPermission,
rbacEnabled,
rbacReadPermission,
user,
userAssignments,
userRoles,
- };
+ }),
+ [rbacAllPermission, rbacEnabled, rbacReadPermission, user, userAssignments, userRoles],
+ );
- return {
+ const permissions = useMemo(
+ () => ({
canAssignRoles: (args: WorkspacePermissionsArgs) => canAssignRoles(rbacOpts, args.workspace),
canCreateExperiment: (args: WorkspacePermissionsArgs) =>
canCreateExperiment(rbacOpts, args.workspace),
@@ -123,7 +130,8 @@ const usePermissions = (): PermissionsHook => {
canMoveExperimentsTo(rbacOpts, args.destination),
canMoveProjects: (args: ProjectPermissionsArgs) =>
canMoveWorkspaceProjects(rbacOpts, args.project),
- canMoveProjectsTo: (args: MovePermissionsArgs) => canMoveProjectsTo(rbacOpts, args.destination),
+ canMoveProjectsTo: (args: MovePermissionsArgs) =>
+ canMoveProjectsTo(rbacOpts, args.destination),
canUpdateRoles: (args: WorkspacePermissionsArgs) => canUpdateRoles(rbacOpts, args.workspace),
canViewExperimentArtifacts: (args: WorkspacePermissionsArgs) =>
canViewExperimentArtifacts(rbacOpts, args.workspace),
@@ -132,7 +140,11 @@ const usePermissions = (): PermissionsHook => {
canViewWorkspace: (args: WorkspacePermissionsArgs) =>
canViewWorkspace(rbacOpts, args.workspace),
canViewWorkspaces: canViewWorkspaces(rbacOpts),
- };
+ }),
+ [rbacOpts],
+ );
+
+ return permissions;
};
// Permissions inside this workspace scope (no workspace = cluster-wide scope)
