diff --git a/src/lib/components/CrateEditor.vue b/src/lib/components/CrateEditor.vue index d5dfed6..aa07b32 100644 --- a/src/lib/components/CrateEditor.vue +++ b/src/lib/components/CrateEditor.vue @@ -182,7 +182,7 @@ function updateEntity(entity, prop, value) { } } -function deleteEntity() { +async function deleteEntity() { //delete //count the links const linksCount = countReverse(data.entity); @@ -190,14 +190,12 @@ function deleteEntity() { if (linksCount === 0 || window.confirm(`This entity is referenced by ${linksCount} other ${entityMessage}. Are you sure you want to delete it?`)) { // const i = state.entities.findIndex(e => e['@id'] === data.entity['@id']); // if (i >= 0) state.entities.splice(i, 1); - state.entities.value.delete(data.entity['@id']); - nextTick(() => { - data.history.pop(); - state.crate.deleteEntity(data.entity, { references: true }); - const prevEntity = data.history[data.history.length - 1] ?? data.rootDataset; - emit("update:crate", props.crate); - emit("update:entityId", prevEntity['@id']); - }) + const e = data.entity; + data.history.pop(); + data.entity = data.history[data.history.length - 1] ?? data.rootDataset; + await state.deleteEntity(e); + emit("update:entityId", data.entity); + emit("update:crate", props.crate); } } diff --git a/src/lib/components/EditorState.js b/src/lib/components/EditorState.js index f702b77..6fe0fab 100644 --- a/src/lib/components/EditorState.js +++ b/src/lib/components/EditorState.js @@ -1,4 +1,4 @@ -import { ref, reactive, shallowReactive, isReactive } from 'vue'; +import { ref, reactive, shallowReactive, isReactive, nextTick } from 'vue'; import { ROCrate } from 'ro-crate'; import { ElCheckbox } from 'element-plus'; import InputDateTime from '../components/InputDateTime.vue'; @@ -132,6 +132,12 @@ export class EditorState { this.entities.value = new Set(this.crate.entities({ filter: e => e['@id'] !== mid })); } + async deleteEntity(e) { + this.entities.value.delete(e); + await nextTick(); + this.crate.deleteEntity(e, { references: true }); + } + /** * Get property definitions based on type as defined in profile * @param {string[]} types One or more (combined) types associated with an entity @@ -338,4 +344,3 @@ export class EditorState { } } } - diff --git a/src/lib/components/Property.vue b/src/lib/components/Property.vue index 6bc1dc3..1abe05e 100644 --- a/src/lib/components/Property.vue +++ b/src/lib/components/Property.vue @@ -94,14 +94,12 @@ function removeValue(i, value) { vals.splice(i, 1); props.components.splice(i, 1); if (typeof value === 'object' && value['@id']) { - if (!countReverse(toRaw(value))) { + let count = countReverse(toRaw(value)); + if (count <= 1) { //todo: confirm to delete entity //const i = state.entities.findIndex(e => e['@id'] === value['@id']); //if (i >= 0) state.entities.splice(i, 1); - state.entities.value.delete(value) - nextTick(() => { - state.crate.deleteEntity(value); - }); + state.deleteEntity(value); } } emit('update:modelValue', vals);