Foreign key issues in edit mode:

1. Couple of foreign key issues in edit mode. Fixes #6837
2. Table "Of type" related issues. Fixes #6825
This commit is contained in:
Aditya Toshniwal 2021-10-04 14:14:27 +05:30 committed by Akshay Joshi
parent 69109a19db
commit e77f933fe7
8 changed files with 31 additions and 14 deletions

View File

@ -22,7 +22,7 @@ export default class CheckConstraintSchema extends BaseUISchema {
if(_.isUndefined(this.nodeInfo)) {
return true;
}
return _.isUndefined(this.nodeInfo['table']);
return _.isUndefined(this.nodeInfo['check_constraint']);
}
isReadonly(state) {

View File

@ -213,7 +213,7 @@ export default class ExclusionConstraintSchema extends BaseUISchema {
if(_.isUndefined(this.nodeInfo)) {
return true;
}
return _.isUndefined(this.nodeInfo['table']);
return _.isUndefined(this.nodeInfo['exclusion_constraint']);
}
initialise(data) {

View File

@ -149,7 +149,7 @@ export default class ForeignKeySchema extends BaseUISchema {
if(_.isUndefined(nodeInfo)) {
return true;
}
return _.isUndefined(nodeInfo['table']);
return _.isUndefined(nodeInfo['foreign_key']);
}
changeColumnOptions(columns) {
@ -222,12 +222,14 @@ export default class ForeignKeySchema extends BaseUISchema {
id: 'convalidated', label: gettext('Validated?'),
type: 'switch', group: gettext('Definition'),
readonly: (state)=>{
// If we are in table edit mode then
if(obj.inTable && obj.top && !obj.top.isNew()) {
return !(_.isUndefined(state.oid) || !state.convalidated);
if(!obj.isNew(state)) {
let origData = {};
if(obj.inTable && obj.top) {
origData = _.find(obj.top.origData['foreign_key'], (r)=>r.cid == state.cid);
} else {
origData = obj.origData;
}
if(!obj.isNew(state) && obj.origData.convalidated) {
return true;
return origData.convalidated;
}
return false;
},

View File

@ -31,7 +31,7 @@ export default class PrimaryKeySchema extends BaseUISchema {
if(_.isUndefined(this.nodeInfo)) {
return true;
}
return _.isUndefined(this.nodeInfo['table']);
return _.isUndefined(this.nodeInfo['primary_key']);
}
changeColumnOptions(columns) {

View File

@ -32,7 +32,7 @@ export default class UniqueConstraintSchema extends BaseUISchema {
if(_.isUndefined(this.nodeInfo)) {
return true;
}
return _.isUndefined(this.nodeInfo['table']);
return _.isUndefined(this.nodeInfo['unique_constraint']);
}
changeColumnOptions(columns) {

View File

@ -650,7 +650,12 @@ export default class TableSchema extends BaseUISchema {
obj.changeColumnOptions(finalCols);
return {
columns: finalCols,
primary_key: []
primary_key: [],
foreign_key: [],
exclude_constraint: [],
unique_constraint: [],
partition_keys: [],
partitions: [],
};
});
};

View File

@ -171,7 +171,7 @@ describe('ForeignKeySchema', ()=>{
let state = {columns: [{local_column: 'id'}]};
let actionObj = {oldState:{name: 'fkname'}};
schemaObj.nodeInfo = {table: {}};
schemaObj.nodeInfo = {foreign_key: {}};
state.autoindex = true;
state.name = 'fkname';
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
@ -197,7 +197,7 @@ describe('ForeignKeySchema', ()=>{
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({});
state.oid = null;
schemaObj.nodeInfo = {};
schemaObj.nodeInfo = {table: {}};
schemaObj.top = schemaObj;
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
autoindex: false,

View File

@ -172,6 +172,11 @@ describe('TableSchema', ()=>{
expect(depChange()).toEqual({
columns: oftypeColumns,
primary_key: [],
foreign_key: [],
exclude_constraint: [],
unique_constraint: [],
partition_keys: [],
partitions: [],
});
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(oftypeColumns);
done();
@ -208,6 +213,11 @@ describe('TableSchema', ()=>{
expect(depChange()).toEqual({
columns: oftypeColumns,
primary_key: [],
foreign_key: [],
exclude_constraint: [],
unique_constraint: [],
partition_keys: [],
partitions: [],
});
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(oftypeColumns);
done();