Add ref_count management for deletions with atomic operations and error handling
This commit is contained in:
@@ -3,12 +3,14 @@ import Layout from './components/Layout';
|
||||
import Home from './pages/Home';
|
||||
import ProjectPage from './pages/ProjectPage';
|
||||
import PackagePage from './pages/PackagePage';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Layout>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/dashboard" element={<Dashboard />} />
|
||||
<Route path="/project/:projectName" element={<ProjectPage />} />
|
||||
<Route path="/project/:projectName/:packageName" element={<PackagePage />} />
|
||||
</Routes>
|
||||
|
||||
@@ -13,6 +13,10 @@ import {
|
||||
ArtifactListParams,
|
||||
ProjectListParams,
|
||||
GlobalSearchResponse,
|
||||
Stats,
|
||||
DeduplicationStats,
|
||||
TimelineStats,
|
||||
CrossProjectStats,
|
||||
} from './types';
|
||||
|
||||
const API_BASE = '/api/v1';
|
||||
@@ -156,3 +160,29 @@ export async function uploadArtifact(projectName: string, packageName: string, f
|
||||
export function getDownloadUrl(projectName: string, packageName: string, ref: string): string {
|
||||
return `${API_BASE}/project/${projectName}/${packageName}/+/${ref}`;
|
||||
}
|
||||
|
||||
// Stats API
|
||||
export async function getStats(): Promise<Stats> {
|
||||
const response = await fetch(`${API_BASE}/stats`);
|
||||
return handleResponse<Stats>(response);
|
||||
}
|
||||
|
||||
export async function getDeduplicationStats(): Promise<DeduplicationStats> {
|
||||
const response = await fetch(`${API_BASE}/stats/deduplication`);
|
||||
return handleResponse<DeduplicationStats>(response);
|
||||
}
|
||||
|
||||
export async function getTimelineStats(
|
||||
period: 'day' | 'week' | 'month' = 'day',
|
||||
fromDate?: string,
|
||||
toDate?: string
|
||||
): Promise<TimelineStats> {
|
||||
const params = buildQueryString({ period, from_date: fromDate, to_date: toDate });
|
||||
const response = await fetch(`${API_BASE}/stats/timeline${params}`);
|
||||
return handleResponse<TimelineStats>(response);
|
||||
}
|
||||
|
||||
export async function getCrossProjectStats(): Promise<CrossProjectStats> {
|
||||
const response = await fetch(`${API_BASE}/stats/cross-project`);
|
||||
return handleResponse<CrossProjectStats>(response);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,15 @@ function Layout({ children }: LayoutProps) {
|
||||
</svg>
|
||||
Projects
|
||||
</Link>
|
||||
<Link to="/dashboard" className={location.pathname === '/dashboard' ? 'active' : ''}>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<rect x="3" y="3" width="7" height="7" rx="1"/>
|
||||
<rect x="14" y="3" width="7" height="7" rx="1"/>
|
||||
<rect x="3" y="14" width="7" height="7" rx="1"/>
|
||||
<rect x="14" y="14" width="7" height="7" rx="1"/>
|
||||
</svg>
|
||||
Dashboard
|
||||
</Link>
|
||||
<a href="/docs" className="nav-link-muted">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
|
||||
|
||||
547
frontend/src/pages/Dashboard.css
Normal file
547
frontend/src/pages/Dashboard.css
Normal file
@@ -0,0 +1,547 @@
|
||||
.dashboard {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.dashboard__header {
|
||||
position: relative;
|
||||
margin-bottom: 48px;
|
||||
padding-bottom: 32px;
|
||||
border-bottom: 1px solid var(--border-primary);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dashboard__header-content {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.dashboard__header h1 {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
letter-spacing: -0.03em;
|
||||
margin-bottom: 8px;
|
||||
background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-primary) 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.dashboard__subtitle {
|
||||
font-size: 1rem;
|
||||
color: var(--text-tertiary);
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.dashboard__header-accent {
|
||||
position: absolute;
|
||||
top: -100px;
|
||||
right: -100px;
|
||||
width: 400px;
|
||||
height: 400px;
|
||||
background: radial-gradient(circle, rgba(16, 185, 129, 0.08) 0%, transparent 70%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.dashboard__section {
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
.dashboard__section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 20px;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.dashboard__section-title svg {
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.dashboard__section-description {
|
||||
color: var(--text-tertiary);
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 20px;
|
||||
margin-top: -8px;
|
||||
}
|
||||
|
||||
.stat-grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.stat-grid--4 {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
|
||||
.stat-grid--3 {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
.stat-grid--2 {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.stat-grid--4 {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.stat-grid--4,
|
||||
.stat-grid--3,
|
||||
.stat-grid--2 {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 20px;
|
||||
transition: all var(--transition-normal);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.stat-card::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 3px;
|
||||
background: var(--border-secondary);
|
||||
transition: background var(--transition-normal);
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
border-color: var(--border-secondary);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
|
||||
.stat-card--success::before {
|
||||
background: var(--accent-gradient);
|
||||
}
|
||||
|
||||
.stat-card--success {
|
||||
background: linear-gradient(135deg, rgba(16, 185, 129, 0.03) 0%, transparent 50%);
|
||||
}
|
||||
|
||||
.stat-card--accent::before {
|
||||
background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
|
||||
}
|
||||
|
||||
.stat-card--accent {
|
||||
background: linear-gradient(135deg, rgba(59, 130, 246, 0.03) 0%, transparent 50%);
|
||||
}
|
||||
|
||||
.stat-card__icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-tertiary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.stat-card--success .stat-card__icon {
|
||||
background: rgba(16, 185, 129, 0.1);
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.stat-card--accent .stat-card__icon {
|
||||
background: rgba(59, 130, 246, 0.1);
|
||||
color: #3b82f6;
|
||||
}
|
||||
|
||||
.stat-card__content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.stat-card__label {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.stat-card__value {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
letter-spacing: -0.02em;
|
||||
line-height: 1.2;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.stat-card__subvalue {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.stat-card__trend {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.stat-card__trend--up {
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.stat-card__trend--down {
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.progress-bar__header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.progress-bar__label {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.progress-bar__percentage {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.progress-bar__track {
|
||||
position: relative;
|
||||
height: 8px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: 100px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-bar__fill {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
background: var(--border-secondary);
|
||||
border-radius: 100px;
|
||||
transition: width 0.5s ease-out;
|
||||
}
|
||||
|
||||
.progress-bar__glow {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
background: transparent;
|
||||
border-radius: 100px;
|
||||
transition: width 0.5s ease-out;
|
||||
}
|
||||
|
||||
.progress-bar--success .progress-bar__fill {
|
||||
background: var(--accent-gradient);
|
||||
}
|
||||
|
||||
.progress-bar--success .progress-bar__glow {
|
||||
box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
|
||||
}
|
||||
|
||||
.progress-bar--accent .progress-bar__fill {
|
||||
background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
|
||||
}
|
||||
|
||||
.effectiveness-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1.5fr 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.effectiveness-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.effectiveness-card {
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.effectiveness-card h3 {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 24px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.storage-comparison {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.storage-bar__label {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.storage-bar__value {
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
||||
}
|
||||
|
||||
.storage-savings {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 20px;
|
||||
background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(5, 150, 105, 0.04) 100%);
|
||||
border: 1px solid rgba(16, 185, 129, 0.2);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.storage-savings__icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent-gradient);
|
||||
color: white;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 0 24px rgba(16, 185, 129, 0.3);
|
||||
}
|
||||
|
||||
.storage-savings__content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.storage-savings__value {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: var(--accent-primary);
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.storage-savings__label {
|
||||
font-size: 0.8125rem;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.dedup-rate {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.dedup-rate__circle {
|
||||
position: relative;
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
}
|
||||
|
||||
.dedup-rate__svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
.dedup-rate__value {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.dedup-rate__number {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
letter-spacing: -0.03em;
|
||||
}
|
||||
|
||||
.dedup-rate__symbol {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.dedup-rate__details {
|
||||
display: flex;
|
||||
gap: 32px;
|
||||
}
|
||||
|
||||
.dedup-rate__detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.dedup-rate__detail-value {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.dedup-rate__detail-label {
|
||||
font-size: 0.6875rem;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.artifacts-table {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.artifact-link {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.artifact-link code {
|
||||
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
||||
font-size: 0.8125rem;
|
||||
padding: 4px 8px;
|
||||
background: var(--bg-tertiary);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--accent-primary);
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.artifact-link:hover code {
|
||||
background: rgba(16, 185, 129, 0.15);
|
||||
}
|
||||
|
||||
.artifact-name {
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
display: block;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.ref-count {
|
||||
display: inline-flex;
|
||||
align-items: baseline;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.ref-count__value {
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.ref-count__label {
|
||||
font-size: 0.6875rem;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.storage-saved {
|
||||
color: var(--success);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.dashboard__loading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
padding: 80px 32px;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.dashboard__loading-spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 3px solid var(--border-primary);
|
||||
border-top-color: var(--accent-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard__error {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
padding: 80px 32px;
|
||||
text-align: center;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: var(--radius-lg);
|
||||
}
|
||||
|
||||
.dashboard__error svg {
|
||||
color: var(--error);
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.dashboard__error h3 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.dashboard__error p {
|
||||
color: var(--text-tertiary);
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.dashboard__error .btn {
|
||||
margin-top: 8px;
|
||||
}
|
||||
436
frontend/src/pages/Dashboard.tsx
Normal file
436
frontend/src/pages/Dashboard.tsx
Normal file
@@ -0,0 +1,436 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Stats, DeduplicationStats, ReferencedArtifact } from '../types';
|
||||
import { getStats, getDeduplicationStats } from '../api';
|
||||
import { DataTable } from '../components/DataTable';
|
||||
import './Dashboard.css';
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
|
||||
}
|
||||
|
||||
function formatNumber(num: number): string {
|
||||
return num.toLocaleString();
|
||||
}
|
||||
|
||||
function truncateHash(hash: string, length: number = 12): string {
|
||||
if (hash.length <= length) return hash;
|
||||
return `${hash.slice(0, length)}...`;
|
||||
}
|
||||
|
||||
interface StatCardProps {
|
||||
label: string;
|
||||
value: string;
|
||||
subvalue?: string;
|
||||
icon: React.ReactNode;
|
||||
variant?: 'default' | 'success' | 'accent';
|
||||
trend?: 'up' | 'down' | 'neutral';
|
||||
}
|
||||
|
||||
function StatCard({ label, value, subvalue, icon, variant = 'default', trend }: StatCardProps) {
|
||||
return (
|
||||
<div className={`stat-card stat-card--${variant}`}>
|
||||
<div className="stat-card__icon">{icon}</div>
|
||||
<div className="stat-card__content">
|
||||
<span className="stat-card__label">{label}</span>
|
||||
<span className="stat-card__value">
|
||||
{value}
|
||||
{trend && (
|
||||
<span className={`stat-card__trend stat-card__trend--${trend}`}>
|
||||
{trend === 'up' && '↑'}
|
||||
{trend === 'down' && '↓'}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
{subvalue && <span className="stat-card__subvalue">{subvalue}</span>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface ProgressBarProps {
|
||||
value: number;
|
||||
max: number;
|
||||
label?: string;
|
||||
showPercentage?: boolean;
|
||||
variant?: 'default' | 'success' | 'accent';
|
||||
}
|
||||
|
||||
function ProgressBar({ value, max, label, showPercentage = true, variant = 'default' }: ProgressBarProps) {
|
||||
const percentage = max > 0 ? Math.min((value / max) * 100, 100) : 0;
|
||||
|
||||
return (
|
||||
<div className={`progress-bar progress-bar--${variant}`}>
|
||||
{label && (
|
||||
<div className="progress-bar__header">
|
||||
<span className="progress-bar__label">{label}</span>
|
||||
{showPercentage && <span className="progress-bar__percentage">{percentage.toFixed(1)}%</span>}
|
||||
</div>
|
||||
)}
|
||||
<div className="progress-bar__track">
|
||||
<div
|
||||
className="progress-bar__fill"
|
||||
style={{ width: `${percentage}%` }}
|
||||
/>
|
||||
<div className="progress-bar__glow" style={{ width: `${percentage}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Dashboard() {
|
||||
const [stats, setStats] = useState<Stats | null>(null);
|
||||
const [dedupStats, setDedupStats] = useState<DeduplicationStats | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
async function loadStats() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const [statsData, dedupData] = await Promise.all([
|
||||
getStats(),
|
||||
getDeduplicationStats(),
|
||||
]);
|
||||
setStats(statsData);
|
||||
setDedupStats(dedupData);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load statistics');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
loadStats();
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="dashboard">
|
||||
<div className="dashboard__loading">
|
||||
<div className="dashboard__loading-spinner" />
|
||||
<span>Loading statistics...</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="dashboard">
|
||||
<div className="dashboard__error">
|
||||
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5">
|
||||
<circle cx="12" cy="12" r="10"/>
|
||||
<line x1="12" y1="8" x2="12" y2="12"/>
|
||||
<line x1="12" y1="16" x2="12.01" y2="16"/>
|
||||
</svg>
|
||||
<h3>Unable to load dashboard</h3>
|
||||
<p>{error}</p>
|
||||
<button className="btn btn-primary" onClick={() => window.location.reload()}>
|
||||
Try Again
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const artifactColumns = [
|
||||
{
|
||||
key: 'artifact_id',
|
||||
header: 'Artifact ID',
|
||||
render: (item: ReferencedArtifact) => (
|
||||
<Link to={`/artifact/${item.artifact_id}`} className="artifact-link">
|
||||
<code>{truncateHash(item.artifact_id, 16)}</code>
|
||||
</Link>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'original_name',
|
||||
header: 'Name',
|
||||
render: (item: ReferencedArtifact) => (
|
||||
<span className="artifact-name" title={item.original_name || 'Unknown'}>
|
||||
{item.original_name || '—'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'size',
|
||||
header: 'Size',
|
||||
render: (item: ReferencedArtifact) => formatBytes(item.size),
|
||||
},
|
||||
{
|
||||
key: 'ref_count',
|
||||
header: 'References',
|
||||
render: (item: ReferencedArtifact) => (
|
||||
<span className="ref-count">
|
||||
<span className="ref-count__value">{formatNumber(item.ref_count)}</span>
|
||||
<span className="ref-count__label">refs</span>
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'storage_saved',
|
||||
header: 'Storage Saved',
|
||||
render: (item: ReferencedArtifact) => (
|
||||
<span className="storage-saved">
|
||||
{formatBytes(item.storage_saved)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="dashboard">
|
||||
<header className="dashboard__header">
|
||||
<div className="dashboard__header-content">
|
||||
<h1>Storage Dashboard</h1>
|
||||
<p className="dashboard__subtitle">Real-time deduplication and storage analytics</p>
|
||||
</div>
|
||||
<div className="dashboard__header-accent" />
|
||||
</header>
|
||||
|
||||
<section className="dashboard__section">
|
||||
<h2 className="dashboard__section-title">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/>
|
||||
</svg>
|
||||
Storage Overview
|
||||
</h2>
|
||||
<div className="stat-grid stat-grid--4">
|
||||
<StatCard
|
||||
label="Total Storage Used"
|
||||
value={formatBytes(stats?.total_size_bytes || 0)}
|
||||
icon={
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>
|
||||
</svg>
|
||||
}
|
||||
variant="default"
|
||||
/>
|
||||
<StatCard
|
||||
label="Storage Saved"
|
||||
value={formatBytes(stats?.storage_saved_bytes || 0)}
|
||||
subvalue="through deduplication"
|
||||
icon={
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="23 6 13.5 15.5 8.5 10.5 1 18"/>
|
||||
<polyline points="17 6 23 6 23 12"/>
|
||||
</svg>
|
||||
}
|
||||
variant="success"
|
||||
/>
|
||||
<StatCard
|
||||
label="Deduplication Ratio"
|
||||
value={`${(stats?.deduplication_ratio || 1).toFixed(2)}x`}
|
||||
subvalue="compression achieved"
|
||||
icon={
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
|
||||
<line x1="3" y1="9" x2="21" y2="9"/>
|
||||
<line x1="9" y1="21" x2="9" y2="9"/>
|
||||
</svg>
|
||||
}
|
||||
variant="accent"
|
||||
/>
|
||||
<StatCard
|
||||
label="Savings Percentage"
|
||||
value={`${(dedupStats?.savings_percentage || 0).toFixed(1)}%`}
|
||||
subvalue="of logical storage"
|
||||
icon={
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="12" cy="12" r="10"/>
|
||||
<polyline points="12 6 12 12 16 14"/>
|
||||
</svg>
|
||||
}
|
||||
variant="success"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="dashboard__section">
|
||||
<h2 className="dashboard__section-title">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M12 20V10"/>
|
||||
<path d="M18 20V4"/>
|
||||
<path d="M6 20v-4"/>
|
||||
</svg>
|
||||
Artifact Statistics
|
||||
</h2>
|
||||
<div className="stat-grid stat-grid--4">
|
||||
<StatCard
|
||||
label="Total Artifacts"
|
||||
value={formatNumber(stats?.total_artifacts || 0)}
|
||||
icon={
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/>
|
||||
<polyline points="14 2 14 8 20 8"/>
|
||||
</svg>
|
||||
}
|
||||
/>
|
||||
<StatCard
|
||||
label="Total Uploads"
|
||||
value={formatNumber(stats?.total_uploads || 0)}
|
||||
icon={
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
|
||||
<polyline points="17 8 12 3 7 8"/>
|
||||
<line x1="12" y1="3" x2="12" y2="15"/>
|
||||
</svg>
|
||||
}
|
||||
/>
|
||||
<StatCard
|
||||
label="Deduplicated Uploads"
|
||||
value={formatNumber(stats?.deduplicated_uploads || 0)}
|
||||
subvalue="uploads reusing existing"
|
||||
icon={
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
|
||||
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
|
||||
</svg>
|
||||
}
|
||||
variant="success"
|
||||
/>
|
||||
<StatCard
|
||||
label="Unique Artifacts"
|
||||
value={formatNumber(stats?.unique_artifacts || 0)}
|
||||
subvalue="distinct content hashes"
|
||||
icon={
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>
|
||||
</svg>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="dashboard__section">
|
||||
<h2 className="dashboard__section-title">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<line x1="12" y1="20" x2="12" y2="10"/>
|
||||
<line x1="18" y1="20" x2="18" y2="4"/>
|
||||
<line x1="6" y1="20" x2="6" y2="16"/>
|
||||
</svg>
|
||||
Deduplication Effectiveness
|
||||
</h2>
|
||||
<div className="effectiveness-grid">
|
||||
<div className="effectiveness-card">
|
||||
<h3>Logical vs Physical Storage</h3>
|
||||
<div className="storage-comparison">
|
||||
<div className="storage-bar">
|
||||
<div className="storage-bar__label">
|
||||
<span>Logical (with duplicates)</span>
|
||||
<span className="storage-bar__value">{formatBytes(dedupStats?.total_logical_bytes || 0)}</span>
|
||||
</div>
|
||||
<ProgressBar
|
||||
value={dedupStats?.total_logical_bytes || 0}
|
||||
max={dedupStats?.total_logical_bytes || 1}
|
||||
showPercentage={false}
|
||||
variant="default"
|
||||
/>
|
||||
</div>
|
||||
<div className="storage-bar">
|
||||
<div className="storage-bar__label">
|
||||
<span>Physical (actual storage)</span>
|
||||
<span className="storage-bar__value">{formatBytes(dedupStats?.total_physical_bytes || 0)}</span>
|
||||
</div>
|
||||
<ProgressBar
|
||||
value={dedupStats?.total_physical_bytes || 0}
|
||||
max={dedupStats?.total_logical_bytes || 1}
|
||||
showPercentage={false}
|
||||
variant="success"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="storage-savings">
|
||||
<div className="storage-savings__icon">
|
||||
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="20 6 9 17 4 12"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div className="storage-savings__content">
|
||||
<span className="storage-savings__value">{formatBytes(dedupStats?.bytes_saved || 0)}</span>
|
||||
<span className="storage-savings__label">saved through deduplication</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="effectiveness-card">
|
||||
<h3>Deduplication Rate</h3>
|
||||
<div className="dedup-rate">
|
||||
<div className="dedup-rate__circle">
|
||||
<svg viewBox="0 0 100 100" className="dedup-rate__svg">
|
||||
<circle
|
||||
cx="50"
|
||||
cy="50"
|
||||
r="45"
|
||||
fill="none"
|
||||
stroke="var(--border-primary)"
|
||||
strokeWidth="8"
|
||||
/>
|
||||
<circle
|
||||
cx="50"
|
||||
cy="50"
|
||||
r="45"
|
||||
fill="none"
|
||||
stroke="url(#gradient)"
|
||||
strokeWidth="8"
|
||||
strokeLinecap="round"
|
||||
strokeDasharray={`${(dedupStats?.savings_percentage || 0) * 2.827} 282.7`}
|
||||
transform="rotate(-90 50 50)"
|
||||
/>
|
||||
<defs>
|
||||
<linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" stopColor="#10b981" />
|
||||
<stop offset="100%" stopColor="#059669" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
<div className="dedup-rate__value">
|
||||
<span className="dedup-rate__number">{(dedupStats?.savings_percentage || 0).toFixed(1)}</span>
|
||||
<span className="dedup-rate__symbol">%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="dedup-rate__details">
|
||||
<div className="dedup-rate__detail">
|
||||
<span className="dedup-rate__detail-value">{(stats?.deduplication_ratio || 1).toFixed(2)}x</span>
|
||||
<span className="dedup-rate__detail-label">Compression Ratio</span>
|
||||
</div>
|
||||
<div className="dedup-rate__detail">
|
||||
<span className="dedup-rate__detail-value">{formatNumber(stats?.deduplicated_uploads || 0)}</span>
|
||||
<span className="dedup-rate__detail-label">Duplicate Uploads</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{dedupStats && dedupStats.most_referenced_artifacts.length > 0 && (
|
||||
<section className="dashboard__section">
|
||||
<h2 className="dashboard__section-title">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>
|
||||
</svg>
|
||||
Top Referenced Artifacts
|
||||
</h2>
|
||||
<p className="dashboard__section-description">
|
||||
These artifacts are referenced most frequently across your storage, maximizing deduplication savings.
|
||||
</p>
|
||||
<DataTable
|
||||
data={dedupStats.most_referenced_artifacts.slice(0, 10)}
|
||||
columns={artifactColumns}
|
||||
keyExtractor={(item) => item.artifact_id}
|
||||
emptyMessage="No referenced artifacts found"
|
||||
className="artifacts-table"
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Dashboard;
|
||||
@@ -161,3 +161,67 @@ export interface GlobalSearchResponse {
|
||||
export interface ProjectListParams extends ListParams {
|
||||
visibility?: 'public' | 'private';
|
||||
}
|
||||
|
||||
// Stats types
|
||||
export interface Stats {
|
||||
total_artifacts: number;
|
||||
total_size_bytes: number;
|
||||
unique_artifacts: number;
|
||||
orphaned_artifacts: number;
|
||||
orphaned_size_bytes: number;
|
||||
total_uploads: number;
|
||||
deduplicated_uploads: number;
|
||||
deduplication_ratio: number;
|
||||
storage_saved_bytes: number;
|
||||
}
|
||||
|
||||
export interface ReferencedArtifact {
|
||||
artifact_id: string;
|
||||
ref_count: number;
|
||||
size: number;
|
||||
original_name: string | null;
|
||||
content_type: string | null;
|
||||
storage_saved: number;
|
||||
}
|
||||
|
||||
export interface DeduplicationStats {
|
||||
total_logical_bytes: number;
|
||||
total_physical_bytes: number;
|
||||
bytes_saved: number;
|
||||
savings_percentage: number;
|
||||
total_uploads: number;
|
||||
unique_artifacts: number;
|
||||
duplicate_uploads: number;
|
||||
average_ref_count: number;
|
||||
max_ref_count: number;
|
||||
most_referenced_artifacts: ReferencedArtifact[];
|
||||
}
|
||||
|
||||
export interface TimelineDataPoint {
|
||||
date: string;
|
||||
uploads: number;
|
||||
deduplicated: number;
|
||||
bytes_uploaded: number;
|
||||
bytes_saved: number;
|
||||
}
|
||||
|
||||
export interface TimelineStats {
|
||||
period: 'day' | 'week' | 'month';
|
||||
start_date: string;
|
||||
end_date: string;
|
||||
data_points: TimelineDataPoint[];
|
||||
}
|
||||
|
||||
export interface CrossProjectDuplicate {
|
||||
artifact_id: string;
|
||||
size: number;
|
||||
original_name: string | null;
|
||||
projects: string[];
|
||||
total_references: number;
|
||||
}
|
||||
|
||||
export interface CrossProjectStats {
|
||||
total_cross_project_duplicates: number;
|
||||
bytes_saved_cross_project: number;
|
||||
duplicates: CrossProjectDuplicate[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user