public inbox for [email protected]  
help / color / mirror / Atom feed
From: Pradip Parkale <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM7299]: Statistics.jsx has sort issue
Date: Tue, 19 Apr 2022 07:17:10 +0530
Message-ID: <CAJ9T6Sv2PRBeNaGXSHdb20AVdjHPF0hHkxnWED3XS8pKmM70sA@mail.gmail.com> (raw)

Hi Hackers,

Please find the attached patch for #7299. I have fixed the sorting issue
for the size column where we are displaying units like 'MB', 'bytes'.

-- 
Thanks & Regards,
Pradip Parkale
Software Engineer | EnterpriseDB Corporation


Attachments:

  [application/octet-stream] RM7299.patch (2.2K, 3-RM7299.patch)
  download | inline diff:
diff --git a/web/pgadmin/misc/statistics/static/js/Statistics.jsx b/web/pgadmin/misc/statistics/static/js/Statistics.jsx
index 7ed0dc198..0ec07f838 100644
--- a/web/pgadmin/misc/statistics/static/js/Statistics.jsx
+++ b/web/pgadmin/misc/statistics/static/js/Statistics.jsx
@@ -57,17 +57,52 @@ const useStyles = makeStyles((theme) => ({
 }));
 
 function getColumn(data, singleLineStatistics) {
-  let columns = [];
+  let columns = [], column;
   if (!singleLineStatistics) {
     if (!_.isUndefined(data)) {
       data.forEach((row) => {
-        var column = {
-          Header: row.name,
-          accessor: row.name,
-          sortble: true,
-          resizable: false,
-          disableGlobalFilter: false,
-        };
+        if (row.name == 'Size') {
+          column = {
+            Header: row.name,
+            accessor: row.name,
+            sortble: true,
+            resizable: false,
+            disableGlobalFilter: false,
+            sortType: ((rowA, rowB, id) => {
+              let val1 = rowA.values[id];
+              let val2 = rowB.values[id];
+              const sizes = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+              sizes.some((t, i) => {
+                if (!_.isNull(rowA.values[id]) && typeof (rowA.values[id]) == 'string' && rowA.values[id].indexOf(t) > -1) {
+                  val1 = (parseInt(rowA.values[id]) * Math.pow(1024, i));
+                }
+  
+                if (!_.isNull(rowB.values[id]) && typeof (rowB.values[id]) == 'string' && rowB.values[id].indexOf(t) > -1) {
+                  val2 = parseInt(rowB.values[id]) * Math.pow(1024, i);
+                }
+              
+              });
+
+              if ((val1) > (val2) || _.isNull(val2)) {
+                return 1;
+              }
+              if ((val2) > (val1) || _.isNull(val1)) {
+                return -1;
+              }
+              return 0;
+
+            })
+          };
+        }else{
+          column = {
+            Header: row.name,
+            accessor: row.name,
+            sortble: true,
+            resizable: false,
+            disableGlobalFilter: false,
+          };
+
+        }
         columns.push(column);
       });
     }


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][RM7299]: Statistics.jsx has sort issue
  In-Reply-To: <CAJ9T6Sv2PRBeNaGXSHdb20AVdjHPF0hHkxnWED3XS8pKmM70sA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox