Просмотр исходного кода

cluster select integrated w/ extra edgecases

jusrhee 5 лет назад
Родитель
Сommit
aac02dfd55

+ 0 - 1
dashboard/src/main/Register.tsx

@@ -48,7 +48,6 @@ export default class Register extends Component<PropsType, StateType> {
         email: email,
         email: email,
         password: password
         password: password
       }, {}, (err: any, res: any) => {
       }, {}, (err: any, res: any) => {
-        console.log('err',err)
         err ? setCurrentError(JSON.stringify(err)) : authenticate();
         err ? setCurrentError(JSON.stringify(err)) : authenticate();
       });
       });
     } 
     } 

+ 9 - 6
dashboard/src/main/home/modals/ClusterConfigModal.tsx

@@ -37,8 +37,7 @@ export default class ClusterConfigModal extends Component<PropsType, StateType>
       if (err) {
       if (err) {
         setCurrentError('getAllClusters: ' + JSON.stringify(err));
         setCurrentError('getAllClusters: ' + JSON.stringify(err));
       } else {
       } else {
-        console.log(res.data)
-        this.setState({ kubeContexts: res.data })
+        this.setState({ kubeContexts: res.data });
       }
       }
     });
     });
   }
   }
@@ -115,6 +114,7 @@ export default class ClusterConfigModal extends Component<PropsType, StateType>
           });
           });
 
 
           this.updateChecklist();
           this.updateChecklist();
+          this.context.currentModalData.updateClusters();
         }
         }
       }
       }
     );
     );
@@ -131,8 +131,6 @@ export default class ClusterConfigModal extends Component<PropsType, StateType>
         allowedContexts.push(x.name);
         allowedContexts.push(x.name);
       }
       }
     });
     });
-
-    console.log(allowedContexts);
     
     
     api.updateUser(
     api.updateUser(
       '<token>',
       '<token>',
@@ -143,6 +141,8 @@ export default class ClusterConfigModal extends Component<PropsType, StateType>
           this.setState({ saveSelectedStatus: 'error' });
           this.setState({ saveSelectedStatus: 'error' });
         } else {
         } else {
           this.setState({ saveSelectedStatus: 'successful' });
           this.setState({ saveSelectedStatus: 'successful' });
+          this.updateChecklist();
+          this.context.currentModalData.updateClusters();
         }
         }
       }
       }
     );
     );
