From d0a21201e25eb6f1654175de49fb3cd1a41cc96e Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Tue, 26 Nov 2024 10:15:50 +0000 Subject: [PATCH 1/4] Fix EnvironmentReadyChecker --- frontend/web/components/EnvironmentReadyChecker.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/web/components/EnvironmentReadyChecker.tsx b/frontend/web/components/EnvironmentReadyChecker.tsx index 0967f5366ff5..1bf9af6caeb3 100644 --- a/frontend/web/components/EnvironmentReadyChecker.tsx +++ b/frontend/web/components/EnvironmentReadyChecker.tsx @@ -13,11 +13,21 @@ const EnvironmentReadyChecker: FC = ({ children, match, }) => { + const { data: isCreatingCheck } = useGetEnvironmentQuery( + { + id: match.params.environmentId, + }, + { skip: true }, + ) + const hasCreateEnvironment = !!isCreatingCheck && !isCreatingCheck.is_creating const { data, isLoading } = useGetEnvironmentQuery( { id: match.params.environmentId, }, - { pollingInterval: 1000, skip: !match.params.environmentId }, + { + pollingInterval: 1000, + skip: !match.params.environmentId || hasCreateEnvironment, + }, ) if (!match?.params?.environmentId) { return children From af5abe8a82507caf41b5a1bdc8e2a066f894a4ab Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Tue, 26 Nov 2024 10:18:28 +0000 Subject: [PATCH 2/4] improve variable name --- frontend/web/components/EnvironmentReadyChecker.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/web/components/EnvironmentReadyChecker.tsx b/frontend/web/components/EnvironmentReadyChecker.tsx index 1bf9af6caeb3..c72df26a1f16 100644 --- a/frontend/web/components/EnvironmentReadyChecker.tsx +++ b/frontend/web/components/EnvironmentReadyChecker.tsx @@ -19,14 +19,14 @@ const EnvironmentReadyChecker: FC = ({ }, { skip: true }, ) - const hasCreateEnvironment = !!isCreatingCheck && !isCreatingCheck.is_creating + const environmentCreated = !!isCreatingCheck && !isCreatingCheck.is_creating const { data, isLoading } = useGetEnvironmentQuery( { id: match.params.environmentId, }, { pollingInterval: 1000, - skip: !match.params.environmentId || hasCreateEnvironment, + skip: !match.params.environmentId || environmentCreated, }, ) if (!match?.params?.environmentId) { From 2a9c21b37e50e47b476ea53f5df36126117ac104 Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Tue, 26 Nov 2024 10:21:22 +0000 Subject: [PATCH 3/4] Improve check for environment created --- .../web/components/EnvironmentReadyChecker.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/web/components/EnvironmentReadyChecker.tsx b/frontend/web/components/EnvironmentReadyChecker.tsx index c72df26a1f16..bf92a1dee5a2 100644 --- a/frontend/web/components/EnvironmentReadyChecker.tsx +++ b/frontend/web/components/EnvironmentReadyChecker.tsx @@ -1,4 +1,4 @@ -import { FC } from 'react' +import { FC, useEffect, useState } from 'react' import { useGetEnvironmentQuery } from 'common/services/useEnvironment' type EnvironmentReadyCheckerType = { @@ -13,13 +13,8 @@ const EnvironmentReadyChecker: FC = ({ children, match, }) => { - const { data: isCreatingCheck } = useGetEnvironmentQuery( - { - id: match.params.environmentId, - }, - { skip: true }, - ) - const environmentCreated = !!isCreatingCheck && !isCreatingCheck.is_creating + const [environmentCreated, setEnvironmentCreated] = useState(false) + const { data, isLoading } = useGetEnvironmentQuery( { id: match.params.environmentId, @@ -29,6 +24,11 @@ const EnvironmentReadyChecker: FC = ({ skip: !match.params.environmentId || environmentCreated, }, ) + useEffect(() => { + if (!!data && !data?.is_creating) { + setEnvironmentCreated(true) + } + }, [data?.is_creating]) if (!match?.params?.environmentId) { return children } From 36b0975de3b8790967a21f7eb8f9010b81951b2c Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Tue, 26 Nov 2024 10:22:40 +0000 Subject: [PATCH 4/4] Fix lint --- frontend/web/components/EnvironmentReadyChecker.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/web/components/EnvironmentReadyChecker.tsx b/frontend/web/components/EnvironmentReadyChecker.tsx index bf92a1dee5a2..cb82fa5abf49 100644 --- a/frontend/web/components/EnvironmentReadyChecker.tsx +++ b/frontend/web/components/EnvironmentReadyChecker.tsx @@ -28,7 +28,7 @@ const EnvironmentReadyChecker: FC = ({ if (!!data && !data?.is_creating) { setEnvironmentCreated(true) } - }, [data?.is_creating]) + }, [data]) if (!match?.params?.environmentId) { return children }