feat(tags): implement cross-app tag system with groups and entity links

Backend (mana-core-auth):
- Add tag_groups table (name, color, icon, sortOrder per user)
- Add tag_links table (tagId + appId + entityId + entityType, cross-app)
- Extend tags table with groupId and sortOrder fields
- Tag Groups API: CRUD + reorder at /tag-groups
- Tag Links API: link/unlink/bulk/sync/query at /tag-links
- Tags API: updated DTOs for groupId/sortOrder

Frontend client (@manacore/shared-tags):
- Add TagGroup, TagLink types and response types
- Add tag group methods: getGroups, createGroup, updateGroup, deleteGroup, reorderGroups
- Add tag link methods: linkTag, bulkLinkTags, unlinkTag, getTagsForEntity, syncEntityTags

Shared UI (@manacore/shared-ui):
- Add TagStrip component with glass-pill styling, tag filtering, management link
- Consistent look across all apps (replaces 3 app-specific implementations)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-26 20:43:34 +01:00
parent 7c7e5eb010
commit 0c479b3e88
27 changed files with 1412 additions and 5 deletions

View file

@ -1,4 +1,17 @@
import type { Tag, TagResponse, CreateTagInput, UpdateTagInput } from './types';
import type {
Tag,
TagResponse,
CreateTagInput,
UpdateTagInput,
TagGroup,
TagGroupResponse,
CreateTagGroupInput,
UpdateTagGroupInput,
TagLink,
TagLinkResponse,
CreateTagLinkInput,
SyncTagLinksInput,
} from './types';
/**
* Configuration for TagsClient
@ -125,6 +138,139 @@ export class TagsClient {
return tags.map(this.normalizeTag);
}
// ── Tag Groups ──────────────────────────────────────────
/**
* Get all tag groups for the current user
*/
async getGroups(): Promise<TagGroup[]> {
const groups = await this.request<TagGroupResponse[]>('/tag-groups');
return groups.map(this.normalizeTagGroup);
}
/**
* Create a new tag group
*/
async createGroup(data: CreateTagGroupInput): Promise<TagGroup> {
const group = await this.request<TagGroupResponse>('/tag-groups', {
method: 'POST',
body: JSON.stringify(data),
});
return this.normalizeTagGroup(group);
}
/**
* Update an existing tag group
*/
async updateGroup(id: string, data: UpdateTagGroupInput): Promise<TagGroup> {
const group = await this.request<TagGroupResponse>(`/tag-groups/${id}`, {
method: 'PUT',
body: JSON.stringify(data),
});
return this.normalizeTagGroup(group);
}
/**
* Delete a tag group
*/
async deleteGroup(id: string): Promise<void> {
await this.request(`/tag-groups/${id}`, {
method: 'DELETE',
});
}
/**
* Reorder tag groups by providing an ordered array of IDs
*/
async reorderGroups(ids: string[]): Promise<void> {
await this.request('/tag-groups/reorder', {
method: 'PUT',
body: JSON.stringify({ ids }),
});
}
// ── Tag Links ───────────────────────────────────────────
/**
* Link a tag to an entity
*/
async linkTag(data: CreateTagLinkInput): Promise<TagLink> {
const link = await this.request<TagLinkResponse>('/tag-links', {
method: 'POST',
body: JSON.stringify(data),
});
return this.normalizeTagLink(link);
}
/**
* Bulk link multiple tags to entities
*/
async bulkLinkTags(links: CreateTagLinkInput[]): Promise<TagLink[]> {
const result = await this.request<TagLinkResponse[]>('/tag-links/bulk', {
method: 'POST',
body: JSON.stringify({ links }),
});
return result.map(this.normalizeTagLink);
}
/**
* Remove a tag link
*/
async unlinkTag(linkId: string): Promise<void> {
await this.request(`/tag-links/${linkId}`, {
method: 'DELETE',
});
}
/**
* Get all tag links for a specific entity
*/
async getLinksForEntity(appId: string, entityId: string): Promise<TagLink[]> {
const links = await this.request<TagLinkResponse[]>(
`/tag-links?appId=${encodeURIComponent(appId)}&entityId=${encodeURIComponent(entityId)}`
);
return links.map(this.normalizeTagLink);
}
/**
* Get all tags for a specific entity (resolved Tag objects)
*/
async getTagsForEntity(appId: string, entityId: string): Promise<Tag[]> {
const tags = await this.request<TagResponse[]>(
`/tag-links/tags-for-entity?appId=${encodeURIComponent(appId)}&entityId=${encodeURIComponent(entityId)}`
);
return tags.map(this.normalizeTag);
}
/**
* Get all links for a specific tag
*/
async getLinksForTag(tagId: string): Promise<TagLink[]> {
const links = await this.request<TagLinkResponse[]>(
`/tag-links?tagId=${encodeURIComponent(tagId)}`
);
return links.map(this.normalizeTagLink);
}
/**
* Sync tags for an entity (add missing, remove extra)
*/
async syncEntityTags(data: SyncTagLinksInput): Promise<{ added: TagLink[]; removed: string[] }> {
const result = await this.request<{ added: TagLinkResponse[]; removed: string[] }>(
'/tag-links/sync',
{
method: 'POST',
body: JSON.stringify(data),
}
);
return {
added: result.added.map(this.normalizeTagLink),
removed: result.removed,
};
}
// ── Normalizers ─────────────────────────────────────────
/**
* Normalize API response to Tag type
*/
@ -135,6 +281,27 @@ export class TagsClient {
updatedAt: new Date(tag.updatedAt),
};
}
/**
* Normalize API response to TagGroup type
*/
private normalizeTagGroup(group: TagGroupResponse): TagGroup {
return {
...group,
createdAt: new Date(group.createdAt),
updatedAt: new Date(group.updatedAt),
};
}
/**
* Normalize API response to TagLink type
*/
private normalizeTagLink(link: TagLinkResponse): TagLink {
return {
...link,
createdAt: new Date(link.createdAt),
};
}
}
/**

View file

@ -8,6 +8,8 @@ export interface Tag {
name: string;
color: string;
icon?: string | null;
groupId?: string | null;
sortOrder?: number;
createdAt: Date | string;
updatedAt: Date | string;
}
@ -19,6 +21,8 @@ export interface CreateTagInput {
name: string;
color?: string;
icon?: string;
groupId?: string | null;
sortOrder?: number;
}
/**
@ -28,6 +32,8 @@ export interface UpdateTagInput {
name?: string;
color?: string;
icon?: string;
groupId?: string | null;
sortOrder?: number;
}
/**
@ -37,3 +43,89 @@ export type TagResponse = Omit<Tag, 'createdAt' | 'updatedAt'> & {
createdAt: string;
updatedAt: string;
};
// ── Tag Groups ──────────────────────────────────────────────
/**
* Tag group entity for organizing tags into categories
*/
export interface TagGroup {
id: string;
userId: string;
name: string;
color: string;
icon?: string | null;
sortOrder: number;
createdAt: Date | string;
updatedAt: Date | string;
}
/**
* Input for creating a new tag group
*/
export interface CreateTagGroupInput {
name: string;
color?: string;
icon?: string;
sortOrder?: number;
}
/**
* Input for updating an existing tag group
*/
export interface UpdateTagGroupInput {
name?: string;
color?: string;
icon?: string;
sortOrder?: number;
}
/**
* API response type for tag groups
*/
export type TagGroupResponse = Omit<TagGroup, 'createdAt' | 'updatedAt'> & {
createdAt: string;
updatedAt: string;
};
// ── Tag Links ───────────────────────────────────────────────
/**
* Tag link entity that connects a tag to an entity in any app
*/
export interface TagLink {
id: string;
tagId: string;
appId: string;
entityId: string;
entityType: string;
userId: string;
createdAt: Date | string;
}
/**
* Input for creating a tag link
*/
export interface CreateTagLinkInput {
tagId: string;
appId: string;
entityId: string;
entityType: string;
}
/**
* Input for syncing tag links on an entity (replaces all tags)
*/
export interface SyncTagLinksInput {
appId: string;
entityId: string;
entityType: string;
tagIds: string[];
}
/**
* API response type for tag links
*/
export type TagLinkResponse = Omit<TagLink, 'createdAt'> & {
createdAt: string;
};

