Fix: Allow removing and re-adding the same tag

like, why would you even do this?
This commit is contained in:
Nelson Chan 2021-09-10 14:21:48 +08:00
parent 9b5abf9bb1
commit fcbeed55bf

View File

@ -198,7 +198,12 @@ export default {
} }
}, },
validateDraftTag() { validateDraftTag() {
if (this.newTags.concat(this.preSelectedTags).filter(tag => ( if (this.deleteTags.find(tag => tag.name == this.newDraftTag.select?.name && tag.value == this.newDraftTag.value)) {
// Undo removing a Tag
this.newDraftTag.nameInvalid = false;
this.newDraftTag.valueInvalid = false;
this.newDraftTag.invalid = false;
} else if (this.newTags.concat(this.preSelectedTags).filter(tag => (
tag.name == this.newDraftTag.select?.name && tag.value == this.newDraftTag.value tag.name == this.newDraftTag.select?.name && tag.value == this.newDraftTag.value
) || ( ) || (
tag.name == this.newDraftTag.name && tag.value == this.newDraftTag.value tag.name == this.newDraftTag.name && tag.value == this.newDraftTag.value
@ -235,6 +240,10 @@ export default {
addDraftTag() { addDraftTag() {
console.log("Adding Draft Tag: ", this.newDraftTag); console.log("Adding Draft Tag: ", this.newDraftTag);
if (this.newDraftTag.select != null) { if (this.newDraftTag.select != null) {
if (this.deleteTags.find(tag => tag.name == this.newDraftTag.select.name && tag.value == this.newDraftTag.value)) {
// Undo removing a tag
this.deleteTags = this.deleteTags.filter(tag => !(tag.name == this.newDraftTag.select.name && tag.value == this.newDraftTag.value));
} else {
// Add an existing Tag // Add an existing Tag
this.newTags.push({ this.newTags.push({
id: this.newDraftTag.select.id, id: this.newDraftTag.select.id,
@ -243,6 +252,7 @@ export default {
value: this.newDraftTag.value, value: this.newDraftTag.value,
new: true, new: true,
}) })
}
} else { } else {
// Add new Tag // Add new Tag
this.newTags.push({ this.newTags.push({