mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed the following code smells:
1) useState call is not destructured into value + setter pair. 2) A fragment with only one child is redundant. 3) Unnecessary '.apply()' and '.call()'. 4) Expected the Promise rejection reason to be an Error.
This commit is contained in:
@@ -128,12 +128,10 @@ class ERDTool extends React.Component {
|
||||
this.diagram = new ERDCore();
|
||||
/* Flag for checking if user has opted for save before close */
|
||||
this.closeOnSave = React.createRef();
|
||||
this.fileInputRef = React.createRef();
|
||||
this.containerRef = React.createRef();
|
||||
this.diagramContainerRef = React.createRef();
|
||||
this.canvasEle = props.isTest ? document.createElement('div') : null;
|
||||
this.noteRefEle = null;
|
||||
this.noteNode = null;
|
||||
this.keyboardActionObj = null;
|
||||
this.erdDialogs = new ERDDialogs(this.context);
|
||||
this.apiObj = getApiInstance();
|
||||
@@ -486,7 +484,7 @@ class ERDTool extends React.Component {
|
||||
})
|
||||
.catch((err)=>{
|
||||
console.error(err);
|
||||
reject();
|
||||
reject(new Error(err));
|
||||
});
|
||||
});
|
||||
const {x, y} = this.diagram.getEngine().getRelativeMousePoint(e);
|
||||
@@ -641,7 +639,7 @@ class ERDTool extends React.Component {
|
||||
this.setTitle(fileName);
|
||||
this.setLoading(null);
|
||||
if(this.closeOnSave) {
|
||||
this.closePanel.call(this);
|
||||
this.closePanel();
|
||||
}
|
||||
}).catch((err)=>{
|
||||
this.setLoading(null);
|
||||
|
||||
@@ -343,12 +343,11 @@ class TableNodeWidgetRaw extends React.Component {
|
||||
}}
|
||||
/>}
|
||||
</div>
|
||||
{tableMetaData.is_promise && <>
|
||||
{tableMetaData.is_promise &&
|
||||
<div className={classes.tableSection}>
|
||||
{!tableMetaData.data_failed && <div className={classes.tableNameText}>{gettext('Fetching...')}</div>}
|
||||
{tableMetaData.data_failed && <div className={clsx(classes.tableNameText, classes.error)}>{gettext('Failed to get data. Please delete this table.')}</div>}
|
||||
</div>
|
||||
</>}
|
||||
</div>}
|
||||
{!tableMetaData.is_promise && <>
|
||||
<div className={classes.tableSection}>
|
||||
<RowIcon icon={SchemaIcon}/>
|
||||
|
||||
@@ -115,9 +115,9 @@ export default function GrantWizard({ sid, did, nodeInfo, nodeData, onClose }) {
|
||||
let steps = [gettext('Object Selection'), gettext('Privilege Selection'), gettext('Review')];
|
||||
const [selectedObject, setSelectedObject] = React.useState([]);
|
||||
const [selectedAcl, setSelectedAcl] = React.useState({});
|
||||
const [msqlData, setSQL] = React.useState('');
|
||||
const [msqlData, setMSQLData] = React.useState('');
|
||||
const [loaderText, setLoaderText] = React.useState('');
|
||||
const [tablebData, setTableData] = React.useState([]);
|
||||
const [tableData, setTableData] = React.useState([]);
|
||||
const [privOptions, setPrivOptions] = React.useState({});
|
||||
const [privileges, setPrivileges] = React.useState([]);
|
||||
const [privSchemaInstance, setPrivSchemaInstance] = React.useState();
|
||||
@@ -201,7 +201,7 @@ export default function GrantWizard({ sid, did, nodeInfo, nodeData, onClose }) {
|
||||
};
|
||||
api.post(msql_url, post_data)
|
||||
.then(res => {
|
||||
setSQL(res.data.data);
|
||||
setMSQLData(res.data.data);
|
||||
setLoaderText('');
|
||||
})
|
||||
.catch(() => {
|
||||
@@ -319,7 +319,7 @@ export default function GrantWizard({ sid, did, nodeInfo, nodeData, onClose }) {
|
||||
className={classes.table}
|
||||
height={window.innerHeight - 450}
|
||||
columns={columns}
|
||||
data={tablebData}
|
||||
data={tableData}
|
||||
isSelectRow={true}
|
||||
getSelectedRows={getTableSelectedRows}>
|
||||
</PgTable>
|
||||
|
||||
@@ -175,7 +175,7 @@ export default function ImportExportServers({onClose}) {
|
||||
.catch(() => {
|
||||
setLoaderText('');
|
||||
setErrMsg(gettext('Error while fetching Server Groups and Servers.'));
|
||||
reject();
|
||||
reject(new Error(gettext('Error while fetching Server Groups and Servers.')));
|
||||
});
|
||||
} else if (selectionFormData.imp_exp == 'i') {
|
||||
let load_servers_url = url_for('import_export_servers.load_servers');
|
||||
@@ -192,7 +192,7 @@ export default function ImportExportServers({onClose}) {
|
||||
.catch((err) => {
|
||||
setLoaderText('');
|
||||
setErrMsg(err.response.data.errormsg);
|
||||
reject();
|
||||
reject(new Error(err.response.data.errormsg));
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -212,11 +212,10 @@ export function TextEditor({row, column, onRowChange, onClose}) {
|
||||
{gettext('Cancel')}
|
||||
</DefaultButton>
|
||||
{column.can_edit &&
|
||||
<>
|
||||
<PrimaryButton startIcon={<CheckRoundedIcon />} onClick={onOK} size="small" className={classes.buttonMargin}>
|
||||
{gettext('OK')}
|
||||
</PrimaryButton>
|
||||
</>}
|
||||
}
|
||||
</Box>
|
||||
</Box>
|
||||
</Portal>
|
||||
@@ -390,11 +389,10 @@ export function JsonTextEditor({row, column, onRowChange, onClose}) {
|
||||
{gettext('Cancel')}
|
||||
</DefaultButton>
|
||||
{column.can_edit &&
|
||||
<>
|
||||
<PrimaryButton startIcon={<CheckRoundedIcon />} onClick={onOK} size="small" className={classes.buttonMargin}>
|
||||
{gettext('OK')}
|
||||
</PrimaryButton>
|
||||
</>}
|
||||
}
|
||||
</Box>
|
||||
</Box>
|
||||
</Portal>
|
||||
|
||||
@@ -130,7 +130,7 @@ export default function FilterDialog({onClose, onSave}) {
|
||||
});
|
||||
};
|
||||
|
||||
return (<>
|
||||
return (
|
||||
<SchemaView
|
||||
formType={'dialog'}
|
||||
getInitData={getInitData}
|
||||
@@ -147,7 +147,7 @@ export default function FilterDialog({onClose, onSave}) {
|
||||
formClassName={classes.root}
|
||||
checkDirtyOnEnableSave={true}
|
||||
/>
|
||||
</>);
|
||||
);
|
||||
}
|
||||
|
||||
FilterDialog.propTypes = {
|
||||
|
||||
@@ -159,7 +159,7 @@ export default function MacrosDialog({onClose, onSave}) {
|
||||
if(keyOptions.length <= 0) {
|
||||
return <></>;
|
||||
}
|
||||
return (<>
|
||||
return (
|
||||
<SchemaView
|
||||
formType={'dialog'}
|
||||
getInitData={()=>{
|
||||
@@ -180,7 +180,7 @@ export default function MacrosDialog({onClose, onSave}) {
|
||||
isTabView={false}
|
||||
formClassName={classes.root}
|
||||
/>
|
||||
</>);
|
||||
);
|
||||
}
|
||||
|
||||
MacrosDialog.propTypes = {
|
||||
|
||||
@@ -255,8 +255,8 @@ export function GraphVisualiser({initColumns}) {
|
||||
const eventBus = useContext(QueryToolEventsContext);
|
||||
const queryToolCtx = useContext(QueryToolContext);
|
||||
const [graphType, setGraphType] = useState('L');
|
||||
const [xaxis, setXAxis] = useState(null);
|
||||
const [yaxis, setYAxis] = useState([]);
|
||||
const [xAxis, setXAxis] = useState(null);
|
||||
const [yAxis, setYAxis] = useState([]);
|
||||
const [[graphData, graphDataKey], setGraphData] = useState([{'datasets': []}, 0]);
|
||||
const [loaderText, setLoaderText] = useState('');
|
||||
const [columns, setColumns] = useState(initColumns);
|
||||
@@ -359,7 +359,7 @@ export function GraphVisualiser({initColumns}) {
|
||||
setLoaderText(gettext('Rendering data points...'));
|
||||
// Set the Graph Data
|
||||
setGraphData(
|
||||
(prev)=> [getGraphDataSet(graphType, res.data.data.result, columns, xaxis, _.isArray(yaxis) ? yaxis : [yaxis] , queryToolCtx), prev[1] + 1]
|
||||
(prev)=> [getGraphDataSet(graphType, res.data.data.result, columns, xAxis, _.isArray(yAxis) ? yAxis : [yAxis] , queryToolCtx), prev[1] + 1]
|
||||
);
|
||||
|
||||
setLoaderText('');
|
||||
@@ -411,7 +411,7 @@ export function GraphVisualiser({initColumns}) {
|
||||
}
|
||||
}} value={graphType} />
|
||||
<DefaultButton style={{marginLeft: 'auto'}} onClick={onGenerate} startIcon={<ShowChartRoundedIcon />}
|
||||
disabled={ _.isEmpty(xaxis) || yaxis.length <= 0 }>
|
||||
disabled={ _.isEmpty(xAxis) || yAxis.length <= 0 }>
|
||||
{gettext('Generate')}
|
||||
</DefaultButton>
|
||||
<PgIconButton title={expandedState ? gettext('Collapse') : gettext('Expand')}
|
||||
@@ -422,12 +422,12 @@ export function GraphVisualiser({initColumns}) {
|
||||
<Box className={classes.displayFlex}>
|
||||
<span className={classes.spanLabel}>{graphType != 'P' ? gettext('X Axis') : gettext('Label')}</span>
|
||||
<InputSelect className={classes.axisSelectCtrl} options={xAxisOptions}
|
||||
onChange={(v)=>setXAxis(v)} value={xaxis} optionsReloadBasis={optionsReload}/>
|
||||
onChange={(v)=>setXAxis(v)} value={xAxis} optionsReloadBasis={optionsReload}/>
|
||||
</Box>
|
||||
<Box className={classes.displayFlex}>
|
||||
<span className={classes.spanLabel}>{graphType != 'P' ? gettext('Y Axis') : gettext('Value')}</span>
|
||||
<InputSelect className={classes.axisSelectCtrl} controlProps={{'multiple': graphType != 'P', allowSelectAll: graphType != 'P'}}
|
||||
options={yAxisOptions} onChange={(v)=>setYAxis(v)} value={yaxis} optionsReloadBasis={optionsReload}/>
|
||||
options={yAxisOptions} onChange={(v)=>setYAxis(v)} value={yAxis} optionsReloadBasis={optionsReload}/>
|
||||
</Box>
|
||||
</>
|
||||
}
|
||||
|
||||
@@ -378,7 +378,6 @@ export function QueryHistory() {
|
||||
const [selectedItemKey, setSelectedItemKey] = React.useState(1);
|
||||
const [showInternal, setShowInternal] = React.useState(true);
|
||||
const [loaderText, setLoaderText] = React.useState('');
|
||||
const [,refresh] = React.useState({});
|
||||
const selectedEntry = qhu.current.getEntry(selectedItemKey);
|
||||
const layoutDocker = useContext(LayoutDockerContext);
|
||||
const listRef = React.useRef();
|
||||
@@ -425,7 +424,6 @@ export function QueryHistory() {
|
||||
};
|
||||
}
|
||||
qhu.current.addEntry(h);
|
||||
refresh({});
|
||||
};
|
||||
|
||||
listRef.current?.focus();
|
||||
|
||||
Reference in New Issue
Block a user