fix(datasets): fix oversized buttons UI + populate linked_dashboard_count in list endpoint

StatsBar — переделаны огромные карточки-кнопки в компактные пилюли
(rounded-full px-3 py-1 text-sm вместо p-3 grid grid-cols-4).

DatasetList — экшн-кнопки из bg-primary в outline-стиль, карточки
плотнее (p-2.5, py-0.5), ESLint-фиксы (#each key).

Backend — linked_dashboard_count теперь заполняется в списке датасетов
через /dataset/{id}/related_objects (конкурентно, Semaphore=3, timeout=10s).
Ранее поле было только в get_dataset_detail и StatsBar показывал 0.
This commit is contained in:
2026-05-24 09:38:21 +03:00
parent d9669698b8
commit 7219c47357
4 changed files with 94 additions and 32 deletions

View File

@@ -1,6 +1,7 @@
<!-- #region DatasetList [C:4] [TYPE Component] [SEMANTICS ui,dataset,card,list,pagination] -->
<!-- @BRIEF Renders paginated dataset cards with mapping progress bars, checkboxes, and quick actions. -->
<!-- @LAYER UI -->
<!-- @RATIONALE Action buttons switched from bg-primary solid to border-outline style, card padding reduced from p-3 to p-2.5, row gap from gap-3 to gap-2.5 — fixes "huge buttons" visual complaint. -->
<!-- @REJECTED Solid blue action buttons rejected — too visually heavy on each card line. -->
<!-- @RELATION BINDS_TO -> [environmentContextStore] -->
<!-- @UX_STATE Loading -> Skeleton cards. -->
<!-- @UX_STATE Loaded -> Cards with progress bars. -->
@@ -76,7 +77,7 @@
<!-- Loading -->
{#if isLoading}
<div class="space-y-3" aria-busy="true">
{#each Array(3) as _}
{#each Array(3) as _, _i (_i)}
<div class="bg-white border border-gray-200 rounded-lg p-4 animate-pulse">
<div class="h-4 bg-gray-200 rounded w-1/3 mb-2"></div>
<div class="h-3 bg-gray-200 rounded w-1/4 mb-3"></div>
@@ -92,25 +93,25 @@
<div class="py-8 text-center text-gray-400 text-sm">{$t.datasets?.empty}</div>
{:else}
<!-- Card Grid -->
<div class="space-y-2">
{#each datasets as dataset}
<div class="space-y-1.5">
{#each datasets as dataset (dataset.id)}
<div
class="bg-white border border-gray-200 rounded-lg p-3 cursor-pointer hover:border-gray-300 hover:shadow-sm transition-all"
class="bg-white border border-gray-200 rounded-lg p-2.5 cursor-pointer hover:border-gray-300 hover:shadow-sm transition-all"
onclick={(e) => handleCardClick(dataset, e)}
role="button"
tabindex="0"
>
<div class="flex items-start gap-3">
<div class="flex items-start gap-2.5">
<!-- Checkbox -->
<input
type="checkbox"
class="mt-0.5 accent-primary"
class="mt-0.5 accent-primary shrink-0"
checked={selectedIds.has(dataset.id)}
onchange={(e) => handleCheckboxChange(dataset, e)}
/>
<!-- Content -->
<div class="flex-1 min-w-0">
<div class="font-medium text-gray-900 truncate">{dataset.table_name}</div>
<div class="font-medium text-gray-900 truncate text-sm">{dataset.table_name}</div>
<div class="text-xs text-gray-500 mt-0.5 flex gap-3 flex-wrap">
<span>{dataset.schema ?? '-'}</span>
<span>{dataset.column_count ?? 0} {$t.datasets?.columns?.toLowerCase() ?? 'columns'}</span>
@@ -120,8 +121,8 @@
</div>
<!-- Progress bar -->
{#if dataset.mappedFields?.total}
<div class="mt-2">
<div class="w-full h-2 bg-gray-100 rounded-full overflow-hidden">
<div class="mt-1.5">
<div class="w-full h-1.5 bg-gray-100 rounded-full overflow-hidden">
<div
class="h-full rounded-full transition-all {getProgressClass(dataset.mappedFields.mapped, dataset.mappedFields.total)}"
style="width: {(dataset.mappedFields.mapped / dataset.mappedFields.total) * 100}%"
@@ -134,13 +135,13 @@
{/if}
</div>
<!-- Quick actions -->
<div class="flex gap-1 shrink-0">
<div class="flex gap-1 shrink-0 items-start">
<button
class="px-2 py-1 text-xs bg-primary text-white rounded hover:bg-primary-hover"
class="px-2 py-0.5 text-xs border border-gray-300 text-gray-500 rounded hover:bg-gray-50 hover:text-gray-700 transition-colors"
onclick={(e) => { e.stopPropagation(); onaction?.(dataset, 'map_columns'); }}
>{$t.datasets?.action_map_columns}</button>
<button
class="px-2 py-1 text-xs bg-primary text-white rounded hover:bg-primary-hover"
class="px-2 py-0.5 text-xs border border-gray-300 text-gray-500 rounded hover:bg-gray-50 hover:text-gray-700 transition-colors"
onclick={(e) => { e.stopPropagation(); onaction?.(dataset, 'generate_docs'); }}
>{$t.datasets?.generate_docs}</button>
</div>

View File

@@ -1,16 +1,16 @@
<!-- #region StatsBar [C:3] [TYPE Component] [SEMANTICS ui,dataset,stats,filter] -->
<!-- @BRIEF Displays 4 aggregate metric tiles (All, Without mapping, Mapped, Linked) and emits filter selection. -->
<!-- @LAYER UI -->
<!-- @BRIEF Compact filter pills showing aggregate counts (All, Without mapping, Mapped, Linked). -->
<!-- @RATIONALE Converted from card tiles (p-3, text-2xl) to compact pills (rounded-full px-3 py-1 text-sm) to fix oversized buttons complaint. -->
<!-- @REJECTED Card-tile filter buttons rejected — were too visually heavy at 12px padding + 24px font, dominating the page top. -->
<!-- @RELATION BINDS_TO -> [environmentContextStore] -->
<!-- @UX_STATE Loading -> 4 skeleton tiles pulsing. -->
<!-- @UX_STATE Loaded -> 4 tiles with numbers, active filter highlighted. -->
<!-- @UX_STATE Filtered -> Selected tile has accent border; parent triggers API reload with filter param. -->
<!-- @UX_STATE Loading -> 4 skeleton pills pulsing. -->
<!-- @UX_STATE Loaded -> pills with numbers, active filter highlighted. -->
<!-- @UX_STATE Filtered -> selected pill has filled background; parent reloads with filter param. -->
<!-- @UX_REACTIVITY Props -> stats, activeFilter, isLoading -->
<!-- @UX_REACTIVITY Events -> onfilter(filterKey) dispatched on tile click; parent calls loadDatasets(filter=filterKey). -->
<!-- @UX_REACTIVITY Events -> onfilter(filterKey) emitted on pill click -->
<script>
import { t } from "$lib/i18n";
/** @type {{ stats: import('./types').StatsCounts | null, activeFilter: string | null, isLoading?: boolean }} */
let { stats = null, activeFilter = null, isLoading = false, onfilter } = $props();
const tiles = [
@@ -29,21 +29,18 @@
}
</script>
<div class="grid grid-cols-4 gap-3 mb-4" role="group" aria-label="Dataset filters">
<div class="flex flex-wrap gap-2 mb-4" role="group" aria-label="Dataset filters">
{#each tiles as tile (tile.key)}
{#if isLoading}
<div class="bg-white border border-gray-200 rounded-lg p-3 animate-pulse" aria-busy="true">
<div class="h-3 bg-gray-200 rounded w-2/3 mb-2"></div>
<div class="h-6 bg-gray-200 rounded w-1/3"></div>
</div>
<div class="h-8 w-24 bg-gray-200 rounded-full animate-pulse" aria-busy="true"></div>
{:else}
<button
class="bg-white border rounded-lg p-3 text-left transition-all {activeFilter === tile.key ? 'border-primary ring-2 ring-primary/20 shadow-sm' : 'border-gray-200 hover:border-gray-300 hover:shadow-sm'}"
class="inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm transition-all {activeFilter === tile.key ? 'bg-primary text-white shadow-sm' : 'bg-white border border-gray-300 text-gray-600 hover:border-gray-400 hover:text-gray-800'}"
onclick={() => handleTileClick(tile.key)}
aria-pressed={activeFilter === tile.key}
>
<div class="text-xs text-gray-500 mb-1">{$t.datasets?.[tile.label] ?? tile.label}</div>
<div class="text-2xl font-bold text-gray-900">{tile.getCount(stats)}</div>
<span>{$t.datasets?.[tile.label] ?? tile.label}</span>
<span class="font-semibold tabular-nums">{tile.getCount(stats)}</span>
</button>
{/if}
{/each}