View file

@ -91,6 +91,7 @@ export {
PillToolbar,
PillToolbarButton,
PillToolbarDivider,
TagStrip,
ExpandableToolbar,
} from './navigation';
export type {

View file

@ -0,0 +1,342 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { Tag, Plus, X } from '@manacore/shared-icons';
interface TagItem {
id: string;
name: string;
color: string;
}
interface Props {
/** Available tags to display */
tags: TagItem[];
/** Currently selected tag IDs */
selectedIds: string[];
/** Called when a tag is toggled */
onToggle: (tagId: string) => void;
/** Called when filter is cleared */
onClear: () => void;
/** Link for "Tags verwalten" pill */
managementHref?: string;
/** Loading state */
loading?: boolean;
/** Whether to show the "+ Neuer Tag" button */
showCreateButton?: boolean;
/** Link for "+ Neuer Tag" pill */
createHref?: string;
/** Whether the filter strip below is visible (adjusts bottom position) */
aboveFilterStrip?: boolean;
}
let {
tags,
selectedIds,
onToggle,
onClear,
managementHref = '/tags',
loading = false,
showCreateButton = true,
createHref,
aboveFilterStrip = false,
}: Props = $props();
const resolvedCreateHref = $derived(createHref ?? managementHref + '?new=true');
const hasSelectedTags = $derived(selectedIds.length > 0);
const hasTags = $derived(tags.length > 0);
const sortedTags = $derived.by(() => {
return [...tags].sort((a, b) => a.name.localeCompare(b.name, 'de'));
});
function isTagSelected(tagId: string): boolean {
return selectedIds.includes(tagId);
}
</script>
<div class="tag-strip-wrapper" class:above-filter-strip={aboveFilterStrip}>
<div class="tag-strip-container">
<!-- Clear Filter Button (always rendered to prevent layout shift) -->
<button
class="clear-filter-pill glass-tag"
class:hidden={!hasSelectedTags}
onclick={() => onClear()}
title="Filter löschen"
disabled={!hasSelectedTags}
>
<X size={16} weight="bold" />
<span class="tag-name">Filter</span>
</button>
<!-- Tags verwalten Pill -->
<button
class="manage-pill glass-tag"
onclick={() => goto(managementHref)}
title="Tags verwalten"
>
<Tag size={18} weight="bold" />
<span class="tag-name">Tags verwalten</span>
</button>
{#if loading}
<div class="loading-state">Lädt...</div>
{:else if !hasTags}
<button class="empty-state glass-tag" onclick={() => goto(managementHref)}>
<span>Keine Tags vorhanden</span>
<span class="add-hint">+ Erstellen</span>
</button>
{:else}
{#each sortedTags as tag (tag.id)}
<button
class="tag-pill glass-tag"
class:selected={isTagSelected(tag.id)}
onclick={() => onToggle(tag.id)}
title={tag.name}
style="--tag-color: {tag.color || '#8b5cf6'}"
>
<span class="tag-dot"></span>
<span class="tag-name">{tag.name}</span>
</button>
{/each}
<!-- Create Tag Button -->
{#if showCreateButton}
<button
class="create-pill glass-tag"
onclick={() => goto(resolvedCreateHref)}
title="Neuer Tag"
>
<Plus size={16} weight="bold" />
<span class="tag-name">Neuer Tag</span>
</button>
{/if}
{/if}
</div>
</div>
<style>
.tag-strip-wrapper {
position: fixed;
bottom: calc(70px + env(safe-area-inset-bottom, 0px));
left: 0;
right: 0;
z-index: 49;
display: flex;
flex-direction: column;
align-items: stretch;
pointer-events: none;
transition: bottom 0.2s ease;
}
/* When filter strip is also visible, stack above it */
.tag-strip-wrapper.above-filter-strip {
bottom: calc(110px + env(safe-area-inset-bottom, 0px));
}
.tag-strip-container {
display: flex;
align-items: center;
gap: 0.75rem;
background: transparent;
pointer-events: auto;
width: fit-content;
max-width: 100%;
margin-left: auto;
margin-right: auto;
padding: 0.5rem 2rem;
overflow-x: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
.tag-strip-container::-webkit-scrollbar {
display: none;
}
.tag-pill,
.manage-pill,
.create-pill,
.clear-filter-pill {
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
flex-shrink: 0;
transition: all 0.15s ease;
}
/* Selected tag state */
.tag-pill.selected {
background: var(--tag-color) !important;
border-color: var(--tag-color) !important;
}
.tag-pill.selected .tag-dot {
background-color: white;
}
.tag-pill.selected .tag-name {
color: white;
}
/* Clear filter pill */
.clear-filter-pill {
color: #ef4444;
background: rgba(239, 68, 68, 0.1) !important;
border-color: rgba(239, 68, 68, 0.3) !important;
}
.clear-filter-pill .tag-name {
color: #ef4444;
font-weight: 600;
}
:global(.dark) .clear-filter-pill {
color: #f87171;
background: rgba(239, 68, 68, 0.15) !important;
border-color: rgba(239, 68, 68, 0.3) !important;
}
:global(.dark) .clear-filter-pill .tag-name {
color: #f87171;
}
.clear-filter-pill:hover:not(.hidden) {
background: rgba(239, 68, 68, 0.2) !important;
border-color: rgba(239, 68, 68, 0.5) !important;
}
.clear-filter-pill.hidden {
visibility: hidden;
pointer-events: none;
}
/* Manage pill with neutral style */
.manage-pill {
color: #374151;
}
.manage-pill .tag-name {
color: #374151;
font-weight: 500;
}
:global(.dark) .manage-pill {
color: #f3f4f6;
}
:global(.dark) .manage-pill .tag-name {
color: #f3f4f6;
}
/* Create pill with neutral style */
.create-pill {
color: #374151;
}
.create-pill .tag-name {
color: #374151;
font-weight: 500;
}
:global(.dark) .create-pill {
color: #f3f4f6;
}
:global(.dark) .create-pill .tag-name {
color: #f3f4f6;
}
/* Glass tag styling */
.glass-tag {
padding: 0.5rem 1rem;
border-radius: 9999px;
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(0, 0, 0, 0.1);
box-shadow:
0 4px 6px -1px rgba(0, 0, 0, 0.1),
0 2px 4px -1px rgba(0, 0, 0, 0.06);
}
:global(.dark) .glass-tag {
background: rgba(255, 255, 255, 0.12);
border: 1px solid rgba(255, 255, 255, 0.15);
}
.glass-tag:hover {
transform: scale(1.05);
background: rgba(255, 255, 255, 0.95);
border-color: rgba(0, 0, 0, 0.15);
box-shadow:
0 10px 15px -3px rgba(0, 0, 0, 0.1),
0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
:global(.dark) .glass-tag:hover {
background: rgba(255, 255, 255, 0.2);
border-color: rgba(255, 255, 255, 0.25);
}
.glass-tag:active {
transform: scale(0.98);
}
.tag-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background-color: var(--tag-color);
flex-shrink: 0;
}
.tag-name {
font-size: 0.9375rem;
font-weight: 500;
color: #374151;
white-space: nowrap;
}
:global(.dark) .tag-name {
color: #f3f4f6;
}
.loading-state {
font-size: 0.875rem;
color: hsl(var(--color-muted-foreground));
padding: 0.5rem;
}
.empty-state {
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
color: #6b7280;
font-size: 0.875rem;
flex-shrink: 0;
}
:global(.dark) .empty-state {
color: #9ca3af;
}
.add-hint {
font-size: 0.875rem;
color: #8b5cf6;
font-weight: 500;
}
/* Responsive */
@media (max-width: 640px) {
.tag-strip-wrapper {
left: 0;
right: 0;
}
.tag-strip-container {
padding: 0.5rem 1rem;
}
}
</style>

View file

@ -11,6 +11,7 @@ export { default as PillViewSwitcher } from './PillViewSwitcher.svelte';
export { default as PillToolbar } from './PillToolbar.svelte';
export { default as PillToolbarButton } from './PillToolbarButton.svelte';
export { default as PillToolbarDivider } from './PillToolbarDivider.svelte';
export { default as TagStrip } from './TagStrip.svelte';
export { ExpandableToolbar } from './expandable-toolbar';
export type { ExpandableToolbarProps } from './expandable-toolbar';
export type {