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

Merge branch 'staging' of https://github.com/porter-dev/porter into staging

mergin
Alexander Belanger 5 лет назад
Родитель
Сommit
acb98e7305

+ 6 - 1
dashboard/src/main/home/dashboard/expanded-chart/ExpandedChart.tsx

@@ -32,6 +32,7 @@ const tabOptions = [
   { label: 'Values Editor', value: 'values' }
   { label: 'Values Editor', value: 'values' }
 ]
 ]
 
 
+// TODO: consolidate revisionPreview and currentChart (currentChart can just be the initial state)
 export default class ExpandedChart extends Component<PropsType, StateType> {
 export default class ExpandedChart extends Component<PropsType, StateType> {
   state = {
   state = {
     showRevisions: false,
     showRevisions: false,
@@ -103,7 +104,11 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
 
 
   renderTabContents = () => {
   renderTabContents = () => {
     let { currentChart, refreshChart, setSidebar } = this.props;
     let { currentChart, refreshChart, setSidebar } = this.props;
-    let chart = this.state.revisionPreview || currentChart;
+    let chart = currentChart;
+    if (this.state.revisionPreview) {
+      chart = this.state.revisionPreview;
+    }
+    console.log(chart)
     
     
     if (this.state.currentTab === 'graph') {
     if (this.state.currentTab === 'graph') {
       return (
       return (

+ 24 - 24
dashboard/src/main/home/dashboard/expanded-chart/graph/GraphDisplay.tsx

@@ -90,9 +90,27 @@ export default class GraphDisplay extends Component<PropsType, StateType> {
     return Math.floor(Math.random() * (max - min) + min);  
     return Math.floor(Math.random() * (max - min) + min);  
   }
   }
 
 
-  componentDidMount() {
+  // Handle graph from localstorage
+  getChartGraph = () => {
     let { components, currentChart } = this.props;
     let { components, currentChart } = this.props;
 
 
+    let graph = localStorage.getItem(`charts.${currentChart.name}-${currentChart.version}`);
+    let nodes = [] as NodeType[];
+    let edges = [] as EdgeType[];
+    if (!graph) {
+      nodes = this.createNodes(components);
+      edges = this.createEdges(components);
+      this.setState({ nodes, edges });
+    } else {
+      let storedState = JSON.parse(localStorage.getItem(
+        `charts.${currentChart.name}-${currentChart.version}`
+      ));
+      this.setState(storedState);
+    }
+  }
+
+  componentDidMount() {
+
     // Initialize origin
     // Initialize origin
     let height = this.spaceRef.offsetHeight;
     let height = this.spaceRef.offsetHeight;
     let width = this.spaceRef.offsetWidth;
     let width = this.spaceRef.offsetWidth;
@@ -108,35 +126,17 @@ export default class GraphDisplay extends Component<PropsType, StateType> {
     document.addEventListener("keydown", this.handleKeyDown);
     document.addEventListener("keydown", this.handleKeyDown);
     document.addEventListener("keyup", this.handleKeyUp);
     document.addEventListener("keyup", this.handleKeyUp);
 
 
-    // Handle graph from localstorage
-    let graph = localStorage.getItem(`charts.${currentChart.name}-${currentChart.version}`);
-    let nodes = [] as NodeType[];
-    let edges = [] as EdgeType[];
-    if (!graph) {
-      nodes = this.createNodes(components);
-      edges = this.createEdges(components);
-      this.setState({ nodes, edges });
-    } else {
-      let storedState = JSON.parse(localStorage.getItem(
-        `charts.${currentChart.name}-${currentChart.version}`
-      ));
-      this.setState(storedState);
-    }
+    this.getChartGraph();
 
 
     window.onbeforeunload = () => {
     window.onbeforeunload = () => {
-      this.storeChart();
+      this.storeChartGraph();
     }
     }
   }
   }
 
 
   // Live update on rollback/upgrade
   // Live update on rollback/upgrade
   componentDidUpdate(prevProps: PropsType) {
   componentDidUpdate(prevProps: PropsType) {
     if (prevProps.components !== this.props.components) {
     if (prevProps.components !== this.props.components) {
-      let nodes = [] as NodeType[];
-      let edges = [] as EdgeType[];
-  
-      nodes = this.createNodes(this.props.components);
-      edges = this.createEdges(this.props.components);
-      this.setState({ nodes, edges, openedNode: null });
+      this.getChartGraph();
     }
     }
   }
   }
 
 
@@ -185,7 +185,7 @@ export default class GraphDisplay extends Component<PropsType, StateType> {
     return edges;
     return edges;
   }
   }
 
 
-  storeChart = () => {
+  storeChartGraph = () => {
     let { currentChart } = this.props;
     let { currentChart } = this.props;
     let graph = JSON.parse(JSON.stringify(this.state));
     let graph = JSON.parse(JSON.stringify(this.state));
 
 
@@ -205,7 +205,7 @@ export default class GraphDisplay extends Component<PropsType, StateType> {
   }
   }
 
 
   componentWillUnmount() {
   componentWillUnmount() {
-    this.storeChart();
+    this.storeChartGraph();
     
     
     this.spaceRef.removeEventListener("touchmove", (e: any) => e.preventDefault());
     this.spaceRef.removeEventListener("touchmove", (e: any) => e.preventDefault());
     this.spaceRef.removeEventListener("mousewheel", (e: any) => e.preventDefault());
     this.spaceRef.removeEventListener("mousewheel", (e: any) => e.preventDefault());