feat: support multi-tag for document knowledge (#1790)
* feat: support multi-tag for document knowledge - Add knowledge_tag_relations join table for many-to-many tag-knowledge mapping - Migrate existing single tag_id data to the new table - Update Knowledge struct, filter, payload types (TagID -> Tags/TagIDs) - Rewrite repository layer: SetKnowledgeTags, GetKnowledgeTags, ListIDsByTagIDs - Update tag count references to query knowledge_tag_relations - Update service/handler layers for multi-tag create/list/batch-update - Frontend: multi-select tag sidebar, multi-tag chip display, tag toggle in popup - FAQ tags remain single-tag model (unchanged) * feat(knowledge): tag edit dialog with dynamic overflow and inline creation - Add TagEditDialog component with search, multi-select, and confirm - Replace inline t-popup tag selector with dialog-based editing - Tags overflow with +N badge, visible count adapts to container width via ResizeObserver - Date/card layout: fixed date width, tags flex to fill remaining space - Add persistent new-tag input bar in dialog (Enter to create, auto-select) - Tag creation emits callback to refresh parent tag list immediately - Apply same overflow + dialog trigger to both card view and list view - Add i18n keys: tagEditDialogTitle, tagEditSearch, tagSelectedCount, tagOverflowTip, tagNewPlaceholder * fix: exclude soft-deleted knowledge from tag reference counts CountReferences, BatchCountReferences, and DeleteUnusedTags now JOIN with knowledges table to filter out soft-deleted records when counting knowledge_tag_relations. Previously they queried knowledge_tag_relations directly without the deleted_at check, causing stale tag counts after knowledge deletion. * fix: refresh tag counts after async knowledge deletion completes Add a second delayed tag list refresh (2.5s) after tag deletion to capture updated reference counts for remaining tags. The original immediate refresh handles removing the deleted tag from the list, while this delayed refresh ensures other tags' counts are correct after the async deletion finishes. --------- Co-authored-by: lyingbug <xiayula2014@gmail.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
-- Migration: 000063_knowledge_multi_tags (rollback)
|
||||
-- Description: Restore single tag_id column and drop the join table.
|
||||
DO $$ BEGIN RAISE NOTICE '[Migration 000063 rollback] Restoring knowledges.tag_id from knowledge_tag_relations...'; END $$;
|
||||
|
||||
-- Restore the tag_id column
|
||||
ALTER TABLE knowledges ADD COLUMN IF NOT EXISTS tag_id VARCHAR(36);
|
||||
CREATE INDEX IF NOT EXISTS idx_knowledges_tag ON knowledges(tag_id);
|
||||
|
||||
-- Restore the first tag (by created_at) from the join table back to knowledges
|
||||
UPDATE knowledges k
|
||||
SET tag_id = (
|
||||
SELECT ktr.tag_id
|
||||
FROM knowledge_tag_relations ktr
|
||||
WHERE ktr.knowledge_id = k.id
|
||||
ORDER BY ktr.created_at ASC
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM knowledge_tag_relations ktr WHERE ktr.knowledge_id = k.id
|
||||
);
|
||||
|
||||
-- Drop the join table
|
||||
DROP TABLE IF EXISTS knowledge_tag_relations;
|
||||
|
||||
DO $$ BEGIN RAISE NOTICE '[Migration 000063 rollback] knowledges.tag_id restored'; END $$;
|
||||
@@ -0,0 +1,31 @@
|
||||
-- Migration: 000063_knowledge_multi_tags
|
||||
-- Description: Add multi-tag support for document knowledge via a join table.
|
||||
DO $$ BEGIN RAISE NOTICE '[Migration 000063] Creating knowledge_tag_relations and migrating data...'; END $$;
|
||||
|
||||
-- Create the many-to-many join table
|
||||
CREATE TABLE IF NOT EXISTS knowledge_tag_relations (
|
||||
knowledge_id VARCHAR(36) NOT NULL,
|
||||
tag_id VARCHAR(36) NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
PRIMARY KEY (knowledge_id, tag_id)
|
||||
);
|
||||
|
||||
-- Index: find all tag IDs for a given knowledge
|
||||
CREATE INDEX IF NOT EXISTS idx_ktr_knowledge
|
||||
ON knowledge_tag_relations(knowledge_id);
|
||||
|
||||
-- Index: find all knowledge IDs for a given tag
|
||||
CREATE INDEX IF NOT EXISTS idx_ktr_tag
|
||||
ON knowledge_tag_relations(tag_id);
|
||||
|
||||
-- Migrate existing single-tag data into the join table
|
||||
INSERT INTO knowledge_tag_relations (knowledge_id, tag_id, created_at)
|
||||
SELECT id, tag_id, updated_at
|
||||
FROM knowledges
|
||||
WHERE tag_id IS NOT NULL AND tag_id != '';
|
||||
|
||||
-- Drop the old index and column
|
||||
DROP INDEX IF EXISTS idx_knowledges_tag;
|
||||
ALTER TABLE knowledges DROP COLUMN IF EXISTS tag_id;
|
||||
|
||||
DO $$ BEGIN RAISE NOTICE '[Migration 000063] knowledge_tag_relations ready'; END $$;
|
||||
Reference in New Issue
Block a user