mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix sonarqube issues for the rule - 'If' statement should not be the only statement in 'else' block
This commit is contained in:
@@ -72,14 +72,12 @@ const getAppDataPath = () => {
|
||||
default:
|
||||
if (platform().startsWith('win')) {
|
||||
appDataPath = path.join(process.env.APPDATA, 'pgadmin');
|
||||
} else {
|
||||
if ('XDG_CONFIG_HOME' in process.env) {
|
||||
} else if ('XDG_CONFIG_HOME' in process.env) {
|
||||
appDataPath = path.join(process.env.XDG_CONFIG_HOME, 'pgadmin');
|
||||
} else {
|
||||
appDataPath = path.join(homedir(), '.config', 'pgadmin');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create directory if not exists
|
||||
createDir(appDataPath);
|
||||
@@ -108,14 +106,12 @@ const getLocalAppDataPath = () => {
|
||||
default:
|
||||
if (platform().startsWith('win')) {
|
||||
localAppDataPath = path.join(process.env.LOCALAPPDATA, 'pgadmin');
|
||||
} else {
|
||||
if ('XDG_DATA_HOME' in process.env) {
|
||||
} else if ('XDG_DATA_HOME' in process.env) {
|
||||
localAppDataPath = path.join(process.env.XDG_DATA_HOME, 'pgadmin');
|
||||
} else {
|
||||
localAppDataPath = path.join(homedir(), '.local', 'share', 'pgadmin');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create directory if not exists
|
||||
createDir(localAppDataPath);
|
||||
@@ -412,15 +408,13 @@ let ConfigureStore = {
|
||||
...this.jsonData,
|
||||
...key,
|
||||
};
|
||||
} else {
|
||||
if(value === '' || value == null || typeof(value) == 'undefined') {
|
||||
} else if(value === '' || value == null || typeof(value) == 'undefined') {
|
||||
if(this.jsonData[key] !== undefined) {
|
||||
delete this.jsonData[key];
|
||||
}
|
||||
} else {
|
||||
this.jsonData[key] = value;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -633,11 +633,9 @@ function updateCheckedMenuItem(menuItem) {
|
||||
sm.checked = menuItem.checked
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (sub.label == menuItem.label && type == 'checkbox') {
|
||||
} else if (sub.label == menuItem.label && type == 'checkbox') {
|
||||
sub.checked = menuItem.checked
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -449,9 +449,8 @@ export default class FunctionSchema extends BaseUISchema {
|
||||
setError('prosrc_c', null);
|
||||
}
|
||||
|
||||
}else {
|
||||
}else if (isEmptyString(state.prosrc)) {
|
||||
/* code validation*/
|
||||
if (isEmptyString(state.prosrc)) {
|
||||
errmsg = gettext('Code cannot be empty.');
|
||||
setError('prosrc', errmsg);
|
||||
return true;
|
||||
@@ -460,4 +459,3 @@ export default class FunctionSchema extends BaseUISchema {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1079,6 +1079,7 @@ class TableView(BaseTableView, DataTypeReader, SchemaDiffTableCompare):
|
||||
return super().update(
|
||||
gid, sid, did, scid, tid, data=data, res=res)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@BaseTableView.check_precondition
|
||||
|
||||
@@ -90,8 +90,7 @@ export default class MainMenuFactory {
|
||||
options.module[options.callback].apply(options.module, [options.data, pgAdmin.Browser.tree?.selected()]);
|
||||
} else if (options?.callback) {
|
||||
options.callback(options);
|
||||
} else {
|
||||
if (options.url != '#') {
|
||||
} else if (options.url != '#') {
|
||||
let api = getApiInstance();
|
||||
api(
|
||||
url_for('tools.initialize')
|
||||
@@ -101,7 +100,6 @@ export default class MainMenuFactory {
|
||||
pgAdmin.Browser.notifier.error(gettext('Error in opening window'));
|
||||
});
|
||||
}
|
||||
}
|
||||
}}, (menu, item)=> {
|
||||
pgAdmin.Browser.Events.trigger('pgadmin:nw-enable-disable-menu-items', menu, item);
|
||||
}, (item) => {
|
||||
|
||||
@@ -56,10 +56,9 @@ define('pgadmin.browser', [
|
||||
// calc method logic
|
||||
calc: (passed_width) => {
|
||||
let iw = window.innerWidth;
|
||||
if(iw > passed_width){
|
||||
if(iw > passed_width)
|
||||
return passed_width;
|
||||
}else{
|
||||
if (iw > pgAdmin.Browser.stdW.lg)
|
||||
else if (iw > pgAdmin.Browser.stdW.lg)
|
||||
return pgAdmin.Browser.stdW.lg;
|
||||
else if (iw > pgAdmin.Browser.stdW.md)
|
||||
return pgAdmin.Browser.stdW.md;
|
||||
@@ -69,8 +68,6 @@ define('pgadmin.browser', [
|
||||
// if avilable screen resolution is still
|
||||
// less then return the width value as it
|
||||
return iw;
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
stdH: {
|
||||
@@ -83,10 +80,9 @@ define('pgadmin.browser', [
|
||||
calc: (passed_height) => {
|
||||
// We are excluding sm as it is too small for dialog
|
||||
let ih = window.innerHeight;
|
||||
if (ih > passed_height){
|
||||
if (ih > passed_height)
|
||||
return passed_height;
|
||||
} else {
|
||||
if (ih > pgAdmin.Browser.stdH.lg)
|
||||
else if (ih > pgAdmin.Browser.stdH.lg)
|
||||
return pgAdmin.Browser.stdH.lg;
|
||||
else if (ih > pgAdmin.Browser.stdH.md)
|
||||
return pgAdmin.Browser.stdH.md;
|
||||
@@ -94,7 +90,6 @@ define('pgadmin.browser', [
|
||||
// if avilable screen resolution is still
|
||||
// less then return the height value as it
|
||||
return ih;
|
||||
}
|
||||
},
|
||||
},
|
||||
// Default panels
|
||||
@@ -666,10 +661,8 @@ define('pgadmin.browser', [
|
||||
if (d._type === 'column') {
|
||||
if (pgAdmin.numeric_comparator(d._id, _data._id) == 1)
|
||||
return true;
|
||||
} else {
|
||||
if (pgAdmin.natural_sort(d._label, _data._label) == 1)
|
||||
} else if (pgAdmin.natural_sort(d._label, _data._label) == 1)
|
||||
return true;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
//when the current element is greater than the end element
|
||||
@@ -693,10 +686,8 @@ define('pgadmin.browser', [
|
||||
if (d._type === 'column') {
|
||||
if (pgAdmin.numeric_comparator(d._id, _data._id) != -1)
|
||||
return true;
|
||||
} else {
|
||||
if (pgAdmin.natural_sort(d._label, _data._label) != -1)
|
||||
} else if (pgAdmin.natural_sort(d._label, _data._label) != -1)
|
||||
return true;
|
||||
}
|
||||
i = items[e];
|
||||
d = __ctx.t.itemData(i);
|
||||
let result;
|
||||
@@ -767,8 +758,7 @@ define('pgadmin.browser', [
|
||||
) {
|
||||
___ctx.t.open(___ctx.i);
|
||||
___ctx.t.select(_i);
|
||||
} else {
|
||||
if (_parent_data) {
|
||||
} else if (_parent_data) {
|
||||
// Unload the parent node so that we'll get
|
||||
// latest data when we try to expand it
|
||||
___ctx.t.unload(___ctx.i).then(
|
||||
@@ -777,7 +767,6 @@ define('pgadmin.browser', [
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
if (typeof(___ctx?.o?.success) == 'function') {
|
||||
___ctx.o.success.apply(___ctx.t, [_i, _data]);
|
||||
}
|
||||
@@ -1154,10 +1143,8 @@ define('pgadmin.browser', [
|
||||
if (d._type === 'column') {
|
||||
if (pgAdmin.numeric_comparator(d._id, _new._id) == 1)
|
||||
return true;
|
||||
} else {
|
||||
if (pgAdmin.natural_sort(d._label, _new._label) == 1)
|
||||
} else if (pgAdmin.natural_sort(d._label, _new._label) == 1)
|
||||
return true;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (e != items.length - 1) {
|
||||
@@ -1174,10 +1161,8 @@ define('pgadmin.browser', [
|
||||
if (d._type === 'column') {
|
||||
if (pgAdmin.numeric_comparator(d._id, _new._id) != -1)
|
||||
return true;
|
||||
} else {
|
||||
if (pgAdmin.natural_sort(d._label, _new._label) != -1)
|
||||
} else if (pgAdmin.natural_sort(d._label, _new._label) != -1)
|
||||
return true;
|
||||
}
|
||||
i = items[e];
|
||||
d = __ctx.t.itemData(i);
|
||||
let result;
|
||||
@@ -1678,14 +1663,10 @@ define('pgadmin.browser', [
|
||||
);
|
||||
});
|
||||
|
||||
if (_callback) {
|
||||
_callback();
|
||||
}
|
||||
_callback?.();
|
||||
});
|
||||
} else {
|
||||
if (_callback) {
|
||||
_callback();
|
||||
}
|
||||
_callback?.();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -821,23 +821,19 @@ define('pgadmin.browser.node', [
|
||||
/* Fit to standard sizes */
|
||||
if(w <= pgBrowser.stdW.sm) {
|
||||
w = pgBrowser.stdW.sm;
|
||||
} else {
|
||||
if(w <= pgBrowser.stdW.md) {
|
||||
} else if(w <= pgBrowser.stdW.md) {
|
||||
w = pgBrowser.stdW.md;
|
||||
} else {
|
||||
w = pgBrowser.stdW.lg;
|
||||
}
|
||||
}
|
||||
|
||||
if(h <= pgBrowser.stdH.sm) {
|
||||
h = pgBrowser.stdH.sm;
|
||||
} else {
|
||||
if(h <= pgBrowser.stdH.md) {
|
||||
} else if(h <= pgBrowser.stdH.md) {
|
||||
h = pgBrowser.stdH.md;
|
||||
} else {
|
||||
h = pgBrowser.stdH.lg;
|
||||
}
|
||||
}
|
||||
|
||||
if(update) {
|
||||
dialogProps.onClose(true);
|
||||
|
||||
@@ -616,11 +616,9 @@ export default function FileManager({params, closeModal, onOK, onCancel, sharedS
|
||||
const onItemEnter = useCallback(async (row)=>{
|
||||
if(row.file_type == 'dir' || row.file_type == 'drive') {
|
||||
await openDir(row.Path, selectedSS);
|
||||
} else {
|
||||
if(params.dialog_type == 'select_file') {
|
||||
} else if(params.dialog_type == 'select_file') {
|
||||
onOkClick();
|
||||
}
|
||||
}
|
||||
}, [filteredItems]);
|
||||
const onItemSelect = useCallback((idx)=>{
|
||||
selectedRowIdx.current = idx;
|
||||
|
||||
@@ -147,19 +147,15 @@ export default function ObjectNodeProperties({panelId, node, treeNodeInfo, nodeD
|
||||
|
||||
if (server.server_type == 'ppas' && node.epasHelp) {
|
||||
fullUrl = getEPASHelpUrl(server.version);
|
||||
} else {
|
||||
if (node.sqlCreateHelp == '' && node.sqlAlterHelp != '') {
|
||||
} else if (node.sqlCreateHelp == '' && node.sqlAlterHelp != '') {
|
||||
fullUrl = getHelpUrl(helpUrl, node.sqlAlterHelp, server.version);
|
||||
} else if (node.sqlCreateHelp != '' && node.sqlAlterHelp == '') {
|
||||
fullUrl = getHelpUrl(helpUrl, node.sqlCreateHelp, server.version);
|
||||
} else {
|
||||
if (isNew) {
|
||||
} else if (isNew) {
|
||||
fullUrl = getHelpUrl(helpUrl, node.sqlCreateHelp, server.version);
|
||||
} else {
|
||||
fullUrl = getHelpUrl(helpUrl, node.sqlAlterHelp, server.version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.open(fullUrl, 'postgres_help');
|
||||
} else {
|
||||
|
||||
@@ -390,12 +390,10 @@ function parsePlan(data, ctx) {
|
||||
plans.push(plan);
|
||||
idx++;
|
||||
});
|
||||
} else{
|
||||
if('loops' in data && 'exclusive' in data) {
|
||||
} else if('loops' in data && 'exclusive' in data) {
|
||||
data['inclusive'] = Math.ceil10(data['Actual Total Time'] / data['loops'] || 1, -3);
|
||||
data['exclusive'] = data['inclusive'];
|
||||
}
|
||||
}
|
||||
|
||||
if ('exclusive' in data) {
|
||||
data['exclusive'] = Math.ceil10(data['exclusive'], -3);
|
||||
|
||||
@@ -41,13 +41,11 @@ export function menuSearch(param, props) {
|
||||
if(subMenu.getMenuItems()) {
|
||||
iterItem(subMenu.getMenuItems(), getMenuName(subMenu), path);
|
||||
}
|
||||
} else {
|
||||
if(typeof(subMenu) == 'object' && !(subMenu instanceof NewMenuItem)) {
|
||||
} else if(typeof(subMenu) == 'object' && !(subMenu instanceof NewMenuItem)) {
|
||||
iterItem(Object.values(subMenu), path, parentPath);
|
||||
} else {
|
||||
iterItem(subMenu, path, parentPath);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -157,9 +157,8 @@ function getChangedData(topSchema, viewHelperProps, sessData, stringify=false, i
|
||||
...levelChanges,
|
||||
...parseChanges(field.schema, origVal, sessVal),
|
||||
};
|
||||
} else {
|
||||
} else if(isEdit && !_.isEqual(_.get(origVal, field.id), _.get(sessVal, field.id))) {
|
||||
/* Check for changes only if its in edit mode, otherwise everything can go through comparator */
|
||||
if(isEdit && !_.isEqual(_.get(origVal, field.id), _.get(sessVal, field.id))) {
|
||||
let change = null;
|
||||
if(field.type === 'collection') {
|
||||
/* Use diffArray package to get the array diff and extract the info.
|
||||
@@ -251,7 +250,6 @@ function getChangedData(topSchema, viewHelperProps, sessData, stringify=false, i
|
||||
attrChanged(field.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
parseChanges.depth--;
|
||||
@@ -294,12 +292,10 @@ function validateSchema(schema, sessData, setError, accessPath=[], collLabel=nul
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if(validateSchema(field.schema, sessData, setError, accessPath)) {
|
||||
/* A nested schema ? Recurse */
|
||||
if(validateSchema(field.schema, sessData, setError, accessPath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Normal field, default validations */
|
||||
let value = sessData[field.id];
|
||||
|
||||
@@ -122,7 +122,7 @@ export default function cmOverride(theme) {
|
||||
|
||||
'&.pg-autocomp-loader': {
|
||||
position: 'absolute',
|
||||
paddingRight: '8px',
|
||||
paddingRight: '1px 12px 1px 2px',
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -182,8 +182,7 @@ export const PgIconButton = forwardRef(({icon, title, shortcut, className, split
|
||||
</DefaultButton>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if(color == 'primary') {
|
||||
} else if(color == 'primary') {
|
||||
return (
|
||||
<Tooltip title={shortcutTitle || title || ''} aria-label={title || ''}>
|
||||
<PrimaryButton ref={ref} style={style}
|
||||
@@ -204,7 +203,6 @@ export const PgIconButton = forwardRef(({icon, title, shortcut, className, split
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
PgIconButton.displayName = 'PgIconButton';
|
||||
PgIconButton.propTypes = {
|
||||
|
||||
@@ -857,13 +857,11 @@ function getRealValue(options, value, creatable, formatter) {
|
||||
/* If multi select options need to be in some format by UI, use formatter */
|
||||
if (formatter) {
|
||||
realValue = formatter.fromRaw(realValue, options);
|
||||
} else {
|
||||
if (creatable) {
|
||||
} else if (creatable) {
|
||||
realValue = realValue.map((val) => ({ label: val, value: val }));
|
||||
} else {
|
||||
realValue = realValue.map((val) => (_.find(options, (option) => _.isEqual(option.value, val))));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let flatOptions = flattenSelectOptions(options);
|
||||
realValue = _.find(flatOptions, (option) => option.value == value) ||
|
||||
|
||||
@@ -7,18 +7,11 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import React, { useEffect, useMemo, useRef } from 'react';
|
||||
import ReactDOMServer from 'react-dom/server';
|
||||
import PropTypes from 'prop-types';
|
||||
import gettext from 'sources/gettext';
|
||||
import { makeStyles } from '@material-ui/core';
|
||||
import { PgIconButton } from '../../Buttons';
|
||||
import { checkTrojanSource } from '../../../utils';
|
||||
import { copyToClipboard } from '../../../clipboard';
|
||||
import { useDelayedCaller } from '../../../custom_hooks';
|
||||
import usePreferences from '../../../../../preferences/static/js/store';
|
||||
import FileCopyRoundedIcon from '@material-ui/icons/FileCopyRounded';
|
||||
import CheckRoundedIcon from '@material-ui/icons/CheckRounded';
|
||||
import KeyboardArrowRightRoundedIcon from '@material-ui/icons/KeyboardArrowRightRounded';
|
||||
import ExpandMoreRoundedIcon from '@material-ui/icons/ExpandMoreRounded';
|
||||
|
||||
@@ -44,7 +37,6 @@ import {
|
||||
foldKeymap,
|
||||
} from '@codemirror/language';
|
||||
|
||||
import FindDialog from './FindDialog';
|
||||
import syntaxHighlighting from '../extensions/highlighting';
|
||||
import PgSQL from '../extensions/dialect';
|
||||
import { sql } from '@codemirror/lang-sql';
|
||||
@@ -52,43 +44,10 @@ import errorMarkerExtn from '../extensions/errorMarker';
|
||||
import CustomEditorView from '../CustomEditorView';
|
||||
import breakpointGutter, { breakpointEffect } from '../extensions/breakpointGutter';
|
||||
import activeLineExtn from '../extensions/activeLineMarker';
|
||||
import GotoDialog from './GotoDialog';
|
||||
|
||||
const arrowRightHtml = ReactDOMServer.renderToString(<KeyboardArrowRightRoundedIcon style={{fontSize: '1.2em'}} />);
|
||||
const arrowDownHtml = ReactDOMServer.renderToString(<ExpandMoreRoundedIcon style={{fontSize: '1.2em'}} />);
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
copyButton: {
|
||||
position: 'absolute',
|
||||
zIndex: 99,
|
||||
right: '4px',
|
||||
top: '4px',
|
||||
}
|
||||
}));
|
||||
|
||||
export function CopyButton({ editor }) {
|
||||
const classes = useStyles();
|
||||
const [isCopied, setIsCopied] = useState(false);
|
||||
const revertCopiedText = useDelayedCaller(() => {
|
||||
setIsCopied(false);
|
||||
});
|
||||
|
||||
return (
|
||||
<PgIconButton size="small" className={classes.copyButton} icon={isCopied ? <CheckRoundedIcon /> : <FileCopyRoundedIcon />}
|
||||
title={isCopied ? gettext('Copied!') : gettext('Copy')}
|
||||
onClick={() => {
|
||||
copyToClipboard(editor?.getValue());
|
||||
setIsCopied(true);
|
||||
revertCopiedText(1500);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
CopyButton.propTypes = {
|
||||
editor: PropTypes.object,
|
||||
};
|
||||
|
||||
function handleDrop(e, editor) {
|
||||
let dropDetails = null;
|
||||
try {
|
||||
@@ -104,7 +63,6 @@ function handleDrop(e, editor) {
|
||||
}
|
||||
} catch (error) {
|
||||
/* if parsing fails, it must be the drag internal of codemirror text */
|
||||
// editor.inputState.handlers.drop(e, editor);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -171,11 +129,8 @@ const defaultExtensions = [
|
||||
|
||||
export default function Editor({
|
||||
currEditor, name, value, options, onCursorActivity, onChange, readonly, disabled, autocomplete = false,
|
||||
breakpoint = false, onBreakPointChange, showActiveLine=false, showCopyBtn = false,
|
||||
keepHistory = true, cid, helpid, labelledBy}) {
|
||||
const [[showFind, isReplace], setShowFind] = useState([false, false]);
|
||||
const [showGoto, setShowGoto] = useState(false);
|
||||
const [showCopy, setShowCopy] = useState(false);
|
||||
breakpoint = false, onBreakPointChange, showActiveLine=false,
|
||||
keepHistory = true, cid, helpid, labelledBy, customKeyMap}) {
|
||||
|
||||
const editorContainerRef = useRef();
|
||||
const editor = useRef();
|
||||
@@ -189,28 +144,6 @@ export default function Editor({
|
||||
const configurables = useRef(new Compartment());
|
||||
const editableConfig = useRef(new Compartment());
|
||||
|
||||
const editMenuKeyMap = [{
|
||||
key: 'Mod-f', run: (view, e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setShowFind([false, false]);
|
||||
setShowFind([true, false]);
|
||||
}
|
||||
}, {
|
||||
key: 'Mod-Alt-f', run: (view, e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setShowFind([false, false]);
|
||||
setShowFind([true, true]);
|
||||
},
|
||||
}, {
|
||||
key: 'Mod-l', run: (view, e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setShowGoto(true);
|
||||
},
|
||||
}];
|
||||
|
||||
useEffect(() => {
|
||||
const finalOptions = { ...defaultOptions, ...options };
|
||||
const finalExtns = [
|
||||
@@ -237,7 +170,7 @@ export default function Editor({
|
||||
extensions: [
|
||||
...finalExtns,
|
||||
configurables.current.of([]),
|
||||
keymap.of(editMenuKeyMap),
|
||||
keymap.of(customKeyMap??[]),
|
||||
editableConfig.current.of([
|
||||
EditorView.editable.of(!disabled),
|
||||
EditorState.readOnly.of(readonly),
|
||||
@@ -403,27 +336,9 @@ export default function Editor({
|
||||
});
|
||||
}, [readonly, disabled, keepHistory]);
|
||||
|
||||
const closeFind = () => {
|
||||
setShowFind([false, false]);
|
||||
editor.current?.focus();
|
||||
};
|
||||
|
||||
const closeGoto = () => {
|
||||
setShowGoto(false);
|
||||
editor.current?.focus();
|
||||
};
|
||||
|
||||
const onMouseEnter = useCallback(()=>{showCopyBtn && setShowCopy(true);});
|
||||
const onMouseLeave = useCallback(()=>{showCopyBtn && setShowCopy(false);});
|
||||
|
||||
return (
|
||||
<div onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} style={{height: '100%'}}>
|
||||
return useMemo(()=>(
|
||||
<div style={{ height: '100%' }} ref={editorContainerRef} name={name}></div>
|
||||
{showCopy && <CopyButton editor={editor.current} />}
|
||||
<FindDialog editor={editor.current} show={showFind} replace={isReplace} onClose={closeFind} />
|
||||
<GotoDialog editor={editor.current} show={showGoto} onClose={closeGoto} />
|
||||
</div>
|
||||
);
|
||||
), []);
|
||||
}
|
||||
|
||||
Editor.propTypes = {
|
||||
@@ -444,4 +359,5 @@ Editor.propTypes = {
|
||||
cid: PropTypes.string,
|
||||
helpid: PropTypes.string,
|
||||
labelledBy: PropTypes.string,
|
||||
customKeyMap: PropTypes.array,
|
||||
};
|
||||
|
||||
@@ -7,27 +7,121 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
||||
import { makeStyles } from '@material-ui/core';
|
||||
import FileCopyRoundedIcon from '@material-ui/icons/FileCopyRounded';
|
||||
import CheckRoundedIcon from '@material-ui/icons/CheckRounded';
|
||||
import clsx from 'clsx';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import gettext from 'sources/gettext';
|
||||
import { PgIconButton } from '../Buttons';
|
||||
import { copyToClipboard } from '../../clipboard';
|
||||
import { useDelayedCaller } from '../../custom_hooks';
|
||||
|
||||
import Editor from './components/Editor';
|
||||
import CustomPropTypes from '../../custom_prop_types';
|
||||
import FindDialog from './components/FindDialog';
|
||||
import GotoDialog from './components/GotoDialog';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
position: 'relative',
|
||||
height: '100%'
|
||||
},
|
||||
copyButton: {
|
||||
position: 'absolute',
|
||||
zIndex: 99,
|
||||
right: '4px',
|
||||
top: '4px',
|
||||
}
|
||||
}));
|
||||
|
||||
export default function CodeMirror({className, ...props}) {
|
||||
|
||||
function CopyButton({ editor }) {
|
||||
const classes = useStyles();
|
||||
const [isCopied, setIsCopied] = useState(false);
|
||||
const revertCopiedText = useDelayedCaller(() => {
|
||||
setIsCopied(false);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={clsx(className, classes.root)}>
|
||||
<Editor {...props} />
|
||||
<PgIconButton size="small" className={classes.copyButton} icon={isCopied ? <CheckRoundedIcon /> : <FileCopyRoundedIcon />}
|
||||
title={isCopied ? gettext('Copied!') : gettext('Copy')}
|
||||
onClick={() => {
|
||||
copyToClipboard(editor?.getValue());
|
||||
setIsCopied(true);
|
||||
revertCopiedText(1500);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
CopyButton.propTypes = {
|
||||
editor: PropTypes.object,
|
||||
};
|
||||
|
||||
|
||||
export default function CodeMirror({className, currEditor, showCopyBtn=false, ...props}) {
|
||||
const classes = useStyles();
|
||||
const editor = useRef();
|
||||
const [[showFind, isReplace], setShowFind] = useState([false, false]);
|
||||
const [showGoto, setShowGoto] = useState(false);
|
||||
const [showCopy, setShowCopy] = useState(false);
|
||||
|
||||
const editMenuKeyMap = useMemo(()=>[{
|
||||
key: 'Mod-f', run: (_view, e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setShowFind([false, false]);
|
||||
setShowFind([true, false]);
|
||||
}
|
||||
}, {
|
||||
key: 'Mod-Alt-f', run: (_view, e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setShowFind([false, false]);
|
||||
setShowFind([true, true]);
|
||||
},
|
||||
}, {
|
||||
key: 'Mod-l', run: (_view, e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setShowGoto(true);
|
||||
},
|
||||
}], []);
|
||||
|
||||
const closeFind = () => {
|
||||
setShowFind([false, false]);
|
||||
editor.current?.focus();
|
||||
};
|
||||
|
||||
const closeGoto = () => {
|
||||
setShowGoto(false);
|
||||
editor.current?.focus();
|
||||
};
|
||||
|
||||
const currEditorWrap = useCallback((obj)=>{
|
||||
editor.current = obj;
|
||||
currEditor?.(obj);
|
||||
}, []);
|
||||
|
||||
|
||||
const onMouseEnter = useCallback(()=>{showCopyBtn && setShowCopy(true);}, []);
|
||||
const onMouseLeave = useCallback(()=>{showCopyBtn && setShowCopy(false);}, []);
|
||||
|
||||
return (
|
||||
<div className={clsx(className, classes.root)} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} >
|
||||
<Editor currEditor={currEditorWrap} customKeyMap={editMenuKeyMap} {...props} />
|
||||
{showCopy && <CopyButton editor={editor.current} />}
|
||||
<FindDialog editor={editor.current} show={showFind} replace={isReplace} onClose={closeFind} />
|
||||
<GotoDialog editor={editor.current} show={showGoto} onClose={closeGoto} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
CodeMirror.propTypes = {
|
||||
currEditor: PropTypes.func,
|
||||
className: CustomPropTypes.className,
|
||||
showCopyBtn: PropTypes.bool,
|
||||
};
|
||||
@@ -133,8 +133,7 @@ class Notifier {
|
||||
if(!error.response) {
|
||||
msg = parseApiError(error);
|
||||
promptmsg = gettext('Connection Lost');
|
||||
} else {
|
||||
if(error.response.headers['content-type'] == 'application/json') {
|
||||
} else if(error.response.headers['content-type'] == 'application/json') {
|
||||
let resp = error.response.data;
|
||||
if(resp.info == 'CRYPTKEY_MISSING') {
|
||||
let pgBrowser = window.pgAdmin.Browser;
|
||||
@@ -159,7 +158,6 @@ class Notifier {
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(type == 'error-noalert' && onJSONResult && typeof(onJSONResult) == 'function') {
|
||||
return onJSONResult();
|
||||
}
|
||||
|
||||
@@ -39,9 +39,8 @@ function manageTreeEvents(event, eventName, item) {
|
||||
console.warn(e.stack || e);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
} else if (d && obj.Nodes[d._type]) {
|
||||
// Events for browser tree.
|
||||
if (d && obj.Nodes[d._type]) {
|
||||
node = obj.Nodes[d._type];
|
||||
|
||||
// If the Browser tree is not initialised yet
|
||||
@@ -72,7 +71,6 @@ function manageTreeEvents(event, eventName, item) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -510,14 +508,12 @@ export class Tree {
|
||||
Object.keys(typeOrTypeDict).forEach((type) => {
|
||||
this.registerDraggableType(type, typeOrTypeDict[type]);
|
||||
});
|
||||
} else {
|
||||
if (dropDetailsFunc != null) {
|
||||
} else if (dropDetailsFunc != null) {
|
||||
typeOrTypeDict.replace(/ +/, ' ').split(' ').forEach((type) => {
|
||||
this.draggableTypes[type] = dropDetailsFunc;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getDraggable(type) {
|
||||
if (this.draggableTypes[type]) {
|
||||
@@ -542,8 +538,7 @@ export class Tree {
|
||||
to: dropDetails.length,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
if (!dropDetails.cur) {
|
||||
} else if (!dropDetails.cur) {
|
||||
dropDetails = {
|
||||
...dropDetails,
|
||||
cur: {
|
||||
@@ -552,7 +547,6 @@ export class Tree {
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
e.dataTransfer.setData('text', JSON.stringify(dropDetails));
|
||||
/* Required by Firefox */
|
||||
|
||||
@@ -37,15 +37,11 @@ export function retrieveAncestorOfTypeServer(pgBrowser, item, errorAlertTitle) {
|
||||
'Databases with = symbols in the name cannot be backed up or restored using this utility.'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
if (databaseNode.anyParent(isServerNode))
|
||||
} else if (databaseNode.anyParent(isServerNode))
|
||||
serverInformation = nodeData;
|
||||
}
|
||||
} else {
|
||||
if (treeNode.anyFamilyMember(isServerNode))
|
||||
} else if (treeNode.anyFamilyMember(isServerNode))
|
||||
serverInformation = nodeData;
|
||||
}
|
||||
}
|
||||
|
||||
if (serverInformation === null) {
|
||||
pgAdmin.Browser.notifier.alert(
|
||||
|
||||
@@ -556,11 +556,9 @@ export default class DebuggerModule {
|
||||
pgAdmin.Browser.notifier.alert(gettext('Debugger Error'), error);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if (err.success == 0) {
|
||||
} else if (err.success == 0) {
|
||||
pgAdmin.Browser.notifier.alert(gettext('Debugger Error'), err.errormsg);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e.stack || e);
|
||||
}
|
||||
|
||||
@@ -326,8 +326,7 @@ export default function DebuggerArgumentComponent({ debuggerInfo, restartDebug,
|
||||
'default_value': defValList[i],
|
||||
'disable_use_default': defValList[i] == DEBUGGER_ARGS.NO_DEFAULT_VALUE,
|
||||
});
|
||||
} else {
|
||||
if (argMode && (argMode[i] == 'i' || argMode[i] == 'b' ||
|
||||
} else if (argMode && (argMode[i] == 'i' || argMode[i] == 'b' ||
|
||||
(isEdbProc && argMode[i] == 'o'))) {
|
||||
myObj.push({
|
||||
'name': myargname[i],
|
||||
@@ -338,7 +337,6 @@ export default function DebuggerArgumentComponent({ debuggerInfo, restartDebug,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return myObj;
|
||||
}
|
||||
|
||||
@@ -528,9 +526,8 @@ export default function DebuggerArgumentComponent({ debuggerInfo, restartDebug,
|
||||
'type': arg.type,
|
||||
'value': 'NULL',
|
||||
});
|
||||
} else {
|
||||
} else if (arg.use_default) {
|
||||
// Check if default value to be used or not
|
||||
if (arg.use_default) {
|
||||
argsValueList.push({
|
||||
'name': arg.name,
|
||||
'type': arg.type,
|
||||
@@ -544,7 +541,6 @@ export default function DebuggerArgumentComponent({ debuggerInfo, restartDebug,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
function getFunctionID(d, treeInfo) {
|
||||
let functionId;
|
||||
if (d._type == 'function') {
|
||||
|
||||
@@ -264,15 +264,13 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
|
||||
} else {
|
||||
points[i].setPosition(points[i - 1].getX(), points[i].getY());
|
||||
}
|
||||
} else {
|
||||
if (this.props.link.getLastPathXdirection()) {
|
||||
} else if (this.props.link.getLastPathXdirection()) {
|
||||
points[i - 1].setPosition(points[i - 1].getX(), points[i].getY());
|
||||
} else {
|
||||
points[i - 1].setPosition(points[i].getX(), points[i - 1].getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is existing link which has two points add one
|
||||
if (points.length === 2 && !this.state.canDrag) {
|
||||
|
||||
@@ -311,12 +311,9 @@ function expandRows(children, filterParams, tempChild, newRows, rowIndex) {
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
if (filterParams.includes(child.status)) {
|
||||
else if (filterParams.includes(child.status)) {
|
||||
tempChild.push(child);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
if (tempChild.length > 0) {
|
||||
newRows.splice(rowIndex + 1, 0, ...tempChild);
|
||||
@@ -548,8 +545,7 @@ export function ResultGridComponent({ gridData, allRowIds, filterParams, selecte
|
||||
let clsName = null;
|
||||
if (selectedRowIds.includes(`${row.id}`) || isCellSelected || row.id == activeRowId) {
|
||||
clsName = isCheckbox ? classes.selectedRowCheckBox : classes.selectedRow;
|
||||
} else {
|
||||
if (row.status == FILTER_NAME.DIFFERENT) {
|
||||
} else if (row.status == FILTER_NAME.DIFFERENT) {
|
||||
clsName = classes.different;
|
||||
} else if (row.status == FILTER_NAME.SOURCE_ONLY) {
|
||||
clsName = classes.source;
|
||||
@@ -558,7 +554,6 @@ export function ResultGridComponent({ gridData, allRowIds, filterParams, selecte
|
||||
} else if (row.status == FILTER_NAME.IDENTICAL) {
|
||||
clsName = classes.identical;
|
||||
}
|
||||
}
|
||||
|
||||
return clsName;
|
||||
}
|
||||
|
||||
@@ -251,9 +251,6 @@ export default function Query() {
|
||||
eventBus.registerListener(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, (value, focus=true)=>{
|
||||
focus && editor.current?.focus();
|
||||
editor.current?.setValue(value, !queryToolCtx.params.is_query_tool);
|
||||
if (value == '' && editor.current) {
|
||||
editor.current.state.autoCompleteList = [];
|
||||
}
|
||||
});
|
||||
eventBus.registerListener(QUERY_TOOL_EVENTS.TRIGGER_QUERY_CHANGE, ()=>{
|
||||
change();
|
||||
|
||||
@@ -1187,9 +1187,8 @@ export function ResultSet() {
|
||||
let clientPK = row[rsu.current.clientPK];
|
||||
if(clientPK in dataChangeStore.deleted) {
|
||||
remove.push(clientPK);
|
||||
} else {
|
||||
} else if(clientPK in dataChangeStore.added) {
|
||||
/* If deleted from newly added */
|
||||
if(clientPK in dataChangeStore.added) {
|
||||
removeNewlyAdded.push(clientPK);
|
||||
} else {
|
||||
let primaryKeys = {};
|
||||
@@ -1199,7 +1198,6 @@ export function ResultSet() {
|
||||
add[clientPK] = primaryKeys;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(removeNewlyAdded.length > 0) {
|
||||
dispatchDataChange({
|
||||
type: 'added',
|
||||
|
||||
Reference in New Issue
Block a user