diff --git a/frontend/src/component/admin/groups/GroupForm/GroupForm.tsx b/frontend/src/component/admin/groups/GroupForm/GroupForm.tsx index 1dfbf97850..e0a4fa538b 100644 --- a/frontend/src/component/admin/groups/GroupForm/GroupForm.tsx +++ b/frontend/src/component/admin/groups/GroupForm/GroupForm.tsx @@ -194,6 +194,7 @@ export const GroupForm: FC = ({ setRootRole(role?.id || null) diff --git a/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountModal.tsx b/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountModal.tsx index 38f74fd654..8213ba4c9a 100644 --- a/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountModal.tsx +++ b/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountModal.tsx @@ -306,6 +306,7 @@ export const ServiceAccountModal = ({ What is your service account allowed to do? ({ display: 'flex', @@ -78,6 +79,7 @@ const UserForm: React.FC = ({ mode, }) => { const { uiConfig } = useUiConfig(); + const { roles } = useUsers(); return ( @@ -106,7 +108,12 @@ const UserForm: React.FC = ({ What is your team member allowed to do? - + { const { uiConfig } = useUiConfig(); - const { roles } = useRoles(); + const { users, roles } = useUsers(); const [name, setName] = useState(initialName); const [email, setEmail] = useState(initialEmail); const [sendEmail, setSendEmail] = useState(false); @@ -19,8 +18,6 @@ const useCreateUserForm = ( ); const [errors, setErrors] = useState({}); - const { users } = useUsers(); - useEffect(() => { setName(initialName); }, [initialName]); diff --git a/frontend/src/component/common/RoleBadge/RoleBadge.tsx b/frontend/src/component/common/RoleBadge/RoleBadge.tsx index 2f1297c8cc..43fc5545bc 100644 --- a/frontend/src/component/common/RoleBadge/RoleBadge.tsx +++ b/frontend/src/component/common/RoleBadge/RoleBadge.tsx @@ -6,12 +6,21 @@ import { RoleDescription } from 'component/common/RoleDescription/RoleDescriptio interface IRoleBadgeProps { roleId: number; + children?: string; } -export const RoleBadge = ({ roleId }: IRoleBadgeProps) => { +export const RoleBadge = ({ roleId, children }: IRoleBadgeProps) => { const { role } = useRole(roleId.toString()); - if (!role) return null; + if (!role) { + if (children) + return ( + }> + {children} + + ); + return null; + } return ( } arrow> diff --git a/frontend/src/component/common/RoleSelect/RoleSelect.tsx b/frontend/src/component/common/RoleSelect/RoleSelect.tsx index 8e373dd9af..b4d04c6cc5 100644 --- a/frontend/src/component/common/RoleSelect/RoleSelect.tsx +++ b/frontend/src/component/common/RoleSelect/RoleSelect.tsx @@ -4,11 +4,9 @@ import { TextField, styled, } from '@mui/material'; -import { useRoles } from 'hooks/api/getters/useRoles/useRoles'; -import { IRole, PredefinedRoleType } from 'interfaces/role'; +import { IRole } from 'interfaces/role'; import { RoleDescription } from '../RoleDescription/RoleDescription'; import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender'; -import { ROOT_ROLE_TYPE } from '@server/util/constants'; const StyledRoleOption = styled('div')(({ theme }) => ({ display: 'flex', @@ -21,23 +19,19 @@ const StyledRoleOption = styled('div')(({ theme }) => ({ interface IRoleSelectProps extends Partial> { - type?: PredefinedRoleType; + roles: IRole[]; value: IRole | null; setValue: (role: IRole | null) => void; required?: boolean; } export const RoleSelect = ({ - type = ROOT_ROLE_TYPE, + roles, value, setValue, required, ...rest }: IRoleSelectProps) => { - const { roles: rootRoles, projectRoles } = useRoles(); - - const roles = type === ROOT_ROLE_TYPE ? rootRoles : projectRoles; - const renderRoleOption = ( props: React.HTMLAttributes, option: IRole diff --git a/frontend/src/component/common/RoleSelect/RoleSelect2.tsx b/frontend/src/component/common/RoleSelect/RoleSelect2.tsx deleted file mode 100644 index 23fad25b48..0000000000 --- a/frontend/src/component/common/RoleSelect/RoleSelect2.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { - Autocomplete, - AutocompleteProps, - TextField, - styled, -} from '@mui/material'; -import { useRoles } from 'hooks/api/getters/useRoles/useRoles'; -import { IRole, PredefinedRoleType } from 'interfaces/role'; -import { RoleDescription } from '../RoleDescription/RoleDescription'; -import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender'; - -const StyledRoleOption = styled('div')(({ theme }) => ({ - display: 'flex', - flexDirection: 'column', - '& > span:last-of-type': { - fontSize: theme.fontSizes.smallerBody, - color: theme.palette.text.secondary, - }, -})); - -interface IRoleSelectProps - extends Partial> { - value: IRole | null; - setValue: (role: IRole | null) => void; - roles: IRole[]; - required?: boolean; -} - -export const RoleSelect = ({ - value, - setValue, - required, - roles, - ...rest -}: IRoleSelectProps) => { - const renderRoleOption = ( - props: React.HTMLAttributes, - option: IRole - ) => ( -
  • - - {option.name} - {option.description} - -
  • - ); - - return ( - <> - setValue(role || null)} - options={roles} - renderOption={renderRoleOption} - getOptionLabel={option => option.name} - renderInput={params => ( - - )} - {...rest} - /> - ( - - )} - /> - - ); -}; diff --git a/frontend/src/component/common/Table/cells/RoleCell/RoleCell.tsx b/frontend/src/component/common/Table/cells/RoleCell/RoleCell.tsx index f8b32610a8..28b97df2f1 100644 --- a/frontend/src/component/common/Table/cells/RoleCell/RoleCell.tsx +++ b/frontend/src/component/common/Table/cells/RoleCell/RoleCell.tsx @@ -10,9 +10,9 @@ interface IRoleCellProps { } export const RoleCell: VFC = ({ roleId, value }) => { - const { isEnterprise, uiConfig } = useUiConfig(); + const { isEnterprise } = useUiConfig(); - if (isEnterprise() && uiConfig.flags.customRootRoles) { + if (isEnterprise()) { return ( ({ display: 'flex', diff --git a/frontend/src/component/user/Profile/ProfileTab/ProfileTab.tsx b/frontend/src/component/user/Profile/ProfileTab/ProfileTab.tsx index c2fab49226..e88f76d244 100644 --- a/frontend/src/component/user/Profile/ProfileTab/ProfileTab.tsx +++ b/frontend/src/component/user/Profile/ProfileTab/ProfileTab.tsx @@ -141,7 +141,9 @@ export const ProfileTab = ({ user }: IProfileTabProps) => { Your root role - + + {profile?.rootRole.name} + )} /> diff --git a/frontend/src/hooks/api/getters/useRole/useRole.ts b/frontend/src/hooks/api/getters/useRole/useRole.ts index 46f34bbfce..4fa6429a95 100644 --- a/frontend/src/hooks/api/getters/useRole/useRole.ts +++ b/frontend/src/hooks/api/getters/useRole/useRole.ts @@ -2,7 +2,7 @@ import { SWRConfiguration } from 'swr'; import { useMemo } from 'react'; import { formatApiPath } from 'utils/formatPath'; import handleErrorResponses from '../httpErrorResponseHandler'; -import { IRole, IRoleWithPermissions } from 'interfaces/role'; +import { IRoleWithPermissions } from 'interfaces/role'; import useUiConfig from '../useUiConfig/useUiConfig'; import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR'; @@ -27,40 +27,15 @@ export const useRole = ( options ); - const { - data: ossData, - error: ossError, - mutate: ossMutate, - } = useConditionalSWR( - Boolean(id) && !isEnterprise(), - { rootRoles: [] }, - formatApiPath(`api/admin/user-admin`), - fetcher, - options + return useMemo( + () => ({ + role: data as IRoleWithPermissions, + loading: !error && !data, + refetch: () => mutate(), + error, + }), + [data, error, mutate] ); - - return useMemo(() => { - if (!isEnterprise()) { - return { - role: { - ...((ossData?.rootRoles ?? []) as IRole[]).find( - ({ id: rId }) => rId === +id! - ), - permissions: [], - } as IRoleWithPermissions, - loading: !ossError && !ossData, - refetch: () => ossMutate(), - error: ossError, - }; - } else { - return { - role: data as IRoleWithPermissions, - loading: !error && !data, - refetch: () => mutate(), - error, - }; - } - }, [data, error, mutate, ossData, ossError, ossMutate]); }; const fetcher = (path: string) => { diff --git a/frontend/src/hooks/api/getters/useRoles/useRoles.ts b/frontend/src/hooks/api/getters/useRoles/useRoles.ts index 506875867e..ea2548cc28 100644 --- a/frontend/src/hooks/api/getters/useRoles/useRoles.ts +++ b/frontend/src/hooks/api/getters/useRoles/useRoles.ts @@ -6,7 +6,6 @@ import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR'; import useUiConfig from '../useUiConfig/useUiConfig'; import { PROJECT_ROLE_TYPES, - ROOT_ROLE_TYPE, ROOT_ROLE_TYPES, PREDEFINED_ROLE_TYPES, } from '@server/util/constants'; @@ -20,7 +19,7 @@ interface IUseRolesOutput { } export const useRoles = (): IUseRolesOutput => { - const { isEnterprise, uiConfig } = useUiConfig(); + const { isEnterprise } = useUiConfig(); const { data, error, mutate } = useConditionalSWR( isEnterprise(), @@ -29,48 +28,20 @@ export const useRoles = (): IUseRolesOutput => { fetcher ); - const { - data: ossData, - error: ossError, - mutate: ossMutate, - } = useConditionalSWR( - !isEnterprise(), - { rootRoles: [] }, - formatApiPath(`api/admin/user-admin`), - fetcher + return useMemo( + () => ({ + roles: (data?.roles + .filter(({ type }: IRole) => ROOT_ROLE_TYPES.includes(type)) + .sort(sortRoles) ?? []) as IRole[], + projectRoles: (data?.roles + .filter(({ type }: IRole) => PROJECT_ROLE_TYPES.includes(type)) + .sort(sortRoles) ?? []) as IRole[], + loading: !error && !data, + refetch: () => mutate(), + error, + }), + [data, error, mutate] ); - - return useMemo(() => { - if (!isEnterprise()) { - return { - roles: ossData?.rootRoles - .filter(({ type }: IRole) => type === ROOT_ROLE_TYPE) - .sort(sortRoles) as IRole[], - projectRoles: [], - loading: !ossError && !ossData, - refetch: () => ossMutate(), - error: ossError, - }; - } else { - return { - roles: (data?.roles - .filter(({ type }: IRole) => - uiConfig.flags.customRootRoles - ? ROOT_ROLE_TYPES.includes(type) - : type === ROOT_ROLE_TYPE - ) - .sort(sortRoles) ?? []) as IRole[], - projectRoles: (data?.roles - .filter(({ type }: IRole) => - PROJECT_ROLE_TYPES.includes(type) - ) - .sort(sortRoles) ?? []) as IRole[], - loading: !error && !data, - refetch: () => mutate(), - error, - }; - } - }, [data, error, mutate, ossData, ossError, ossMutate]); }; const fetcher = (path: string) => {