Ver código fonte

don't process old releases returned over websocket

Anukul Sangwan 4 anos atrás
pai
commit
d9a20a4046

+ 11 - 5
dashboard/src/main/home/cluster-dashboard/chart/ChartList.tsx

@@ -86,22 +86,28 @@ const ChartList: React.FunctionComponent<Props> = ({
       },
       onmessage: (evt: MessageEvent) => {
         let event = JSON.parse(evt.data);
-        const newChart = event.Object;
+        const newChart: ChartType = event.Object;
         const matches = (chart: ChartType) => chart.name === newChart.name;
         setCharts((currentCharts) => {
           switch (event.event_type) {
             case "ADD":
             // upgrades emit both ADD and UPDATE events
             case "UPDATE":
-              let updated = false;
+              let updated = false,
+                isOld = false;
               const result = currentCharts.map((chart) => {
                 if (matches(chart)) {
-                  updated = true;
-                  return newChart;
+                  // TODO: figure out why websocket returns old releases
+                  if (newChart.version < chart.version) {
+                    isOld = true;
+                  } else {
+                    updated = true;
+                    return newChart;
+                  }
                 }
                 return chart;
               });
-              if (!updated) {
+              if (!updated && !isOld) {
                 result.push(newChart);
               }
               return result;