Fixed SonarQube issues.

This commit is contained in:
Aditya Toshniwal
2022-08-09 15:42:16 +05:30
committed by Akshay Joshi
parent f96653e9af
commit f5793e9a7a
7 changed files with 35 additions and 138 deletions

View File

@@ -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');

View File

@@ -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];
}
};
});

View File

@@ -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);
}