@umituz/web-dashboard 11.12.0 → 11.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ import type { ActivityGroup, ActivityItem } from './types';
2
+
3
+ export function toDate(timestamp: string | number | Date): Date {
4
+ if (timestamp instanceof Date) return timestamp;
5
+ if (typeof timestamp === 'number') return new Date(timestamp);
6
+ return new Date(timestamp);
7
+ }
8
+
9
+ export function toIsoDayKey(date: Date): string {
10
+ const y = date.getFullYear();
11
+ const m = String(date.getMonth() + 1).padStart(2, '0');
12
+ const d = String(date.getDate()).padStart(2, '0');
13
+ return `${y}-${m}-${d}`;
14
+ }
15
+
16
+ export function formatDayLabel(date: Date, locale = 'en-US'): string {
17
+ const now = new Date();
18
+ const todayKey = toIsoDayKey(now);
19
+ const targetKey = toIsoDayKey(date);
20
+
21
+ if (targetKey === todayKey) return 'Today';
22
+
23
+ const yesterday = new Date(now);
24
+ yesterday.setDate(yesterday.getDate() - 1);
25
+ if (targetKey === toIsoDayKey(yesterday)) return 'Yesterday';
26
+
27
+ return new Intl.DateTimeFormat(locale, {
28
+ month: 'short',
29
+ day: 'numeric',
30
+ year: now.getFullYear() === date.getFullYear() ? undefined : 'numeric',
31
+ }).format(date);
32
+ }
33
+
34
+ export function formatActivityRelativeTime(date: Date): string {
35
+ const diffSec = Math.floor((Date.now() - date.getTime()) / 1000);
36
+ if (diffSec < 60) return 'just now';
37
+ const diffMin = Math.floor(diffSec / 60);
38
+ if (diffMin < 60) return `${diffMin}m ago`;
39
+ const diffHour = Math.floor(diffMin / 60);
40
+ if (diffHour < 24) return `${diffHour}h ago`;
41
+ const diffDay = Math.floor(diffHour / 24);
42
+ if (diffDay < 30) return `${diffDay}d ago`;
43
+ const diffMonth = Math.floor(diffDay / 30);
44
+ if (diffMonth < 12) return `${diffMonth}mo ago`;
45
+ return `${Math.floor(diffMonth / 12)}y ago`;
46
+ }
47
+
48
+ export function groupActivitiesByDay<T>(
49
+ items: readonly ActivityItem<T>[],
50
+ locale = 'en-US',
51
+ ): readonly ActivityGroup<T>[] {
52
+ const groups: Map<string, { label: string; items: ActivityItem<T>[] }> = new Map();
53
+
54
+ for (const item of items) {
55
+ const d = toDate(item.timestamp);
56
+ const key = toIsoDayKey(d);
57
+ const existing = groups.get(key);
58
+ if (existing) {
59
+ existing.items.push(item);
60
+ } else {
61
+ groups.set(key, {
62
+ label: formatDayLabel(d, locale),
63
+ items: [item],
64
+ });
65
+ }
66
+ }
67
+
68
+ return Array.from(groups.entries()).map(([dateKey, val]) => ({
69
+ dateKey,
70
+ label: val.label,
71
+ items: val.items,
72
+ }));
73
+ }
@@ -0,0 +1,65 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import { DataToolbar } from './DataToolbar';
4
+
5
+ describe('DataToolbar', () => {
6
+ it('renders search input and calls onChange', () => {
7
+ const handleSearch = vi.fn();
8
+ render(
9
+ <DataToolbar
10
+ search={{ value: '', onChange: handleSearch, placeholder: 'Filter records…' }}
11
+ />,
12
+ );
13
+ const input = screen.getByPlaceholderText('Filter records…');
14
+ expect(input).toBeTruthy();
15
+ fireEvent.change(input, { target: { value: 'test' } });
16
+ expect(handleSearch).toHaveBeenCalledWith('test');
17
+ });
18
+
19
+ it('renders record count label', () => {
20
+ render(<DataToolbar count={{ shown: 10, total: 50 }} />);
21
+ expect(screen.getByTestId('data-toolbar-count').textContent).toBe('10 of 50');
22
+ });
23
+
24
+ it('renders active filter chips and handles remove and clear all', () => {
25
+ const handleRemove = vi.fn();
26
+ const handleClearAll = vi.fn();
27
+ render(
28
+ <DataToolbar
29
+ activeFilters={[
30
+ { id: 'status', label: 'Status', valueLabel: 'Active', onRemove: handleRemove },
31
+ ]}
32
+ onClearAllFilters={handleClearAll}
33
+ />,
34
+ );
35
+ expect(screen.getByText('Status:')).toBeTruthy();
36
+ expect(screen.getByText('Active')).toBeTruthy();
37
+
38
+ fireEvent.click(screen.getByLabelText('Remove filter Status'));
39
+ expect(handleRemove).toHaveBeenCalled();
40
+
41
+ fireEvent.click(screen.getByText('Clear all'));
42
+ expect(handleClearAll).toHaveBeenCalled();
43
+ });
44
+
45
+ it('renders view switcher buttons and handles change', () => {
46
+ const handleViewChange = vi.fn();
47
+ render(
48
+ <DataToolbar
49
+ viewSwitcher={{
50
+ current: 'table',
51
+ options: [
52
+ { id: 'table', label: 'Table' },
53
+ { id: 'kanban', label: 'Kanban' },
54
+ ],
55
+ onChange: handleViewChange,
56
+ }}
57
+ />,
58
+ );
59
+ expect(screen.getByText('Table')).toBeTruthy();
60
+ expect(screen.getByText('Kanban')).toBeTruthy();
61
+
62
+ fireEvent.click(screen.getByText('Kanban'));
63
+ expect(handleViewChange).toHaveBeenCalledWith('kanban');
64
+ });
65
+ });
@@ -0,0 +1,119 @@
1
+ import { FilterSelect } from '@umituz/web-design-system/molecules';
2
+ import { cn } from '@umituz/web-design-system/utils';
3
+ import type { DataToolbarProps } from '../types';
4
+
5
+ export function DataToolbar({
6
+ search,
7
+ filters,
8
+ activeFilters,
9
+ onClearAllFilters,
10
+ count,
11
+ viewSwitcher,
12
+ actions,
13
+ children,
14
+ className,
15
+ }: DataToolbarProps) {
16
+ const countLabel = (() => {
17
+ if (count === undefined) return null;
18
+ if (typeof count === 'number') return `${count}`;
19
+ if (count.total !== undefined) return `${count.shown} of ${count.total}`;
20
+ return `${count.shown}`;
21
+ })();
22
+
23
+ return (
24
+ <div className={cn('udb-data-toolbar', className)}>
25
+ <div className="udb-data-toolbar__main">
26
+ {search && (
27
+ <div className="udb-data-toolbar__search">
28
+ <input
29
+ type="search"
30
+ value={search.value}
31
+ onChange={(e) => search.onChange(e.target.value)}
32
+ placeholder={search.placeholder ?? 'Search…'}
33
+ className="w-full h-8 px-3 text-xs rounded-md border border-line-border bg-surface text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary"
34
+ />
35
+ </div>
36
+ )}
37
+
38
+ {filters && filters.length > 0 && (
39
+ <div className="udb-data-toolbar__filters">
40
+ {filters.map((f) => (
41
+ <FilterSelect
42
+ key={f.id}
43
+ value={f.value}
44
+ onChange={f.onChange}
45
+ options={f.options}
46
+ ariaLabel={f.label}
47
+ allLabel={f.allLabel ?? 'All'}
48
+ />
49
+ ))}
50
+ </div>
51
+ )}
52
+
53
+ {children}
54
+
55
+ <div className="udb-data-toolbar__right">
56
+ {actions}
57
+
58
+ {viewSwitcher && (
59
+ <div className="udb-data-toolbar__view-switcher" role="radiogroup" aria-label="View mode">
60
+ {viewSwitcher.options.map((opt) => {
61
+ const isActive = opt.id === viewSwitcher.current;
62
+ return (
63
+ <button
64
+ key={opt.id}
65
+ type="button"
66
+ role="radio"
67
+ aria-checked={isActive}
68
+ onClick={() => viewSwitcher.onChange(opt.id)}
69
+ className={cn(
70
+ 'udb-data-toolbar__view-button',
71
+ isActive && 'udb-data-toolbar__view-button--active',
72
+ )}
73
+ >
74
+ {opt.icon}
75
+ <span>{opt.label}</span>
76
+ </button>
77
+ );
78
+ })}
79
+ </div>
80
+ )}
81
+
82
+ {countLabel && (
83
+ <span className="udb-data-toolbar__count" data-testid="data-toolbar-count">
84
+ {countLabel}
85
+ </span>
86
+ )}
87
+ </div>
88
+ </div>
89
+
90
+ {activeFilters && activeFilters.length > 0 && (
91
+ <div className="udb-data-toolbar__chips">
92
+ {activeFilters.map((chip) => (
93
+ <span key={chip.id} className="udb-data-toolbar__chip">
94
+ <span className="text-muted-foreground">{chip.label}:</span>
95
+ <strong className="font-medium text-foreground">{chip.valueLabel}</strong>
96
+ <button
97
+ type="button"
98
+ onClick={chip.onRemove}
99
+ className="udb-data-toolbar__chip-remove"
100
+ aria-label={`Remove filter ${chip.label}`}
101
+ >
102
+ ×
103
+ </button>
104
+ </span>
105
+ ))}
106
+ {onClearAllFilters && (
107
+ <button
108
+ type="button"
109
+ onClick={onClearAllFilters}
110
+ className="udb-data-toolbar__clear-all"
111
+ >
112
+ Clear all
113
+ </button>
114
+ )}
115
+ </div>
116
+ )}
117
+ </div>
118
+ );
119
+ }
@@ -0,0 +1 @@
1
+ export { DataToolbar } from './DataToolbar';
@@ -0,0 +1,128 @@
1
+ .udb-data-toolbar {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 8px;
5
+ width: 100%;
6
+ }
7
+
8
+ .udb-data-toolbar__main {
9
+ display: flex;
10
+ align-items: center;
11
+ gap: 12px;
12
+ flex-wrap: wrap;
13
+ width: 100%;
14
+ }
15
+
16
+ .udb-data-toolbar__search {
17
+ flex: 0 1 240px;
18
+ min-width: 180px;
19
+ }
20
+
21
+ .udb-data-toolbar__filters {
22
+ display: flex;
23
+ align-items: center;
24
+ gap: 8px;
25
+ flex-wrap: wrap;
26
+ }
27
+
28
+ .udb-data-toolbar__right {
29
+ display: flex;
30
+ align-items: center;
31
+ gap: 12px;
32
+ margin-left: auto;
33
+ }
34
+
35
+ .udb-data-toolbar__count {
36
+ font-size: 13px;
37
+ color: var(--text-tertiary, #94a3b8);
38
+ font-variant-numeric: tabular-nums;
39
+ white-space: nowrap;
40
+ }
41
+
42
+ .udb-data-toolbar__chips {
43
+ display: flex;
44
+ align-items: center;
45
+ gap: 6px;
46
+ flex-wrap: wrap;
47
+ padding-top: 4px;
48
+ }
49
+
50
+ .udb-data-toolbar__chip {
51
+ display: inline-flex;
52
+ align-items: center;
53
+ gap: 6px;
54
+ padding: 2px 8px;
55
+ border-radius: 9999px;
56
+ font-size: 12px;
57
+ background: var(--surface-secondary, rgba(0, 0, 0, 0.05));
58
+ color: var(--text-secondary, #475569);
59
+ border: 1px solid var(--line-border, rgba(0, 0, 0, 0.08));
60
+ }
61
+
62
+ .udb-data-toolbar__chip-remove {
63
+ display: inline-flex;
64
+ align-items: center;
65
+ justify-content: center;
66
+ width: 14px;
67
+ height: 14px;
68
+ border-radius: 9999px;
69
+ border: none;
70
+ background: transparent;
71
+ color: var(--text-tertiary, #94a3b8);
72
+ cursor: pointer;
73
+ padding: 0;
74
+ font-size: 12px;
75
+ line-height: 1;
76
+ }
77
+
78
+ .udb-data-toolbar__chip-remove:hover {
79
+ color: var(--text-primary, #0f172a);
80
+ }
81
+
82
+ .udb-data-toolbar__clear-all {
83
+ font-size: 12px;
84
+ color: var(--signal-600, #3b82f6);
85
+ background: transparent;
86
+ border: none;
87
+ cursor: pointer;
88
+ padding: 2px 6px;
89
+ font-weight: 500;
90
+ }
91
+
92
+ .udb-data-toolbar__clear-all:hover {
93
+ text-decoration: underline;
94
+ }
95
+
96
+ .udb-data-toolbar__view-switcher {
97
+ display: inline-flex;
98
+ align-items: center;
99
+ padding: 2px;
100
+ border-radius: 8px;
101
+ background: var(--surface-secondary, rgba(0, 0, 0, 0.05));
102
+ border: 1px solid var(--line-border, rgba(0, 0, 0, 0.08));
103
+ gap: 2px;
104
+ }
105
+
106
+ .udb-data-toolbar__view-button {
107
+ display: inline-flex;
108
+ align-items: center;
109
+ justify-content: center;
110
+ padding: 4px 8px;
111
+ border-radius: 6px;
112
+ border: none;
113
+ background: transparent;
114
+ color: var(--text-tertiary, #94a3b8);
115
+ font-size: 12px;
116
+ cursor: pointer;
117
+ transition: all 0.15s ease;
118
+ }
119
+
120
+ .udb-data-toolbar__view-button:hover {
121
+ color: var(--text-primary, #0f172a);
122
+ }
123
+
124
+ .udb-data-toolbar__view-button--active {
125
+ background: var(--surface, #ffffff);
126
+ color: var(--text-primary, #0f172a);
127
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
128
+ }
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './components';
@@ -0,0 +1,48 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ export interface DataToolbarFilterOption {
4
+ readonly value: string;
5
+ readonly label: string;
6
+ }
7
+
8
+ export interface DataToolbarFilter {
9
+ readonly id: string;
10
+ readonly label: string;
11
+ readonly value: string;
12
+ readonly options: readonly DataToolbarFilterOption[];
13
+ readonly onChange: (value: string) => void;
14
+ readonly allLabel?: string;
15
+ }
16
+
17
+ export interface ActiveFilterChip {
18
+ readonly id: string;
19
+ readonly label: string;
20
+ readonly valueLabel: string;
21
+ readonly onRemove: () => void;
22
+ }
23
+
24
+ export interface ViewSwitcherOption {
25
+ readonly id: string;
26
+ readonly label: string;
27
+ readonly icon?: ReactNode;
28
+ }
29
+
30
+ export interface DataToolbarProps {
31
+ readonly search?: {
32
+ readonly value: string;
33
+ readonly onChange: (value: string) => void;
34
+ readonly placeholder?: string;
35
+ };
36
+ readonly filters?: readonly DataToolbarFilter[];
37
+ readonly activeFilters?: readonly ActiveFilterChip[];
38
+ readonly onClearAllFilters?: () => void;
39
+ readonly count?: number | { readonly shown: number; readonly total?: number };
40
+ readonly viewSwitcher?: {
41
+ readonly current: string;
42
+ readonly options: readonly ViewSwitcherOption[];
43
+ readonly onChange: (viewId: string) => void;
44
+ };
45
+ readonly actions?: ReactNode;
46
+ readonly children?: ReactNode;
47
+ readonly className?: string;
48
+ }
@@ -0,0 +1,96 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import { MemoryRouter } from 'react-router';
4
+ import { DetailPage } from './DetailPage';
5
+
6
+ describe('DetailPage', () => {
7
+ it('renders notFound empty state when notFound is true', () => {
8
+ render(
9
+ <MemoryRouter>
10
+ <DetailPage
11
+ title="Not Found"
12
+ notFound={{ title: 'Client not found', description: 'Could not find client.' }}
13
+ />
14
+ </MemoryRouter>,
15
+ );
16
+ expect(screen.getByText('Client not found')).toBeTruthy();
17
+ expect(screen.getByText('Could not find client.')).toBeTruthy();
18
+ });
19
+
20
+ it('renders title, description, badge, and back button', () => {
21
+ render(
22
+ <MemoryRouter>
23
+ <DetailPage
24
+ backTo={{ href: '/clients', label: 'All clients' }}
25
+ title="Acme Corp"
26
+ badge={<span>Active</span>}
27
+ description="Enterprise legal client since 2024"
28
+ >
29
+ <div>Main Details</div>
30
+ </DetailPage>
31
+ </MemoryRouter>,
32
+ );
33
+ expect(screen.getByText('Acme Corp')).toBeTruthy();
34
+ expect(screen.getByText('All clients')).toBeTruthy();
35
+ expect(screen.getByText('Active')).toBeTruthy();
36
+ expect(screen.getByText('Enterprise legal client since 2024')).toBeTruthy();
37
+ expect(screen.getByText('Main Details')).toBeTruthy();
38
+ });
39
+
40
+ it('renders tabs and switches active tab on click', () => {
41
+ const handleTabChange = vi.fn();
42
+ render(
43
+ <MemoryRouter>
44
+ <DetailPage
45
+ title="Acme Corp"
46
+ tabs={[
47
+ { id: 'overview', label: 'Overview', content: <div>Overview Content</div> },
48
+ { id: 'cases', label: 'Cases', count: 5, content: <div>Cases Content</div> },
49
+ ]}
50
+ onTabChange={handleTabChange}
51
+ />
52
+ </MemoryRouter>,
53
+ );
54
+ expect(screen.getByText('Overview Content')).toBeTruthy();
55
+ expect(screen.getByText('Cases')).toBeTruthy();
56
+ expect(screen.getByText('5')).toBeTruthy();
57
+
58
+ fireEvent.click(screen.getByText('Cases'));
59
+ expect(handleTabChange).toHaveBeenCalledWith('cases');
60
+ expect(screen.getByText('Cases Content')).toBeTruthy();
61
+ });
62
+
63
+ it('renders sidebar layout when sidebar prop is provided', () => {
64
+ render(
65
+ <MemoryRouter>
66
+ <DetailPage
67
+ title="Acme Corp"
68
+ sidebar={<div>Sidebar Information</div>}
69
+ >
70
+ <div>Body Information</div>
71
+ </DetailPage>
72
+ </MemoryRouter>,
73
+ );
74
+ expect(screen.getByText('Sidebar Information')).toBeTruthy();
75
+ expect(screen.getByText('Body Information')).toBeTruthy();
76
+ });
77
+
78
+ it('renders KPI metrics when provided', () => {
79
+ render(
80
+ <MemoryRouter>
81
+ <DetailPage
82
+ title="Acme Corp"
83
+ kpis={[
84
+ { label: 'Active Matters', value: '12', delta: { value: '+3', direction: 'up' } },
85
+ { label: 'Total Billed', value: '$45,000' },
86
+ ]}
87
+ />
88
+ </MemoryRouter>,
89
+ );
90
+ expect(screen.getByText('Active Matters')).toBeTruthy();
91
+ expect(screen.getByText('12')).toBeTruthy();
92
+ expect(screen.getByText('+3')).toBeTruthy();
93
+ expect(screen.getByText('Total Billed')).toBeTruthy();
94
+ expect(screen.getByText('$45,000')).toBeTruthy();
95
+ });
96
+ });