Skip to content

Commit 6efe2fe

Browse files
BenjaminCharmesml-evs
authored andcommitted
Use removeItemsFromCollection instead of saveItem to remove item from collection
1 parent 15a24e4 commit 6efe2fe

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

webapp/src/components/CollectionSelect.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
<script>
4040
import vSelect from "vue-select";
4141
import FormattedCollectionName from "@/components/FormattedCollectionName.vue";
42-
import { searchCollections, createNewCollection } from "@/server_fetch_utils.js";
42+
import {
43+
searchCollections,
44+
createNewCollection,
45+
removeItemsFromCollection,
46+
} from "@/server_fetch_utils.js";
4347
import { validateEntryID } from "@/field_utils.js";
4448
import { debounceTime } from "@/resources.js";
4549
@@ -65,6 +69,7 @@ export default {
6569
collections: [],
6670
isSearchFetchError: false,
6771
searchQuery: "",
72+
pendingRemovals: [],
6873
};
6974
},
7075
computed: {
@@ -74,6 +79,14 @@ export default {
7479
return this.modelValue;
7580
},
7681
set(newValue) {
82+
const oldIds = this.modelValue?.map((c) => c.collection_id) || [];
83+
const newIds = newValue?.map((c) => c.collection_id) || [];
84+
const removedIds = oldIds.filter((id) => !newIds.includes(id));
85+
86+
if (removedIds.length > 0) {
87+
this.pendingRemovals.push(...removedIds);
88+
}
89+
7790
this.$emit("update:modelValue", newValue);
7891
},
7992
},
@@ -151,6 +164,19 @@ export default {
151164
}
152165
}
153166
},
167+
async processPendingRemovals() {
168+
if (this.pendingRemovals.length > 0) {
169+
const item_id = this.item_id;
170+
for (const collection_id of this.pendingRemovals) {
171+
try {
172+
await removeItemsFromCollection(collection_id, [item_id]);
173+
} catch (error) {
174+
console.error("Error removing item from collection:", error);
175+
}
176+
}
177+
this.pendingRemovals = [];
178+
}
179+
},
154180
},
155181
};
156182
</script>

webapp/src/components/SampleInformation.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
<ToggleableCreatorsFormGroup v-model="ItemCreators" :refcode="Refcode" />
3434
</div>
3535
<div class="col-md-6 col-sm-7 pr-2">
36-
<ToggleableCollectionFormGroup v-model="Collections" />
36+
<ToggleableCollectionFormGroup
37+
ref="collectionsFormGroup"
38+
v-model="Collections"
39+
:item_id="item_id"
40+
/>
3741
</div>
3842
</div>
3943
<div class="form-row">

webapp/src/components/ToggleableCollectionFormGroup.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
:options="{ ignore: [outerDivRef] }"
2626
@trigger="isEditingCollections = false"
2727
>
28-
<CollectionSelect v-model="value" aria-labelledby="collections" multiple @click.stop />
28+
<CollectionSelect
29+
ref="collectionSelect"
30+
v-model="value"
31+
aria-labelledby="collections"
32+
:item_id="item_id"
33+
multiple
34+
@click.stop
35+
/>
2936
</OnClickOutside>
3037
</div>
3138
</div>

webapp/src/views/EditPage.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@
6161

6262
<!-- Item-type header information goes here -->
6363
<div class="editor-body">
64-
<component :is="itemTypeEntry?.itemInformationComponent" :item_id="item_id" />
65-
64+
<component
65+
:is="itemTypeEntry?.itemInformationComponent"
66+
ref="sampleInformation"
67+
:item_id="item_id"
68+
/>
6669
<FileList :item_id="item_id" :stored_files="stored_files" />
6770

6871
<div class="container">

0 commit comments

Comments
 (0)