diff --git a/lib/component-data/actions.js b/lib/component-data/actions.js index f6a4cfbb0..7c88ca037 100644 --- a/lib/component-data/actions.js +++ b/lib/component-data/actions.js @@ -300,7 +300,7 @@ function addComponentsToComponentList(store, data, {currentURI, parentURI, path, * @returns {Promise} */ function addComponentsToComponentProp(store, data, {parentURI, path, components, clone}) { - const oldURI = data[path][refProp]; + const oldURI = _.get(data, `${path}.${refProp}`); if (components.length > 1) { log.warn(`Attempting to add multiple components to a component prop: ${getComponentName(parentURI)} ยป ${path}. Only the first component (${_.head(components).name}) will be added!`, { action: 'addComponentsToComponentProp' }); @@ -309,7 +309,9 @@ function addComponentsToComponentProp(store, data, {parentURI, path, components, // only create the first one return create([_.head(components)], clone).then((newComponents) => { return store.dispatch('saveComponent', { uri: parentURI, data: { [path]: _.head(newComponents) } }).then(() => { - store.commit(REMOVE_COMPONENT, { uri: oldURI }); + if (oldURI) { + store.commit(REMOVE_COMPONENT, { uri: oldURI }); + } // return the LAST element added return find(`[${refAttr}="${_.head(newComponents)[refProp]}"]`); }); diff --git a/lib/decorators/selector.vue b/lib/decorators/selector.vue index 2e2a1298d..4f6793a76 100644 --- a/lib/decorators/selector.vue +++ b/lib/decorators/selector.vue @@ -199,7 +199,6 @@ - @@ -248,10 +247,8 @@ componentLabel: label(getComponentName(this.$options.uri)), parentField: this.$options.parentField, parentURI: this.$options.parentURI, - // note: only for components in LISTS! components in properties can be replaced but not removed (for now) - hasRemove: this.$options.parentField && this.$options.parentField.type === 'list' && this.$options.parentField.isEditable, - hasAddComponent: this.$options.parentField && this.$options.parentField.type === 'list' && this.$options.parentField.isEditable, - hasReplaceComponent: this.$options.parentField && this.$options.parentField.type === 'prop' && this.$options.parentField.isEditable + hasRemove: this.$options.parentField && this.$options.parentField.isEditable, + hasAddComponent: this.$options.parentField && this.$options.parentField.type === 'list' && this.$options.parentField.isEditable }; }, computed: { diff --git a/lib/forms/overlay.vue b/lib/forms/overlay.vue index 1cb8fb2e0..9c7648bda 100644 --- a/lib/forms/overlay.vue +++ b/lib/forms/overlay.vue @@ -114,7 +114,6 @@ -
@@ -229,8 +228,7 @@ }, isCurrentlySelected: (state) => _.get(state, 'ui.currentForm.uri') === _.get(state, 'ui.currentSelection.uri'), hasRemove(state) { - // note: this only shows up if the component that contains this form is selected - return this.isCurrentlySelected && _.get(state, 'ui.currentSelection.parentField.type') === 'list' && _.get(state, 'ui.currentSelection.parentField.isEditable'); + return this.isCurrentlySelected && _.get(state, 'ui.currentSelection.parentField.isEditable'); }, hasDuplicateComponent(state) { return this.isCurrentlySelected && _.get(state, 'ui.currentSelection.parentField.type') === 'list' && _.get(state, 'ui.currentSelection.parentField.isEditable') && !_.get(state, 'ui.metaKey'); @@ -239,13 +237,8 @@ return this.isCurrentlySelected && _.get(state, 'ui.currentSelection.parentField.type') === 'list' && _.get(state, 'ui.currentSelection.parentField.isEditable') && _.get(state, 'ui.metaKey'); }, hasAddComponent(state) { - // note: this only shows up if the component that contains this form is selected return this.isCurrentlySelected && _.get(state, 'ui.currentSelection.parentField.type') === 'list' && _.get(state, 'ui.currentSelection.parentField.isEditable'); }, - hasReplaceComponent(state) { - // note: this only shows up if the component that contains this form is selected - return this.isCurrentlySelected && _.get(state, 'ui.currentSelection.parentField.type') === 'prop' && _.get(state, 'ui.currentSelection.parentField.isEditable'); - }, addComponentText(state) { if (this.hasAddComponent) { const schema = getSchema(_.get(state, 'ui.currentSelection.parentURI'), _.get(state, 'ui.currentSelection.parentField.path')),