From 524ed00d84b9a65a1c65357c223620ae29f166dd Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Thu, 21 May 2026 12:39:03 +0200 Subject: [PATCH] fix(tags): put new created tag above 'Other' Signed-off-by: Maksim Sukharev --- src/stores/__tests__/conversationTags.spec.js | 14 ++++++++++++-- src/stores/conversationTags.ts | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/stores/__tests__/conversationTags.spec.js b/src/stores/__tests__/conversationTags.spec.js index 7a04a96cca6..20092db3e99 100644 --- a/src/stores/__tests__/conversationTags.spec.js +++ b/src/stores/__tests__/conversationTags.spec.js @@ -43,6 +43,14 @@ const favoritesTag = { collapsed: false, } +const otherTag = { + id: 'other', + name: 'Other', + type: 'other', + sortOrder: 2, + collapsed: false, +} + const customTagOne = { id: 'tag-1', name: 'Alpha', @@ -115,6 +123,7 @@ describe('conversationTagsStore', () => { }) it('creates a tag and persists it', async () => { + BrowserStorage.getItem.mockReturnValueOnce(JSON.stringify([favoritesTag, otherTag])) conversationTagsStore = useConversationTagsStore() createTagApi.mockResolvedValue(generateOCSResponse({ payload: customTagOne })) @@ -123,8 +132,9 @@ describe('conversationTagsStore', () => { expect(createTagApi).toHaveBeenCalledWith(customTagOne.name) expect(tag).toEqual(customTagOne) - expect(conversationTagsStore.tags[customTagOne.id]).toEqual(customTagOne) - expect(getPersistedTags()).toEqual([customTagOne]) + // Other's sortOrder bumped from 2 to 3, so new tag (2) appears before Other (3) + expect(conversationTagsStore.sortedTags.map((t) => t.id)).toEqual([favoritesTag.id, customTagOne.id, otherTag.id]) + expect(conversationTagsStore.tags[otherTag.id].sortOrder).toBe(3) }) it('updates a tag name', async () => { diff --git a/src/stores/conversationTags.ts b/src/stores/conversationTags.ts index 9fcaa4eb6c2..ccafad85005 100644 --- a/src/stores/conversationTags.ts +++ b/src/stores/conversationTags.ts @@ -75,6 +75,11 @@ export const useConversationTagsStore = defineStore('conversationTags', () => { async function createTag(name: string) { const response = await createTagApi(name) const tag = response.data.ocs.data + // Mirror backend logic: if Other's sortOrder collides with the new tag's, bump it by 1. + const otherTag = Object.values(tags).find((t) => t.type === 'other') + if (otherTag && otherTag.sortOrder === tag.sortOrder) { + otherTag.sortOrder += 1 + } tags[tag.id] = tag return tag }