Skip to content

Commit

Permalink
Fixed SonarQube code smells.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-joshi committed Jun 13, 2024
1 parent ad34ee2 commit 5866da8
Show file tree
Hide file tree
Showing 45 changed files with 130 additions and 164 deletions.
9 changes: 7 additions & 2 deletions docs/en_US/release_notes_8_9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Version 8.9

Release date: 2024-06-27

This release contains a number of bug fixes and new features since the release of pgAdmin 4 v8.7.
This release contains a number of bug fixes and new features since the release of pgAdmin 4 v8.8.

Supported Database Servers
**************************
Expand All @@ -19,8 +19,8 @@ Bundled PostgreSQL Utilities

New features
************
| `Issue #5932 <https://github.com/pgadmin-org/pgadmin4/issues/5932>`_ - Provide option to set theme based on OS theme preference.

| `Issue #5932 <https://github.com/pgadmin-org/pgadmin4/issues/5932>`_ - Provide option to set theme based on OS theme preference.
Housekeeping
************
Expand All @@ -31,6 +31,11 @@ Bug fixes
*********

| `Issue #6357 <https://github.com/pgadmin-org/pgadmin4/issues/6357>`_ - Disable the query tool editor input if any SQL is being loaded to prevent users from typing.
| `Issue #7241 <https://github.com/pgadmin-org/pgadmin4/issues/7241>`_ - Fixed an issue where resizable data editors in query tool should not be allowed to resize beyond the app window bounds.
| `Issue #7295 <https://github.com/pgadmin-org/pgadmin4/issues/7295>`_ - Fixed new line indentation in query editor and add a user preference to disable it.
| `Issue #7306 <https://github.com/pgadmin-org/pgadmin4/issues/7306>`_ - Ensure that a user can connect to a server using SSL certificates and identity files from a shared storage.
| `Issue #7414 <https://github.com/pgadmin-org/pgadmin4/issues/7414>`_ - Add support for comments on RLS policy object.
| `Issue #7481 <https://github.com/pgadmin-org/pgadmin4/issues/7481>`_ - Fixed an issue where dark theme shows white background when all tabs are closed.
| `Issue #7516 <https://github.com/pgadmin-org/pgadmin4/issues/7516>`_ - Ensure preferences can be loaded using preferences.json.
| `Issue #7536 <https://github.com/pgadmin-org/pgadmin4/issues/7536>`_ - Search Objects dialog should focus on search input on open.
| `Issue #7555 <https://github.com/pgadmin-org/pgadmin4/issues/7555>`_ - Fixed an issue where query tool shortcuts for find/replace are not working.
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ export default class CollationSchema extends BaseUISchema {
else {
if (actionObj.oldState.is_deterministic) {
return { is_deterministic: false };
} else {
return { is_deterministic: true };
}
return { is_deterministic: true };
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def get_inner(sql):
if sql is None:
return None
start = 0
start_position = re.search("\\s+[is|as]+\\s+", sql, flags=re.I)
start_position = re.search("\\s+(is|as)+\\s+", sql, flags=re.I)

if start_position:
start = start_position.start() + 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def get_inner(sql):
if sql is None:
return None
start = 0
start_position = re.search(r"\s+[is|as]+\s+", sql, flags=re.I)
start_position = re.search(r"\s+(is|as)+\s+", sql, flags=re.I)

if start_position:
start = start_position.start() + 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ export default class CompoundTriggerSchema extends BaseUISchema {
}
// Enable column only if update event is set true
let isUpdate = state.evnt_update;
if(!_.isUndefined(isUpdate) && isUpdate) {
return false;
}
return true;
return !(!_.isUndefined(isUpdate) && isUpdate);
},
readonly: function(state) { return !obj.isNew(state); },
},{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ define('pgadmin.node.table', [
handle_cache: function() {
// Clear Table's cache as column's type is dependent on two node
// 1) Type node 2) Domain node
this.clear_cache.apply(this, null);
this.clear_cache(...null);
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,13 @@ def parse_rule_definition(res):
# Parse data for condition
condition = ''
condition_part_match = re.search(
r"((?:ON)\s+(?:[\s\S]+?)"
r"(?:TO)\s+(?:[\s\S]+?)(?:DO))", data_def)
r"(ON\s+[\s\S]+?"
r"TO\s+[\s\S]+?DO)", data_def)
if condition_part_match is not None:
condition_part = condition_part_match.group(1)

condition_match = re.search(
r"(?:WHERE)\s+(\([\s\S]*\))\s+(?:DO)", condition_part)
r"WHERE\s+(\([\s\S]*\))\s+DO", condition_part)

if condition_match is not None:
condition = condition_match.group(1)
Expand All @@ -537,7 +537,7 @@ def parse_rule_definition(res):

# Parse data for statements
statement_match = re.search(
r"(?:DO\s+)(?:INSTEAD\s+)?([\s\S]*)(?:;)", data_def)
r"DO\s+(?:INSTEAD\s+)?([\s\S]*);", data_def)

statement = ''
if statement_match is not None:
Expand Down
1 change: 0 additions & 1 deletion web/pgadmin/browser/static/css/wizard.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

.wizard {
width: 100%;
/*height: 550px;*/
}

.step {
Expand Down
4 changes: 2 additions & 2 deletions web/pgadmin/misc/cloud/static/js/azure.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function AzureCredentials(props) {

let _eventBus = React.useContext(CloudWizardEventsContext);
React.useMemo(() => {
const azureCloudDBCredSchema = new AzureCredSchema({
const azureCloudDBCredSchema = new AzureCredSchema(_eventBus, {
authenticateAzure:(auth_type, azure_tenant_id) => {
let loading_icon_url = url_for(
'static', { 'filename': 'img/loading.gif'}
Expand Down Expand Up @@ -77,7 +77,7 @@ export function AzureCredentials(props) {
}, 1000);
});
}
}, {}, _eventBus);
}, {});
setCloudDBCredInstance(azureCloudDBCredSchema);
}, [props.cloudProvider]);

Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/misc/cloud/static/js/azure_schema.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isEmptyString } from 'sources/validators';
import pgAdmin from 'sources/pgadmin';

