Browse Source

fix: show error in save() until dismissed explicitly

tophf 4 years ago
parent
commit
45940f9ab7
2 changed files with 9 additions and 8 deletions
  1. 5 5
      src/common/ui/index.js
  2. 4 3
      src/options/views/edit/index.vue

+ 5 - 5
src/common/ui/index.js

@@ -31,8 +31,8 @@ export function showMessage(message) {
  * @param {string} text - the text to display in the modal
  * @param {Object} cfg
  * @param {string | false} [cfg.input=false] if not false, shows a text input with this string
- * @param {Object} [cfg.ok] additional props for the Ok button
- * @param {Object} [cfg.cancel] additional props for the Cancel button
+ * @param {?Object|false} [cfg.ok] additional props for the Ok button or `false` to remove it
+ * @param {?Object|false} [cfg.cancel] same for the Cancel button
  * @return {Promise<?string>} resolves on Ok to `false` or the entered string, rejects otherwise
  */
 export function showConfirmation(text, { ok, cancel, input = false } = {}) {
@@ -41,9 +41,9 @@ export function showConfirmation(text, { ok, cancel, input = false } = {}) {
       input,
       text,
       buttons: [
-        { text: i18n('buttonOK'), onClick: resolve, ...ok },
-        { text: i18n('buttonCancel'), onClick: reject, ...cancel },
-      ],
+        ok !== false && { text: i18n('buttonOK'), onClick: resolve, ...ok },
+        cancel !== false && { text: i18n('buttonCancel'), onClick: reject, ...cancel },
+      ].filter(Boolean),
       onBackdropClick: reject,
       onDismiss: reject, // Esc key
     });

+ 4 - 3
src/options/views/edit/index.vue

@@ -65,7 +65,7 @@ import {
   sendCmdDirectly, trueJoin,
 } from '#/common';
 import { deepCopy, deepEqual, objectPick } from '#/common/object';
-import { showMessage } from '#/common/ui';
+import { showConfirmation, showMessage } from '#/common/ui';
 import { keyboardService } from '#/common/keyboard';
 import VmCode from '#/common/ui/code';
 import options from '#/common/options';
@@ -304,8 +304,9 @@ export default {
         this.canSave = false; // ...and set it explicitly in case codeDirty was false
         if (res?.where?.id) this.script = res.update;
       } catch (err) {
-        // Stripping stack info added by browser.js
-        showMessage({ text: `${err.message || err}`.split('\n\n')[0] });
+        showConfirmation(`${err.message || err}`, {
+          cancel: false,
+        });
       }
     },
     close(cm) {