From 06d08a8fffce695119868653c1163a3c4362ca82 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 25 Oct 2021 23:22:41 +0100 Subject: [PATCH] :sparkles: Implements Add new Item functionality --- src/components/InteractiveEditor/EditItem.vue | 15 ++++++++--- src/components/LinkItems/Item.vue | 11 ++++++-- src/components/LinkItems/Section.vue | 26 ++++++++++++++++++- src/store.js | 12 +++++++++ src/utils/StoreMutations.js | 1 + 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/components/InteractiveEditor/EditItem.vue b/src/components/InteractiveEditor/EditItem.vue index dd79f4c8..ead995a3 100644 --- a/src/components/InteractiveEditor/EditItem.vue +++ b/src/components/InteractiveEditor/EditItem.vue @@ -94,6 +94,8 @@ export default { }, props: { itemId: String, + isNew: Boolean, + parentSectionTitle: String, // If adding new item, which section to add it under }, computed: {}, components: { @@ -105,7 +107,9 @@ export default { BinIcon, }, mounted() { - this.item = this.getItemFromState(this.itemId); + if (!this.isNew) { // Get existing item data + this.item = this.getItemFromState(this.itemId); + } this.formData = this.makeInitialFormData(); this.$modal.show(modalNames.EDIT_ITEM); }, @@ -187,8 +191,13 @@ export default { this.formData.forEach((row) => { structured[row.name] = row.value; }); // Some attributes need a little extra formatting const newItem = this.formatBeforeSave(structured); - // Update the data store, with new item data - this.$store.commit(StoreKeys.UPDATE_ITEM, { newItem, itemId: this.itemId }); + 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 diff --git a/src/components/LinkItems/Item.vue b/src/components/LinkItems/Item.vue index 8fc556da..8763ef08 100644 --- a/src/components/LinkItems/Item.vue +++ b/src/components/LinkItems/Item.vue @@ -5,7 +5,7 @@ @contextmenu.prevent :href="hyperLinkHref" :target="anchorTarget" - :class="`item ${!icon? 'short': ''} size-${itemSize}`" + :class="`item ${!icon? 'short': ''} size-${itemSize} ${isAddNew ? 'add-new' : ''}`" v-tooltip="getTooltipOptions()" rel="noopener noreferrer" tabindex="0" :id="`link-${id}`" @@ -44,7 +44,9 @@ @openDeleteItem="openDeleteItem" /> - + @@ -90,6 +92,8 @@ export default { statusCheckUrl: String, statusCheckInterval: Number, statusCheckAllowInsecure: Boolean, + parentSectionTitle: String, + isAddNew: Boolean, }, components: { Icon, @@ -360,6 +364,9 @@ export default { &.short:not(.size-large) { height: 2rem; } + &.add-new { + border-style: dashed !important; + } } /* Text in tile */ diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue index adba954b..5c3b681b 100644 --- a/src/components/LinkItems/Section.vue +++ b/src/components/LinkItems/Section.vue @@ -11,13 +11,15 @@ @openEditSection="openEditSection" @openContextMenu="openContextMenu" > +
No Items to Show Yet
+
+ > + +
+ + + diff --git a/src/store.js b/src/store.js index 13fcd701..42d85aa1 100644 --- a/src/store.js +++ b/src/store.js @@ -22,6 +22,7 @@ const { REMOVE_SECTION, COPY_ITEM, REMOVE_ITEM, + INSERT_ITEM, } = Keys; const store = new Vuex.Store({ @@ -122,6 +123,17 @@ const store = new Vuex.Store({ } state.config = newConfig; }, + [INSERT_ITEM](state, payload) { + const { newItem, targetSection } = payload; + const config = { ...state.config }; + config.sections.forEach((section) => { + if (section.name === targetSection) { + section.items.push(newItem); + } + }); + config.sections = applyItemId(config.sections); + state.config = config; + }, [COPY_ITEM](state, payload) { const { item, toSection, appendTo } = payload; const config = { ...state.config }; diff --git a/src/utils/StoreMutations.js b/src/utils/StoreMutations.js index f48aca9e..dd6f16c4 100644 --- a/src/utils/StoreMutations.js +++ b/src/utils/StoreMutations.js @@ -12,6 +12,7 @@ const KEY_NAMES = [ 'REMOVE_SECTION', 'COPY_ITEM', 'REMOVE_ITEM', + 'INSERT_ITEM', ]; // Convert array of key names into an object, and export