From 93551a71b03743e761cbd4270b8490f2e516631d Mon Sep 17 00:00:00 2001 From: Sergey Voytsehovich Date: Thu, 21 Dec 2023 12:03:48 +0300 Subject: [PATCH] Fix same tags adding uberf 4427 (#4235) Signed-off-by: Sergey Voytsehovich --- .../src/components/TagsEditorPopup.svelte | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/tags-resources/src/components/TagsEditorPopup.svelte b/plugins/tags-resources/src/components/TagsEditorPopup.svelte index 78c7584454..69ae2c06ce 100644 --- a/plugins/tags-resources/src/components/TagsEditorPopup.svelte +++ b/plugins/tags-resources/src/components/TagsEditorPopup.svelte @@ -28,16 +28,29 @@ }) const client = getClient() async function addRef ({ title, color, _id: tag }: TagElement): Promise { + // 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 { 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