mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -06:00
Fixed SonarQube issues.
This commit is contained in:
parent
f96653e9af
commit
f5793e9a7a
@ -11,7 +11,6 @@ import React from 'react';
|
||||
import gettext from 'sources/gettext';
|
||||
import Notify from '../../../static/js/helpers/Notifier';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import pgBrowser from 'top/browser/static/js/browser';
|
||||
import AboutComponent from './AboutComponent';
|
||||
import current_user from 'pgadmin.user_management.current_user';
|
||||
|
||||
@ -25,11 +24,6 @@ class About {
|
||||
return About.instance;
|
||||
}
|
||||
|
||||
constructor(pgAdmin, pgBrowser) {
|
||||
this.pgAdmin = pgAdmin;
|
||||
this.pgBrowser = pgBrowser;
|
||||
}
|
||||
|
||||
init() {
|
||||
if (this.initialized)
|
||||
return;
|
||||
@ -55,7 +49,7 @@ class About {
|
||||
}
|
||||
}
|
||||
|
||||
pgAdmin.About = About.getInstance(pgAdmin, pgBrowser);
|
||||
pgAdmin.About = About.getInstance();
|
||||
|
||||
module.exports = {
|
||||
About: About,
|
||||
|
@ -15,10 +15,11 @@ import PropTypes from 'prop-types';
|
||||
import Notify from '../../../../static/js/helpers/Notifier';
|
||||
import getApiInstance from 'sources/api_instance';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import sizePrettify from 'sources/size_prettify';
|
||||
import { getURL } from '../../../static/utils/utils';
|
||||
import Loader from 'sources/components/Loader';
|
||||
import EmptyPanelMessage from '../../../../static/js/components/EmptyPanelMessage';
|
||||
import { compareSizeVals, toPrettySize } from '../../../../static/js/utils';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
emptyPanel: {
|
||||
minHeight: '100%',
|
||||
@ -64,28 +65,7 @@ function getColumn(data, singleLineStatistics) {
|
||||
resizable: true,
|
||||
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;
|
||||
|
||||
return compareSizeVals(rowA.values[id], rowB.values[id]);
|
||||
})
|
||||
};
|
||||
}else{
|
||||
@ -133,7 +113,7 @@ function getTableData(res, node) {
|
||||
// Prettify the field values
|
||||
if (!_.isEmpty(node.statsPrettifyFields)) {
|
||||
node.statsPrettifyFields.forEach((field) => {
|
||||
row[field] = sizePrettify(row[field]);
|
||||
row[field] = toPrettySize(row[field]);
|
||||
});
|
||||
}
|
||||
nodeStats.push({ ...row, icon: '' });
|
||||
@ -159,7 +139,7 @@ function createSingleLineStatistics(data, prettifyFields) {
|
||||
if (row && row[name]) {
|
||||
value =
|
||||
_.indexOf(prettifyFields, name) != -1
|
||||
? sizePrettify(row[name])
|
||||
? toPrettySize(row[name])
|
||||
: row[name];
|
||||
} else {
|
||||
value = null;
|
||||
|
@ -1,6 +1,6 @@
|
||||
export function copyToClipboard(text) {
|
||||
export async function copyToClipboard(text) {
|
||||
try {
|
||||
navigator.clipboard.writeText(text);
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch {
|
||||
/* Suppress error */
|
||||
console.error('Does not have clipboard acccess');
|
||||
|
@ -1,31 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
define([],
|
||||
function () {
|
||||
return function (rawSize) {
|
||||
var size = Math.abs(rawSize),
|
||||
limit = 10 * 1024,
|
||||
limit2 = limit - 1,
|
||||
cnt = 0,
|
||||
sizeUnits = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'];
|
||||
|
||||
if (size < limit)
|
||||
return size + ' ' + sizeUnits[cnt]; // return in bytes format
|
||||
else
|
||||
{
|
||||
do {
|
||||
size = size / 1024;
|
||||
cnt += 1;
|
||||
} while (size > limit2);
|
||||
|
||||
return Math.round(size) + ' ' + sizeUnits[cnt];
|
||||
}
|
||||
};
|
||||
});
|
@ -13,6 +13,7 @@ import gettext from 'sources/gettext';
|
||||
import 'wcdocker';
|
||||
import Notify from './helpers/Notifier';
|
||||
import { hasTrojanSource } from 'anti-trojan-source';
|
||||
import convert from 'convert-units';
|
||||
|
||||
var wcDocker = window.wcDocker;
|
||||
|
||||
@ -494,3 +495,29 @@ export function downloadBlob(blob, fileName) {
|
||||
}
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
export function toPrettySize(rawSize) {
|
||||
try {
|
||||
let conVal = convert(rawSize).from('B').toBest();
|
||||
conVal.val = Math.round(conVal.val * 100) / 100;
|
||||
return `${conVal.val} ${conVal.unit}`;
|
||||
}
|
||||
catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export function compareSizeVals(val1, val2) {
|
||||
const parseAndConvert = (val)=>{
|
||||
try {
|
||||
let [size, unit] = val.split(' ');
|
||||
return convert(size).from(unit.toUpperCase()).to('B');
|
||||
} catch {
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
val1 = parseAndConvert(val1);
|
||||
val2 = parseAndConvert(val2);
|
||||
if(val1 > val2) return 1;
|
||||
return (val1 < val2 ? -1 : 0);
|
||||
}
|
||||
|
@ -24,11 +24,6 @@ export default class ImportExportServersModule {
|
||||
return ImportExportServersModule.instance;
|
||||
}
|
||||
|
||||
constructor(pgAdmin, pgBrowser) {
|
||||
this.pgAdmin = pgAdmin;
|
||||
this.pgBrowser = pgBrowser;
|
||||
}
|
||||
|
||||
init() {
|
||||
if (this.initialized)
|
||||
return;
|
||||
|
@ -1,68 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define(['sources/size_prettify'], function (sizePrettify) {
|
||||
describe('sizePrettify', function () {
|
||||
describe('when size is 0', function () {
|
||||
it('returns 0 bytes', function () {
|
||||
expect(sizePrettify(0)).toEqual('0 bytes');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when size >= 10kB and size < 10 MB', function () {
|
||||
it('returns size in kB', function () {
|
||||
expect(sizePrettify(10240)).toEqual('10 kB');
|
||||
});
|
||||
|
||||
it('returns size in kB', function () {
|
||||
expect(sizePrettify(99999)).toEqual('98 kB');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('when size >= 10MB and size < 10 GB', function () {
|
||||
it('returns size in MB', function () {
|
||||
expect(sizePrettify(10485760)).toEqual('10 MB');
|
||||
});
|
||||
|
||||
it('returns size in MB', function () {
|
||||
expect(sizePrettify(44040192)).toEqual('42 MB');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('when size >= 10GB and size < 10 TB', function () {
|
||||
it('returns size in GB', function () {
|
||||
expect(sizePrettify(10737418240)).toEqual('10 GB');
|
||||
});
|
||||
|
||||
it('returns size in GB', function () {
|
||||
expect(sizePrettify(10736344498176)).toEqual('9999 GB');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when size >= 10TB and size < 10 PB', function () {
|
||||
it('returns size in TB', function () {
|
||||
expect(sizePrettify(10995116277760)).toEqual('10 TB');
|
||||
});
|
||||
|
||||
it('returns size in TB', function () {
|
||||
expect(sizePrettify(29995116277760)).toEqual('27 TB');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when size >= 10 PB', function () {
|
||||
it('returns size in PB', function () {
|
||||
expect(sizePrettify(11258999068426200)).toEqual('10 PB');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user