Fixed SonarQube issues.

This commit is contained in:
Aditya Toshniwal 2022-09-12 11:28:00 +05:30 committed by Akshay Joshi
parent 76a6feb2e7
commit 93f5fbc797
6 changed files with 34 additions and 153 deletions

View File

@ -9,7 +9,6 @@
import { getNodeListByName } from '../../../../../../../../static/js/node_ajax';
import UserMappingSchema from './user_mapping.ui';
import _ from 'lodash';
define('pgadmin.node.user_mapping', [
'sources/gettext', 'sources/url_for',
@ -89,23 +88,6 @@ define('pgadmin.node.user_mapping', [
}
);
},
// Defining model for user mapping node
model: pgAdmin.Browser.Node.Model.extend({
idAttribute: 'oid',
// Default values!
initialize: function(attrs, args) {
let isNew = (_.size(attrs) === 0);
if (isNew) {
let userInfo = pgBrowser.serverInfo[args.node_info.server._id].user;
this.set({'name': userInfo.name}, {silent: true});
}
pgAdmin.Browser.Node.Model.prototype.initialize.apply(this, arguments);
},
}),
});
}

View File

@ -109,83 +109,6 @@ define('pgadmin.node.primary_key', [
index: ()=>getNodeListByName('index', treeNodeInfo, itemNodeData, {jumpAfterNode: 'schema'}),
}, treeNodeInfo);
},
// Define the model for index constraint node
model: pgAdmin.Browser.Node.Model.extend({
idAttribute: 'oid',
defaults: {
name: undefined,
oid: undefined,
is_sys_obj: undefined,
comment: undefined,
spcname: undefined,
index: undefined,
fillfactor: undefined,
condeferrable: undefined,
condeferred: undefined,
columns: [],
include: [],
},
genResetColOptions: function() {
let self = this;
setTimeout(function () {
self.custom_options();
self.render.apply(self);
}, 50);
},
genCustomOptions: function() {
// We will add all the columns entered by user in table model
let columns = this.model.top.get('columns'),
added_columns_from_tables = [];
if (columns.length > 0) {
_.each(columns.models, function(m) {
let col = m.get('name');
if(!_.isUndefined(col) && !_.isNull(col)) {
added_columns_from_tables.push(
{label: col, value: col, image:'icon-column'}
);
}
});
}
// Set the values in to options so that user can select
this.field.set('options', added_columns_from_tables);
},
checkReadOnly(m) {
// If we are in table edit mode then
if (_.has(m, 'top') && !_.isUndefined(m.top)
&& !m.top.isNew()) {
// If OID is undefined then user is trying to add
// new constraint which should be allowed for Unique
return !_.isUndefined(m.get('oid'));
}
// We can't update columns of existing index constraint.
return !m.isNew();
},
validate: function() {
this.errorModel.clear();
// Clear parent's error as well
if (_.has(this, 'top')) {
this.top.errorModel.clear();
}
let columns = this.get('columns'),
index = this.get('index');
if ((_.isUndefined(index) || String(index).replace(/^\s+|\s+$/g, '') == '') &&
(_.isUndefined(columns) || _.isNull(columns) || columns.length < 1)) {
let msg = gettext('Please specify columns for %s.', gettext('Primary key'));
this.errorModel.set('columns', msg);
return msg;
}
return null;
},
}),
});
}

View File

