소스 검색

Fixed branches not loading

jnfrati 3 년 전
부모
커밋
ddae35cd8c
1개의 변경된 파일13개의 추가작업 그리고 26개의 파일을 삭제
  1. 13 26
      dashboard/src/main/home/cluster-dashboard/preview-environments/environments/EnvironmentSettings.tsx

+ 13 - 26
dashboard/src/main/home/cluster-dashboard/preview-environments/environments/EnvironmentSettings.tsx

@@ -45,16 +45,16 @@ const EnvironmentSettings = ({ environmentId }: { environmentId: string }) => {
     );
   };
 
-  const getBranches = async () => {
+  const getBranches = async (env: Environment) => {
     return api.getBranches<string[]>(
       "<token>",
       {},
       {
-        project_id: environment.project_id,
-        git_repo_id: environment.git_installation_id,
+        project_id: env.project_id,
+        git_repo_id: env.git_installation_id,
         kind: "github",
-        owner: environment.git_repo_owner,
-        name: environment.git_repo_name,
+        owner: env.git_repo_owner,
+        name: env.git_repo_name,
       }
     );
   };
@@ -67,28 +67,15 @@ const EnvironmentSettings = ({ environmentId }: { environmentId: string }) => {
     setIsLoading(true);
 
     try {
-      const [environmentResponse, branchesResponse] = await Promise.allSettled([
-        getEnvironment(),
-        getBranches(),
-      ]);
-
-      if (environmentResponse.status === "fulfilled") {
-        const environment = environmentResponse.value.data;
-
-        setEnvironment(environment);
-        setIsNewCommentsDisabled(environment.disable_new_comments);
-        setDeploymentMode(environment.mode);
-        setSelectedBranches(environment.git_repo_branches.filter(Boolean));
-      } else {
-        throw new Error("Failed to get environment");
-      }
+      const environment = await getEnvironment().then((res) => res.data);
+      const branches = await getBranches(environment).then((res) => res.data);
 
-      if (branchesResponse.status === "fulfilled") {
-        const branches = branchesResponse.value.data;
-        setAvailableBranches(branches);
-      } else {
-        throw new Error("Failed to get branches");
-      }
+      setEnvironment(environment);
+      setIsNewCommentsDisabled(environment.disable_new_comments);
+      setDeploymentMode(environment.mode);
+      setSelectedBranches(environment.git_repo_branches.filter(Boolean));
+
+      setAvailableBranches(branches);
     } catch (error) {
       console.error(error);
     } finally {