Skip to content

Commit

Permalink
Fixed SonarQube code smell 'Unnecessary use of boolean literals in co…
Browse files Browse the repository at this point in the history
…nditional expression'.
  • Loading branch information
akshay-joshi committed Apr 8, 2024
1 parent fc4b419 commit d236abf
Show file tree
Hide file tree
Showing 38 changed files with 104 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class DomainConstSchema extends BaseUISchema {
type: 'checkbox',
readonly: function(state) {
let currCon = _.find(obj.top.origData.constraints, (con)=>con.conoid == state.conoid);
return !obj.isNew(state) && currCon.convalidated ? true : false;
return !obj.isNew(state) && currCon.convalidated;
},
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class ForeignTableSchema extends BaseUISchema {
let newColInherits = state.inherits || [];
let oldColInherits = actionObj.oldState.inherits || [];

let tabName = undefined;
let tabName;
let tabColsResponse;

// Add columns logic
Expand Down Expand Up @@ -199,7 +199,7 @@ export default class ForeignTableSchema extends BaseUISchema {
canAdd: true, canDelete: true, columns: ['conname','consrc', 'connoinherit', 'convalidated'],
canEdit: true,
canDeleteRow: function(state) {
return (state.conislocal || _.isUndefined(state.conislocal)) ? true : false;
return (state.conislocal || _.isUndefined(state.conislocal));
},
canEditRow: function(state) {
return obj.isNew(state);
Expand Down Expand Up @@ -307,7 +307,7 @@ export class ColumnSchema extends BaseUISchema {
}

editable_check_for_column(state) {
return (_.isUndefined(state.inheritedid) || _.isNull(state.inheritedid) || _.isUndefined(state.inheritedfrom) || _.isNull(state.inheritedfrom)) ? true : false;
return (_.isUndefined(state.inheritedid) || _.isNull(state.inheritedid) || _.isUndefined(state.inheritedfrom) || _.isNull(state.inheritedfrom));
}

// Check whether the column is a generated column
Expand Down Expand Up @@ -355,10 +355,10 @@ export class ColumnSchema extends BaseUISchema {
type: 'multiline', mode: ['properties', 'create', 'edit'],
},
{
id: 'cltype',
label: gettext('Data type'),
id: 'cltype',
label: gettext('Data type'),
minWidth: 150,
group: gettext('Definition'),
group: gettext('Definition'),
noEmpty: true,
editable: obj.editable_check_for_column,
disabled: (state)=>{
Expand Down Expand Up @@ -416,7 +416,7 @@ export class ColumnSchema extends BaseUISchema {
},
{
id: 'attlen',
label: gettext('Length'),
label: gettext('Length'),
group: gettext('Definition'),
deps: ['cltype'],
type: 'int',
Expand Down Expand Up @@ -486,10 +486,10 @@ export class ColumnSchema extends BaseUISchema {
id: 'max_val_attprecision', skipChange: true, visible: false, type: '',
},
{
id: 'attstattarget',
label: gettext('Statistics'),
id: 'attstattarget',
label: gettext('Statistics'),
cell: 'text',
type: 'text',
type: 'text',
readonly: obj.inSchemaWithColumnCheck,
mode: ['properties', 'edit'],
group: gettext('Definition'),
Expand Down Expand Up @@ -524,12 +524,12 @@ export class ColumnSchema extends BaseUISchema {
},
},
{
id: 'attnotnull',
label: gettext('Not NULL?'),
id: 'attnotnull',
label: gettext('Not NULL?'),
cell: 'switch',
type: 'switch',
type: 'switch',
minWidth: 80,
group: gettext('Constraints'),
group: gettext('Constraints'),
editable: obj.editable_check_for_column,
},
{
Expand All @@ -540,7 +540,7 @@ export class ColumnSchema extends BaseUISchema {
type: (state)=>{
let options = [
{ 'label': gettext('NONE'), 'value': 'n'},
];
];
// You can't change the existing column to Generated column.
if (this.isNew(state)) {
options.push({
Expand All @@ -553,25 +553,25 @@ export class ColumnSchema extends BaseUISchema {
'value': 'g',
'disabled': true,
});
}
}
return {
type: 'toggle',
options: options,
};
},
disabled: function(state) {
return (!this.isNew(state) && state.colconstype == 'g');
},
},
min_version: 120000,
},
{
id: 'genexpr',
label: gettext('Expression'),
id: 'genexpr',
label: gettext('Expression'),
type: 'text',
mode: ['properties', 'create', 'edit'],
mode: ['properties', 'create', 'edit'],
group: gettext('Constraints'),
min_version: 120000,
deps: ['colconstype'],
min_version: 120000,
deps: ['colconstype'],
visible: this.isTypeGenerated,
readonly: function(state) {
return !this.isNew(state);
Expand All @@ -596,7 +596,7 @@ export class ColumnSchema extends BaseUISchema {

return (_.isUndefined(state.inheritedid)
|| _.isNull(state.inheritedid) ||
_.isUndefined(state.inheritedfrom) ||
_.isUndefined(state.inheritedfrom) ||
_.isNull(state.inheritedfrom));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export default class FTSConfigurationSchema extends BaseUISchema {
//disable parser when user select copy_config manually and vica-versa
disabled: function(state) {
let copy_config = state.copy_config;
return (_.isNull(copy_config) ||
return !(_.isNull(copy_config) ||
_.isUndefined(copy_config) ||
copy_config === '') ? false : true;
copy_config === '');
},
readonly: function(state) { return !obj.isNew(state); },
}, {
Expand All @@ -145,9 +145,9 @@ export default class FTSConfigurationSchema extends BaseUISchema {
//disable copy_config when user select parser manually and vica-versa
disabled: function(state) {
let parser = state.prsname;
return (_.isNull(parser) ||
return !(_.isNull(parser) ||
_.isUndefined(parser) ||
parser === '') ? false : true;
parser === '');
},
readonly: function(state) { return !obj.isNew(state); },
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class SynonymSchema extends BaseUISchema {
};
},
readonly: function() {
return !obj.inCatalog() ? false : true;
return obj.inCatalog();
}
}, {
id: 'is_sys_obj', label: gettext('System synonym?'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ForeignKeyHeaderSchema extends BaseUISchema {
optionsReloadBasis: this.fieldOptions.references?.map ? _.join(this.fieldOptions.references.map((c)=>c.label), ',') : null,
optionsLoaded: (rows)=>obj.refTables=rows,
disabled: (state) => {
return state._disable_references ? true : false;
return state._disable_references;
}
},{
id: 'referenced', label: gettext('Referencing'), editable: false, deps: ['references'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default class PartitionTableSchema extends BaseUISchema {
this.getAttachTables = getAttachTables;

this.partitionKeysObj = new PartitionKeysSchema([], getCollations, getOperatorClass);
this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables, fieldOptions.table_amname_list);
this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, fieldOptions.table_amname_list, getAttachTables);
this.constraintsObj = this.schemas.constraints();
}

Expand Down Expand Up @@ -236,7 +236,7 @@ export default class PartitionTableSchema extends BaseUISchema {
return {
type: 'select', options: this.fieldOptions.table_amname_list,
controlProps: {
allowClear: obj.isNew(state) ? true : false,
allowClear: obj.isNew(state),
}
};
}, mode: ['create', 'properties', 'edit'], min_version: 120000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class PartitionKeysSchema extends BaseUISchema {
}
}
export class PartitionsSchema extends BaseUISchema {
constructor(nodeInfo, getCollations, getOperatorClass, getAttachTables=()=>[], table_amname_list) {
constructor(nodeInfo, getCollations, getOperatorClass, table_amname_list, getAttachTables=()=>[]) {
super({
oid: undefined,
is_attach: false,
Expand Down Expand Up @@ -206,7 +206,7 @@ export class PartitionsSchema extends BaseUISchema {
return {
type: 'select', options: this.table_amname_list,
controlProps: {
allowClear: obj.isNew(state) ? true : false,
allowClear: obj.isNew(state),
}
};
}, min_version: 120000, disabled: state => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export default class TableSchema extends BaseUISchema {
this.nodeInfo = nodeInfo;
this.getColumns = getColumns;

this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, getAttachTables, fieldOptions.table_amname_list);
this.partitionsObj = new PartitionsSchema(this.nodeInfo, getCollations, getOperatorClass, fieldOptions.table_amname_list, getAttachTables);
this.constraintsObj = this.schemas.constraints?.() || {};
this.columnsSchema = this.schemas.columns?.() || {};
this.vacuumSettingsSchema = this.schemas.vacuum_settings?.() || {};
Expand Down Expand Up @@ -464,7 +464,7 @@ export default class TableSchema extends BaseUISchema {
id: 'oid', label: gettext('OID'), type: 'text', mode: ['properties'],
},{
id: 'relowner', label: gettext('Owner'), type: 'select',
options: this.fieldOptions.relowner, noEmpty: this.inErd ? false : true,
options: this.fieldOptions.relowner, noEmpty: !this.inErd,
mode: ['properties', 'create', 'edit'], controlProps: {allowClear: false},
readonly: this.inCatalog, visible: !this.inErd,
},{
Expand All @@ -480,7 +480,7 @@ export default class TableSchema extends BaseUISchema {
return {
type: 'select', options: this.fieldOptions.spcname,
controlProps: {
allowClear: obj.isNew(state) ? true : false,
allowClear: obj.isNew(state),
}
};
}
Expand Down Expand Up @@ -782,7 +782,7 @@ export default class TableSchema extends BaseUISchema {
return {
type: 'select', options: this.fieldOptions.table_amname_list,
controlProps: {
allowClear: obj.isNew(state) ? true : false,
allowClear: obj.isNew(state),
}
};
}, mode: ['create', 'properties', 'edit'], min_version: 120000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export default class TriggerSchema extends BaseUISchema {
state.tginitdeferred = false;
}
// If constraint trigger is set then do not disable
return state.is_constraint_trigger ? false : true;
return !state.is_constraint_trigger;
}
} else {
// readonly it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class RangeSchema extends BaseUISchema {
this.options = [];
}

return disableCollNameControl ? false : true;
return !disableCollNameControl;
},
readonly: function(state) {
return !obj.isNew(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class MViewSchema extends BaseUISchema {
return {
type: 'select', options: obj.fieldOptions.table_amname_list,
controlProps: {
allowClear: obj.isNew(state) ? true : false,
allowClear: obj.isNew(state),
}
};
}, mode: ['create', 'properties', 'edit'], min_version: 120000,
Expand All @@ -110,7 +110,7 @@ export default class MViewSchema extends BaseUISchema {
},{
id: 'definition', label: gettext('Definition'), cell: 'text',
type: 'sql', mode: ['create', 'edit'], group: gettext('Code'),
isFullTab: true, controlProps: { readOnly: this.nodeInfo && 'catalog' in this.nodeInfo ? true: false },
isFullTab: true, controlProps: { readOnly: this.nodeInfo && 'catalog' in this.nodeInfo },
},
{
type: 'nested-tab', group: gettext('Parameter'), mode: ['create', 'edit'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class ViewSchema extends BaseUISchema {
id: 'definition', label: gettext('Code'), cell: 'text',
type: 'sql', mode: ['create', 'edit'], group: gettext('Code'),
isFullTab: true,
controlProps: { readOnly: obj.nodeInfo && 'catalog' in obj.nodeInfo ? true: false },
controlProps: { readOnly: obj.nodeInfo && 'catalog' in obj.nodeInfo },
},

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ define('pgadmin.node.database', [
// If node_info is not present in current object then it might in its
// parent in case if we used sub node control
let node_info = args.node_info || args.handler.node_info;
return 'catalog' in node_info ? false : true;
return !('catalog' in node_info);
}
return true;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ export default class SubscriptionSchema extends BaseUISchema{
return false;
}
isRefresh(state){
if (!state.refresh_pub || _.isUndefined(state.refresh_pub)){
return true;
}
return false;
return !state.refresh_pub || _.isUndefined(state.refresh_pub);
}
isSSL(state) {
return this.SSL_MODES.indexOf(state.sslmode) == -1;
Expand Down Expand Up @@ -336,7 +333,11 @@ export default class SubscriptionSchema extends BaseUISchema{
state.copy_data_after_refresh = false;
return true;
}, depChange: (state)=>{
state.copy_data_after_refresh = state.refresh_pub ? state.copy_data_after_refresh ? false : true : false;
let copy_data_after_refresh = false;
if (state.refresh_pub && !state.copy_data_after_refresh) {
copy_data_after_refresh = true;
}
state.copy_data_after_refresh = copy_data_after_refresh;
},
},{
id: 'connect', label: gettext('Connect?'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class RoleReassign extends BaseUISchema{
helpMessage: gettext('New owner of the affected objects'),
deps: ['role_op'],
disabled: (state)=>{
return state.role_op == 'drop'? true: false;
return state.role_op == 'drop';
},
depChange: (state) =>{
if (state.role_op == 'drop'){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class BinaryPathSchema extends BaseUISchema {
width: 32,
radioType: true,
disabled: function (state) {
return state?.binaryPath && state?.binaryPath.length > 0 ? false : true;
return !(state?.binaryPath && state?.binaryPath.length > 0);
},
cell: 'radio',
deps: ['binaryPath'],
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/browser/static/js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ define('pgadmin.browser', [
url: _m.url || '#',
target: _m.target,
icon: _m.icon,
enable: enable ? enable : true,
enable: enable || true,
node: _m.node,
checked: _m.checked,
below: _m.below,
Expand Down
6 changes: 3 additions & 3 deletions web/pgadmin/dashboard/static/js/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function Dashboard({
disableGlobalFilter: false,
minWidth: 26,
width: 80,
isVisible: !did ? true: false
isVisible: !did
},
{
accessor: 'usename',
Expand Down Expand Up @@ -506,7 +506,7 @@ function Dashboard({
resizable: true,
disableGlobalFilter: false,
minWidth: 26,
isVisible: !did ? true: false,
isVisible: !did,
width: 80
},
{
Expand Down Expand Up @@ -623,7 +623,7 @@ function Dashboard({
disableGlobalFilter: false,
minWidth: 26,
width: 80,
isVisible: !did ? true: false
isVisible: !did
},
{
accessor: 'Owner',
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/misc/cloud/static/js/CloudWizard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export default function CloudWizard({ nodeInfo, nodeData, onClose, cloudPanelId}
<br/>{gettext('By clicking the below button, you will be redirected to the EDB BigAnimal authentication page in a new tab.')}
</Box>
</Box>}
{cloudProvider == CLOUD_PROVIDERS.BIGANIMAL && <PrimaryButton onClick={authenticateBigAnimal} disabled={verificationIntiated ? true: false}>
{cloudProvider == CLOUD_PROVIDERS.BIGANIMAL && <PrimaryButton onClick={authenticateBigAnimal} disabled={verificationIntiated}>
{gettext('Click here to authenticate yourself to EDB BigAnimal')}
</PrimaryButton>}
{cloudProvider == CLOUD_PROVIDERS.BIGANIMAL && <Box className={classes.messageBox}>
Expand Down
Loading

0 comments on commit d236abf

Please sign in to comment.