From bc0b25d995243969ed789d5873c88b5ce18b00ec Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Mon, 31 Jan 2022 13:41:22 +0530 Subject: [PATCH] 1) Fixed an issue where a warning message was shown after database creation/modification. Fixes #7142. 2) Added error boundary to schema view which will improve the exception stack trace details. 3) Fixed Jasmine test cases. --- docs/en_US/release_notes_6_5.rst | 1 + .../databases/static/js/database.ui.js | 3 +- web/pgadmin/static/js/SchemaView/index.jsx | 9 ++++- .../static/js/components/FormComponents.jsx | 3 +- .../static/js/helpers/ErrorBoundary.jsx | 38 +++++++++++++++++++ 5 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 web/pgadmin/static/js/helpers/ErrorBoundary.jsx diff --git a/docs/en_US/release_notes_6_5.rst b/docs/en_US/release_notes_6_5.rst index 60ff5743b..f1c004aca 100644 --- a/docs/en_US/release_notes_6_5.rst +++ b/docs/en_US/release_notes_6_5.rst @@ -29,3 +29,4 @@ Bug fixes | `Issue #7126 `_ - Fixed an issue where the F2 Function key removes browser panel contents. | `Issue #7127 `_ - Added validation for Hostname in the server dialog. | `Issue #7135 `_ - Enforce the minimum Windows version that the installer will run on. +| `Issue #7142 `_ - Fixed an issue where a warning message was shown after database creation/modification. diff --git a/web/pgadmin/browser/server_groups/servers/databases/static/js/database.ui.js b/web/pgadmin/browser/server_groups/servers/databases/static/js/database.ui.js index c23c0ec0e..0715ea1b7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/static/js/database.ui.js +++ b/web/pgadmin/browser/server_groups/servers/databases/static/js/database.ui.js @@ -7,6 +7,7 @@ // ////////////////////////////////////////////////////////////// +import _ from 'lodash'; import gettext from 'sources/gettext'; import BaseUISchema from 'sources/SchemaView/base_schema.ui'; import SecLabelSchema from '../../../static/js/sec_label.ui'; @@ -203,7 +204,7 @@ export default class DatabaseSchema extends BaseUISchema { obj.informText = undefined; } - if(obj.origData.schema_res != state.schema_res) { + if(!_.isEqual(obj.origData.schema_res, state.schema_res)) { obj.informText = gettext( 'Please refresh the Schemas node to make changes to the schema restriction take effect.' ); diff --git a/web/pgadmin/static/js/SchemaView/index.jsx b/web/pgadmin/static/js/SchemaView/index.jsx index 52ab97a30..11f2a0849 100644 --- a/web/pgadmin/static/js/SchemaView/index.jsx +++ b/web/pgadmin/static/js/SchemaView/index.jsx @@ -38,6 +38,7 @@ import FieldSetView from './FieldSetView'; import DataGridView from './DataGridView'; import { useIsMounted } from '../custom_hooks'; import Notify from '../helpers/Notifier'; +import ErrorBoundary from '../helpers/ErrorBoundary'; const useDialogStyles = makeStyles((theme)=>({ root: { @@ -947,13 +948,17 @@ export default function SchemaView({formType, ...props}) { if(formType === 'tab') { return ( - + + + ); } return ( - + + + ); } diff --git a/web/pgadmin/static/js/components/FormComponents.jsx b/web/pgadmin/static/js/components/FormComponents.jsx index 25ec140ef..40d61ee92 100644 --- a/web/pgadmin/static/js/components/FormComponents.jsx +++ b/web/pgadmin/static/js/components/FormComponents.jsx @@ -767,7 +767,8 @@ export function InputSelect({ } else { selectedVal = _.find(flatRes, (o)=>o.selected)?.value; } - if(!_.isUndefined(selectedVal)) { + + if((!_.isUndefined(selectedVal) && !_.isArray(selectedVal)) || (_.isArray(selectedVal) && selectedVal.length != 0)) { onChange && onChange(selectedVal); } setFinalOptions([res || [], false]); diff --git a/web/pgadmin/static/js/helpers/ErrorBoundary.jsx b/web/pgadmin/static/js/helpers/ErrorBoundary.jsx new file mode 100644 index 000000000..220cdf6bf --- /dev/null +++ b/web/pgadmin/static/js/helpers/ErrorBoundary.jsx @@ -0,0 +1,38 @@ +///////////////////////////////////////////////////////////// +// +// pgAdmin 4 - PostgreSQL Tools +// +// Copyright (C) 2013 - 2022, The pgAdmin Development Team +// This software is released under the PostgreSQL Licence +// +////////////////////////////////////////////////////////////// + +/* https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html */ +import React from 'react'; +import CustomPropTypes from '../custom_prop_types'; + +export default class ErrorBoundary extends React.Component { + constructor(props) { + super(props); + this.state = { hasError: false }; + } + + componentDidCatch(error, info) { + // Display fallback UI + this.setState({ hasError: true }); + // You can also log the error to an error reporting service + console.error(error, info); + } + + render() { + if (this.state.hasError) { + // You can render any custom fallback UI + return

Something went wrong.

; + } + return this.props.children; + } +} + +ErrorBoundary.propTypes = { + children: CustomPropTypes.children, +};