pgadmin4/web/pgadmin/static/js/Dialogs/ChangePasswordContent.jsx
Ashesh Vashi 5e96f0fd61
Fixes the Variable Schema UI issues and InlineView bug reported in #7884
* Show the icon for the 'Reset' button. (Reference #7884)

* Reload the server list after connecting to a server in the 'New
connection' dialog (QueryTool). (Reference: #7884)

* Pass the grid path during the bulk update (click on a radio action)

* Don't assign the cell value to the 'rowValue' variable.

* Don't rely on the 'optionsLoaded' for setting the variable types as it
is loaded asynchronously, and variable types data may not be available
while rendering the 'value' cell. (Fixes #7884)

* Fixed a type while checking for the 'inline-group'. fixes (#7884)

* 'vnameOptions' can be a Promise function too, hence - taken care accrodingly.

* Introduced a parameter 'reloadOnDepChanges' in the BaseSchemaUI field
to force reload the control on value change for one of the
dependencies.

* Reload on the components in case of dependent value changes.

* Introduced 'useSchemaStateSubscriber', which generates a state
subscriber mananager instance. It helps multiple subscribers in a
single control as we could have multiple subscribe within a control.
(For example - value, options, errors, etc).

* Fixed all the issues reported (#7884)
2024-09-16 00:04:37 +05:30

97 lines
2.5 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import gettext from 'sources/gettext';
import BaseUISchema from '../SchemaView/base_schema.ui';
import SchemaView from '../SchemaView';
class ChangePasswordSchema extends BaseUISchema {
constructor(user, isPgpassFileUsed, hasCsrfToken=false, showUser=true) {
super({
user: user,
password: '',
newPassword: '',
confirmPassword: ''
});
this.isPgpassFileUsed = isPgpassFileUsed;
this.hasCsrfToken = hasCsrfToken;
this.showUser = showUser;
}
get baseFields() {
let self = this;
return [
{
id: 'user', label: gettext('User'), type: 'text', disabled: true, visible: this.showUser
}, {
id: 'password', label: gettext('Current Password'), type: 'password',
disabled: self.isPgpassFileUsed, noEmpty: !self.isPgpassFileUsed,
controlProps: {
maxLength: null,
autoComplete: 'new-password'
}
}, {
id: 'newPassword', label: gettext('New Password'), type: 'password',
noEmpty: true,
controlProps: {
maxLength: null
}
}, {
id: 'confirmPassword', label: gettext('Confirm Password'), type: 'password',
noEmpty: true,
controlProps: {
maxLength: null
}
}
].concat(this.hasCsrfToken ? [
{
id: 'csrf_token', visible: false, type: 'text'
}
]: []);
}
validate(state, setError) {
let errmsg = null;
if (state.newPassword !== state.confirmPassword) {
errmsg = gettext('Passwords do not match.');
setError('confirmPassword', errmsg);
return true;
} else {
setError('confirmPassword', null);
}
return false;
}
}
export default function ChangePasswordContent({getInitData=() => { /*This is intentional (SonarQube)*/ },
onSave, onClose, hasCsrfToken=false, showUser=true}) {
const schema=React.useRef(null);
if (!schema.current)
schema.current = new ChangePasswordSchema(
'', false, hasCsrfToken, showUser
);
return <SchemaView
formType={'dialog'}
getInitData={getInitData}
schema={schema.current}
viewHelperProps={{
mode: 'create',
}}
customSaveBtnName={'Change'}
onSave={onSave}
onClose={onClose}
hasSQL={false}
disableSqlHelp={true}
disableDialogHelp={true}
isTabView={false}
/>;
}
ChangePasswordContent.propTypes = {
onSave: PropTypes.func,
onClose: PropTypes.func,
getInitData: PropTypes.func,
hasCsrfToken: PropTypes.bool,
showUser: PropTypes.bool
};