Sean Rhee 5 лет назад
Родитель
Сommit
a9afb987af

+ 21 - 5
dashboard/src/main/home/cluster-dashboard/ClusterDashboard.tsx

@@ -8,6 +8,7 @@ import api from '../../../shared/api';
 
 
 import ChartList from './chart/ChartList';
 import ChartList from './chart/ChartList';
 import NamespaceSelector from './NamespaceSelector';
 import NamespaceSelector from './NamespaceSelector';
+import SortSelector from './SortSelector';
 import ExpandedChart from './expanded-chart/ExpandedChart';
 import ExpandedChart from './expanded-chart/ExpandedChart';
 
 
 type PropsType = {
 type PropsType = {
@@ -18,12 +19,14 @@ type PropsType = {
 
 
 type StateType = {
 type StateType = {
   namespace: string,
   namespace: string,
+  sortType: string,
   currentChart: ChartType | null
   currentChart: ChartType | null
 };
 };
 
 
 export default class ClusterDashboard extends Component<PropsType, StateType> {
 export default class ClusterDashboard extends Component<PropsType, StateType> {
   state = {
   state = {
     namespace: 'default',
     namespace: 'default',
+    sortType: 'chronological',
     currentChart: null as (ChartType | null)
     currentChart: null as (ChartType | null)
   }
   }
 
 
@@ -31,7 +34,7 @@ export default class ClusterDashboard extends Component<PropsType, StateType> {
 
 
     // Reset namespace filter and close expanded chart on cluster change
     // Reset namespace filter and close expanded chart on cluster change
     if (prevProps.currentCluster !== this.props.currentCluster) {
     if (prevProps.currentCluster !== this.props.currentCluster) {
-      this.setState({ namespace: 'default', currentChart: null });
+      this.setState({ namespace: 'default', sortType: 'chronological', currentChart: null });
     }
     }
   }
   }
 
 
@@ -101,15 +104,22 @@ export default class ClusterDashboard extends Component<PropsType, StateType> {
           >
           >
             <i className="material-icons">add</i> Deploy Template
             <i className="material-icons">add</i> Deploy Template
           </Button>
           </Button>
-          <NamespaceSelector
-            setNamespace={(namespace) => this.setState({ namespace })}
-            namespace={this.state.namespace}
-          />
+          <SortFilterWrapper>
+            <SortSelector
+              setSortType={(sortType) => this.setState({ sortType })}
+              sortType={this.state.sortType}
+            />
+            <NamespaceSelector
+              setNamespace={(namespace) => this.setState({ namespace })}
+              namespace={this.state.namespace}
+            />
+          </SortFilterWrapper>
         </ControlRow>
         </ControlRow>
 
 
         <ChartList
         <ChartList
           currentCluster={currentCluster}
           currentCluster={currentCluster}
           namespace={this.state.namespace}
           namespace={this.state.namespace}
+          sortType={this.state.sortType}
           setCurrentChart={(x: ChartType | null) => this.setState({ currentChart: x })}
           setCurrentChart={(x: ChartType | null) => this.setState({ currentChart: x })}
         />
         />
       </div>
       </div>
@@ -297,4 +307,10 @@ const TitleSection = styled.div`
     }
     }
     margin-bottom: -3px;
     margin-bottom: -3px;
   }
   }
+`;
+
+const SortFilterWrapper = styled.div`
+  width: 468px;
+  display: flex;
+  justify-content: space-between;
 `;
 `;

+ 63 - 0
dashboard/src/main/home/cluster-dashboard/SortSelector.tsx

@@ -0,0 +1,63 @@
+import React, { Component } from 'react';
+import styled from 'styled-components';
+
+import { Context } from '../../../shared/Context';
+
+import Selector from '../../../components/Selector';
+
+type PropsType = {
+  setSortType: (x: string) => void,
+  sortType: string
+};
+
+type StateType = {
+  sortOptions: { label: string, value: string }[]
+};
+
+// TODO: fix update to unmounted component 
+export default class SortSelector extends Component<PropsType, StateType> {
+  state = {
+    sortOptions: [
+      { label: 'chronological', value: 'chronological' },
+      { label: 'alphabetical', value: 'alphabetical' }
+    ] as {label: string, value: string}[]
+  }
+
+  render() {
+    return ( 
+      <StyledSortSelector>
+        <Label>
+          <i className="material-icons">sort</i> Sort
+        </Label>
+        <Selector
+          activeValue={this.props.sortType}
+          setActiveValue={(sortType) => this.props.setSortType(sortType)}
+          options={this.state.sortOptions}
+          dropdownLabel='Sort By'
+          width='150px'
+          dropdownWidth='230px'
+          closeOverlay={true}
+        />
+      </StyledSortSelector>
+    );
+  }
+}
+
+SortSelector.contextType = Context;
+
+const Label = styled.div`
+  display: flex;
+  align-items: center;
+  margin-right: 12px;
+
+  > i {
+    margin-right: 8px;
+    font-size: 18px;
+  }
+`;
+
+const StyledSortSelector = styled.div`
+  display: flex;
+  align-items: center;
+  font-size: 13px;
+`;

+ 10 - 1
dashboard/src/main/home/cluster-dashboard/chart/ChartList.tsx

@@ -11,6 +11,7 @@ import Loading from '../../../../components/Loading';
 type PropsType = {
 type PropsType = {
   currentCluster: ClusterType,
   currentCluster: ClusterType,
   namespace: string,
   namespace: string,
+  sortType: string,
   setCurrentChart: (c: ChartType) => void
   setCurrentChart: (c: ChartType) => void
 };
 };
 
 
@@ -53,6 +54,13 @@ export default class ChartList extends Component<PropsType, StateType> {
         this.setState({ loading: false, error: true });
         this.setState({ loading: false, error: true });
       } else {
       } else {
         let charts = res.data || [];
         let charts = res.data || [];
+        console.log(Date.parse(charts[0].info.last_deployed));
+        console.log(charts[0].name);
+        if (this.props.sortType == "chronological") {
+          charts.sort((a: any, b: any) => (Date.parse(a.info.last_deployed) > Date.parse(b.info.last_deployed)) ? -1 : 1);
+        } else if (this.props.sortType == "alphabetical") {
+          charts.sort((a: any, b: any) => (a.name > b.name) ? 1: -1);
+        }
         this.setState({ charts }, () => {
         this.setState({ charts }, () => {
           this.setState({ loading: false, error: false });
           this.setState({ loading: false, error: false });
         });
         });
@@ -176,7 +184,8 @@ export default class ChartList extends Component<PropsType, StateType> {
   componentDidUpdate(prevProps: PropsType) {
   componentDidUpdate(prevProps: PropsType) {
     // Ret2: Prevents reload when opening ClusterConfigModal
     // Ret2: Prevents reload when opening ClusterConfigModal
     if (prevProps.currentCluster !== this.props.currentCluster || 
     if (prevProps.currentCluster !== this.props.currentCluster || 
-      prevProps.namespace !== this.props.namespace) {
+      prevProps.namespace !== this.props.namespace ||
+      prevProps.sortType !== this.props.sortType) {
       this.updateCharts(this.getControllers);
       this.updateCharts(this.getControllers);
     }
     }
   }
   }

+ 1 - 1
internal/config/config.go

@@ -29,7 +29,7 @@ type ServerConf struct {
 	IsLocal        bool          `env:"IS_LOCAL,default=false"`
 	IsLocal        bool          `env:"IS_LOCAL,default=false"`
 	IsTesting      bool          `env:"IS_TESTING,default=false"`
 	IsTesting      bool          `env:"IS_TESTING,default=false"`
 
 
-	DefaultHelmRepoURL string `env:"HELM_REPO_URL,default=https://porter-dev.github.io/chart-repo/"`
+	DefaultHelmRepoURL string `env:"HELM_REPO_URL,default=https://s2011r2593.github.io/test-porter-chart-repo/"`
 
 
 	GithubClientID     string `env:"GITHUB_CLIENT_ID"`
 	GithubClientID     string `env:"GITHUB_CLIENT_ID"`
 	GithubClientSecret string `env:"GITHUB_CLIENT_SECRET"`
 	GithubClientSecret string `env:"GITHUB_CLIENT_SECRET"`