@@ -168,7 +168,7 @@ export default class ClusterConfigModal extends Component<PropsType, StateType>
 
 
     return (
     return (
       <div>
       <div>
-        <Subtitle>Select the clusters you want Porter to connect to</Subtitle>
+        <Subtitle>Select the contexts you want Porter to use</Subtitle>
         <ClusterList>
         <ClusterList>
           {this.renderClusterList()}
           {this.renderClusterList()}
         </ClusterList>
         </ClusterList>
@@ -185,7 +185,10 @@ export default class ClusterConfigModal extends Component<PropsType, StateType>
   render() {
   render() {
     return (
     return (
       <StyledClusterConfigModal>
       <StyledClusterConfigModal>
-        <CloseButton onClick={() => { this.context.setCurrentModal(null) }}>
+        <CloseButton onClick={() => {
+          this.context.setCurrentModal(null);
+          this.context.setCurrentModalData(null);
+        }}>
           <CloseButtonImg src={close} />
           <CloseButtonImg src={close} />
         </CloseButton>
         </CloseButton>
 
 

+ 23 - 8
dashboard/src/main/home/sidebar/ClusterSection.tsx

@@ -4,6 +4,7 @@ import drawerBg from '../../../assets/drawer-bg.png';
 
 
 import api from '../../../shared/api';
 import api from '../../../shared/api';
 import { Context } from '../../../shared/Context';
 import { Context } from '../../../shared/Context';
+import { KubeContextConfig } from '../../../shared/types';
 
 
 import Drawer from './Drawer';
 import Drawer from './Drawer';
 
 
@@ -16,7 +17,7 @@ type StateType = {
   configExists: boolean,
   configExists: boolean,
   showDrawer: boolean,
   showDrawer: boolean,
   initializedDrawer: boolean,
   initializedDrawer: boolean,
-  kubeContexts: string[],
+  kubeContexts: KubeContextConfig[],
   activeIndex: number,
   activeIndex: number,
 };
 };
 
 
@@ -27,22 +28,30 @@ export default class ClusterSection extends Component<PropsType, StateType> {
     configExists: true,
     configExists: true,
     showDrawer: false,
     showDrawer: false,
     initializedDrawer: false,
     initializedDrawer: false,
-    kubeContexts: [] as string[],
+    kubeContexts: [] as KubeContextConfig[],
     activeIndex: 0,
     activeIndex: 0,
   };
   };
 
 
-  componentDidMount() {
+  updateClusters = () => {
     let { setCurrentError, userId } = this.context;
     let { setCurrentError, userId } = this.context;
 
 
-    api.getContexts('<token>', {}, { id: userId }, (err: any, res: any) => {      
+    // TODO: query with selected filter once implemented
+    api.getContexts('<token>', {}, { id: userId }, (err: any, res: any) => {
       if (err) {
       if (err) {
-        setCurrentError(JSON.stringify(err));
+        setCurrentError('getContexts: ' + JSON.stringify(err));
       } else {
       } else {
-        this.setState({ kubeContexts: res });
+
+        // Filter selected (temporary)
+        let kubeContexts = res.data.filter((x: KubeContextConfig) => x.selected);
+        this.setState({ kubeContexts });
       }
       }
     });
     });
   }
   }
 
 
+  componentDidMount() {
+    this.updateClusters();
+  }
+
   // Need to override showDrawer when the sidebar is closed
   // Need to override showDrawer when the sidebar is closed
   componentDidUpdate(prevProps: PropsType) {
   componentDidUpdate(prevProps: PropsType) {
     if (prevProps !== this.props) {
     if (prevProps !== this.props) {
@@ -64,6 +73,7 @@ export default class ClusterSection extends Component<PropsType, StateType> {
     if (this.state.initializedDrawer) {
     if (this.state.initializedDrawer) {
       return (
       return (
         <Drawer
         <Drawer
+          updateClusters={this.updateClusters}
           toggleDrawer={this.toggleDrawer}
           toggleDrawer={this.toggleDrawer}
           showDrawer={this.state.showDrawer}
           showDrawer={this.state.showDrawer}
           kubeContexts={this.state.kubeContexts}
           kubeContexts={this.state.kubeContexts}
@@ -74,6 +84,11 @@ export default class ClusterSection extends Component<PropsType, StateType> {
     }
     }
   };
   };
 
 
+  showClusterConfigModal = () => {
+    this.context.setCurrentModal('ClusterConfigModal');
+    this.context.setCurrentModalData({ updateClusters: this.updateClusters });
+  }
+
   renderContents = (): JSX.Element => {
   renderContents = (): JSX.Element => {
     let { kubeContexts, activeIndex, showDrawer } = this.state;
     let { kubeContexts, activeIndex, showDrawer } = this.state;
 
 
@@ -82,7 +97,7 @@ export default class ClusterSection extends Component<PropsType, StateType> {
         <ClusterSelector showDrawer={showDrawer}>
         <ClusterSelector showDrawer={showDrawer}>
           <LinkWrapper>
           <LinkWrapper>
             <ClusterIcon><i className="material-icons">polymer</i></ClusterIcon>
             <ClusterIcon><i className="material-icons">polymer</i></ClusterIcon>
-            <ClusterName>{kubeContexts[activeIndex]}</ClusterName>
+            <ClusterName>{kubeContexts[activeIndex].name}</ClusterName>
           </LinkWrapper>
           </LinkWrapper>
           <DrawerButton onClick={this.toggleDrawer}>
           <DrawerButton onClick={this.toggleDrawer}>
             <BgAccent src={drawerBg} />
             <BgAccent src={drawerBg} />
@@ -95,7 +110,7 @@ export default class ClusterSection extends Component<PropsType, StateType> {
     }
     }
 
 
     return (
     return (
-      <InitializeButton onClick={() => this.context.setCurrentModal('ClusterConfigModal')}>
+      <InitializeButton onClick={this.showClusterConfigModal}>
         <Plus>+</Plus> Add a Cluster
         <Plus>+</Plus> Add a Cluster
       </InitializeButton>
       </InitializeButton>
     )
     )

+ 45 - 25
dashboard/src/main/home/sidebar/Drawer.tsx

@@ -3,13 +3,15 @@ import styled from 'styled-components';
 import close from '../../../assets/close.png';
 import close from '../../../assets/close.png';
 
 
 import { Context } from '../../../shared/Context';
 import { Context } from '../../../shared/Context';
+import { KubeContextConfig } from '../../../shared/types';
 
 
 type PropsType = {
 type PropsType = {
   toggleDrawer: () => void,
   toggleDrawer: () => void,
   showDrawer: boolean,
   showDrawer: boolean,
-  kubeContexts: string[],
+  kubeContexts: KubeContextConfig[],
   activeIndex: number,
   activeIndex: number,
-  setActiveIndex: (i: number) => void
+  setActiveIndex: (i: number) => void,
+  updateClusters: () => void
 };
 };
 
 
 type StateType = {
 type StateType = {
@@ -17,24 +19,29 @@ type StateType = {
 
 
 export default class Drawer extends Component<PropsType, StateType> {
 export default class Drawer extends Component<PropsType, StateType> {
 
 
-  renderClusterList = (): JSX.Element[] => {
-    return this.props.kubeContexts.map((kubeContext: string, i: number) => {
-      /*
-      let active = this.context.activeProject &&
-        this.context.activeProject.namespace == val.namespace; 
-      */
+  renderClusterList = (): JSX.Element[] | JSX.Element => {
+    let { kubeContexts, activeIndex, setActiveIndex } = this.props;
+    if (kubeContexts.length > 0) {
+      return kubeContexts.map((kubeContext: KubeContextConfig, i: number) => {
+        /*
+        let active = this.context.activeProject &&
+          this.context.activeProject.namespace == val.namespace; 
+        */
+
+        return (
+          <ClusterOption
+            key={i}
+            active={i === activeIndex}
+            onClick={() => setActiveIndex(i)}
+          >
+            <ClusterIcon><i className="material-icons">polymer</i></ClusterIcon>
+            <ClusterName>{kubeContext.name}</ClusterName>
+          </ClusterOption>
+        );
+      });
+    }
 
 
-      return (
-        <ClusterOption 
-          key={i}
-          active={i === this.props.activeIndex}
-          onClick={() => this.props.setActiveIndex(i)}
-        >
-          <ClusterIcon><i className="material-icons">polymer</i></ClusterIcon>
-          <ClusterName>{kubeContext}</ClusterName>
-        </ClusterOption>
-      );
-    });
+    return <Placeholder>No clusters selected</Placeholder>
   };
   };
 
 
   renderCloseOverlay = (): JSX.Element | undefined => {
   renderCloseOverlay = (): JSX.Element | undefined => {
@@ -56,7 +63,10 @@ export default class Drawer extends Component<PropsType, StateType> {
 
 
           {this.renderClusterList()}
           {this.renderClusterList()}
 
 
-          <InitializeButton onClick={() => this.context.setCurrentModal('ClusterConfigModal')}>
+          <InitializeButton onClick={() => {
+            this.context.setCurrentModal('ClusterConfigModal');
+            this.context.setCurrentModalData({ updateClusters: this.props.updateClusters });
+          }}>
             <Plus>+</Plus> Manage Clusters
             <Plus>+</Plus> Manage Clusters
           </InitializeButton>
           </InitializeButton>
         </StyledDrawer>
         </StyledDrawer>
@@ -87,7 +97,7 @@ const InitializeButton = styled.div`
   justify-content: center;
   justify-content: center;
   width: calc(100% - 30px);
   width: calc(100% - 30px);
   height: 38px;
   height: 38px;
-  margin: 20px 15px 12px;
+  margin: 45px 15px 12px;
   font-size: 13px;
   font-size: 13px;
   font-weight: 500;
   font-weight: 500;
   border-radius: 3px;
   border-radius: 3px;
@@ -107,7 +117,7 @@ const ClusterOption = styled.div`
   padding-right: 30px;
   padding-right: 30px;
   display: flex;
   display: flex;
   align-items: center;
   align-items: center;
-  height: 50px;
+  height: 42px;
   text-decoration: none;
   text-decoration: none;
   color: white;
   color: white;
   font-size: 14px;
   font-size: 14px;
@@ -115,9 +125,19 @@ const ClusterOption = styled.div`
   overflow: hidden;
   overflow: hidden;
   text-overflow: ellipsis;
   text-overflow: ellipsis;
   cursor: pointer;
   cursor: pointer;
-  background: ${(props: { active: boolean }) => props.active ? '#ffffff22' : ''};
+  background: ${(props: { active?: boolean }) => props.active ? '#ffffff18' : ''};
   :hover {
   :hover {
-    background: #ffffff33;
+    background: #ffffff22;
+  }
+`;
+
+const Placeholder = styled(ClusterOption)`
+  color: #ffffff99;
+  justify-content: center;
+  padding: 0;
+  cursor: default;
+  :hover {
+    background: none;
   }
   }
 `;
 `;
 
 
@@ -166,7 +186,7 @@ const ClusterIcon = styled.div`
 const StyledDrawer = styled.div`
 const StyledDrawer = styled.div`
   position: absolute;
   position: absolute;
   height: 100%;
   height: 100%;
-  padding-top: 36px;
+  padding-top: 41px;
   width: 230px;
   width: 230px;
   overflow-y: auto;
   overflow-y: auto;
   padding-bottom: 40px;
   padding-bottom: 40px;

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

@@ -28,9 +28,12 @@ class ContextProvider extends Component {
     setCurrentModal: (currentModal: string): void => {
     setCurrentModal: (currentModal: string): void => {
       this.setState({ currentModal });
       this.setState({ currentModal });
     },
     },
+    currentModalData: null as any,
+    setCurrentModalData: (currentModalData: any): void => {
+      this.setState({ currentModalData });
+    },
     currentError: null as string | null,
     currentError: null as string | null,
     setCurrentError: (currentError: string): void => {
     setCurrentError: (currentError: string): void => {
-      console.log('setting err', currentError)
       this.setState({ currentError });
       this.setState({ currentError });
     },
     },
     currentCluster: null as string | null,
     currentCluster: null as string | null,