Skip to content

Commit

Permalink
Used 'origData' variable to get the initiail data for validation of
Browse files Browse the repository at this point in the history
the data.

I never realised that - we were using 'origData' for schema
validation to get the initial data, and replaced it with 'sessData'
variable by mistake. Changing it back to use 'origData' based on the
feedback from Aditya.
  • Loading branch information
asheshv committed Sep 2, 2024
1 parent 4c80dd9 commit 3ff9916
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default class PublicationSchema extends BaseUISchema {
}
if (
!_.isUndefined(table) && table.length > 0 &&
!_.isEqual(this.sessData.pubtable, state.pubtable)
!_.isEqual(this.origData.pubtable, state.pubtable)
){
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class DomainConstraintSchema extends BaseUISchema {
cell:'boolean', group: gettext('Definition'), min_version: 90200,
mode: ['properties', 'create', 'edit'],
readonly: function(state) {
return !obj.isNew(state) && obj.sessData.convalidated;
return !obj.isNew(state) && obj.origData.convalidated;
}
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class DomainConstSchema extends BaseUISchema {
id: 'convalidated', label: gettext('Validate?'), cell: 'checkbox',
type: 'checkbox',
readonly: function(state) {
let currCon = _.find(obj.top.sessData.constraints, (con)=>con.conoid == state.conoid);
let currCon = _.find(
obj.top.origData.constraints, (con) => con.conoid == state.conoid
);
return !obj.isNew(state) && currCon.convalidated;
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class PackageSchema extends BaseUISchema {
depChange: (state, source, topState, actionObj) => {

if(
packageSchemaObj.sessData.oid &&
packageSchemaObj.origData.oid &&
state.pkgheadsrc != actionObj.oldState.pkgheadsrc
) {
packageSchemaObj.warningText = gettext(
Expand All @@ -120,7 +120,7 @@ export default class PackageSchema extends BaseUISchema {
depChange: (state, source, topState, actionObj) => {

if(
packageSchemaObj.sessData.oid &&
packageSchemaObj.origData.oid &&
state.pkgbodysrc != actionObj.oldState.pkgbodysrc
) {
packageSchemaObj.warningText = gettext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ export default class ColumnSchema extends BaseUISchema {
}

if (!this.isNew(state) && state.colconstype == 'i'
&& (this.sessData.attidentity == 'a' || this.sessData.attidentity == 'd')
&& (this.origData.attidentity == 'a' || this.origData.attidentity == 'd')
&& (state.attidentity == 'a' || state.attidentity == 'd')) {
if(isEmptyString(state.seqincrement)) {
msg = gettext('Increment value cannot be empty.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class CheckConstraintSchema extends BaseUISchema {
if(obj.inTable && obj.top && !obj.top.isNew()) {
return !(_.isUndefined(state.oid) || state.convalidated);
}
return !obj.isNew(state) && !obj.sessData.convalidated;
return !obj.isNew(state) && !obj.origData.convalidated;
},
mode: ['properties', 'create', 'edit'],
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ class ForeignKeyHeaderSchema extends BaseUISchema {
}

addDisabled(state) {
return !(state.local_column && (state.references || this.sessData.references) && state.referenced);
return !(
state.local_column && (
state.references || this.origData.references
) && state.referenced
);
}

/* Data to ForeignKeyColumnSchema will added using the header form */
getNewData(data) {
let references_table_name = _.find(this.refTables, (t)=>t.value==data.references || t.value == this.sessData.references)?.label;
let references_table_name = _.find(
this.refTables,
(t) => t.value == data.references || t.value == this.origData.references
)?.label;

return {
local_column: data.local_column,
referenced: data.referenced,
Expand Down Expand Up @@ -228,16 +236,16 @@ export default class ForeignKeySchema extends BaseUISchema {
type: 'switch', group: gettext('Definition'),
readonly: (state)=>{
if(!obj.isNew(state)) {
let sessData = {};
let origData = {};
if(obj.inTable && obj.top) {
sessData = _.find(
obj.top.sessData['foreign_key'],
origData = _.find(
obj.top.origData['foreign_key'],
(r) => r.cid == state.cid
);
} else {
sessData = obj.sessData;
origData = obj.origData;
}
return sessData.convalidated;
return origData.convalidated;
}
return false;
},
Expand Down Expand Up @@ -363,8 +371,10 @@ export default class ForeignKeySchema extends BaseUISchema {
}
if(actionObj.type == SCHEMA_STATE_ACTIONS.ADD_ROW) {
// Set references value.
obj.fkHeaderSchema.sessData.references = null;
obj.fkHeaderSchema.sessData._disable_references = true;
obj.fkHeaderSchema.origData.references = null;
obj.fkHeaderSchema.origData.references =
obj.fkHeaderSchema.sessData.references;
obj.fkHeaderSchema.origData._disable_references = true;
}
return {columns: currColumns};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class IndexColumnSchema extends BaseUISchema {
* to access method selected by user if not selected
* send btree related op_class options
*/
let amname = obj.top?.sessData.amname;
let amname = obj.top?.sessData.amname ||
obj.top?.origData.amname;

if(_.isUndefined(amname))
return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ export default class TableSchema extends BaseUISchema {
type: 'switch', mode: ['properties','edit', 'create'],
group: 'advanced', min_version: 90600,
depChange: (state)=>{
if (state.rlspolicy && this.sessData.rlspolicy != state.rlspolicy) {
if (state.rlspolicy && this.origData.rlspolicy != state.rlspolicy) {
pgAdmin.Browser.notifier.alert(
gettext('Check Policy?'),
gettext('Please check if any policy exists. If no policy exists for the table, a default-deny policy is used, meaning that no rows are visible or can be modified by other users')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -154,7 +155,10 @@ export default class MViewSchema extends BaseUISchema {

if (state.definition) {
obj.warningText = null;
if (obj.sessData.oid !== undefined && state.definition !== obj.sessData.definition) {
if (
!_.isUndefined(obj.origData.oid) &&
state.definition !== obj.origData.definition
) {
obj.warningText = gettext(
'Updating the definition will drop and re-create the materialized view. It may result in loss of information about its dependent objects.'
) + '<br><br><b>' + gettext('Do you want to continue?') + '</b>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -135,22 +136,23 @@ export default class ViewSchema extends BaseUISchema {
}

if (state.definition) {
if (!(obj.nodeInfo.server.server_type == 'pg' &&
if (!(
obj.nodeInfo.server.server_type == 'pg' &&
// No need to check this when creating a view
obj.sessData.oid !== undefined
!_.isUndefined(obj.sessData.oid)
) || (
state.definition === obj.sessData.definition
state.definition === obj.origData.definition
)) {
obj.warningText = null;
return false;
}

let old_def = obj.sessData.definition?.replace(
let old_def = obj.origData.definition?.replace(
/\s/gi, ''
).split('FROM'),
new_def = [];

if (state.definition !== undefined) {
if (!_.isUndefined(state.definition)) {
new_def = state.definition.replace(
/\s/gi, ''
).split('FROM');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export default class DatabaseSchema extends BaseUISchema {
obj.informText = undefined;
}

if(!_.isEqual(obj.sessData.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.'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ export default class SubscriptionSchema extends BaseUISchema{
id: 'port', label: gettext('Port'), type: 'int', group: gettext('Connection'),
mode: ['properties', 'edit', 'create'], min: 1, max: 65535,
depChange: (state)=>{
if(obj.sessData.port != state.port && !obj.isNew(state) && state.connected){
if(
obj.origData.port != state.port && !obj.isNew(state) &&
state.connected
) {
obj.informText = gettext(
'To apply changes to the connection configuration, please disconnect from the server and then reconnect.'
);
Expand All @@ -145,7 +148,10 @@ export default class SubscriptionSchema extends BaseUISchema{
id: 'username', label: gettext('Username'), type: 'text', group: gettext('Connection'),
mode: ['properties', 'edit', 'create'],
depChange: (state)=>{
if(obj.sessData.username != state.username && !obj.isNew(state) && state.connected){
if(
obj.origData.username != state.username && !obj.isNew(state) &&
state.connected
) {
obj.informText = gettext(
'To apply changes to the connection configuration, please disconnect from the server and then reconnect.'
);
Expand Down
10 changes: 5 additions & 5 deletions web/pgadmin/browser/server_groups/servers/static/js/server.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ export default class ServerSchema extends BaseUISchema {
controlProps: { maxLength: 64},
mode: ['properties', 'create', 'edit'], deps: ['shared', 'username'],
readonly: (s) => {
return !(!this.sessData.shared && s.shared);
return !(!this.origData.shared && s.shared);
}, visible: ()=>{
return current_user.is_admin && pgAdmin.server_mode == 'True';
},
depChange: (state, source, _topState, actionObj)=>{
let ret = {};
if(this.sessData.shared) {
if(this.origData.shared) {
return ret;
}
if(source == 'username' && actionObj.oldState.username == state.shared_username) {
Expand All @@ -169,7 +169,7 @@ export default class ServerSchema extends BaseUISchema {
id: 'host', label: gettext('Host name/address'), type: 'text', group: gettext('Connection'),
mode: ['properties', 'edit', 'create'], disabled: obj.isShared,
depChange: (state)=>{
if(obj.sessData.host != state.host && !obj.isNew(state) && state.connected){
if(obj.origData.host != state.host && !obj.isNew(state) && state.connected){
obj.informText = gettext(
'To apply changes to the connection configuration, please disconnect from the server and then reconnect.'
);
Expand All @@ -182,7 +182,7 @@ export default class ServerSchema extends BaseUISchema {
id: 'port', label: gettext('Port'), type: 'int', group: gettext('Connection'),
mode: ['properties', 'edit', 'create'], min: 1, max: 65535, disabled: obj.isShared,
depChange: (state)=>{
if(obj.sessData.port != state.port && !obj.isNew(state) && state.connected){
if(obj.origData.port != state.port && !obj.isNew(state) && state.connected){
obj.informText = gettext(
'To apply changes to the connection configuration, please disconnect from the server and then reconnect.'
);
Expand All @@ -198,7 +198,7 @@ export default class ServerSchema extends BaseUISchema {
id: 'username', label: gettext('Username'), type: 'text', group: gettext('Connection'),
mode: ['properties', 'edit', 'create'],
depChange: (state)=>{
if(obj.sessData.username != state.username && !obj.isNew(state) && state.connected){
if(obj.origData.username != state.username && !obj.isNew(state) && state.connected){
obj.informText = gettext(
'To apply changes to the connection configuration, please disconnect from the server and then reconnect.'
);
Expand Down

0 comments on commit 3ff9916

Please sign in to comment.