From 99f5f44482aa81a17ca58be561a43199af5d9f95 Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Tue, 17 Jan 2023 18:33:34 -0300 Subject: [PATCH] fix: Only fetch groups when it is enabled (#5753) --- site/src/pages/GroupsPage/GroupsPage.tsx | 5 +++-- site/src/xServices/groups/groupsXService.ts | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/site/src/pages/GroupsPage/GroupsPage.tsx b/site/src/pages/GroupsPage/GroupsPage.tsx index 3319fe74e2..f51e2d788c 100644 --- a/site/src/pages/GroupsPage/GroupsPage.tsx +++ b/site/src/pages/GroupsPage/GroupsPage.tsx @@ -10,14 +10,15 @@ import GroupsPageView from "./GroupsPageView" export const GroupsPage: FC = () => { const organizationId = useOrganizationId() + const { createGroup: canCreateGroup } = usePermissions() + const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility() const [state] = useMachine(groupsMachine, { context: { organizationId, + shouldFetchGroups: isTemplateRBACEnabled, }, }) const { groups } = state.context - const { createGroup: canCreateGroup } = usePermissions() - const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility() return ( <> diff --git a/site/src/xServices/groups/groupsXService.ts b/site/src/xServices/groups/groupsXService.ts index 451bd85fc5..ff17e94dc5 100644 --- a/site/src/xServices/groups/groupsXService.ts +++ b/site/src/xServices/groups/groupsXService.ts @@ -11,6 +11,7 @@ export const groupsMachine = createMachine( schema: { context: {} as { organizationId: string + shouldFetchGroups: boolean groups?: Group[] }, services: {} as { @@ -23,6 +24,7 @@ export const groupsMachine = createMachine( initial: "loading", states: { loading: { + always: [{ target: "idle", cond: "cantFetchGroups" }], invoke: { src: "loadGroups", onDone: { @@ -39,6 +41,9 @@ export const groupsMachine = createMachine( }, }, { + guards: { + cantFetchGroups: ({ shouldFetchGroups }) => !shouldFetchGroups, + }, services: { loadGroups: ({ organizationId }) => getGroups(organizationId), },