Skip to content

Commit 99f5f44

Browse files
fix: Only fetch groups when it is enabled (coder#5753)
1 parent 35d4766 commit 99f5f44

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

site/src/pages/GroupsPage/GroupsPage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import GroupsPageView from "./GroupsPageView"
1010

1111
export const GroupsPage: FC = () => {
1212
const organizationId = useOrganizationId()
13+
const { createGroup: canCreateGroup } = usePermissions()
14+
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility()
1315
const [state] = useMachine(groupsMachine, {
1416
context: {
1517
organizationId,
18+
shouldFetchGroups: isTemplateRBACEnabled,
1619
},
1720
})
1821
const { groups } = state.context
19-
const { createGroup: canCreateGroup } = usePermissions()
20-
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility()
2122

2223
return (
2324
<>

site/src/xServices/groups/groupsXService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const groupsMachine = createMachine(
1111
schema: {
1212
context: {} as {
1313
organizationId: string
14+
shouldFetchGroups: boolean
1415
groups?: Group[]
1516
},
1617
services: {} as {
@@ -23,6 +24,7 @@ export const groupsMachine = createMachine(
2324
initial: "loading",
2425
states: {
2526
loading: {
27+
always: [{ target: "idle", cond: "cantFetchGroups" }],
2628
invoke: {
2729
src: "loadGroups",
2830
onDone: {
@@ -39,6 +41,9 @@ export const groupsMachine = createMachine(
3941
},
4042
},
4143
{
44+
guards: {
45+
cantFetchGroups: ({ shouldFetchGroups }) => !shouldFetchGroups,
46+
},
4247
services: {
4348
loadGroups: ({ organizationId }) => getGroups(organizationId),
4449
},

0 commit comments

Comments
 (0)