From bf3ccc13d039b5e7f0b8358f00af59a0375420d8 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 29 Dec 2021 22:31:59 +0000 Subject: [PATCH] :bug: Fixes save item without title bug (#377) Closes #377. This bg was caused by adding items without a title, meaning an ID could not be calculated. The solution was to add a validtion check to ensure that a title is specified befire saving --- src/assets/locales/en.json | 3 ++ src/components/InteractiveEditor/EditItem.vue | 33 +++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json index f8e05fea..72d370d0 100644 --- a/src/assets/locales/en.json +++ b/src/assets/locales/en.json @@ -224,6 +224,9 @@ "save-stage-btn": "Save", "cancel-stage-btn": "Cancel" }, + "edit-item": { + "missing-title-err": "An item title is required" + }, "edit-section": { "edit-section-title": "Edit Section", "add-section-title": "Add New Section", diff --git a/src/components/InteractiveEditor/EditItem.vue b/src/components/InteractiveEditor/EditItem.vue index 14c7bfa0..3133a654 100644 --- a/src/components/InteractiveEditor/EditItem.vue +++ b/src/components/InteractiveEditor/EditItem.vue @@ -198,19 +198,26 @@ export default { // Convert form data back into section.item data structure const structured = {}; this.formData.forEach((row) => { structured[row.name] = row.value; }); - // Some attributes need a little extra formatting - const newItem = this.formatBeforeSave(structured); - if (this.isNew) { // Insert new item into data store - newItem.id = `temp_${newItem.title}`; - const payload = { newItem, targetSection: this.parentSectionTitle }; - this.$store.commit(StoreKeys.INSERT_ITEM, payload); - } else { // Update existing item from form data, in the store - this.$store.commit(StoreKeys.UPDATE_ITEM, { newItem, itemId: this.itemId }); + if (!structured.title) { // Missing title, show error and don't proceed + this.$toasted.show( + this.$t('interactive-editor.edit-item.missing-title-err'), + { className: 'toast-error' }, + ); + } else { + // Some attributes need a little extra formatting + const newItem = this.formatBeforeSave(structured); + if (this.isNew) { // Insert new item into data store + newItem.id = `temp_${newItem.title}`; + const payload = { newItem, targetSection: this.parentSectionTitle }; + this.$store.commit(StoreKeys.INSERT_ITEM, payload); + } else { // Update existing item from form data, in the store + this.$store.commit(StoreKeys.UPDATE_ITEM, { newItem, itemId: this.itemId }); + } + // If we're not already in edit mode, enable it now + this.$store.commit(StoreKeys.SET_EDIT_MODE, true); + // Close edit menu + this.$emit('closeEditMenu'); } - // If we're not already in edit mode, enable it now - this.$store.commit(StoreKeys.SET_EDIT_MODE, true); - // Close edit menu - this.$emit('closeEditMenu'); }, /* Some fields require a bit of extra processing before they're saved */ formatBeforeSave(item) { @@ -225,7 +232,7 @@ export default { if (str === undefined) return undefined; return str === 'true'; }; - if (newItem.tags) newItem.tags = strToTags(newItem.tags); + if (newItem.tags) newItem.tags = newItem.tags ? strToTags(newItem.tags) : []; if (newItem.statusCheck) newItem.statusCheck = strToBool(newItem.statusCheck); if (newItem.statusCheckAllowInsecure) { newItem.statusCheckAllowInsecure = strToBool(newItem.statusCheckAllowInsecure);