@pattern-stack/frontend-patterns 0.0.4 → 0.0.5
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.
- package/dist/frontend-patterns.css +1 -1
- package/dist/index.es.js +1917 -2
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1916 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/src/App.tsx +11 -1
- package/src/atoms/composed/SalesPanel/SalesPanel.tsx +116 -0
- package/src/atoms/composed/SalesPanel/index.ts +1 -0
- package/src/atoms/composed/SalesPanel/mockSalesData.ts +151 -0
- package/src/atoms/composed/index.ts +1 -0
- package/src/atoms/types/entity-config.ts +127 -0
- package/src/atoms/types/index.ts +2 -1
- package/src/atoms/utils/metric-engine.ts +236 -0
- package/src/atoms/utils/utils.ts +2 -1
- package/src/molecules/layout/DashboardWithSidePanel/DashboardWithSidePanel.tsx +42 -0
- package/src/molecules/layout/DashboardWithSidePanel/index.ts +1 -0
- package/src/molecules/layout/Sidebar.tsx +10 -2
- package/src/molecules/layout/index.ts +1 -0
- package/src/organisms/entity/CategoryBreakdownPanel.tsx +427 -0
- package/src/organisms/entity/EntityListPanel.tsx +339 -0
- package/src/organisms/entity/MetricsOverviewPanel.tsx +236 -0
- package/src/organisms/entity/TrendAnalysisPanel.tsx +337 -0
- package/src/organisms/entity/index.ts +4 -0
- package/src/organisms/index.ts +4 -1
- package/src/pages/AdminShowcase/AdminDashboardShowcase.tsx +77 -75
- package/src/pages/AdminShowcase/SalesPerformanceDashboard.tsx +158 -0
- package/src/pages/AdminShowcase/index.tsx +2 -1
- package/src/pages/EntityShowcase/EntityManagementShowcase.tsx +137 -0
- package/src/pages/EntityShowcase/EntityPerformanceShowcase.tsx +117 -0
- package/src/pages/EntityShowcase/index.ts +2 -0
- package/src/pages/EntityTemplateExample.tsx +229 -0
- package/src/pages/TestEntityTemplate.tsx +40 -0
- package/src/pages/index.ts +2 -1
- package/src/templates/entity/EntityManagementTemplate.tsx +430 -0
- package/src/templates/entity/EntityPerformanceDashboardTemplate.tsx +277 -0
- package/src/templates/entity/configs/financial-config.ts +141 -0
- package/src/templates/entity/configs/index.ts +1 -0
- package/src/templates/entity/index.ts +3 -0
- package/src/templates/financial/FinancialDashboardTemplate.tsx +326 -0
- package/src/templates/index.ts +3 -0
- package/dist/atoms/composed/Accordion/Accordion.d.ts +0 -20
- package/dist/atoms/composed/Accordion/Accordion.d.ts.map +0 -1
- package/dist/atoms/composed/Accordion/index.d.ts +0 -2
- package/dist/atoms/composed/Accordion/index.d.ts.map +0 -1
- package/dist/atoms/composed/Alert/Alert.d.ts +0 -25
- package/dist/atoms/composed/Alert/Alert.d.ts.map +0 -1
- package/dist/atoms/composed/Alert/index.d.ts +0 -2
- package/dist/atoms/composed/Alert/index.d.ts.map +0 -1
- package/dist/atoms/composed/Breadcrumb/Breadcrumb.d.ts +0 -17
- package/dist/atoms/composed/Breadcrumb/Breadcrumb.d.ts.map +0 -1
- package/dist/atoms/composed/Breadcrumb/index.d.ts +0 -2
- package/dist/atoms/composed/Breadcrumb/index.d.ts.map +0 -1
- package/dist/atoms/composed/Chart/Chart.d.ts +0 -37
- package/dist/atoms/composed/Chart/Chart.d.ts.map +0 -1
- package/dist/atoms/composed/Chart/index.d.ts +0 -3
- package/dist/atoms/composed/Chart/index.d.ts.map +0 -1
- package/dist/atoms/composed/ColorSwatch/ColorSwatch.d.ts +0 -19
- package/dist/atoms/composed/ColorSwatch/ColorSwatch.d.ts.map +0 -1
- package/dist/atoms/composed/ColorSwatch/index.d.ts +0 -2
- package/dist/atoms/composed/ColorSwatch/index.d.ts.map +0 -1
- package/dist/atoms/composed/DarkModeToggle.d.ts +0 -4
- package/dist/atoms/composed/DarkModeToggle.d.ts.map +0 -1
- package/dist/atoms/composed/DataBadge/DataBadge.d.ts +0 -13
- package/dist/atoms/composed/DataBadge/DataBadge.d.ts.map +0 -1
- package/dist/atoms/composed/DataBadge/index.d.ts +0 -2
- package/dist/atoms/composed/DataBadge/index.d.ts.map +0 -1
- package/dist/atoms/composed/DataTable/DataTable.d.ts +0 -28
- package/dist/atoms/composed/DataTable/DataTable.d.ts.map +0 -1
- package/dist/atoms/composed/DataTable/TableCellWithTooltip.d.ts +0 -10
- package/dist/atoms/composed/DataTable/TableCellWithTooltip.d.ts.map +0 -1
- package/dist/atoms/composed/DataTable/index.d.ts +0 -3
- package/dist/atoms/composed/DataTable/index.d.ts.map +0 -1
- package/dist/atoms/composed/DateTimePicker/DateTimePicker.d.ts +0 -45
- package/dist/atoms/composed/DateTimePicker/DateTimePicker.d.ts.map +0 -1
- package/dist/atoms/composed/DateTimePicker/index.d.ts +0 -3
- package/dist/atoms/composed/DateTimePicker/index.d.ts.map +0 -1
- package/dist/atoms/composed/DetailedCard/DetailedCard.d.ts +0 -30
- package/dist/atoms/composed/DetailedCard/DetailedCard.d.ts.map +0 -1
- package/dist/atoms/composed/DetailedCard/index.d.ts +0 -3
- package/dist/atoms/composed/DetailedCard/index.d.ts.map +0 -1
- package/dist/atoms/composed/EmptyState/EmptyState.d.ts +0 -18
- package/dist/atoms/composed/EmptyState/EmptyState.d.ts.map +0 -1
- package/dist/atoms/composed/EmptyState/index.d.ts +0 -2
- package/dist/atoms/composed/EmptyState/index.d.ts.map +0 -1
- package/dist/atoms/composed/FileUpload/FileUpload.d.ts +0 -46
- package/dist/atoms/composed/FileUpload/FileUpload.d.ts.map +0 -1
- package/dist/atoms/composed/FileUpload/index.d.ts +0 -3
- package/dist/atoms/composed/FileUpload/index.d.ts.map +0 -1
- package/dist/atoms/composed/FormField/FormField.d.ts +0 -23
- package/dist/atoms/composed/FormField/FormField.d.ts.map +0 -1
- package/dist/atoms/composed/FormField/index.d.ts +0 -2
- package/dist/atoms/composed/FormField/index.d.ts.map +0 -1
- package/dist/atoms/composed/GlobalSearch/GlobalSearch.d.ts +0 -8
- package/dist/atoms/composed/GlobalSearch/GlobalSearch.d.ts.map +0 -1
- package/dist/atoms/composed/GlobalSearch/index.d.ts +0 -2
- package/dist/atoms/composed/GlobalSearch/index.d.ts.map +0 -1
- package/dist/atoms/composed/IconBadge/IconBadge.d.ts +0 -16
- package/dist/atoms/composed/IconBadge/IconBadge.d.ts.map +0 -1
- package/dist/atoms/composed/IconBadge/index.d.ts +0 -3
- package/dist/atoms/composed/IconBadge/index.d.ts.map +0 -1
- package/dist/atoms/composed/Modal/Modal.d.ts +0 -18
- package/dist/atoms/composed/Modal/Modal.d.ts.map +0 -1
- package/dist/atoms/composed/Modal/index.d.ts +0 -3
- package/dist/atoms/composed/Modal/index.d.ts.map +0 -1
- package/dist/atoms/composed/PaletteSwitcher.d.ts +0 -7
- package/dist/atoms/composed/PaletteSwitcher.d.ts.map +0 -1
- package/dist/atoms/composed/ProgressBar/ProgressBar.d.ts +0 -25
- package/dist/atoms/composed/ProgressBar/ProgressBar.d.ts.map +0 -1
- package/dist/atoms/composed/ProgressBar/index.d.ts +0 -2
- package/dist/atoms/composed/ProgressBar/index.d.ts.map +0 -1
- package/dist/atoms/composed/StatCard/StatCard.d.ts +0 -21
- package/dist/atoms/composed/StatCard/StatCard.d.ts.map +0 -1
- package/dist/atoms/composed/StatCard/index.d.ts +0 -2
- package/dist/atoms/composed/StatCard/index.d.ts.map +0 -1
- package/dist/atoms/composed/StyleGuide.d.ts +0 -3
- package/dist/atoms/composed/StyleGuide.d.ts.map +0 -1
- package/dist/atoms/composed/Toast/Toast.d.ts +0 -40
- package/dist/atoms/composed/Toast/Toast.d.ts.map +0 -1
- package/dist/atoms/composed/Toast/index.d.ts +0 -2
- package/dist/atoms/composed/Toast/index.d.ts.map +0 -1
- package/dist/atoms/composed/Tooltip/Tooltip.d.ts +0 -16
- package/dist/atoms/composed/Tooltip/Tooltip.d.ts.map +0 -1
- package/dist/atoms/composed/Tooltip/index.d.ts +0 -2
- package/dist/atoms/composed/Tooltip/index.d.ts.map +0 -1
- package/dist/atoms/composed/UserAvatar/UserAvatar.d.ts +0 -8
- package/dist/atoms/composed/UserAvatar/UserAvatar.d.ts.map +0 -1
- package/dist/atoms/composed/UserAvatar/index.d.ts +0 -2
- package/dist/atoms/composed/UserAvatar/index.d.ts.map +0 -1
- package/dist/atoms/composed/UserMenu/UserMenu.d.ts +0 -8
- package/dist/atoms/composed/UserMenu/UserMenu.d.ts.map +0 -1
- package/dist/atoms/composed/UserMenu/index.d.ts +0 -2
- package/dist/atoms/composed/UserMenu/index.d.ts.map +0 -1
- package/dist/atoms/composed/index.d.ts +0 -25
- package/dist/atoms/composed/index.d.ts.map +0 -1
- package/dist/atoms/hooks/useApi.d.ts +0 -25
- package/dist/atoms/hooks/useApi.d.ts.map +0 -1
- package/dist/atoms/hooks/useHealth.d.ts +0 -19
- package/dist/atoms/hooks/useHealth.d.ts.map +0 -1
- package/dist/atoms/index.d.ts +0 -9
- package/dist/atoms/index.d.ts.map +0 -1
- package/dist/atoms/services/api/client.d.ts +0 -20
- package/dist/atoms/services/api/client.d.ts.map +0 -1
- package/dist/atoms/services/auth-service.d.ts +0 -24
- package/dist/atoms/services/auth-service.d.ts.map +0 -1
- package/dist/atoms/services/health.d.ts +0 -7
- package/dist/atoms/services/health.d.ts.map +0 -1
- package/dist/atoms/services/index.d.ts +0 -4
- package/dist/atoms/services/index.d.ts.map +0 -1
- package/dist/atoms/shared/config/constants.d.ts +0 -15
- package/dist/atoms/shared/config/constants.d.ts.map +0 -1
- package/dist/atoms/shared/config/dashboard-sizes.d.ts +0 -83
- package/dist/atoms/shared/config/dashboard-sizes.d.ts.map +0 -1
- package/dist/atoms/shared/config/environment.d.ts +0 -10
- package/dist/atoms/shared/config/environment.d.ts.map +0 -1
- package/dist/atoms/shared/index.d.ts +0 -4
- package/dist/atoms/shared/index.d.ts.map +0 -1
- package/dist/atoms/types/auth.d.ts +0 -56
- package/dist/atoms/types/auth.d.ts.map +0 -1
- package/dist/atoms/types/generated.d.ts +0 -1469
- package/dist/atoms/types/generated.d.ts.map +0 -1
- package/dist/atoms/types/index.d.ts +0 -4
- package/dist/atoms/types/index.d.ts.map +0 -1
- package/dist/atoms/types/loading.d.ts +0 -26
- package/dist/atoms/types/loading.d.ts.map +0 -1
- package/dist/atoms/ui/Badge.d.ts +0 -10
- package/dist/atoms/ui/Badge.d.ts.map +0 -1
- package/dist/atoms/ui/ErrorBoundary.d.ts +0 -18
- package/dist/atoms/ui/ErrorBoundary.d.ts.map +0 -1
- package/dist/atoms/ui/Select.d.ts +0 -28
- package/dist/atoms/ui/Select.d.ts.map +0 -1
- package/dist/atoms/ui/Switch.d.ts +0 -9
- package/dist/atoms/ui/Switch.d.ts.map +0 -1
- package/dist/atoms/ui/Tabs.d.ts +0 -30
- package/dist/atoms/ui/Tabs.d.ts.map +0 -1
- package/dist/atoms/ui/avatar.d.ts +0 -7
- package/dist/atoms/ui/avatar.d.ts.map +0 -1
- package/dist/atoms/ui/button.d.ts +0 -14
- package/dist/atoms/ui/button.d.ts.map +0 -1
- package/dist/atoms/ui/card.d.ts +0 -12
- package/dist/atoms/ui/card.d.ts.map +0 -1
- package/dist/atoms/ui/dropdown-menu.d.ts +0 -28
- package/dist/atoms/ui/dropdown-menu.d.ts.map +0 -1
- package/dist/atoms/ui/index.d.ts +0 -15
- package/dist/atoms/ui/index.d.ts.map +0 -1
- package/dist/atoms/ui/input.d.ts +0 -5
- package/dist/atoms/ui/input.d.ts.map +0 -1
- package/dist/atoms/ui/label.d.ts +0 -6
- package/dist/atoms/ui/label.d.ts.map +0 -1
- package/dist/atoms/ui/skeleton.d.ts +0 -3
- package/dist/atoms/ui/skeleton.d.ts.map +0 -1
- package/dist/atoms/ui/spinner.d.ts +0 -14
- package/dist/atoms/ui/spinner.d.ts.map +0 -1
- package/dist/atoms/ui/table.d.ts +0 -11
- package/dist/atoms/ui/table.d.ts.map +0 -1
- package/dist/atoms/utils/animations.d.ts +0 -65
- package/dist/atoms/utils/animations.d.ts.map +0 -1
- package/dist/atoms/utils/tooltip-helpers.d.ts +0 -71
- package/dist/atoms/utils/tooltip-helpers.d.ts.map +0 -1
- package/dist/atoms/utils/utils.d.ts +0 -4
- package/dist/atoms/utils/utils.d.ts.map +0 -1
- package/dist/features/auth/components/LoginForm.d.ts +0 -2
- package/dist/features/auth/components/LoginForm.d.ts.map +0 -1
- package/dist/features/auth/components/LogoutButton.d.ts +0 -2
- package/dist/features/auth/components/LogoutButton.d.ts.map +0 -1
- package/dist/features/auth/components/ProtectedRoute.d.ts +0 -10
- package/dist/features/auth/components/ProtectedRoute.d.ts.map +0 -1
- package/dist/features/auth/components/index.d.ts +0 -4
- package/dist/features/auth/components/index.d.ts.map +0 -1
- package/dist/features/auth/hooks/index.d.ts +0 -3
- package/dist/features/auth/hooks/index.d.ts.map +0 -1
- package/dist/features/auth/hooks/useAuth.d.ts +0 -10
- package/dist/features/auth/hooks/useAuth.d.ts.map +0 -1
- package/dist/features/auth/hooks/usePermissions.d.ts +0 -13
- package/dist/features/auth/hooks/usePermissions.d.ts.map +0 -1
- package/dist/features/auth/index.d.ts +0 -3
- package/dist/features/auth/index.d.ts.map +0 -1
- package/dist/features/index.d.ts +0 -2
- package/dist/features/index.d.ts.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/molecules/forms/FormGroup.d.ts +0 -17
- package/dist/molecules/forms/FormGroup.d.ts.map +0 -1
- package/dist/molecules/forms/SearchInput.d.ts +0 -36
- package/dist/molecules/forms/SearchInput.d.ts.map +0 -1
- package/dist/molecules/forms/index.d.ts +0 -3
- package/dist/molecules/forms/index.d.ts.map +0 -1
- package/dist/molecules/index.d.ts +0 -4
- package/dist/molecules/index.d.ts.map +0 -1
- package/dist/molecules/layout/AppHeader/AppHeader.d.ts +0 -7
- package/dist/molecules/layout/AppHeader/AppHeader.d.ts.map +0 -1
- package/dist/molecules/layout/AppHeader/index.d.ts +0 -2
- package/dist/molecules/layout/AppHeader/index.d.ts.map +0 -1
- package/dist/molecules/layout/AppLayout.d.ts +0 -2
- package/dist/molecules/layout/AppLayout.d.ts.map +0 -1
- package/dist/molecules/layout/PageTemplate.d.ts +0 -19
- package/dist/molecules/layout/PageTemplate.d.ts.map +0 -1
- package/dist/molecules/layout/SectionHeader/SectionHeader.d.ts +0 -24
- package/dist/molecules/layout/SectionHeader/SectionHeader.d.ts.map +0 -1
- package/dist/molecules/layout/SectionHeader/index.d.ts +0 -2
- package/dist/molecules/layout/SectionHeader/index.d.ts.map +0 -1
- package/dist/molecules/layout/ShowcaseSection.d.ts +0 -22
- package/dist/molecules/layout/ShowcaseSection.d.ts.map +0 -1
- package/dist/molecules/layout/Sidebar.d.ts +0 -6
- package/dist/molecules/layout/Sidebar.d.ts.map +0 -1
- package/dist/molecules/layout/SidebarButton/SidebarButton.d.ts +0 -13
- package/dist/molecules/layout/SidebarButton/SidebarButton.d.ts.map +0 -1
- package/dist/molecules/layout/SidebarButton/index.d.ts +0 -2
- package/dist/molecules/layout/SidebarButton/index.d.ts.map +0 -1
- package/dist/molecules/layout/SidebarContext.d.ts +0 -12
- package/dist/molecules/layout/SidebarContext.d.ts.map +0 -1
- package/dist/molecules/layout/index.d.ts +0 -8
- package/dist/molecules/layout/index.d.ts.map +0 -1
- package/dist/molecules/navigation/NavMenu.d.ts +0 -20
- package/dist/molecules/navigation/NavMenu.d.ts.map +0 -1
- package/dist/molecules/navigation/Pagination.d.ts +0 -14
- package/dist/molecules/navigation/Pagination.d.ts.map +0 -1
- package/dist/molecules/navigation/index.d.ts +0 -3
- package/dist/molecules/navigation/index.d.ts.map +0 -1
- package/dist/organisms/index.d.ts +0 -2
- package/dist/organisms/index.d.ts.map +0 -1
- package/dist/organisms/showcase/ComponentShowcasePage.d.ts +0 -3
- package/dist/organisms/showcase/ComponentShowcasePage.d.ts.map +0 -1
- package/dist/templates/AuthTemplate.d.ts +0 -68
- package/dist/templates/AuthTemplate.d.ts.map +0 -1
- package/dist/templates/ComponentShowcaseTemplate.d.ts +0 -53
- package/dist/templates/ComponentShowcaseTemplate.d.ts.map +0 -1
- package/dist/templates/DashboardTemplate.d.ts +0 -62
- package/dist/templates/DashboardTemplate.d.ts.map +0 -1
- package/dist/templates/DataTemplate.d.ts +0 -78
- package/dist/templates/DataTemplate.d.ts.map +0 -1
- package/dist/templates/admin/AdminCRUDTemplate.d.ts +0 -105
- package/dist/templates/admin/AdminCRUDTemplate.d.ts.map +0 -1
- package/dist/templates/admin/AdminDashboardTemplate.d.ts +0 -89
- package/dist/templates/admin/AdminDashboardTemplate.d.ts.map +0 -1
- package/dist/templates/admin/AdminDetailTemplate.d.ts +0 -132
- package/dist/templates/admin/AdminDetailTemplate.d.ts.map +0 -1
- package/dist/templates/admin/index.d.ts +0 -4
- package/dist/templates/admin/index.d.ts.map +0 -1
- package/dist/templates/factory.d.ts +0 -28
- package/dist/templates/factory.d.ts.map +0 -1
- package/dist/templates/index.d.ts +0 -7
- package/dist/templates/index.d.ts.map +0 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { MetricConfig, MetricValue, EntityData, FormatConfig, TrendDataPoint } from '../types';
|
|
2
|
+
|
|
3
|
+
export class MetricCalculationEngine {
|
|
4
|
+
static calculateMetric(
|
|
5
|
+
config: MetricConfig,
|
|
6
|
+
data: EntityData[],
|
|
7
|
+
previousData?: EntityData[]
|
|
8
|
+
): MetricValue {
|
|
9
|
+
const currentValue = this.aggregateValue(config, data);
|
|
10
|
+
const previousValue = previousData ? this.aggregateValue(config, previousData) : undefined;
|
|
11
|
+
|
|
12
|
+
const trend = this.calculateTrend(currentValue, previousValue);
|
|
13
|
+
const formattedValue = this.formatValue(currentValue, config.format, config.type);
|
|
14
|
+
|
|
15
|
+
const target = typeof config.target === 'function'
|
|
16
|
+
? config.target(data)
|
|
17
|
+
: config.target;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
current: currentValue,
|
|
21
|
+
previous: previousValue,
|
|
22
|
+
trend,
|
|
23
|
+
target,
|
|
24
|
+
formattedValue
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private static aggregateValue(config: MetricConfig, data: EntityData[]): number {
|
|
29
|
+
if (!data.length) return 0;
|
|
30
|
+
|
|
31
|
+
const values = data
|
|
32
|
+
.map(item => {
|
|
33
|
+
const value = this.extractValue(item, config.key);
|
|
34
|
+
return typeof value === 'number' ? value : 0;
|
|
35
|
+
})
|
|
36
|
+
.filter(value => !isNaN(value));
|
|
37
|
+
|
|
38
|
+
if (!values.length) return 0;
|
|
39
|
+
|
|
40
|
+
switch (config.aggregation || 'sum') {
|
|
41
|
+
case 'sum':
|
|
42
|
+
return values.reduce((sum, value) => sum + value, 0);
|
|
43
|
+
case 'avg':
|
|
44
|
+
return values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
45
|
+
case 'count':
|
|
46
|
+
return values.length;
|
|
47
|
+
case 'min':
|
|
48
|
+
return Math.min(...values);
|
|
49
|
+
case 'max':
|
|
50
|
+
return Math.max(...values);
|
|
51
|
+
default:
|
|
52
|
+
return values.reduce((sum, value) => sum + value, 0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private static extractValue(item: EntityData, key: string): unknown {
|
|
57
|
+
return key.split('.').reduce((obj: any, k: string) => obj?.[k], item);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private static calculateTrend(current: number, previous?: number): 'up' | 'down' | 'neutral' {
|
|
61
|
+
if (previous === undefined || previous === 0) return 'neutral';
|
|
62
|
+
|
|
63
|
+
const change = ((current - previous) / Math.abs(previous)) * 100;
|
|
64
|
+
|
|
65
|
+
if (change > 1) return 'up';
|
|
66
|
+
if (change < -1) return 'down';
|
|
67
|
+
return 'neutral';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private static formatValue(value: number, format?: FormatConfig, type?: string): string {
|
|
71
|
+
let formatted = value;
|
|
72
|
+
|
|
73
|
+
if (format?.decimals !== undefined) {
|
|
74
|
+
formatted = Number(value.toFixed(format.decimals));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let result = formatted.toString();
|
|
78
|
+
|
|
79
|
+
if (format?.thousands !== false && Math.abs(formatted) >= 1000) {
|
|
80
|
+
result = formatted.toLocaleString();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
switch (type) {
|
|
84
|
+
case 'currency':
|
|
85
|
+
result = new Intl.NumberFormat('en-US', {
|
|
86
|
+
style: 'currency',
|
|
87
|
+
currency: 'USD',
|
|
88
|
+
minimumFractionDigits: format?.decimals ?? 2,
|
|
89
|
+
maximumFractionDigits: format?.decimals ?? 2
|
|
90
|
+
}).format(formatted);
|
|
91
|
+
break;
|
|
92
|
+
case 'percentage':
|
|
93
|
+
result = `${formatted.toFixed(format?.decimals ?? 1)}%`;
|
|
94
|
+
break;
|
|
95
|
+
case 'duration':
|
|
96
|
+
result = this.formatDuration(formatted);
|
|
97
|
+
break;
|
|
98
|
+
case 'ratio':
|
|
99
|
+
result = `${formatted.toFixed(format?.decimals ?? 2)}:1`;
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
if (format?.prefix) result = format.prefix + result;
|
|
103
|
+
if (format?.suffix) result = result + format.suffix;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private static formatDuration(minutes: number): string {
|
|
110
|
+
const hours = Math.floor(minutes / 60);
|
|
111
|
+
const mins = Math.floor(minutes % 60);
|
|
112
|
+
|
|
113
|
+
if (hours > 0) {
|
|
114
|
+
return `${hours}h ${mins}m`;
|
|
115
|
+
}
|
|
116
|
+
return `${mins}m`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static calculateTrendData(
|
|
120
|
+
config: MetricConfig,
|
|
121
|
+
data: EntityData[],
|
|
122
|
+
dateField: string = 'date',
|
|
123
|
+
periods: number = 12
|
|
124
|
+
): TrendDataPoint[] {
|
|
125
|
+
const groupedData = this.groupByPeriod(data, dateField);
|
|
126
|
+
const sortedDates = Object.keys(groupedData).sort();
|
|
127
|
+
|
|
128
|
+
return sortedDates.slice(-periods).map(date => ({
|
|
129
|
+
date,
|
|
130
|
+
value: this.aggregateValue(config, groupedData[date]),
|
|
131
|
+
label: this.formatDateLabel(date)
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private static groupByPeriod(data: EntityData[], dateField: string): Record<string, EntityData[]> {
|
|
136
|
+
return data.reduce((groups, item) => {
|
|
137
|
+
const date = this.extractValue(item, dateField);
|
|
138
|
+
if (!date) return groups;
|
|
139
|
+
|
|
140
|
+
const period = new Date(date as string | number | Date).toISOString().split('T')[0];
|
|
141
|
+
|
|
142
|
+
if (!groups[period]) groups[period] = [];
|
|
143
|
+
groups[period].push(item);
|
|
144
|
+
|
|
145
|
+
return groups;
|
|
146
|
+
}, {} as Record<string, EntityData[]>);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private static formatDateLabel(dateString: string): string {
|
|
150
|
+
const date = new Date(dateString);
|
|
151
|
+
return date.toLocaleDateString('en-US', {
|
|
152
|
+
month: 'short',
|
|
153
|
+
day: 'numeric'
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static calculateCategoryBreakdown(
|
|
158
|
+
data: EntityData[],
|
|
159
|
+
categoryField: string,
|
|
160
|
+
valueField: string,
|
|
161
|
+
maxCategories: number = 8
|
|
162
|
+
) {
|
|
163
|
+
const groups = data.reduce((acc, item) => {
|
|
164
|
+
const category = String(this.extractValue(item, categoryField) || 'Unknown');
|
|
165
|
+
const value = this.extractValue(item, valueField) || 0;
|
|
166
|
+
|
|
167
|
+
if (!acc[category]) acc[category] = 0;
|
|
168
|
+
acc[category] += typeof value === 'number' ? value : 0;
|
|
169
|
+
|
|
170
|
+
return acc;
|
|
171
|
+
}, {} as Record<string, number>);
|
|
172
|
+
|
|
173
|
+
const total = Object.values(groups).reduce((sum, value) => sum + value, 0);
|
|
174
|
+
|
|
175
|
+
let categories = Object.entries(groups)
|
|
176
|
+
.map(([category, value]) => ({
|
|
177
|
+
category,
|
|
178
|
+
value,
|
|
179
|
+
percentage: total > 0 ? (value / total) * 100 : 0
|
|
180
|
+
}))
|
|
181
|
+
.sort((a, b) => b.value - a.value);
|
|
182
|
+
|
|
183
|
+
if (categories.length > maxCategories) {
|
|
184
|
+
const topCategories = categories.slice(0, maxCategories - 1);
|
|
185
|
+
const otherValue = categories.slice(maxCategories - 1)
|
|
186
|
+
.reduce((sum, cat) => sum + cat.value, 0);
|
|
187
|
+
|
|
188
|
+
topCategories.push({
|
|
189
|
+
category: 'Other',
|
|
190
|
+
value: otherValue,
|
|
191
|
+
percentage: total > 0 ? (otherValue / total) * 100 : 0
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
categories = topCategories;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return categories;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
static detectInsights(
|
|
201
|
+
metrics: Record<string, MetricValue>,
|
|
202
|
+
thresholds: Record<string, { warning: number; critical: number }> = {}
|
|
203
|
+
) {
|
|
204
|
+
const insights = [];
|
|
205
|
+
|
|
206
|
+
for (const [key, metric] of Object.entries(metrics)) {
|
|
207
|
+
const threshold = thresholds[key];
|
|
208
|
+
|
|
209
|
+
if (metric.target && metric.current < metric.target * 0.8) {
|
|
210
|
+
insights.push({
|
|
211
|
+
type: 'negative' as const,
|
|
212
|
+
message: `${key} is significantly below target`,
|
|
213
|
+
value: metric.current
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (metric.trend === 'up' && metric.previous && metric.current > metric.previous * 1.2) {
|
|
218
|
+
insights.push({
|
|
219
|
+
type: 'positive' as const,
|
|
220
|
+
message: `${key} showing strong growth`,
|
|
221
|
+
value: metric.current
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (threshold && metric.current >= threshold.critical) {
|
|
226
|
+
insights.push({
|
|
227
|
+
type: 'negative' as const,
|
|
228
|
+
message: `${key} has reached critical threshold`,
|
|
229
|
+
value: metric.current
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return insights.slice(0, 5);
|
|
235
|
+
}
|
|
236
|
+
}
|
package/src/atoms/utils/utils.ts
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { cn } from '../../../atoms/utils/utils';
|
|
3
|
+
|
|
4
|
+
interface DashboardWithSidePanelProps {
|
|
5
|
+
/** Main dashboard content */
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/** Side panel component to display */
|
|
8
|
+
sidePanel?: React.ReactNode;
|
|
9
|
+
/** Whether to show the side panel */
|
|
10
|
+
showSidePanel?: boolean;
|
|
11
|
+
/** Side panel width in Tailwind units (e.g., 72, 80) */
|
|
12
|
+
sidePanelWidth?: number;
|
|
13
|
+
/** Additional CSS classes */
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const DashboardWithSidePanel: React.FC<DashboardWithSidePanelProps> = ({
|
|
18
|
+
children,
|
|
19
|
+
sidePanel,
|
|
20
|
+
showSidePanel = false,
|
|
21
|
+
sidePanelWidth = 72,
|
|
22
|
+
className
|
|
23
|
+
}) => {
|
|
24
|
+
const marginClass = `pr-${sidePanelWidth}`;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div className={cn('relative h-full', className)}>
|
|
28
|
+
{/* Main Dashboard Content */}
|
|
29
|
+
<div
|
|
30
|
+
className={cn(
|
|
31
|
+
'transition-all duration-300',
|
|
32
|
+
showSidePanel ? marginClass : ''
|
|
33
|
+
)}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
{/* Side Panel */}
|
|
39
|
+
{showSidePanel && sidePanel}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DashboardWithSidePanel } from './DashboardWithSidePanel';
|
|
@@ -8,7 +8,11 @@ import {
|
|
|
8
8
|
Menu,
|
|
9
9
|
X,
|
|
10
10
|
Shield,
|
|
11
|
-
Users
|
|
11
|
+
Users,
|
|
12
|
+
BarChart3,
|
|
13
|
+
Database,
|
|
14
|
+
TrendingUp,
|
|
15
|
+
Layout
|
|
12
16
|
} from 'lucide-react';
|
|
13
17
|
|
|
14
18
|
interface SidebarItem {
|
|
@@ -32,7 +36,11 @@ export const Sidebar = ({ className }: SidebarProps) => {
|
|
|
32
36
|
const items: SidebarItem[] = [
|
|
33
37
|
{ value: 'showcase', label: 'Showcase', icon: <Palette className="w-5 h-5" />, path: '/showcase', category: 5 },
|
|
34
38
|
{ value: 'admin-dashboard', label: 'Admin Dashboard', icon: <Shield className="w-5 h-5" />, path: '/admin/dashboard', category: 2 },
|
|
35
|
-
{ value: 'admin-users', label: 'User Management', icon: <Users className="w-5 h-5" />, path: '/admin/users', category: 3 }
|
|
39
|
+
{ value: 'admin-users', label: 'User Management', icon: <Users className="w-5 h-5" />, path: '/admin/users', category: 3 },
|
|
40
|
+
{ value: 'admin-sales', label: 'Sales Dashboard', icon: <TrendingUp className="w-5 h-5" />, path: '/admin/sales', category: 4 },
|
|
41
|
+
{ value: 'entity-performance', label: 'Performance Dashboard', icon: <BarChart3 className="w-5 h-5" />, path: '/entity/performance', category: 6 },
|
|
42
|
+
{ value: 'entity-management', label: 'Entity Management', icon: <Database className="w-5 h-5" />, path: '/entity/management', category: 7 },
|
|
43
|
+
{ value: 'entity-template', label: 'Template Example', icon: <Layout className="w-5 h-5" />, path: '/entity/template-example', category: 1 }
|
|
36
44
|
];
|
|
37
45
|
|
|
38
46
|
const handleNavigation = (path: string) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { PageTemplate, type PageTemplateProps } from './PageTemplate';
|
|
2
2
|
export { ShowcaseSection } from './ShowcaseSection';
|
|
3
3
|
export { AppLayout } from './AppLayout';
|
|
4
|
+
export { DashboardWithSidePanel } from './DashboardWithSidePanel';
|
|
4
5
|
export { SectionHeader } from './SectionHeader';
|
|
5
6
|
export { SidebarButton } from './SidebarButton';
|
|
6
7
|
export { AppHeader } from './AppHeader';
|