From 3f563d8cbfd8778f7ce52d4dd6f37af05b96a35f Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Mon, 25 Jan 2021 19:44:24 +0530 Subject: [PATCH] 1) Fixed an issue where the Save button is disabled due to the existing table check in ERD. 2) Fix warnings given by webpack. --- .../static/scss/resources/_default.variables.scss | 2 +- .../resources/high_contrast/_theme.variables.scss | 2 -- .../erd/static/js/erd_tool/dialogs/TableDialog.js | 12 ++++++++---- .../static/js/erd_tool/ui_components/BodyWidget.jsx | 10 +++++----- .../javascript/erd/ui_components/body_widget_spec.js | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/web/pgadmin/static/scss/resources/_default.variables.scss b/web/pgadmin/static/scss/resources/_default.variables.scss index b71c86a4c..46dcb1d6f 100644 --- a/web/pgadmin/static/scss/resources/_default.variables.scss +++ b/web/pgadmin/static/scss/resources/_default.variables.scss @@ -324,7 +324,7 @@ $schemadiff-target-row-color: #fbe3bf !default; $schema-diff-color-fg: $input-color !default; /* Custom controls bootstrap changes */ -$custom-forms-transition: none !default; +$custom-forms-transition: none, none, none; $custom-control-indicator-focus-border-color: $input-focus-border-color !default; $custom-control-indicator-border-color: $input-border-color !default; diff --git a/web/pgadmin/static/scss/resources/high_contrast/_theme.variables.scss b/web/pgadmin/static/scss/resources/high_contrast/_theme.variables.scss index b895a1223..75daf4a35 100644 --- a/web/pgadmin/static/scss/resources/high_contrast/_theme.variables.scss +++ b/web/pgadmin/static/scss/resources/high_contrast/_theme.variables.scss @@ -176,8 +176,6 @@ $card-header-border-color: $card-header-bg; $card-border-color: transparent; $card-bg: $color-gray; - -$custom-forms-transition: none; $custom-control-indicator-focus-border-color: #FFFFFF !important; $custom-control-indicator-border-color: $color-gray-lighter; diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/dialogs/TableDialog.js b/web/pgadmin/tools/erd/static/js/erd_tool/dialogs/TableDialog.js index 2b56ea1c4..3375fdc6f 100644 --- a/web/pgadmin/tools/erd/static/js/erd_tool/dialogs/TableDialog.js +++ b/web/pgadmin/tools/erd/static/js/erd_tool/dialogs/TableDialog.js @@ -50,7 +50,7 @@ export default class TableDialog { return 'entity_dialog'; } - getDataModel(attributes, existingTables, colTypes, schemas, sVersion) { + getDataModel(attributes, isNew, allTables, colTypes, schemas, sVersion) { let dialogObj = this; let columnsModel = this.pgBrowser.DataModel.extend({ idAttribute: 'attnum', @@ -694,7 +694,11 @@ export default class TableDialog { msg = gettext('Table name cannot be empty.'); this.errorModel.set('name', msg); return msg; - } else if(_.findIndex(existingTables, (table)=>table[0]==schema&&table[1]==name) >= 0) { + } + + /* Check existing table names */ + let sameNameCount = _.filter(allTables, (table)=>table[0]==schema&&table[1]==name).length; + if(isNew && this.sessAttrs['name'] && sameNameCount > 0 || isNew && sameNameCount > 0) { msg = gettext('Table name already exists.'); this.errorModel.set('name', msg); return msg; @@ -737,9 +741,9 @@ export default class TableDialog { return Alertify[dialogName]; } - show(title, attributes, existingTables, colTypes, schemas, sVersion, callback) { + show(title, attributes, isNew, allTables, colTypes, schemas, sVersion, callback) { let dialogTitle = title || gettext('Unknown'); const dialog = this.createOrGetDialog('table_dialog'); - dialog(dialogTitle, this.getDataModel(attributes, existingTables, colTypes, schemas, sVersion), callback).resizeTo(this.pgBrowser.stdW.md, this.pgBrowser.stdH.md); + dialog(dialogTitle, this.getDataModel(attributes, isNew, allTables, colTypes, schemas, sVersion), callback).resizeTo(this.pgBrowser.stdW.md, this.pgBrowser.stdH.md); } } diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/ui_components/BodyWidget.jsx b/web/pgadmin/tools/erd/static/js/erd_tool/ui_components/BodyWidget.jsx index 83f0491d6..1e3eff031 100644 --- a/web/pgadmin/tools/erd/static/js/erd_tool/ui_components/BodyWidget.jsx +++ b/web/pgadmin/tools/erd/static/js/erd_tool/ui_components/BodyWidget.jsx @@ -301,12 +301,12 @@ export default class BodyWidget extends React.Component { getDialog(dialogName) { if(dialogName === 'entity_dialog') { - let existingTables = this.diagram.getModel().getNodes().map((node)=>{ + let allTables = this.diagram.getModel().getNodes().map((node)=>{ return node.getSchemaTableName(); }); - return (title, attributes, callback)=>{ + return (title, attributes, isNew, callback)=>{ this.props.getDialog(dialogName).show( - title, attributes, existingTables, this.diagram.getCache('colTypes'), this.diagram.getCache('schemas'), this.state.server_version, callback + title, attributes, isNew, allTables, this.diagram.getCache('colTypes'), this.diagram.getCache('schemas'), this.state.server_version, callback ); }; } else if(dialogName === 'onetomany_dialog' || dialogName === 'manytomany_dialog') { @@ -335,12 +335,12 @@ export default class BodyWidget extends React.Component { let dialog = this.getDialog('entity_dialog'); if(node) { let [schema, table] = node.getSchemaTableName(); - dialog(_.escape(`Table: ${table} (${schema})`), node.getData(), (newData)=>{ + dialog(_.escape(`Table: ${table} (${schema})`), node.getData(), false, (newData)=>{ node.setData(newData); this.diagram.repaint(); }); } else { - dialog('New table', {name: this.diagram.getNextTableName()}, (newData)=>{ + dialog('New table', {name: this.diagram.getNextTableName()}, true, (newData)=>{ let newNode = this.diagram.addNode(newData); newNode.setSelected(true); }); diff --git a/web/regression/javascript/erd/ui_components/body_widget_spec.js b/web/regression/javascript/erd/ui_components/body_widget_spec.js index 3114ba627..2095ecd90 100644 --- a/web/regression/javascript/erd/ui_components/body_widget_spec.js +++ b/web/regression/javascript/erd/ui_components/body_widget_spec.js @@ -252,7 +252,7 @@ describe('ERD BodyWidget', ()=>{ bodyInstance.addEditNode(); expect(tableDialog.show).toHaveBeenCalled(); - let saveCallback = tableDialog.show.calls.mostRecent().args[6]; + let saveCallback = tableDialog.show.calls.mostRecent().args[7]; let newData = {key: 'value'}; saveCallback(newData); expect(bodyInstance.diagram.addNode).toHaveBeenCalledWith(newData); @@ -267,7 +267,7 @@ describe('ERD BodyWidget', ()=>{ bodyInstance.addEditNode(node); expect(tableDialog.show).toHaveBeenCalled(); - saveCallback = tableDialog.show.calls.mostRecent().args[6]; + saveCallback = tableDialog.show.calls.mostRecent().args[7]; newData = {key: 'value'}; saveCallback(newData); expect(node.setData).toHaveBeenCalledWith(newData);