mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
- Properties tab should refresh if node is updated. - Error should be hierarchical and not just id based.
This commit is contained in:
parent
2a76027cce
commit
ae49b556ce
@ -1248,12 +1248,7 @@ define('pgadmin.browser.node', [
|
||||
if(that.getSchema) {
|
||||
let treeNodeInfo = that.getTreeNodeHierarchy.apply(this, [item]);
|
||||
getNodeView(
|
||||
that.type, treeNodeInfo, 'properties', data, 'tab', j[0], this, onCancelFunc, onEdit,
|
||||
(nodeData)=>{
|
||||
if(nodeData.node) {
|
||||
onSaveFunc(nodeData.node, treeNodeInfo);
|
||||
}
|
||||
}
|
||||
that.type, treeNodeInfo, 'properties', data, 'tab', j[0], this, onEdit
|
||||
);
|
||||
return;
|
||||
}
|
||||
@ -1514,10 +1509,28 @@ define('pgadmin.browser.node', [
|
||||
if(that.getSchema) {
|
||||
let treeNodeInfo = that.getTreeNodeHierarchy.apply(this, [item]);
|
||||
getNodeView(
|
||||
that.type, treeNodeInfo, action, data, 'dialog', j[0], this, onCancelFunc, onEdit,
|
||||
that.type, treeNodeInfo, action, data, 'dialog', j[0], this, onEdit,
|
||||
(nodeData)=>{
|
||||
if(nodeData.node) {
|
||||
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');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -20,7 +20,7 @@ import gettext from 'sources/gettext';
|
||||
import 'wcdocker';
|
||||
|
||||
/* 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 serverInfo = treeNodeInfo && ('server' in treeNodeInfo) &&
|
||||
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 */
|
||||
warnOnCloseFlag = false;
|
||||
resolve(res.data);
|
||||
onSave(res.data);
|
||||
onSave && onSave(res.data);
|
||||
}).catch((err)=>{
|
||||
reject(err);
|
||||
});
|
||||
|
@ -257,7 +257,7 @@ export default function FormView({
|
||||
}
|
||||
} else {
|
||||
/* 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
|
||||
* lets pass the new changes to dependent and get the new values
|
||||
* from there as well.
|
||||
|
@ -207,7 +207,7 @@ function getChangedData(topSchema, viewHelperProps, sessData, stringify=false) {
|
||||
return changedData;
|
||||
}
|
||||
|
||||
function validateSchema(schema, sessData, setError) {
|
||||
function validateSchema(schema, sessData, setError, accessPath=[]) {
|
||||
sessData = sessData || {};
|
||||
for(let field of schema.fields) {
|
||||
/* Skip id validation */
|
||||
@ -219,6 +219,7 @@ function validateSchema(schema, sessData, setError) {
|
||||
/* A collection is an array */
|
||||
if(field.type === 'collection') {
|
||||
let rows = sessData[field.id] || [];
|
||||
let currPath = accessPath.concat(field.id);
|
||||
|
||||
/* Validate duplicate rows */
|
||||
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)
|
||||
.map((uf)=>uf.label).join(', ');
|
||||
if (isEmptyString(field.label)) {
|
||||
setError(field.uniqueCol[0], gettext('%s must be unique.', uniqueColNames));
|
||||
setError(currPath, gettext('%s must be unique.', uniqueColNames));
|
||||
} 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;
|
||||
}
|
||||
/* Loop through data */
|
||||
for(const row of rows) {
|
||||
if(validateSchema(field.schema, row, setError)) {
|
||||
for(const [rownum, row] of rows.entries()) {
|
||||
if(validateSchema(field.schema, row, setError, currPath.concat(rownum))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* A nested schema ? Recurse */
|
||||
if(validateSchema(field.schema, sessData, setError)) {
|
||||
if(validateSchema(field.schema, sessData, setError, accessPath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -260,12 +261,12 @@ function validateSchema(schema, sessData, setError) {
|
||||
message = numberValidator(field.label, value);
|
||||
}
|
||||
if(message) {
|
||||
setError(field.id, message);
|
||||
setError(accessPath.concat(field.id), message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return schema.validate(sessData, setError);
|
||||
return schema.validate(sessData, (id, message)=>setError(accessPath.concat(id), message));
|
||||
}
|
||||
|
||||
export const SCHEMA_STATE_ACTIONS = {
|
||||
@ -419,10 +420,10 @@ function SchemaDialogView({
|
||||
if(!formReady) return;
|
||||
/* Set the _sessData, can be usefull to some deep controls */
|
||||
schema._sessData = sessData;
|
||||
let isNotValid = validateSchema(schema, sessData, (name, message)=>{
|
||||
let isNotValid = validateSchema(schema, sessData, (path, message)=>{
|
||||
if(message) {
|
||||
setFormErr({
|
||||
name: name,
|
||||
name: path,
|
||||
message: message,
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user