feat(UI-Overhaul-Phase6): Tags Umstrukturierung
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
Migration 0138: Add parent_id, applicable_to, icon columns to tags table Backend: - Tag model: add parent_id (self-FK), applicable_to (JSONB), icon (VARCHAR) - TagCreate/TagUpdate/TagResponse schemas: add new fields - Tags routes: create_tag, update_tag, list_tags return new fields Frontend: - api/tags.ts: Tag interface, CreateTagPayload, UpdateTagPayload updated with new fields - Tags route moved from /tags to /settings/tags (under Settings) - Tags.tsx: TagFormModal updated with parent tag selector, icon picker, applicable_to multi-select - TagsPage passes tags list to TagFormModal for parent selection tsc clean, backend import OK
This commit is contained in:
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import ForeignKey, Index, String, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
||||
from sqlalchemy.dialects.postgresql import UUID as PGUUID, JSONB
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.db import Base, TenantMixin
|
||||
@@ -24,6 +24,7 @@ class Tag(Base, TenantMixin, OwnedMixin):
|
||||
__table_args__ = (
|
||||
UniqueConstraint("tenant_id", "name", name="uq_tags_tenant_name"),
|
||||
Index("ix_tags_tenant", "tenant_id"),
|
||||
Index("ix_tags_parent", "parent_id"),
|
||||
)
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(
|
||||
@@ -31,6 +32,11 @@ class Tag(Base, TenantMixin, OwnedMixin):
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
color: Mapped[str] = mapped_column(String(7), nullable=False, default="#6B7280")
|
||||
parent_id: Mapped[uuid.UUID | None] = mapped_column(
|
||||
PGUUID(as_uuid=True), ForeignKey("tags.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
applicable_to: Mapped[list[str] | None] = mapped_column(JSONB, nullable=True)
|
||||
icon: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||||
|
||||
|
||||
class TagAssignment(Base, TenantMixin, OwnedMixin):
|
||||
|
||||
@@ -78,6 +78,9 @@ async def list_tags(
|
||||
"name": tag.name,
|
||||
"color": tag.color,
|
||||
"entity_count": count,
|
||||
"parent_id": str(tag.parent_id) if tag.parent_id else None,
|
||||
"applicable_to": tag.applicable_to,
|
||||
"icon": tag.icon,
|
||||
}
|
||||
for tag, count in rows
|
||||
]
|
||||
@@ -102,7 +105,15 @@ async def create_tag(
|
||||
|
||||
from app.core.hooks import do_action
|
||||
await do_action("tag.before_create", body, db=db, tenant_id=tenant_id, user_id=user_id)
|
||||
tag = Tag(tenant_id=tenant_id, name=body.name, color=body.color, owner_id=user_id)
|
||||
tag = Tag(
|
||||
tenant_id=tenant_id,
|
||||
name=body.name,
|
||||
color=body.color,
|
||||
owner_id=user_id,
|
||||
parent_id=uuid.UUID(body.parent_id) if body.parent_id else None,
|
||||
applicable_to=body.applicable_to,
|
||||
icon=body.icon,
|
||||
)
|
||||
db.add(tag)
|
||||
await db.flush()
|
||||
from app.core.hooks import do_action
|
||||
@@ -112,6 +123,9 @@ async def create_tag(
|
||||
"name": tag.name,
|
||||
"color": tag.color,
|
||||
"entity_count": 0,
|
||||
"parent_id": str(tag.parent_id) if tag.parent_id else None,
|
||||
"applicable_to": tag.applicable_to,
|
||||
"icon": tag.icon,
|
||||
}
|
||||
|
||||
|
||||
@@ -145,6 +159,12 @@ async def update_tag(
|
||||
tag.name = data["name"]
|
||||
if "color" in data:
|
||||
tag.color = data["color"]
|
||||
if "parent_id" in data:
|
||||
tag.parent_id = uuid.UUID(data["parent_id"]) if data["parent_id"] else None
|
||||
if "applicable_to" in data:
|
||||
tag.applicable_to = data["applicable_to"]
|
||||
if "icon" in data:
|
||||
tag.icon = data["icon"]
|
||||
|
||||
await db.flush()
|
||||
return {
|
||||
@@ -152,6 +172,9 @@ async def update_tag(
|
||||
"name": tag.name,
|
||||
"color": tag.color,
|
||||
"entity_count": 0,
|
||||
"parent_id": str(tag.parent_id) if tag.parent_id else None,
|
||||
"applicable_to": tag.applicable_to,
|
||||
"icon": tag.icon,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,11 +8,17 @@ from pydantic import BaseModel, Field
|
||||
class TagCreate(BaseModel):
|
||||
name: str = Field(..., min_length=1, max_length=100)
|
||||
color: str = Field("#6B7280", max_length=7)
|
||||
parent_id: str | None = None
|
||||
applicable_to: list[str] | None = None
|
||||
icon: str | None = None
|
||||
|
||||
|
||||
class TagUpdate(BaseModel):
|
||||
name: str | None = Field(None, min_length=1, max_length=100)
|
||||
color: str | None = Field(None, max_length=7)
|
||||
parent_id: str | None = None
|
||||
applicable_to: list[str] | None = None
|
||||
icon: str | None = None
|
||||
|
||||
|
||||
class TagResponse(BaseModel):
|
||||
@@ -20,6 +26,9 @@ class TagResponse(BaseModel):
|
||||
name: str
|
||||
color: str
|
||||
entity_count: int = 0
|
||||
parent_id: str | None = None
|
||||
applicable_to: list[str] | None = None
|
||||
icon: str | None = None
|
||||
|
||||
|
||||
class TagAssignRequest(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user