Просмотр исходного кода

HUE-3790 [editor] Disable format query when query is too big

Enrico Berti 9 лет назад
Родитель
Сommit
91328eb

+ 4 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -680,6 +680,10 @@
       self.execute();
     };
 
+    self.formatEnabled = ko.pureComputed(function () {
+      return self.statement_raw && self.statement_raw().length < 400000; // ie: 5000 lines at 80 chars per line
+    });
+
     self.format = function () {
       if (self.isSqlDialect() && vkbeautify) {
         if (self.ace().getSelectedText() != '') {

+ 2 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1666,11 +1666,13 @@ ${ hueIcons.symbols() }
             <i class="fa fa-fw fa-map-o"></i> ${_('Explain')}
           </a>
         </li>
+        <!-- ko if: formatEnabled -->
         <li>
           <a href="javascript:void(0)" data-bind="click: format, css: {'disabled': statement() === '' }" title="${ _('Format the current SQL query') }">
             <i class="fa fa-fw fa-indent"></i> ${_('Format')}
           </a>
         </li>
+        <!-- /ko -->
         <li>
           <a href="javascript:void(0)" data-bind="click: clear, css: {'disabled': statement() === '' }" title="${ _('Clear the current editor') }">
             <i class="fa fa-fw fa-eraser"></i> ${_('Clear')}