瀏覽代碼

Fixed state not being populated properly

jnfrati 4 年之前
父節點
當前提交
0d8a11b752
共有 1 個文件被更改,包括 26 次插入15 次删除
  1. 26 15
      dashboard/src/main/home/cluster-dashboard/expanded-chart/BuildSettingsTab.tsx

+ 26 - 15
dashboard/src/main/home/cluster-dashboard/expanded-chart/BuildSettingsTab.tsx

@@ -485,15 +485,17 @@ const BuildpackConfigSection: React.FC<{
       return buildpack.buildpack;
       return buildpack.buildpack;
     });
     });
 
 
+    onChange(buildConfig);
+  }, [selectedBuilder, selectedBuildpacks, selectedStack]);
+
+  useEffect(() => {
     populateState(
     populateState(
       selectedBuilder,
       selectedBuilder,
       selectedStack,
       selectedStack,
       availableBuildpacks,
       availableBuildpacks,
       selectedBuildpacks
       selectedBuildpacks
     );
     );
-
-    onChange(buildConfig);
-  }, [selectedBuilder, selectedBuildpacks, selectedStack]);
+  }, [selectedBuilder, selectedBuildpacks, selectedStack, availableBuildpacks]);
 
 
   const builderOptions = useMemo(() => {
   const builderOptions = useMemo(() => {
     if (!Array.isArray(builders)) {
     if (!Array.isArray(builders)) {
@@ -547,7 +549,24 @@ const BuildpackConfigSection: React.FC<{
     buildpacks: Buildpack[],
     buildpacks: Buildpack[],
     action: "remove" | "add"
     action: "remove" | "add"
   ) => {
   ) => {
-    return buildpacks?.map((buildpack) => {
+    if (!buildpacks.length && action === "remove") {
+      return (
+        <StyledCard>
+          Buildpacks are going to be automatically detected.
+        </StyledCard>
+      );
+    }
+
+    if (!buildpacks.length && action === "add") {
+      return (
+        <StyledCard>
+          There are no more buildpacks available, you can try adding a custom
+          one if you want.
+        </StyledCard>
+      );
+    }
+
+    return buildpacks?.map((buildpack, i) => {
       const icon = `devicon-${buildpack?.name?.toLowerCase()}-plain colored`;
       const icon = `devicon-${buildpack?.name?.toLowerCase()}-plain colored`;
 
 
       let disableIcon = false;
       let disableIcon = false;
@@ -559,7 +578,7 @@ const BuildpackConfigSection: React.FC<{
       }
       }
 
 
       return (
       return (
-        <StyledCard>
+        <StyledCard key={i}>
           <ContentContainer>
           <ContentContainer>
             <Icon disableMarginRight={disableIcon} className={icon} />
             <Icon disableMarginRight={disableIcon} className={icon} />
             <EventInformation>
             <EventInformation>
@@ -639,7 +658,6 @@ const BuildpackConfigSection: React.FC<{
           setActiveValue={(option) => handleSelectBuilder(option)}
           setActiveValue={(option) => handleSelectBuilder(option)}
           label="Select a builder"
           label="Select a builder"
         />
         />
-
         <SelectRow
         <SelectRow
           value={selectedStack}
           value={selectedStack}
           width="100%"
           width="100%"
@@ -651,20 +669,13 @@ const BuildpackConfigSection: React.FC<{
           The following buildpacks were automatically detected. You can also
           The following buildpacks were automatically detected. You can also
           manually add/remove buildpacks.
           manually add/remove buildpacks.
         </Helper>
         </Helper>
-
-        {!!selectedBuildpacks?.length &&
-          renderBuildpacksList(selectedBuildpacks, "remove")}
-
+        <>{renderBuildpacksList(selectedBuildpacks, "remove")}</>
         <Helper>Available buildpacks:</Helper>
         <Helper>Available buildpacks:</Helper>
-        {!!availableBuildpacks?.length && (
-          <>{renderBuildpacksList(availableBuildpacks, "add")}</>
-        )}
-
+        <>{renderBuildpacksList(availableBuildpacks, "add")}</>
         <Helper>
         <Helper>
           You may also add buildpacks by directly providing their GitHub links
           You may also add buildpacks by directly providing their GitHub links
           or links to ZIP files that contain the buildpack source code.
           or links to ZIP files that contain the buildpack source code.
         </Helper>
         </Helper>
-
         <AddCustomBuildpackForm onAdd={handleAddCustomBuildpack} />
         <AddCustomBuildpackForm onAdd={handleAddCustomBuildpack} />
       </>
       </>
     </BuildpackConfigurationContainer>
     </BuildpackConfigurationContainer>