Fix same tags adding uberf 4427 (#4235)

Signed-off-by: Sergey Voytsehovich <syargreg@gmail.com>
This commit is contained in:
Sergey Voytsehovich 2023-12-21 12:03:48 +03:00 committed by GitHub
parent d80ca00f98
commit 93551a71b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,16 +28,29 @@
})
const client = getClient()
async function addRef ({ title, color, _id: tag }: TagElement): Promise<void> {
// check if tag already attached, could happen if 'add' clicked faster than ui updates
const containsTag = selected.some((refElement) => refElement === tag)
if (containsTag) {
return
}
selected.push(tag)
await client.addCollection(tags.class.TagReference, object.space, object._id, object._class, 'labels', {
title,
color,
tag
})
}
async function removeTag (tag: TagElement): Promise<void> {
const tagRef = await client.findOne(tags.class.TagReference, { tag: tag._id, attachedTo: object._id })
if (tagRef) await client.remove(tagRef)
if (tagRef) {
await client.remove(tagRef)
selected.splice(selected.indexOf(tag._id), 1)
}
}
async function onUpdate (event: CustomEvent<{ action: string, tag: TagElement }>) {
const result = event.detail
if (result === undefined) return