diff --git a/web/pgadmin/static/js/sqleditor/macro.js b/web/pgadmin/static/js/sqleditor/macro.js
index c8f9292f3..74c7dab2d 100644
--- a/web/pgadmin/static/js/sqleditor/macro.js
+++ b/web/pgadmin/static/js/sqleditor/macro.js
@@ -194,6 +194,8 @@ let MacroDialog = {
// We got the latest attributes of the object. Render the view
// now.
$container.append(self.view.render().$el);
+ self.__internal.buttons[2].element.disabled = true;
+
// Enable/disable save button and show/hide statusbar based on session
self.view.listenTo(self.view.model, 'pgadmin-session:start', function() {
@@ -272,11 +274,12 @@ let MacroDialog = {
${gettext('Manage Macros...')}
-
-
`;
+ `;
+
+ let macro_list_tmpl = '';
_.each(macros, function(m) {
if (m.name) {
- str += `
+ macro_list_tmpl += `
${_.escape(m.name)}
(${m.key_label})
@@ -285,6 +288,7 @@ let MacroDialog = {
}
});
+ if (macro_list_tmpl.length > 0) str += '' + macro_list_tmpl;
$($.find('div.btn-group.mr-1.user_macros ul.dropdown-menu')).html($(str));
self.close(); // Close the dialog now
diff --git a/web/pgadmin/static/js/sqleditor/macro_model.js b/web/pgadmin/static/js/sqleditor/macro_model.js
index 4a9351a38..7886e63b7 100644
--- a/web/pgadmin/static/js/sqleditor/macro_model.js
+++ b/web/pgadmin/static/js/sqleditor/macro_model.js
@@ -126,18 +126,22 @@ export default function macroModel(transId) {
var that = this;
// We will check if row is deletable or not
- Alertify.confirm(
- gettext('Clear All Rows'),
- gettext('Are you sure you wish to clear all rows?'),
- function() {
- _.each(that.collection.toJSON(), function(m) {
- that.collection.get(m.id).set({'name': null, 'sql': null});
- });
- },
- function() {
- return true;
- }
- );
+ let macros = that.collection.toJSON().filter(m => m.name !== undefined && m.name !== null);
+
+ if (macros.length > 0) {
+ Alertify.confirm(
+ gettext('Clear All Rows'),
+ gettext('Are you sure you wish to clear all rows?'),
+ function() {
+ _.each(that.collection.toJSON(), function(m) {
+ that.collection.get(m.id).set({'name': null, 'sql': null});
+ });
+ },
+ function() {
+ return true;
+ }
+ );
+ }
},
render: function() {
this.$el.empty();
diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
index 05deebc41..576793252 100644
--- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js
@@ -4376,6 +4376,8 @@ define('tools.querytool', [
// Find the next space from the character or end of line
var error_line = self.gridView.query_tool_obj.getLine(error_line_no);
+
+ if (_.isUndefined(error_line)) return;
end_marker = error_line.indexOf(' ', start_marker);
if (end_marker < 0)
end_marker = error_line.length;