From 796a8a013a5a4bd570d8e35877f62ee2bf4d4076 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Wed, 9 Sep 2020 13:08:58 +0530 Subject: [PATCH] 1) Changing the state of the react directly is not recommended, so avoid changing it directly. 2) Fixed API test cases. --- web/pgadmin/dashboard/static/js/Graphs.jsx | 17 +++++++++++------ web/pgadmin/utils/driver/psycopg2/connection.py | 5 +++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/web/pgadmin/dashboard/static/js/Graphs.jsx b/web/pgadmin/dashboard/static/js/Graphs.jsx index e8862a109..ad2b3cf92 100644 --- a/web/pgadmin/dashboard/static/js/Graphs.jsx +++ b/web/pgadmin/dashboard/static/js/Graphs.jsx @@ -80,15 +80,20 @@ export function statsReducer(state, action) { action.counterData = action.incoming; } + let newState = {}; Object.keys(action.incoming).forEach(label => { - let newEle = action.counter ? action.incoming[label] - action.counterData[label] : action.incoming[label]; - state[label] = state[label] || []; - if(state[label].length >= X_AXIS_LENGTH) { - state[label].pop(); + if(state[label]) { + newState[label] = [ + action.counter ? action.incoming[label] - action.counterData[label] : action.incoming[label], + ...state[label].slice(0, X_AXIS_LENGTH-1), + ]; + } else { + newState[label] = [ + action.counter ? action.incoming[label] - action.counterData[label] : action.incoming[label], + ]; } - state[label].unshift(newEle); }); - return state; + return newState; } const chartsDefault = { diff --git a/web/pgadmin/utils/driver/psycopg2/connection.py b/web/pgadmin/utils/driver/psycopg2/connection.py index 5795f9160..9cb65bc53 100644 --- a/web/pgadmin/utils/driver/psycopg2/connection.py +++ b/web/pgadmin/utils/driver/psycopg2/connection.py @@ -1167,8 +1167,9 @@ WHERE db.datname = current_database()""") rows = [] self.row_count = cur.rowcount - for row in cur: - rows.append(dict(row)) + if cur.rowcount > 0: + for row in cur: + rows.append(dict(row)) return True, {'columns': columns, 'rows': rows}