From 740a50680eb9c8f05ea77b1cae9b809804e3c75a Mon Sep 17 00:00:00 2001 From: Yogesh Mahajan Date: Thu, 13 Feb 2025 11:56:10 +0530 Subject: [PATCH] Fix the following SonarQube issues: 1. Do not use the Array index in keys 2. Visible, non-interactive elements with click handlers must have at least one keyboard listener. 3. Add replacement fields or use a normal string instead of an f-string. 4. Add a parameter to the parent lambda function --- .../static/js/SchemaView/FieldControl.jsx | 2 +- .../static/js/SchemaView/FieldSetView.jsx | 4 ++-- web/pgadmin/static/js/SchemaView/FormView.jsx | 6 +++--- .../js/SchemaView/SchemaPropertiesView.jsx | 2 +- .../js/components/PgReactTableStyled.jsx | 3 ++- .../PgTree/FileTreeItem/DoubleClickHandler.jsx | 5 +++-- web/pgadmin/static/js/utils.js | 10 ++++++++++ web/pgadmin/tools/backup/__init__.py | 18 +++++++++--------- .../js/components/sections/StatusBar.jsx | 3 ++- .../feature_tests/query_tool_tests.py | 3 +-- web/regression/python_test_utils/test_utils.py | 2 +- 11 files changed, 35 insertions(+), 23 deletions(-) diff --git a/web/pgadmin/static/js/SchemaView/FieldControl.jsx b/web/pgadmin/static/js/SchemaView/FieldControl.jsx index 3a186cd41..0937e5584 100644 --- a/web/pgadmin/static/js/SchemaView/FieldControl.jsx +++ b/web/pgadmin/static/js/SchemaView/FieldControl.jsx @@ -18,7 +18,7 @@ export const FieldControl = ({schemaId, item}) => { { children?.map( - (child, idx) => + (child, idx) => ) } , [schemaId, Control, props, children] diff --git a/web/pgadmin/static/js/SchemaView/FieldSetView.jsx b/web/pgadmin/static/js/SchemaView/FieldSetView.jsx index 71e415227..f95f08c8d 100644 --- a/web/pgadmin/static/js/SchemaView/FieldSetView.jsx +++ b/web/pgadmin/static/js/SchemaView/FieldSetView.jsx @@ -56,10 +56,10 @@ export default function FieldSetView({
{fieldGroups.map( (fieldGroup, gidx) => ( - + {fieldGroup.controls.map( (item, idx) => + item={item} key={`${item.controlProps.id}-${idx}`} schemaId={schema._id} /> )} ) diff --git a/web/pgadmin/static/js/SchemaView/FormView.jsx b/web/pgadmin/static/js/SchemaView/FormView.jsx index 2d8169560..e9edd6e16 100644 --- a/web/pgadmin/static/js/SchemaView/FormView.jsx +++ b/web/pgadmin/static/js/SchemaView/FormView.jsx @@ -230,7 +230,7 @@ export default function FormView({ { group.controls.map( (item, idx) => + item={item} key={`${item.controlProps.id}-${idx}`} schemaId={schema._id} /> ) } @@ -282,10 +282,10 @@ export default function FormView({ className={contentClassName.join(' ')}> { finalGroups.map((group, idx) => - { + { group.controls.map( (item, idx) => ) } diff --git a/web/pgadmin/static/js/SchemaView/SchemaPropertiesView.jsx b/web/pgadmin/static/js/SchemaView/SchemaPropertiesView.jsx index 5ae9e4aa7..36f9ab5f3 100644 --- a/web/pgadmin/static/js/SchemaView/SchemaPropertiesView.jsx +++ b/web/pgadmin/static/js/SchemaView/SchemaPropertiesView.jsx @@ -91,7 +91,7 @@ export default function SchemaPropertiesView({ { group.controls.map( (item, idx) => ) } diff --git a/web/pgadmin/static/js/components/PgReactTableStyled.jsx b/web/pgadmin/static/js/components/PgReactTableStyled.jsx index 241fe9c15..9c8fa8221 100644 --- a/web/pgadmin/static/js/components/PgReactTableStyled.jsx +++ b/web/pgadmin/static/js/components/PgReactTableStyled.jsx @@ -20,7 +20,7 @@ import { PgIconButton } from './Buttons'; import CustomPropTypes from '../custom_prop_types'; import { InputSwitch } from './FormComponents'; import { Checkbox } from '@mui/material'; - +import { getEnterKeyHandler } from '../utils'; const StyledDiv = styled('div')(({theme})=>({ '&.pgrt': { @@ -265,6 +265,7 @@ export function PgReactTableHeader({table}) {
{flexRender(header.column.columnDef.header, header.getContext())} {header.column.getCanSort() && header.column.getIsSorted() && diff --git a/web/pgadmin/static/js/components/PgTree/FileTreeItem/DoubleClickHandler.jsx b/web/pgadmin/static/js/components/PgTree/FileTreeItem/DoubleClickHandler.jsx index e8a7cc4e0..16f6da42d 100644 --- a/web/pgadmin/static/js/components/PgTree/FileTreeItem/DoubleClickHandler.jsx +++ b/web/pgadmin/static/js/components/PgTree/FileTreeItem/DoubleClickHandler.jsx @@ -11,11 +11,12 @@ import { useSingleAndDoubleClick } from '../../../custom_hooks'; import * as React from 'react'; import PropTypes from 'prop-types'; import CustomPropTypes from '../../../../js/custom_prop_types'; - +import { getEnterKeyHandler } from '../../../../js/utils'; + export default function DoubleClickHandler({onSingleClick, onDoubleClick, children}){ const onClick = useSingleAndDoubleClick(onSingleClick, onDoubleClick) ; return( -
onClick(e)}> +
onClick(e)} onKeyDown = { getEnterKeyHandler(onClick)}> {children}
); diff --git a/web/pgadmin/static/js/utils.js b/web/pgadmin/static/js/utils.js index 74d9f8d9b..3fd6d91de 100644 --- a/web/pgadmin/static/js/utils.js +++ b/web/pgadmin/static/js/utils.js @@ -48,6 +48,16 @@ export function isShortcutValue(obj) { return [obj.alt, obj.control, obj?.key, obj?.key?.char].every((k)=>!_.isUndefined(k)); } + +export function getEnterKeyHandler(clickHandler) { + return (e)=>{ + if(e.code === 'Enter'){ + e.preventDefault(); + clickHandler(e); + } + }; +} + // Convert shortcut obj to codemirror key format export function toCodeMirrorKey(obj) { let shortcut = ''; diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py index 81b7b658e..571eee71d 100644 --- a/web/pgadmin/tools/backup/__init__.py +++ b/web/pgadmin/tools/backup/__init__.py @@ -368,17 +368,17 @@ def _get_args_params_values(data, conn, backup_obj_type, backup_file, server, if 'objects' in data: selected_objects = data.get('objects', {}) for _key in selected_objects: - param = 'schema' if _key == 'schema' else 'table' + selected_key = 'schema' if _key == 'schema' else 'table' args.extend( functools.reduce(operator.iconcat, map( - lambda s: [f'--{param}', - r'{0}.{1}'.format( - driver.qtIdent(conn, s['schema']).replace( - '"', '\"'), - driver.qtIdent(conn, s['name']).replace( - '"', '\"')) if type( - s) is dict else driver.qtIdent( - conn, s).replace('"', '\"')], + lambda s, param=selected_key:[ + f'--{param}', + r'{0}.{1}'.format( + driver.qtIdent(conn, s['schema']). + replace('"', '\"'), + driver.qtIdent(conn, s['name']).replace('"', '\"')) + if type(s) is dict + else driver.qtIdent(conn, s).replace('"', '\"')], selected_objects[_key] or []), []) ) diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/StatusBar.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/StatusBar.jsx index 6cee85e0f..6b1ea3e2e 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/StatusBar.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/StatusBar.jsx @@ -17,7 +17,7 @@ import { QueryToolEventsContext } from '../QueryToolComponent'; import gettext from 'sources/gettext'; import { PgMenu, PgMenuItem, usePgMenuGroup } from '../../../../../../static/js/components/Menu'; import PropTypes from 'prop-types'; - +import { getEnterKeyHandler } from '../../../../../../static/js/utils'; const StyledBox = styled(Box)(({theme}) => ({ display: 'flex', @@ -131,6 +131,7 @@ export function StatusBar({eol, handleEndOfLineChange}) {