Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bac7743

Browse files
committed
raise a FE prop field up the stack
1 parent 40e362c commit bac7743

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

site/src/components/UsersTable/UsersTable.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface UsersTableProps {
3636
) => void
3737
isNonInitialPage: boolean
3838
actorID: string
39+
oidcRoleSyncEnabled: boolean
3940
}
4041

4142
export const UsersTable: FC<React.PropsWithChildren<UsersTableProps>> = ({
@@ -54,6 +55,7 @@ export const UsersTable: FC<React.PropsWithChildren<UsersTableProps>> = ({
5455
isLoading,
5556
isNonInitialPage,
5657
actorID,
58+
oidcRoleSyncEnabled,
5759
}) => {
5860
return (
5961
<TableContainer>
@@ -91,6 +93,7 @@ export const UsersTable: FC<React.PropsWithChildren<UsersTableProps>> = ({
9193
onUpdateUserRoles={onUpdateUserRoles}
9294
isNonInitialPage={isNonInitialPage}
9395
actorID={actorID}
96+
oidcRoleSyncEnabled={oidcRoleSyncEnabled}
9497
/>
9598
</TableBody>
9699
</Table>

site/src/components/UsersTable/UsersTableBody.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ import { TableRowMenu } from "../TableRowMenu/TableRowMenu"
1616
import { EditRolesButton } from "components/EditRolesButton/EditRolesButton"
1717
import { Stack } from "components/Stack/Stack"
1818
import { EnterpriseBadge } from "components/DeploySettingsLayout/Badges"
19-
import { usePermissions } from "hooks"
20-
import { deploymentConfigMachine } from "xServices/deploymentConfig/deploymentConfigMachine"
21-
import { useMachine } from "@xstate/react"
2219

2320
const isOwnerRole = (role: TypesGen.Role): boolean => {
2421
return role.name === "owner"
@@ -51,6 +48,10 @@ interface UsersTableBodyProps {
5148
) => void
5249
isNonInitialPage: boolean
5350
actorID: string
51+
// oidcRoleSyncEnabled should be set to false if unknown.
52+
// This is used to determine if the oidc roles are synced from the oidc idp and
53+
// editing via the UI should be disabled.
54+
oidcRoleSyncEnabled: boolean
5455
}
5556

5657
export const UsersTableBody: FC<
@@ -71,22 +72,11 @@ export const UsersTableBody: FC<
7172
isLoading,
7273
isNonInitialPage,
7374
actorID,
75+
oidcRoleSyncEnabled,
7476
}) => {
7577
const styles = useStyles()
7678
const { t } = useTranslation("usersPage")
7779

78-
const permissions = usePermissions()
79-
const canViewDeployment = Boolean(permissions.viewDeploymentValues)
80-
// Ideally this only runs if 'canViewDeployment' is true.
81-
// TODO: Prevent api call if the user does not have the perms.
82-
const [state] = useMachine(deploymentConfigMachine)
83-
const { deploymentValues } = state.context
84-
85-
// Indicates if oidc roles are synced from the oidc idp.
86-
// Assign 'false' if unknown.
87-
const oidcRoleSync =
88-
canViewDeployment && deploymentValues?.config.oidc?.user_role_field !== ""
89-
9080
return (
9181
<ChooseOne>
9282
<Cond condition={Boolean(isLoading)}>
@@ -143,7 +133,7 @@ export const UsersTableBody: FC<
143133
selectedRoles={userRoles}
144134
isLoading={Boolean(isUpdatingUserRoles)}
145135
userLoginType={user.login_type}
146-
oidcRoleSync={oidcRoleSync}
136+
oidcRoleSync={oidcRoleSyncEnabled}
147137
onChange={(roles) => {
148138
// Remove the fallback role because it is only for the UI
149139
const rolesWithoutFallback = roles.filter(

site/src/pages/UsersPage/UsersPage.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { UsersPageView } from "./UsersPageView"
2020
import { useStatusFilterMenu } from "./UsersFilter"
2121
import { useFilter } from "components/Filter/filter"
2222
import { useDashboard } from "components/Dashboard/DashboardProvider"
23+
import { deploymentConfigMachine } from "xServices/deploymentConfig/deploymentConfigMachine"
2324

2425
export const Language = {
2526
suspendDialogTitle: "Suspend user",
@@ -61,14 +62,24 @@ export const UsersPage: FC<{ children?: ReactNode }> = () => {
6162
count,
6263
} = usersState.context
6364

64-
const { updateUsers: canEditUsers } = usePermissions()
65+
const { updateUsers: canEditUsers, viewDeploymentValues } = usePermissions()
6566
const [rolesState] = useMachine(siteRolesMachine, {
6667
context: {
6768
hasPermission: canEditUsers,
6869
},
6970
})
7071
const { roles } = rolesState.context
7172

73+
// Ideally this only runs if 'canViewDeployment' is true.
74+
// TODO: Prevent api call if the user does not have the perms.
75+
const [state] = useMachine(deploymentConfigMachine)
76+
const { deploymentValues } = state.context
77+
// Indicates if oidc roles are synced from the oidc idp.
78+
// Assign 'false' if unknown.
79+
const oidcRoleSyncEnabled =
80+
viewDeploymentValues &&
81+
deploymentValues?.config.oidc?.user_role_field !== ""
82+
7283
// Is loading if
7384
// - users are loading or
7485
// - the user can edit the users but the roles are loading
@@ -102,6 +113,7 @@ export const UsersPage: FC<{ children?: ReactNode }> = () => {
102113
<title>{pageTitle("Users")}</title>
103114
</Helmet>
104115
<UsersPageView
116+
oidcRoleSyncEnabled={oidcRoleSyncEnabled}
105117
roles={roles}
106118
users={users}
107119
count={count}

site/src/pages/UsersPage/UsersPageView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface UsersPageViewProps {
1616
roles?: TypesGen.AssignableRoles[]
1717
isUpdatingUserRoles?: boolean
1818
canEditUsers?: boolean
19+
oidcRoleSyncEnabled?: boolean
1920
canViewActivity?: boolean
2021
isLoading?: boolean
2122
onSuspendUser: (user: TypesGen.User) => void
@@ -47,6 +48,7 @@ export const UsersPageView: FC<React.PropsWithChildren<UsersPageViewProps>> = ({
4748
onUpdateUserRoles,
4849
isUpdatingUserRoles,
4950
canEditUsers,
51+
oidcRoleSyncEnabled,
5052
canViewActivity,
5153
isLoading,
5254
filterProps,
@@ -77,6 +79,7 @@ export const UsersPageView: FC<React.PropsWithChildren<UsersPageViewProps>> = ({
7779
onUpdateUserRoles={onUpdateUserRoles}
7880
isUpdatingUserRoles={isUpdatingUserRoles}
7981
canEditUsers={canEditUsers}
82+
oidcRoleSyncEnabled={oidcRoleSyncEnabled}
8083
canViewActivity={canViewActivity}
8184
isLoading={isLoading}
8285
isNonInitialPage={isNonInitialPage}

0 commit comments

Comments
 (0)