class AzureCredSchema extends BaseUISchema {
constructor(fieldOptions = {}, initValues = {}, eventBus) {
constructor(eventBus, fieldOptions = {}, initValues = {}) {
super({
oid: null,
auth_type: 'interactive_browser_credential',
Expand Down
15 changes: 7 additions & 8 deletions web/pgadmin/static/js/AppMenuBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
//////////////////////////////////////////////////////////////
import { Box } from '@mui/material';
import { styled } from '@mui/material/styles';
import React, { useState, useEffect } from 'react';
import React, { useEffect } from 'react';
import { PrimaryButton } from './components/Buttons';
import { PgMenu, PgMenuDivider, PgMenuItem, PgSubMenu } from './components/Menu';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import AccountCircleRoundedIcon from '@mui/icons-material/AccountCircleRounded';
import { usePgAdmin } from '../../static/js/BrowserComponent';
import { useForceUpdate } from './custom_hooks';


const StyledBox = styled(Box)(({theme}) => ({
Expand All @@ -39,7 +40,7 @@ const StyledBox = styled(Box)(({theme}) => ({
alignItems: 'center',
gap: '2px',
marginLeft: '16px',

'& .MuiButton-containedPrimary': {
padding: '1px 8px',
}
Expand All @@ -59,17 +60,15 @@ const StyledBox = styled(Box)(({theme}) => ({

export default function AppMenuBar() {

const [,setRefresh] = useState(false);
const forceUpdate = useForceUpdate();
const pgAdmin = usePgAdmin();

const reRenderMenus = ()=>setRefresh((prev)=>!prev);

useEffect(()=>{
pgAdmin.Browser.Events.on('pgadmin:nw-enable-disable-menu-items', _.debounce(()=>{
reRenderMenus();
forceUpdate();
}, 100));
pgAdmin.Browser.Events.on('pgadmin:nw-refresh-menu-item', _.debounce(()=>{
reRenderMenus();
forceUpdate();
}, 100));
}, []);

Expand All @@ -85,7 +84,7 @@ export default function AppMenuBar() {
onClick={()=>{
menuItem.callback();
if(hasCheck) {
reRenderMenus();
forceUpdate();
}
}}
hasCheck={hasCheck}
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/static/js/Dialogs/UrlDialogContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function UrlDialogContent({ url, helpFile, onClose }) {
return (
<ModalContent>
<Box flexGrow="1">
<iframe src={url} width="100%" height="100%" onLoad={(e)=>{
<iframe src={url} title=" " width="100%" height="100%" onLoad={(e)=>{
e.target?.contentWindow?.focus();
}}/>
</Box>
Expand Down
1 change: 1 addition & 0 deletions web/pgadmin/static/js/QuickSearch/HiddenIframe.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function HiddenIframe({id, srcURL, onLoad}) {
<iframe
id={id}
src={srcURL}
title=" "
onLoad={onLoad}
width={'20'}
height={'20'}
Expand Down
4 changes: 3 additions & 1 deletion web/pgadmin/static/js/SchemaView/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,14 @@ const sessDataReducer = (state, action)=>{
data = getDepChange(action.path, data, state, action);
break;
case SCHEMA_STATE_ACTIONS.MOVE_ROW:
{
rows = _.get(data, action.path)||[];
var row = rows[action.oldIndex];
let row = rows[action.oldIndex];
rows.splice(action.oldIndex, 1);
rows.splice(action.newIndex, 0, row);
_.set(data, action.path, rows);
break;
}
case SCHEMA_STATE_ACTIONS.CLEAR_DEFERRED_QUEUE:
data.__deferred__ = [];
break;
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/static/js/components/FormComponents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ function OptionView({ image, imageUrl, label }) {
return (
<Root>
{image && <span className={'Form-optionIcon ' + image}></span>}
{imageUrl && <img style={{height: '20px', marginRight: '4px'}} src={imageUrl} />}
{imageUrl && <img style={{height: '20px', marginRight: '4px'}} src={imageUrl} alt="" />}
<span>{label}</span>
</Root>
);
Expand Down
6 changes: 3 additions & 3 deletions web/pgadmin/static/js/components/KeyboardShortcuts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function KeyboardShortcuts({ value, onChange, fields, name }) {
{hasKeys &&
<>
<ToggleButtonGroup value={value?.shift ? ['shift'] : []} onChange={(e, val)=>{
onChangeButton('shift', val.length == 0 ? false : true);
onChangeButton('shift', val.length != 0 );
}}>
<ToggleCheckButton value="shift" label={gettext('Shift')} selected={value?.shift} />
</ToggleButtonGroup>
Expand All @@ -93,7 +93,7 @@ export default function KeyboardShortcuts({ value, onChange, fields, name }) {
{isMac() && <ToggleCheckButton value="ctrl_is_meta" label={gettext('Cmd')} selected={ctrlValue == 'ctrl_is_meta'} />}
</ToggleButtonGroup>
<ToggleButtonGroup value={value?.alt ? ['alt'] : []} onChange={(e, val)=>{
onChangeButton('alt', val.length == 0 ? false : true);
onChangeButton('alt', val.length != 0);
}}>
<ToggleCheckButton value="alt" label={isMac() ? gettext('Option') : gettext('Alt')} selected={value?.alt} />
</ToggleButtonGroup>
Expand All @@ -112,4 +112,4 @@ KeyboardShortcuts.propTypes = {
onChange: PropTypes.func,
fields: PropTypes.array,
name: PropTypes.string,
};
};
7 changes: 4 additions & 3 deletions web/pgadmin/static/js/components/PgReactDataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import React, { useContext, useEffect } from 'react';
import React, { useContext, useEffect, useMemo } from 'react';
import ReactDataGrid, { Row } from 'react-data-grid';
import { Box } from '@mui/material';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -108,7 +108,7 @@ export function CustomRow({inTest=false, ...props}) {
}
}, [props.selectedCellIdx]);
if(inTest) {
return <div data-test='test-div' tabIndex={0} onKeyDown={handleKeyDown}></div>;
return <div data-test='test-div' tabIndex={-1} onKeyDown={handleKeyDown}></div>;
}
const onRowClick = (...args)=>{
gridUtils.onItemClick?.(props.rowIdx);
Expand All @@ -135,8 +135,9 @@ export default function PgReactDataGrid({gridRef, className, hasSelectColumn=tru
hasSelectColumn && finalClassName.push('ReactGrid-hasSelectColumn');
props.enableCellSelect && finalClassName.push('ReactGrid-cellSelection');
finalClassName.push(className);
const valObj = useMemo(() => ({onItemEnter, onItemSelect, onItemClick}), [onItemEnter, onItemSelect, onItemClick]);
return (
<GridContextUtils.Provider value={{onItemEnter, onItemSelect, onItemClick}}>
<GridContextUtils.Provider value={valObj}>
<StyledReactDataGrid
ref={gridRef}
className={finalClassName.join(' ')}
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/static/js/components/Privilege.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default function Privilege({value, onChange, controlProps}) {
return (
<Root>
<InputText value={textValue} readOnly/>
<table className={'Privilege-table priv-table'} tabIndex="0">
<table className={'Privilege-table priv-table'} tabIndex="-1">
{(realVal.length > 1) && <thead>
<tr>
<td className='Privilege-tableCell'>
Expand Down
6 changes: 5 additions & 1 deletion web/pgadmin/static/js/custom_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import {useRef, useEffect, useState, useCallback, useLayoutEffect} from 'react';
import React, {useRef, useEffect, useState, useCallback, useLayoutEffect} from 'react';
import moment from 'moment';
import { isMac } from './keyboard_shortcuts';

Expand Down Expand Up @@ -205,3 +205,7 @@ export function useWindowSize() {
}, []);
return size;
}

export function useForceUpdate() {
return React.useReducer(() => ({}), {})[1];
}
2 changes: 1 addition & 1 deletion web/pgadmin/static/js/helpers/Layout/LayoutIframeTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function LayoutIframeTab({target, src, children}) {
if(r) setIframeTarget(r.querySelector('#'+target));
}} container={document.querySelector('#layout-portal')}>
{src ?
<iframe src={src} id={target} style={{position: 'fixed', border: 0}} />:
<iframe src={src} title=" " id={target} style={{position: 'fixed', border: 0}} />:
<Frame src={src} id={target} style={{position: 'fixed', border: 0}}>
{children}
</Frame>
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ export function pgHandleItemError(error, args) {

export function fullHexColor(shortHex) {
if(shortHex?.length == 4) {
return shortHex.replace(RegExp('#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])'), '#$1$1$2$2$3$3').toUpperCase();
return shortHex.replace(/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/, '#$1$1$2$2$3$3').toUpperCase();
}
return shortHex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,7 @@ export default function DebuggerArgumentComponent({ debuggerInfo, restartDebug,
let myObj = [];
for (let i = 0; i < argType.length; i++) {
let useDefValue = checkIsDefault(defValList[i]);
if (debuggerInfo['proargmodes'] == null) {
myObj.push({
'name': myargname[i],
'type': argType[i],
'use_default': useDefValue,
'default_value': defValList[i],
'disable_use_default': defValList[i] == DEBUGGER_ARGS.NO_DEFAULT_VALUE,
});
} else if (argMode && (argMode[i] == 'i' || argMode[i] == 'b' ||
(isEdbProc && argMode[i] == 'o'))) {
if (debuggerInfo['proargmodes'] == null || (argMode?.[i] == 'i' || argMode?.[i] == 'b' || (isEdbProc && argMode?.[i] == 'o'))) {
myObj.push({
'name': myargname[i],
'type': argType[i],
Expand Down
Loading

0 comments on commit 5866da8

Please sign in to comment.