- Properties tab should refresh if node is updated. - Error should be hierarchical and not just id based.

This commit is contained in:
Aditya Toshniwal 2021-08-27 14:59:44 +05:30 committed by Akshay Joshi
parent 2a76027cce
commit ae49b556ce
4 changed files with 34 additions and 20 deletions

View File

@ -1248,12 +1248,7 @@ define('pgadmin.browser.node', [
if(that.getSchema) { if(that.getSchema) {
let treeNodeInfo = that.getTreeNodeHierarchy.apply(this, [item]); let treeNodeInfo = that.getTreeNodeHierarchy.apply(this, [item]);
getNodeView( getNodeView(
that.type, treeNodeInfo, 'properties', data, 'tab', j[0], this, onCancelFunc, onEdit, that.type, treeNodeInfo, 'properties', data, 'tab', j[0], this, onEdit
(nodeData)=>{
if(nodeData.node) {
onSaveFunc(nodeData.node, treeNodeInfo);
}
}
); );
return; return;
} }
@ -1514,10 +1509,28 @@ define('pgadmin.browser.node', [
if(that.getSchema) { if(that.getSchema) {
let treeNodeInfo = that.getTreeNodeHierarchy.apply(this, [item]); let treeNodeInfo = that.getTreeNodeHierarchy.apply(this, [item]);
getNodeView( getNodeView(
that.type, treeNodeInfo, action, data, 'dialog', j[0], this, onCancelFunc, onEdit, that.type, treeNodeInfo, action, data, 'dialog', j[0], this, onEdit,
(nodeData)=>{ (nodeData)=>{
if(nodeData.node) { if(nodeData.node) {
onSaveFunc(nodeData.node, treeNodeInfo); onSaveFunc(nodeData.node, treeNodeInfo);
// Removing the node-prop property of panel
// so that we show updated data on panel
var pnlProperties = pgBrowser.docker.findPanels('properties')[0],
pnlSql = pgBrowser.docker.findPanels('sql')[0],
pnlStats = pgBrowser.docker.findPanels('statistics')[0],
pnlDependencies = pgBrowser.docker.findPanels('dependencies')[0],
pnlDependents = pgBrowser.docker.findPanels('dependents')[0];
if (pnlProperties)
$(pnlProperties).removeData('node-prop');
if (pnlSql)
$(pnlSql).removeData('node-prop');
if (pnlStats)
$(pnlStats).removeData('node-prop');
if (pnlDependencies)
$(pnlDependencies).removeData('node-prop');
if (pnlDependents)
$(pnlDependents).removeData('node-prop');
} }
} }
); );

View File

@ -20,7 +20,7 @@ import gettext from 'sources/gettext';
import 'wcdocker'; import 'wcdocker';
/* The entry point for rendering React based view in properties, called in node.js */ /* The entry point for rendering React based view in properties, called in node.js */
export function getNodeView(nodeType, treeNodeInfo, actionType, itemNodeData, formType, container, containerPanel, onCancel, onEdit, onSave) { export function getNodeView(nodeType, treeNodeInfo, actionType, itemNodeData, formType, container, containerPanel, onEdit, onSave) {
let nodeObj = pgAdmin.Browser.Nodes[nodeType]; let nodeObj = pgAdmin.Browser.Nodes[nodeType];
let serverInfo = treeNodeInfo && ('server' in treeNodeInfo) && let serverInfo = treeNodeInfo && ('server' in treeNodeInfo) &&
pgAdmin.Browser.serverInfo && pgAdmin.Browser.serverInfo[treeNodeInfo.server._id]; pgAdmin.Browser.serverInfo && pgAdmin.Browser.serverInfo[treeNodeInfo.server._id];
@ -62,7 +62,7 @@ export function getNodeView(nodeType, treeNodeInfo, actionType, itemNodeData, fo
/* Don't warn the user before closing dialog */ /* Don't warn the user before closing dialog */
warnOnCloseFlag = false; warnOnCloseFlag = false;
resolve(res.data); resolve(res.data);
onSave(res.data); onSave && onSave(res.data);
}).catch((err)=>{ }).catch((err)=>{
reject(err); reject(err);
}); });

View File

@ -257,7 +257,7 @@ export default function FormView({
} }
} else { } else {
/* Its a form control */ /* Its a form control */
const hasError = field.id == formErr.name; const hasError = _.isEqual(accessPath.concat(field.id), formErr.name);
/* When there is a change, the dependent values can change /* When there is a change, the dependent values can change
* lets pass the new changes to dependent and get the new values * lets pass the new changes to dependent and get the new values
* from there as well. * from there as well.

View File

@ -207,7 +207,7 @@ function getChangedData(topSchema, viewHelperProps, sessData, stringify=false) {
return changedData; return changedData;
} }
function validateSchema(schema, sessData, setError) { function validateSchema(schema, sessData, setError, accessPath=[]) {
sessData = sessData || {}; sessData = sessData || {};
for(let field of schema.fields) { for(let field of schema.fields) {
/* Skip id validation */ /* Skip id validation */
@ -219,6 +219,7 @@ function validateSchema(schema, sessData, setError) {
/* A collection is an array */ /* A collection is an array */
if(field.type === 'collection') { if(field.type === 'collection') {
let rows = sessData[field.id] || []; let rows = sessData[field.id] || [];
let currPath = accessPath.concat(field.id);
/* Validate duplicate rows */ /* Validate duplicate rows */
let dupInd = checkUniqueCol(rows, field.uniqueCol); let dupInd = checkUniqueCol(rows, field.uniqueCol);
@ -226,21 +227,21 @@ function validateSchema(schema, sessData, setError) {
let uniqueColNames = _.filter(field.schema.fields, (uf)=>field.uniqueCol.indexOf(uf.id) > -1) let uniqueColNames = _.filter(field.schema.fields, (uf)=>field.uniqueCol.indexOf(uf.id) > -1)
.map((uf)=>uf.label).join(', '); .map((uf)=>uf.label).join(', ');
if (isEmptyString(field.label)) { if (isEmptyString(field.label)) {
setError(field.uniqueCol[0], gettext('%s must be unique.', uniqueColNames)); setError(currPath, gettext('%s must be unique.', uniqueColNames));
} else { } else {
setError(field.uniqueCol[0], gettext('%s in %s must be unique.', uniqueColNames, field.label)); setError(currPath, gettext('%s in %s must be unique.', uniqueColNames, field.label));
} }
return true; return true;
} }
/* Loop through data */ /* Loop through data */
for(const row of rows) { for(const [rownum, row] of rows.entries()) {
if(validateSchema(field.schema, row, setError)) { if(validateSchema(field.schema, row, setError, currPath.concat(rownum))) {
return true; return true;
} }
} }
} else { } else {
/* A nested schema ? Recurse */ /* A nested schema ? Recurse */
if(validateSchema(field.schema, sessData, setError)) { if(validateSchema(field.schema, sessData, setError, accessPath)) {
return true; return true;
} }
} }
@ -260,12 +261,12 @@ function validateSchema(schema, sessData, setError) {
message = numberValidator(field.label, value); message = numberValidator(field.label, value);
} }
if(message) { if(message) {
setError(field.id, message); setError(accessPath.concat(field.id), message);
return true; return true;
} }
} }
} }
return schema.validate(sessData, setError); return schema.validate(sessData, (id, message)=>setError(accessPath.concat(id), message));
} }
export const SCHEMA_STATE_ACTIONS = { export const SCHEMA_STATE_ACTIONS = {
@ -419,10 +420,10 @@ function SchemaDialogView({
if(!formReady) return; if(!formReady) return;
/* Set the _sessData, can be usefull to some deep controls */ /* Set the _sessData, can be usefull to some deep controls */
schema._sessData = sessData; schema._sessData = sessData;
let isNotValid = validateSchema(schema, sessData, (name, message)=>{ let isNotValid = validateSchema(schema, sessData, (path, message)=>{
if(message) { if(message) {
setFormErr({ setFormErr({
name: name, name: path,
message: message, message: message,
}); });
} }