Fix SonarQube code smells:

1) String literals should not be duplicated.
2) Prefer using an optional chain expression instead, as it's more concise and easier to read.
3) Expected the Promise rejection reason to be an Error.
This commit is contained in:
Akshay Joshi
2024-06-10 18:04:32 +05:30
parent 2d2aa45ec5
commit 8857f0d179
57 changed files with 210 additions and 205 deletions

View File

@@ -191,7 +191,7 @@ define('pgadmin.browser', [
if(categoryMenuOptions?.above) {
menuItemList.push(MainMenuFactory.getSeparator(label, priority));
}
if(!allMenuItemsDisabled && skipDisabled) {
if((!allMenuItemsDisabled && skipDisabled) || !skipDisabled) {
let _menuItem = MainMenuFactory.createMenuItem({
name: c,
label: label,
@@ -201,17 +201,6 @@ define('pgadmin.browser', [
priority: priority
});
menuItemList.push(_menuItem);
} else if(!skipDisabled){
let _menuItem = MainMenuFactory.createMenuItem({
name: c,
label: label,
module:c,
category: c,
menu_items: category[c],
priority: priority
});
menuItemList.push(_menuItem);
}
if(categoryMenuOptions?.below) {
@@ -223,9 +212,7 @@ define('pgadmin.browser', [
});
category[c].forEach((m)=> {
if(!skipDisabled) {
menuItemList.push(m);
} else if(skipDisabled && !m.isDisabled){
if(!skipDisabled || (skipDisabled && !m.isDisabled)) {
menuItemList.push(m);
}
});
@@ -1127,7 +1114,7 @@ define('pgadmin.browser', [
this.t.openPath(this.i);
this.t.select(this.i);
if (
_ctx.o && _ctx.o.success && typeof(_ctx.o.success) == 'function'
_ctx.o?.success && typeof(_ctx.o?.success) == 'function'
) {
_ctx.o.success.apply(_ctx.t, [_ctx.i, _new]);
}
@@ -1356,7 +1343,7 @@ define('pgadmin.browser', [
ctx.b._refreshNode(ctx, ctx.branch);
},
error: function() {
let fail = (_opts.o && _opts.o.fail) || _opts.fail;
let fail = _opts.o?.fail || _opts?.fail;
if (typeof(fail) == 'function') {
fail();
@@ -1673,7 +1660,7 @@ define('pgadmin.browser', [
_refreshNode: function(_ctx, _d) {
let traverseNodes = function(__d) {
let __ctx = this, idx = 0, ctx, d,
size = (__d.branch && __d.branch.length) || 0,
size = __d?.branch?.length || 0,
findNode = function(i_findNode, d_findNode, ctx_findNode) {
setTimeout(
function() {
@@ -1703,7 +1690,7 @@ define('pgadmin.browser', [
}
}.bind(_ctx, _d);
if (!_d || !_d.open)
if (!_d?.open)
return;
if (!_ctx.t.isOpen(_ctx.i)) {

View File

@@ -935,9 +935,7 @@ define('pgadmin.browser.node', [
cache: function(url, node_info, level, data) {
let cached = this.cached = this.cached || {},
hash = url,
min_priority = (
node_info?.[level] && node_info?.[level].priority
) || 0;
min_priority = node_info?.[level]?.priority || 0;
if (node_info) {
_.each(_.sortBy(_.values(_.pickBy(

View File

@@ -124,7 +124,7 @@ export function getNodeAjaxOptions(url, nodeObj, treeNodeInfo, itemNodeData, par
otherParams.useCache && cacheNode.cache(nodeObj.type + '#' + url, treeNodeInfo, cacheLevel, data);
resolve(transform(data));
}).catch((err)=>{
reject(err);
reject(new Error(err));
});
} else {
// To fetch only options from cache, we do not need time from 'at'