@ -24,34 +24,6 @@ define('pgadmin.node.server', [
) {
if (!pgBrowser.Nodes['server']) {
pgBrowser.SecLabelModel = pgBrowser.Node.Model.extend({
defaults: {
provider: undefined,
label: undefined,
},
schema: [{
id: 'provider', label: gettext('Provider'),
type: 'text', editable: true,
cellHeaderClasses:'width_percent_50',
},{
id: 'label', label: gettext('Security label'),
type: 'text', editable: true,
cellHeaderClasses:'override_label_class_font_size',
}],
validate: function() {
this.errorModel.clear();
if (_.isUndefined(this.get('label')) ||
_.isNull(this.get('label')) ||
String(this.get('label')).replace(/^\s+|\s+$/g, '') == '') {
let errmsg = gettext('Security label must be specified.');
this.errorModel.set('label', errmsg);
return errmsg;
}
return null;
},
});
pgAdmin.Browser.Nodes['server'] = pgAdmin.Browser.Node.extend({
parent_type: 'server_group',
type: 'server',

View File

@ -859,13 +859,13 @@ define([
return null;
},
number_validate: function(value, field) {
if (!/^-?[0-9]+(\.?[0-9]*)?$/.test(value)) {
if (!/^-?\d+(\.?\d*)$/.test(value)) {
return pgadminUtils.sprintf(pgAdmin.Browser.messages.MUST_BE_NUM, field.label);
}
return this.check_min_max(value, field);
},
integer_validate: function(value, field) {
if (!/^-?[0-9]*$/.test(value)) {
if (!/^-?\d*$/.test(value)) {
return pgadminUtils.sprintf(pgAdmin.Browser.messages.MUST_BE_INT, field.label);
}
return this.check_min_max(value, field);

View File

@ -27,7 +27,7 @@ export function minMaxValidator(label, value, minValue, maxValue) {
export function numberValidator(label, value) {
if((_.isUndefined(value) || _.isNull(value) || String(value) === ''))
return null;
if (!/^-?[0-9]+(\.?[0-9]*)?$/.test(value)) {
if (!/^-?\d+(\.?\d*)$/.test(value)) {
return sprintf(pgAdmin.Browser.messages.MUST_BE_NUM, label);
}
return null;
@ -37,7 +37,7 @@ export function numberValidator(label, value) {
export function integerValidator(label, value) {
if((_.isUndefined(value) || _.isNull(value) || String(value) === ''))
return null;
if (!/^-?[0-9]*$/.test(value)) {
if (!/^-?\d*$/.test(value)) {
return sprintf(pgAdmin.Browser.messages.MUST_BE_INT, label);
}
return null;

View File

@ -79,6 +79,33 @@ const useStyles = makeStyles((theme)=>({
},
}));
function ObjectNameFormatter({row}) {
const classes = useStyles();
return (
<div className='rdg-cell-value'>
<Box className={row.show_node ? '' : classes.cellMuted}>
<span className={clsx(classes.gridCell, row.icon)}></span>
{row.name}
{row.other_info != null && row.other_info != '' && <>
<span className={classes.funcArgs}onClick={()=>{row.showArgs = true;}}> {row?.showArgs ? `(${row.other_info})` : '(...)'}</span>
</>}
</Box>
</div>
);
}
ObjectNameFormatter.propTypes = {
row: PropTypes.object,
};
function TypePathFormatter({row}) {
const classes = useStyles();
return (
<Box className={row.show_node ? '' : classes.cellMuted}>{row.type_label}</Box>
);
}
TypePathFormatter.propTypes = {
row: PropTypes.object,
};
const columns = [
@ -86,40 +113,17 @@ const columns = [
key: 'name',
name: gettext('Object name'),
width: 250,
formatter: ({row})=>{
const classes = useStyles();
return (
<div className='rdg-cell-value'>
<Box className={row.show_node ? '' : classes.cellMuted}>
<span className={clsx(classes.gridCell, row.icon)}></span>
{row.name}
{row.other_info != null && row.other_info != '' && <>
<span className={classes.funcArgs}onClick={()=>{row.showArgs = true;}}> {row?.showArgs ? `(${row.other_info})` : '(...)'}</span>
</>}
</Box>
</div>
);
}
formatter: ObjectNameFormatter,
},{
key: 'type',
name: gettext('Type'),
width: 30,
formatter: ({row})=>{
const classes = useStyles();
return (
<Box className={row.show_node ? '' : classes.cellMuted}>{row.type_label}</Box>
);
}
formatter: TypePathFormatter,
},{
key: 'path',
name: gettext('Browser path'),
sortable: false,
formatter: ({row})=>{
const classes = useStyles();
return (
<Box className={row.show_node ? '' : classes.cellMuted}>{row.path}</Box>
);
}
formatter: TypePathFormatter,
}
];