jusrhee 5 lat temu
rodzic
commit
21ccc88672

+ 4 - 4
dashboard/src/components/image-selector/TagList.tsx

@@ -8,7 +8,7 @@ import { Context } from "shared/Context";
 
 import Loading from "../Loading";
 
-var ecrRepoRegex = /(^[a-zA-Z0-9][a-zA-Z0-9-_]*)\.dkr\.ecr(\-fips)?\.([a-zA-Z0-9][a-zA-Z0-9-_]*)\.amazonaws\.com(\.cn)?/igm
+var ecrRepoRegex = /(^[a-zA-Z0-9][a-zA-Z0-9-_]*)\.dkr\.ecr(\-fips)?\.([a-zA-Z0-9][a-zA-Z0-9-_]*)\.amazonaws\.com(\.cn)?/gim;
 
 type PropsType = {
   setSelectedTag: (x: string) => void;
@@ -38,12 +38,12 @@ export default class TagList extends Component<PropsType, StateType> {
     let splits = this.props.selectedImageUrl.split("/");
     let repoName = splits[splits.length - 1];
 
-    let matches = this.props.selectedImageUrl.match(ecrRepoRegex)
+    let matches = this.props.selectedImageUrl.match(ecrRepoRegex);
 
     if (matches) {
-      repoName = this.props.selectedImageUrl.split(/\/(.+)/)[1]
+      repoName = this.props.selectedImageUrl.split(/\/(.+)/)[1];
     }
-  
+
     api
       .getImageTags(
         "<token>",

+ 38 - 6
dashboard/src/components/values-form/ValuesForm.tsx

@@ -33,7 +33,13 @@ export default class ValuesForm extends Component<PropsType, StateType> {
       let key = item.name || item.variable;
       let value = this.props.metaState[key]?.value;
 
-      if (item.settings && item.settings.unit && value && value.includes) {
+      if (
+        item.settings &&
+        item.settings.unit &&
+        value &&
+        value.includes &&
+        !item.settings.omitUnitFromValue
+      ) {
         value = value.split(item.settings.unit)[0];
       }
       return value;
@@ -138,7 +144,13 @@ export default class ValuesForm extends Component<PropsType, StateType> {
               type="text"
               value={this.getInputValue(item)}
               setValue={(x: string) => {
-                if (item.settings && item.settings.unit && x !== "") {
+                console.log("dafuq");
+                if (
+                  item.settings &&
+                  item.settings.unit &&
+                  x !== "" &&
+                  !item.settings.omitUnitFromValue
+                ) {
                   x = x + item.settings.unit;
                 }
                 this.props.setMetaState(key, x);
@@ -156,7 +168,12 @@ export default class ValuesForm extends Component<PropsType, StateType> {
               type="password"
               value={this.getInputValue(item)}
               setValue={(x: string) => {
-                if (item.settings && item.settings.unit && x !== "") {
+                if (
+                  item.settings &&
+                  item.settings.unit &&
+                  x !== "" &&
+                  !item.settings.omitUnitFromValue
+                ) {
                   x = x + item.settings.unit;
                 }
                 this.props.setMetaState(key, x);
@@ -181,7 +198,12 @@ export default class ValuesForm extends Component<PropsType, StateType> {
                 }
 
                 // Convert to string if unit is set
-                if (item.settings && item.settings.unit) {
+                console.log("huh", item);
+                if (
+                  item.settings &&
+                  item.settings.unit &&
+                  !item.settings.omitUnitFromValue
+                ) {
                   val = x.toString();
                   val = val + item.settings.unit;
                 }
@@ -229,7 +251,12 @@ export default class ValuesForm extends Component<PropsType, StateType> {
               type="text"
               value={this.getInputValue(item)}
               setValue={(x: string) => {
-                if (item.settings && item.settings.unit && x !== "") {
+                if (
+                  item.settings &&
+                  item.settings.unit &&
+                  x !== "" &&
+                  !item.settings.omitUnitFromValue
+                ) {
                   x = x + item.settings.unit;
                 }
                 this.props.setMetaState(key, btoa(x));
@@ -247,7 +274,12 @@ export default class ValuesForm extends Component<PropsType, StateType> {
               type="password"
               value={this.getInputValue(item)}
               setValue={(x: string) => {
-                if (item.settings && item.settings.unit && x !== "") {
+                if (
+                  item.settings &&
+                  item.settings.unit &&
+                  x !== "" &&
+                  !item.settings.omitUnitFromValue
+                ) {
                   x = x + item.settings.unit;
                 }
                 this.props.setMetaState(key, btoa(x));

+ 13 - 8
dashboard/src/main/Main.tsx

@@ -55,13 +55,14 @@ export default class Main extends Component<PropsType, StateType> {
         }
       })
       .catch((err) => this.setState({ isLoggedIn: false, loading: false }));
-    
-    api.getCapabilities("", {}, {})
-    .then((res) => {
-      console.log(res.data)
-      this.setState({local: !res.data?.provisioner})
-    })
-    .catch((err) => console.log(err));
+
+    api
+      .getCapabilities("", {}, {})
+      .then((res) => {
+        console.log(res.data);
+        this.setState({ local: !res.data?.provisioner });
+      })
+      .catch((err) => console.log(err));
   }
 
   initialize = () => {
@@ -109,7 +110,11 @@ export default class Main extends Component<PropsType, StateType> {
     }
 
     // if logged in but not verified, block until email verification
-    if (!this.state.local && this.state.isLoggedIn && !this.state.isEmailVerified) {
+    if (
+      !this.state.local &&
+      this.state.isLoggedIn &&
+      !this.state.isEmailVerified
+    ) {
       return (
         <Switch>
           <Route

+ 12 - 11
dashboard/src/main/auth/Login.tsx

@@ -40,11 +40,12 @@ export default class Login extends Component<PropsType, StateType> {
       : document.addEventListener("keydown", this.handleKeyDown);
 
     // get capabilities to case on github
-    api.getCapabilities("", {}, {})
-    .then((res) => {
-      this.setState({hasGithub: res.data?.github})
-    })
-    .catch((err) => console.log(err));
+    api
+      .getCapabilities("", {}, {})
+      .then((res) => {
+        this.setState({ hasGithub: res.data?.github });
+      })
+      .catch((err) => console.log(err));
   }
 
   componentWillUnmount() {
@@ -119,19 +120,19 @@ export default class Login extends Component<PropsType, StateType> {
       return (
         <>
           <OAuthButton onClick={this.githubRedirect}>
-          <IconWrapper>
-            <Icon src={github} />
-            Log in with GitHub
-          </IconWrapper>
+            <IconWrapper>
+              <Icon src={github} />
+              Log in with GitHub
+            </IconWrapper>
           </OAuthButton>
           <OrWrapper>
             <Line />
             <Or>or</Or>
           </OrWrapper>
         </>
-      )
+      );
     }
-  }
+  };
 
   render() {
     let { email, password, credentialError, emailError } = this.state;

+ 17 - 17
dashboard/src/main/auth/Register.tsx

@@ -38,11 +38,12 @@ export default class Register extends Component<PropsType, StateType> {
     document.addEventListener("keydown", this.handleKeyDown);
 
     // get capabilities to case on github
-    api.getCapabilities("", {}, {})
-    .then((res) => {      
-      this.setState({hasGithub: res.data?.github})
-    })
-    .catch((err) => console.log(err));
+    api
+      .getCapabilities("", {}, {})
+      .then((res) => {
+        this.setState({ hasGithub: res.data?.github });
+      })
+      .catch((err) => console.log(err));
   }
 
   componentWillUnmount() {
@@ -120,20 +121,19 @@ export default class Register extends Component<PropsType, StateType> {
       return (
         <>
           <OAuthButton onClick={this.githubRedirect}>
-              <IconWrapper>
-                <Icon src={github} />
-                Sign up with GitHub
-              </IconWrapper>
-            </OAuthButton>
-            <OrWrapper>
-              <Line />
-              <Or>or</Or>
-            </OrWrapper>
+            <IconWrapper>
+              <Icon src={github} />
+              Sign up with GitHub
+            </IconWrapper>
+          </OAuthButton>
+          <OrWrapper>
+            <Line />
+            <Or>or</Or>
+          </OrWrapper>
         </>
-      )
+      );
     }
-  }
-
+  };
 
   render() {
     let {

+ 5 - 9
dashboard/src/main/home/Home.tsx

@@ -87,19 +87,15 @@ class Home extends Component<PropsType, StateType> {
     if (!currentProject) return;
 
     api
-      .getCapabilities(
-        "<token>",
-        {},
-        {}
-      )
+      .getCapabilities("<token>", {}, {})
       .then((res) => {
-        console.log(res.data)
-        this.context.setCapabilities(res.data)
+        console.log(res.data);
+        this.context.setCapabilities(res.data);
       })
       .catch((err) => {
-        console.log(err)
+        console.log(err);
       });
-  }
+  };
 
   getProjects = (id?: number) => {
     let { user, setProjects } = this.context;

+ 3 - 5
dashboard/src/main/home/dashboard/Dashboard.tsx

@@ -136,12 +136,10 @@ class Dashboard extends Component<PropsType, StateType> {
       { label: "Project Overview", value: "overview" },
       { label: "Create a Cluster", value: "create-cluster" },
       { label: "Provisioner Status", value: "provisioner" },
-    ]
-    
+    ];
+
     if (!capabilities?.provisioner) {
-      tabOptions = [
-        { label: "Project Overview", value: "overview" },
-      ]
+      tabOptions = [{ label: "Project Overview", value: "overview" }];
     }
 
     return (

+ 13 - 11
dashboard/src/main/home/launch/expanded-template/LaunchTemplate.tsx

@@ -541,17 +541,19 @@ class LaunchTemplate extends Component<PropsType, StateType> {
     if (this.state.sourceType === "") {
       return (
         <BlockList>
-          {capabilities.github && (<Block
-            onClick={() => {
-              this.setState({ sourceType: "repo" });
-            }}
-          >
-            <BlockIcon src="https://3.bp.blogspot.com/-xhNpNJJyQhk/XIe4GY78RQI/AAAAAAAAItc/ouueFUj2Hqo5dntmnKqEaBJR4KQ4Q2K3ACK4BGAYYCw/s1600/logo%2Bgit%2Bicon.png" />
-            <BlockTitle>Git Repository</BlockTitle>
-            <BlockDescription>
-              Deploy using source from a Git repo.
-            </BlockDescription>
-          </Block>)}
+          {capabilities.github && (
+            <Block
+              onClick={() => {
+                this.setState({ sourceType: "repo" });
+              }}
+            >
+              <BlockIcon src="https://3.bp.blogspot.com/-xhNpNJJyQhk/XIe4GY78RQI/AAAAAAAAItc/ouueFUj2Hqo5dntmnKqEaBJR4KQ4Q2K3ACK4BGAYYCw/s1600/logo%2Bgit%2Bicon.png" />
+              <BlockTitle>Git Repository</BlockTitle>
+              <BlockDescription>
+                Deploy using source from a Git repo.
+              </BlockDescription>
+            </Block>
+          )}
           <Block
             onClick={() => {
               this.setState({ sourceType: "registry" });

+ 2 - 4
dashboard/src/main/home/navbar/Navbar.tsx

@@ -42,11 +42,9 @@ export default class Navbar extends Component<PropsType, StateType> {
 
   renderFeedbackButton = () => {
     if (this.context?.capabilities?.provisioner) {
-      return (
-        <Feedback currentView={this.props.currentView} />
-      )
+      return <Feedback currentView={this.props.currentView} />;
     }
-  }
+  };
 
   render() {
     return (

+ 5 - 1
dashboard/src/main/home/new-project/NewProject.tsx

@@ -59,7 +59,11 @@ export default class NewProject extends Component<PropsType, StateType> {
             width="470px"
           />
         </InputWrapper>
-        <ProvisionerSettings isInNewProject={true} projectName={projectName} provisioner={capabilities?.provisioner} />
+        <ProvisionerSettings
+          isInNewProject={true}
+          projectName={projectName}
+          provisioner={capabilities?.provisioner}
+        />
         <Br />
       </StyledNewProject>
     );

+ 12 - 17
dashboard/src/main/home/provisioner/ProvisionerSettings.tsx

@@ -52,7 +52,6 @@ class NewProject extends Component<PropsType, StateType> {
     }
 
     let renderSkipHelper = () => {
-
       if (!this.props.provisioner) {
         return;
       }
@@ -139,7 +138,9 @@ class NewProject extends Component<PropsType, StateType> {
     let { selectedProvider } = this.state;
     let { isInNewProject } = this.props;
     let { provisioner } = this.props;
-    let helper = provisioner ? "Note: Provisioning can take up to 15 minutes" : ""
+    let helper = provisioner
+      ? "Note: Provisioning can take up to 15 minutes"
+      : "";
 
     if (isInNewProject && !selectedProvider) {
       return (
@@ -161,24 +162,22 @@ class NewProject extends Component<PropsType, StateType> {
             helper={helper}
           />
         </>
-      )
+      );
     }
-  }
+  };
 
   componentDidMount() {
     let { provisioner } = this.props;
 
     if (!provisioner) {
-      this.setState({selectedProvider: "skipped"})
+      this.setState({ selectedProvider: "skipped" });
     }
   }
 
   componentDidUpdate(prevProps: PropsType) {
-    if (
-      prevProps.provisioner !== this.props.provisioner
-    ) {
+    if (prevProps.provisioner !== this.props.provisioner) {
       if (!this.props.provisioner) {
-        this.setState({selectedProvider: "skipped"})
+        this.setState({ selectedProvider: "skipped" });
       }
     }
   }
@@ -194,22 +193,18 @@ class NewProject extends Component<PropsType, StateType> {
         <>
           Select your hosting backend:<Required>*</Required>
         </>
-      )
+      );
     } else {
-      return (
-        "Need a cluster? Provision through Porter:"
-      )
+      return "Need a cluster? Provision through Porter:";
     }
-  }
+  };
 
   render() {
     let { selectedProvider } = this.state;
 
     return (
       <StyledProvisionerSettings>
-        <Helper>
-          {this.renderHelperText()}
-        </Helper>
+        <Helper>{this.renderHelperText()}</Helper>
         {!selectedProvider ? (
           <BlockList>
             {providers.map((provider: string, i: number) => {

+ 1 - 1
dashboard/src/shared/Context.tsx

@@ -65,7 +65,7 @@ class ContextProvider extends Component {
     },
     capabilities: null as CapabilityType,
     setCapabilities: (capabilities: CapabilityType) => {
-      this.setState({ capabilities })
+      this.setState({ capabilities });
     },
     clearContext: () => {
       this.setState({

+ 2 - 1
dashboard/src/shared/types.tsx

@@ -109,6 +109,7 @@ export interface FormElement {
   settings?: {
     default?: number | string | boolean;
     options?: any[];
+    omitUnitFromValue?: boolean;
     unit?: string;
   };
 }
@@ -172,4 +173,4 @@ export interface ActionConfigType {
 export interface CapabilityType {
   github: boolean;
   provisioner: boolean;
-}
+}

+ 5 - 4
internal/models/templates.go

@@ -51,10 +51,11 @@ type FormContent struct {
 	Placeholder string       `yaml:"placeholder,omitempty" json:"placeholder,omitempty"`
 	Value       interface{}  `yaml:"value,omitempty" json:"value,omitempty"`
 	Settings    struct {
-		Default     interface{} `yaml:"default,omitempty" json:"default,omitempty"`
-		Unit        interface{} `yaml:"unit,omitempty" json:"unit,omitempty"`
-		Options     interface{} `yaml:"options,omitempty" json:"options,omitempty"`
-		Placeholder string      `yaml:"placeholder,omitempty" json:"placeholder,omitempty"`
+		Default           interface{} `yaml:"default,omitempty" json:"default,omitempty"`
+		Unit              interface{} `yaml:"unit,omitempty" json:"unit,omitempty"`
+		OmitUnitFromValue bool        `yaml:"omitUnitFromValue,omitempty" json:"omitUnitFromValue,omitempty"`
+		Options           interface{} `yaml:"options,omitempty" json:"options,omitempty"`
+		Placeholder       string      `yaml:"placeholder,omitempty" json:"placeholder,omitempty"`
 	} `yaml:"settings,omitempty" json:"settings,omitempty"`
 }