@umituz/web-dashboard 6.10.0 → 7.0.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.
- package/package.json +11 -12
- package/src/domains/analytics/components/AnalyticsCard.tsx +11 -0
- package/src/domains/analytics/components/AnalyticsChart.tsx +24 -5
- package/src/domains/analytics/components/AnalyticsLayout.tsx +26 -26
- package/src/domains/analytics/components/MetricCard.tsx +2 -5
- package/src/domains/analytics/hooks/useAnalytics.ts +1 -7
- package/src/domains/analytics/index.ts +0 -1
- package/src/domains/analytics/types/analytics.ts +11 -0
- package/src/domains/analytics/utils/analytics.ts +2 -115
- package/src/domains/analytics/utils/index.ts +0 -1
- package/src/domains/calendar/services/CalendarService.ts +2 -25
- package/src/domains/charts/components.test.tsx +1 -0
- package/src/domains/charts/components.tsx +65 -0
- package/src/domains/layouts/components/BrandLogo.tsx +1 -0
- package/src/domains/layouts/components/DashboardHeader.tsx +57 -21
- package/src/domains/layouts/components/DashboardLayout.test.tsx +40 -22
- package/src/domains/layouts/components/DashboardLayout.tsx +60 -28
- package/src/domains/layouts/components/DashboardSidebar.tsx +34 -33
- package/src/domains/layouts/components/FilterBar.test.tsx +3 -0
- package/src/domains/layouts/components/FilterBar.tsx +5 -9
- package/src/domains/layouts/components/FilterSelect.test.tsx +28 -0
- package/src/domains/layouts/components/FilterSelect.tsx +47 -0
- package/src/domains/layouts/components/PageHeader.test.tsx +18 -0
- package/src/domains/layouts/components/PageHeader.tsx +13 -3
- package/src/domains/layouts/components/SectionHeader.tsx +7 -4
- package/src/domains/layouts/components/index.ts +2 -0
- package/src/domains/layouts/hooks/dashboard.ts +4 -7
- package/src/domains/layouts/types/index.ts +12 -1
- package/src/domains/layouts/types/layout.ts +72 -58
- package/src/domains/layouts/types/sidebar.ts +0 -8
- package/src/domains/layouts/utils/dashboard.test.ts +2 -2
- package/src/domains/layouts/utils/dashboard.ts +15 -11
- package/src/domains/layouts/utils/index.ts +2 -1
- package/src/domains/modules/build.test.tsx +4 -0
- package/src/domains/modules/build.tsx +1 -0
- package/src/domains/onboarding/calc/slider-value-bounds.ts +1 -1
- package/src/domains/onboarding/components/AnimationWrapper.tsx +3 -0
- package/src/domains/onboarding/components/OnboardingErrorBoundary.tsx +6 -0
- package/src/domains/onboarding/components/OnboardingFlow.test.tsx +48 -27
- package/src/domains/onboarding/components/OnboardingFlow.tsx +10 -2
- package/src/domains/onboarding/components/OnboardingIntl.tsx +7 -65
- package/src/domains/onboarding/components/PrimaryButton.tsx +3 -0
- package/src/domains/onboarding/components/ProgressBar.tsx +5 -1
- package/src/domains/onboarding/components/QuestionWrapper.tsx +5 -0
- package/src/domains/onboarding/components/ScreenContainer.tsx +4 -0
- package/src/domains/onboarding/components/SwipeCard.test.tsx +43 -1
- package/src/domains/onboarding/components/SwipeCard.tsx +7 -0
- package/src/domains/onboarding/components/screens/AccountGateScreen.tsx +7 -0
- package/src/domains/onboarding/components/screens/AppDemoScreen.tsx +4 -0
- package/src/domains/onboarding/components/screens/ComparisonScreen.tsx +9 -0
- package/src/domains/onboarding/components/screens/GoalQuestionScreen.tsx +3 -0
- package/src/domains/onboarding/components/screens/PainPointsScreen.tsx +3 -0
- package/src/domains/onboarding/components/screens/PaywallScreen.tsx +17 -0
- package/src/domains/onboarding/components/screens/PermissionPrimingScreen.tsx +10 -0
- package/src/domains/onboarding/components/screens/PersonalizedSolutionScreen.tsx +9 -0
- package/src/domains/onboarding/components/screens/PreferencesScreen.tsx +15 -0
- package/src/domains/onboarding/components/screens/ProcessingScreen.tsx +8 -0
- package/src/domains/onboarding/components/screens/SocialProofScreen.tsx +17 -0
- package/src/domains/onboarding/components/screens/TinderCardsScreen.tsx +12 -0
- package/src/domains/onboarding/components/screens/ValueDeliveryScreen.tsx +9 -0
- package/src/domains/onboarding/components/screens/WelcomeScreen.tsx +7 -0
- package/src/domains/onboarding/hooks/useOnboardingProgress.test.tsx +4 -5
- package/src/domains/onboarding/index.ts +0 -12
- package/src/domains/onboarding/predicates/predicates.test.ts +1 -1
- package/src/domains/onboarding/types/config.ts +1 -1
- package/src/domains/onboarding/types/labels.ts +1 -0
- package/src/domains/onboarding/utils/analytics-dispatch.ts +2 -2
- package/src/domains/onboarding/utils/local-storage-bridge.ts +1 -1
- package/src/domains/onboarding/validation/validation.test.ts +2 -2
- package/src/domains/permissions/PermissionsContext.tsx +6 -18
- package/src/domains/permissions/index.ts +0 -1
- package/src/domains/search/searchItems.test.ts +1 -1
- package/src/domains/search/searchItems.ts +0 -3
- package/src/domains/settings/components/AuditLogList.tsx +14 -7
- package/src/domains/settings/components/PermissionMatrixScreen.tsx +10 -0
- package/src/domains/settings/components/SettingsLayout.tsx +21 -4
- package/src/domains/settings/components/SettingsSection.tsx +13 -7
- package/src/domains/settings/components/UserManagementTable.tsx +16 -9
- package/src/domains/settings/types/settings.ts +7 -1
- package/src/domains/settings/utils/index.ts +0 -1
- package/src/domains/timing/hooks/useCountdown.test.ts +1 -2
- package/src/domains/timing/hooks/useCountdown.ts +0 -4
- package/src/internal/formatPattern.ts +8 -0
- package/src/domains/analytics/utils/i18nKeys.ts +0 -31
- package/src/domains/onboarding/templates/TemplateDemoFallback.tsx +0 -92
- package/src/domains/onboarding/templates/art-onboarding.ts +0 -71
- package/src/domains/onboarding/templates/health-onboarding.ts +0 -92
- package/src/domains/onboarding/templates/index.ts +0 -6
- package/src/domains/onboarding/templates/platform-onboarding.ts +0 -201
- package/src/domains/onboarding/templates/video-onboarding.ts +0 -95
- package/src/domains/permissions/utils/i18nKeys.ts +0 -6
- package/src/domains/settings/utils/i18nKeys.ts +0 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
7
7
|
"types": "./src/index.ts",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"version:major": "npm version major -m 'chore: release v%s'"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
+
"framer-motion": "^12.0.0",
|
|
62
63
|
"react": "^18.0.0 || ^19.0.0",
|
|
63
64
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
64
|
-
"react-router
|
|
65
|
-
"framer-motion": "^12.0.0"
|
|
65
|
+
"react-router": "^6.0.0 || ^7.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependenciesMeta": {
|
|
68
68
|
"framer-motion": {
|
|
@@ -70,24 +70,23 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"
|
|
74
|
-
"lucide-react": "^0.577.0",
|
|
75
|
-
"@umituz/web-localization": "^1.2.1"
|
|
73
|
+
"lucide-react": "^0.577.0"
|
|
76
74
|
},
|
|
77
75
|
"devDependencies": {
|
|
76
|
+
"@testing-library/dom": "^10.4.2",
|
|
77
|
+
"@testing-library/react": "^16.3.3",
|
|
78
78
|
"@types/node": "^22.20.5",
|
|
79
79
|
"@types/react": "^19.2.14",
|
|
80
80
|
"@types/react-dom": "^19.2.3",
|
|
81
81
|
"@typescript-eslint/eslint-plugin": "^8.57.2",
|
|
82
82
|
"@typescript-eslint/parser": "^8.57.2",
|
|
83
|
+
"@umituz/web-design-system": "^4.21.0",
|
|
83
84
|
"eslint": "^10.0.2",
|
|
84
85
|
"framer-motion": "^12.23.12",
|
|
85
|
-
"
|
|
86
|
+
"jsdom": "^29.1.1",
|
|
87
|
+
"react-router": "^7.13.1",
|
|
86
88
|
"typescript": "^5.9.3",
|
|
87
|
-
"vitest": "^5.0.1"
|
|
88
|
-
"@testing-library/dom": "^10.4.2",
|
|
89
|
-
"@testing-library/react": "^16.3.3",
|
|
90
|
-
"jsdom": "^29.1.1"
|
|
89
|
+
"vitest": "^5.0.1"
|
|
91
90
|
},
|
|
92
91
|
"keywords": [
|
|
93
92
|
"dashboard",
|
|
@@ -35,7 +35,9 @@ export const AnalyticsCard = ({
|
|
|
35
35
|
<div className="udb-analytics-card__status" role="status">
|
|
36
36
|
<Loader2 className="udb-spin udb-analytics-card__spinner" aria-hidden="true" />
|
|
37
37
|
</div>
|
|
38
|
+
|
|
38
39
|
</Card>
|
|
40
|
+
|
|
39
41
|
);
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -45,8 +47,11 @@ export const AnalyticsCard = ({
|
|
|
45
47
|
<div className="udb-analytics-card__status udb-analytics-card__status--error" role="alert">
|
|
46
48
|
<AlertCircle className="udb-analytics-card__error-icon" aria-hidden="true" />
|
|
47
49
|
<p className="udb-analytics-card__error-text">{error}</p>
|
|
50
|
+
|
|
48
51
|
</div>
|
|
52
|
+
|
|
49
53
|
</Card>
|
|
54
|
+
|
|
50
55
|
);
|
|
51
56
|
}
|
|
52
57
|
|
|
@@ -55,8 +60,11 @@ export const AnalyticsCard = ({
|
|
|
55
60
|
{(title || description) && (
|
|
56
61
|
<CardHeader>
|
|
57
62
|
{title && <CardTitle>{title}</CardTitle>}
|
|
63
|
+
|
|
58
64
|
{description && <CardDescription>{description}</CardDescription>}
|
|
65
|
+
|
|
59
66
|
</CardHeader>
|
|
67
|
+
|
|
60
68
|
)}
|
|
61
69
|
<CardContent>
|
|
62
70
|
{chart && <AnalyticsChart config={chart} />}
|
|
@@ -66,10 +74,13 @@ export const AnalyticsCard = ({
|
|
|
66
74
|
<MetricCard key={metric.id} metric={metric} size="sm" />
|
|
67
75
|
))}
|
|
68
76
|
</div>
|
|
77
|
+
|
|
69
78
|
)}
|
|
70
79
|
{children}
|
|
71
80
|
</CardContent>
|
|
81
|
+
|
|
72
82
|
</Card>
|
|
83
|
+
|
|
73
84
|
);
|
|
74
85
|
};
|
|
75
86
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { cn } from "@umituz/web-design-system/utils/cn";
|
|
3
|
-
import { useT } from "@umituz/web-localization/react";
|
|
4
3
|
import type { ChartConfig, ChartData, TimeSeriesData } from "../types/analytics";
|
|
5
4
|
import { generateChartColors } from "../utils/analytics";
|
|
6
|
-
import { ANALYTICS_KEYS } from "../utils/i18nKeys";
|
|
7
5
|
|
|
8
6
|
const VIEWBOX_W = 600;
|
|
9
7
|
const DEFAULT_CHART_HEIGHT_PX = 300;
|
|
@@ -68,12 +66,12 @@ const polarPoint = (cx: number, cy: number, r: number, angle: number): [number,
|
|
|
68
66
|
|
|
69
67
|
interface AnalyticsChartProps {
|
|
70
68
|
config: ChartConfig;
|
|
69
|
+
unsupportedLabel?: string;
|
|
71
70
|
className?: string;
|
|
72
71
|
height?: number | string;
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProps) => {
|
|
76
|
-
const t = useT();
|
|
74
|
+
export const AnalyticsChart = ({ config, unsupportedLabel, className, height }: AnalyticsChartProps) => {
|
|
77
75
|
|
|
78
76
|
const chartHeight = height ?? config.height ?? DEFAULT_CHART_HEIGHT_PX;
|
|
79
77
|
const viewBoxH = typeof chartHeight === "number" ? chartHeight : DEFAULT_CHART_HEIGHT_PX;
|
|
@@ -115,8 +113,9 @@ export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProp
|
|
|
115
113
|
|
|
116
114
|
const renderUnsupported = () => (
|
|
117
115
|
<div className="udb-chart__empty" role="alert">
|
|
118
|
-
{
|
|
116
|
+
{unsupportedLabel ?? config.type}
|
|
119
117
|
</div>
|
|
118
|
+
|
|
120
119
|
);
|
|
121
120
|
|
|
122
121
|
const renderCartesian = () => {
|
|
@@ -164,7 +163,9 @@ export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProp
|
|
|
164
163
|
<text className="udb-chart__axis" x={PAD.left - 6} y={y + 4} textAnchor="end">
|
|
165
164
|
{compactFmt.format(value)}
|
|
166
165
|
</text>
|
|
166
|
+
|
|
167
167
|
</g>
|
|
168
|
+
|
|
168
169
|
);
|
|
169
170
|
})}
|
|
170
171
|
|
|
@@ -179,6 +180,7 @@ export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProp
|
|
|
179
180
|
>
|
|
180
181
|
{row.label}
|
|
181
182
|
</text>
|
|
183
|
+
|
|
182
184
|
) : null,
|
|
183
185
|
)}
|
|
184
186
|
|
|
@@ -209,9 +211,12 @@ export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProp
|
|
|
209
211
|
fill={color}
|
|
210
212
|
>
|
|
211
213
|
<title>{`${rows[index].label} — ${key}: ${value}`}</title>
|
|
214
|
+
|
|
212
215
|
</circle>
|
|
216
|
+
|
|
213
217
|
))}
|
|
214
218
|
</g>
|
|
219
|
+
|
|
215
220
|
);
|
|
216
221
|
})}
|
|
217
222
|
|
|
@@ -239,13 +244,17 @@ export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProp
|
|
|
239
244
|
fill={color}
|
|
240
245
|
>
|
|
241
246
|
<title>{`${row.label} — ${key}: ${value}`}</title>
|
|
247
|
+
|
|
242
248
|
</rect>
|
|
249
|
+
|
|
243
250
|
);
|
|
244
251
|
})}
|
|
245
252
|
</g>
|
|
253
|
+
|
|
246
254
|
);
|
|
247
255
|
})}
|
|
248
256
|
</svg>
|
|
257
|
+
|
|
249
258
|
);
|
|
250
259
|
};
|
|
251
260
|
|
|
@@ -285,13 +294,17 @@ export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProp
|
|
|
285
294
|
strokeDashoffset={-offset}
|
|
286
295
|
>
|
|
287
296
|
<title>{`${slice.label}: ${Math.round(slice.fraction * 100)}%`}</title>
|
|
297
|
+
|
|
288
298
|
</circle>
|
|
299
|
+
|
|
289
300
|
);
|
|
290
301
|
offset += dash;
|
|
291
302
|
return element;
|
|
292
303
|
})}
|
|
293
304
|
</g>
|
|
305
|
+
|
|
294
306
|
</svg>
|
|
307
|
+
|
|
295
308
|
);
|
|
296
309
|
}
|
|
297
310
|
|
|
@@ -317,10 +330,13 @@ export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProp
|
|
|
317
330
|
return (
|
|
318
331
|
<path key={`${slice.label}-${index}`} d={path} fill={colors[index % colors.length]}>
|
|
319
332
|
<title>{`${slice.label}: ${Math.round(slice.fraction * 100)}%`}</title>
|
|
333
|
+
|
|
320
334
|
</path>
|
|
335
|
+
|
|
321
336
|
);
|
|
322
337
|
})}
|
|
323
338
|
</svg>
|
|
339
|
+
|
|
324
340
|
);
|
|
325
341
|
};
|
|
326
342
|
|
|
@@ -358,10 +374,13 @@ export const AnalyticsChart = ({ config, className, height }: AnalyticsChartProp
|
|
|
358
374
|
/>
|
|
359
375
|
{item.label}
|
|
360
376
|
</span>
|
|
377
|
+
|
|
361
378
|
))}
|
|
362
379
|
</div>
|
|
380
|
+
|
|
363
381
|
)}
|
|
364
382
|
</div>
|
|
383
|
+
|
|
365
384
|
);
|
|
366
385
|
};
|
|
367
386
|
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { RefreshCw, Download, Calendar, Loader2 } from "lucide-react";
|
|
3
|
-
import { useT } from "@umituz/web-localization/react";
|
|
4
3
|
import { cn } from "@umituz/web-design-system/utils/cn";
|
|
5
4
|
import { Button } from "@umituz/web-design-system/atoms";
|
|
6
5
|
import type { AnalyticsLayoutProps, AnalyticsPeriod } from "../types/analytics";
|
|
7
6
|
import { AnalyticsCard } from "./AnalyticsCard";
|
|
8
7
|
import { MetricCard } from "./MetricCard";
|
|
9
|
-
import { ANALYTICS_KEYS } from "../utils/i18nKeys";
|
|
10
8
|
|
|
11
|
-
const
|
|
12
|
-
'7d': ANALYTICS_KEYS.common.last7Days,
|
|
13
|
-
'30d': ANALYTICS_KEYS.common.last30Days,
|
|
14
|
-
'90d': ANALYTICS_KEYS.common.last90Days,
|
|
15
|
-
'1y': ANALYTICS_KEYS.common.lastYear,
|
|
16
|
-
};
|
|
9
|
+
const DEFAULT_PERIODS: AnalyticsPeriod[] = ["7d", "30d", "90d", "1y"];
|
|
17
10
|
|
|
18
11
|
export const AnalyticsLayout = ({
|
|
19
12
|
config,
|
|
13
|
+
labels,
|
|
20
14
|
title,
|
|
21
15
|
description,
|
|
22
16
|
metrics,
|
|
@@ -32,8 +26,6 @@ export const AnalyticsLayout = ({
|
|
|
32
26
|
onExport,
|
|
33
27
|
children,
|
|
34
28
|
}: AnalyticsLayoutProps) => {
|
|
35
|
-
const t = useT();
|
|
36
|
-
|
|
37
29
|
const visibleMetrics = useMemo(() => metrics ?? [], [metrics]);
|
|
38
30
|
|
|
39
31
|
const showRefreshAction = showRefresh && Boolean(onRefresh);
|
|
@@ -43,16 +35,11 @@ export const AnalyticsLayout = ({
|
|
|
43
35
|
<div className="udb-analytics">
|
|
44
36
|
<div className="udb-analytics__header">
|
|
45
37
|
<div className="udb-analytics__heading">
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
{title ??
|
|
49
|
-
(config?.brandName
|
|
50
|
-
? `${config.brandName} ${t(ANALYTICS_KEYS.layout.title)}`
|
|
51
|
-
: t(ANALYTICS_KEYS.layout.title))}
|
|
52
|
-
</h1>
|
|
53
|
-
)}
|
|
38
|
+
<h1 className="udb-analytics__title">{title ?? labels.title}</h1>
|
|
39
|
+
|
|
54
40
|
{description && (
|
|
55
41
|
<p className="udb-analytics__description">{description}</p>
|
|
42
|
+
|
|
56
43
|
)}
|
|
57
44
|
</div>
|
|
58
45
|
|
|
@@ -60,20 +47,24 @@ export const AnalyticsLayout = ({
|
|
|
60
47
|
{showDateRange && onPeriodChange && period && (
|
|
61
48
|
<label className="udb-period-select">
|
|
62
49
|
<Calendar className="udb-period-select__icon" aria-hidden="true" />
|
|
63
|
-
<span className="udb-sr-only">{
|
|
50
|
+
<span className="udb-sr-only">{labels.periodSelector}</span>
|
|
51
|
+
|
|
64
52
|
<select
|
|
65
53
|
className="udb-period-select__select"
|
|
66
54
|
value={period}
|
|
67
55
|
onChange={(e) => onPeriodChange(e.target.value as AnalyticsPeriod)}
|
|
68
|
-
aria-label={
|
|
56
|
+
aria-label={labels.periodSelector}
|
|
69
57
|
>
|
|
70
|
-
{(config?.availablePeriods ??
|
|
58
|
+
{(config?.availablePeriods ?? DEFAULT_PERIODS).map((p) => (
|
|
71
59
|
<option key={p} value={p}>
|
|
72
|
-
{
|
|
60
|
+
{labels.periods[p] ?? p}
|
|
73
61
|
</option>
|
|
62
|
+
|
|
74
63
|
))}
|
|
75
64
|
</select>
|
|
65
|
+
|
|
76
66
|
</label>
|
|
67
|
+
|
|
77
68
|
)}
|
|
78
69
|
|
|
79
70
|
{showRefreshAction && (
|
|
@@ -82,13 +73,14 @@ export const AnalyticsLayout = ({
|
|
|
82
73
|
size="sm"
|
|
83
74
|
onClick={onRefresh}
|
|
84
75
|
disabled={loading}
|
|
85
|
-
aria-label={
|
|
76
|
+
aria-label={labels.refresh}
|
|
86
77
|
>
|
|
87
78
|
<RefreshCw
|
|
88
79
|
className={cn("udb-analytics__action-icon", loading && "udb-spin")}
|
|
89
80
|
aria-hidden="true"
|
|
90
81
|
/>
|
|
91
82
|
</Button>
|
|
83
|
+
|
|
92
84
|
)}
|
|
93
85
|
|
|
94
86
|
{showExportAction && (
|
|
@@ -97,15 +89,18 @@ export const AnalyticsLayout = ({
|
|
|
97
89
|
size="sm"
|
|
98
90
|
onClick={onExport}
|
|
99
91
|
disabled={loading}
|
|
100
|
-
aria-label={
|
|
92
|
+
aria-label={labels.export}
|
|
101
93
|
>
|
|
102
94
|
<Download className="udb-analytics__action-icon" aria-hidden="true" />
|
|
103
|
-
<span>{
|
|
95
|
+
<span>{labels.export}</span>
|
|
96
|
+
|
|
104
97
|
</Button>
|
|
98
|
+
|
|
105
99
|
)}
|
|
106
100
|
|
|
107
101
|
{headerContent}
|
|
108
102
|
</div>
|
|
103
|
+
|
|
109
104
|
</div>
|
|
110
105
|
|
|
111
106
|
{loading && (
|
|
@@ -115,8 +110,10 @@ export const AnalyticsLayout = ({
|
|
|
115
110
|
aria-live="polite"
|
|
116
111
|
>
|
|
117
112
|
<Loader2 className="udb-spin udb-analytics__loading-spinner" aria-hidden="true" />
|
|
118
|
-
<span className="udb-sr-only">{
|
|
113
|
+
<span className="udb-sr-only">{labels.loading}</span>
|
|
114
|
+
|
|
119
115
|
</div>
|
|
116
|
+
|
|
120
117
|
)}
|
|
121
118
|
|
|
122
119
|
{!loading && visibleMetrics.length > 0 && (
|
|
@@ -130,6 +127,7 @@ export const AnalyticsLayout = ({
|
|
|
130
127
|
<MetricCard key={metric.id} metric={metric} />
|
|
131
128
|
))}
|
|
132
129
|
</div>
|
|
130
|
+
|
|
133
131
|
)}
|
|
134
132
|
|
|
135
133
|
{!loading && charts && charts.length > 0 && (
|
|
@@ -143,10 +141,12 @@ export const AnalyticsLayout = ({
|
|
|
143
141
|
/>
|
|
144
142
|
))}
|
|
145
143
|
</div>
|
|
144
|
+
|
|
146
145
|
)}
|
|
147
146
|
|
|
148
147
|
{!loading && children}
|
|
149
148
|
</div>
|
|
149
|
+
|
|
150
150
|
);
|
|
151
151
|
};
|
|
152
152
|
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MetricCard as DSMetricCard,
|
|
3
3
|
} from "@umituz/web-design-system/organisms";
|
|
4
|
-
import { useT } from "@umituz/web-localization/react";
|
|
5
4
|
import type { MetricCardProps } from "../types/analytics";
|
|
6
5
|
import { formatMetricValue, calculateGrowth, getTrend } from "../utils/analytics";
|
|
7
|
-
import { ANALYTICS_KEYS } from "../utils/i18nKeys";
|
|
8
6
|
|
|
9
7
|
export const MetricCard = ({
|
|
10
8
|
metric,
|
|
11
9
|
size = "md",
|
|
12
10
|
showTrend = true,
|
|
13
11
|
showIcon = true,
|
|
12
|
+
lastPeriodLabel = "",
|
|
14
13
|
className,
|
|
15
14
|
onClick,
|
|
16
15
|
}: MetricCardProps) => {
|
|
17
|
-
const t = useT();
|
|
18
|
-
|
|
19
16
|
const hasPrevious = metric.previousValue !== undefined;
|
|
20
17
|
const growth = hasPrevious ? calculateGrowth(metric.value, metric.previousValue as number) : null;
|
|
21
18
|
const trend = growth !== null ? getTrend(growth) : "stable";
|
|
@@ -32,7 +29,7 @@ export const MetricCard = ({
|
|
|
32
29
|
showTrend && growth !== null && trend !== "stable"
|
|
33
30
|
? {
|
|
34
31
|
value: growth,
|
|
35
|
-
label:
|
|
32
|
+
label: lastPeriodLabel,
|
|
36
33
|
}
|
|
37
34
|
: undefined
|
|
38
35
|
}
|
|
@@ -113,8 +113,7 @@ export function useAnalytics(options: UseAnalyticsOptions): UseAnalyticsReturn {
|
|
|
113
113
|
document.body.removeChild(link);
|
|
114
114
|
URL.revokeObjectURL(url);
|
|
115
115
|
} catch (err) {
|
|
116
|
-
|
|
117
|
-
// so callers that trigger the export programmatically can react.
|
|
116
|
+
|
|
118
117
|
setError(toErrorMessage(err, 'Failed to export analytics'));
|
|
119
118
|
throw toError(err, 'Failed to export analytics');
|
|
120
119
|
}
|
|
@@ -149,11 +148,6 @@ export function useAnalytics(options: UseAnalyticsOptions): UseAnalyticsReturn {
|
|
|
149
148
|
);
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
/**
|
|
153
|
-
* Convenience factory: returns a stub client that throws. Useful
|
|
154
|
-
* in Storybook / tests; the consumer must wire a real client
|
|
155
|
-
* before the hook is useful in production.
|
|
156
|
-
*/
|
|
157
151
|
export const createStubAnalyticsApiClient = (
|
|
158
152
|
overrides?: Partial<AnalyticsApiClient>,
|
|
159
153
|
): AnalyticsApiClient => {
|
|
@@ -100,6 +100,7 @@ export type AnalyticsPeriod = '7d' | '30d' | '90d' | '1y' | (string & {});
|
|
|
100
100
|
|
|
101
101
|
export interface MetricCardProps {
|
|
102
102
|
metric: Metric;
|
|
103
|
+
lastPeriodLabel?: string;
|
|
103
104
|
size?: "sm" | "md" | "lg";
|
|
104
105
|
showTrend?: boolean;
|
|
105
106
|
showIcon?: boolean;
|
|
@@ -119,8 +120,18 @@ export interface AnalyticsCardProps {
|
|
|
119
120
|
children?: React.ReactNode;
|
|
120
121
|
}
|
|
121
122
|
|
|
123
|
+
export interface AnalyticsLayoutLabels {
|
|
124
|
+
title: string;
|
|
125
|
+
periodSelector: string;
|
|
126
|
+
periods: Record<AnalyticsPeriod, string>;
|
|
127
|
+
refresh: string;
|
|
128
|
+
export: string;
|
|
129
|
+
loading: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
122
132
|
export interface AnalyticsLayoutProps {
|
|
123
133
|
config?: AnalyticsConfig;
|
|
134
|
+
labels: AnalyticsLayoutLabels;
|
|
124
135
|
title?: string;
|
|
125
136
|
description?: string;
|
|
126
137
|
metrics?: Metric[];
|
|
@@ -19,15 +19,6 @@ export function formatPercentage(value: number, decimals: number = 1): string {
|
|
|
19
19
|
return `${value.toFixed(decimals)}%`;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Format currency
|
|
24
|
-
*
|
|
25
|
-
* @param value - Value to format
|
|
26
|
-
* @param currency - Currency code (default: USD)
|
|
27
|
-
* @param decimals - Number of decimal places (default: 0)
|
|
28
|
-
* @param locale - BCP 47 locale (default: en-US)
|
|
29
|
-
* @returns Formatted currency string
|
|
30
|
-
*/
|
|
31
22
|
export function formatCurrency(
|
|
32
23
|
value: number,
|
|
33
24
|
currency: string = "USD",
|
|
@@ -42,37 +33,17 @@ export function formatCurrency(
|
|
|
42
33
|
}).format(value);
|
|
43
34
|
}
|
|
44
35
|
|
|
45
|
-
/**
|
|
46
|
-
* Calculate growth rate
|
|
47
|
-
*
|
|
48
|
-
* @param current - Current value
|
|
49
|
-
* @param previous - Previous value
|
|
50
|
-
* @returns Growth rate percentage
|
|
51
|
-
*/
|
|
52
36
|
export function calculateGrowth(current: number, previous: number): number {
|
|
53
37
|
if (previous === 0) return current > 0 ? 100 : 0;
|
|
54
38
|
return ((current - previous) / previous) * 100;
|
|
55
39
|
}
|
|
56
40
|
|
|
57
|
-
/**
|
|
58
|
-
* Get trend direction from growth
|
|
59
|
-
*
|
|
60
|
-
* @param growth - Growth rate
|
|
61
|
-
* @returns Trend direction
|
|
62
|
-
*/
|
|
63
41
|
export function getTrend(growth: number): "up" | "down" | "stable" {
|
|
64
42
|
if (growth > 0.1) return "up";
|
|
65
43
|
if (growth < -0.1) return "down";
|
|
66
44
|
return "stable";
|
|
67
45
|
}
|
|
68
46
|
|
|
69
|
-
/**
|
|
70
|
-
* Create KPI data object
|
|
71
|
-
*
|
|
72
|
-
* @param current - Current value
|
|
73
|
-
* @param previous - Previous value
|
|
74
|
-
* @returns KPI data object
|
|
75
|
-
*/
|
|
76
47
|
export function createKPI(current: number, previous: number): KPIData {
|
|
77
48
|
const growth = calculateGrowth(current, previous);
|
|
78
49
|
return {
|
|
@@ -82,16 +53,6 @@ export function createKPI(current: number, previous: number): KPIData {
|
|
|
82
53
|
};
|
|
83
54
|
}
|
|
84
55
|
|
|
85
|
-
/**
|
|
86
|
-
* Create metric object
|
|
87
|
-
*
|
|
88
|
-
* @param id - Metric ID
|
|
89
|
-
* @param name - Metric name
|
|
90
|
-
* @param value - Current value
|
|
91
|
-
* @param previousValue - Previous value
|
|
92
|
-
* @param unit - Optional unit
|
|
93
|
-
* @returns Metric object
|
|
94
|
-
*/
|
|
95
56
|
export function createMetric(
|
|
96
57
|
id: string,
|
|
97
58
|
name: string,
|
|
@@ -110,12 +71,6 @@ export function createMetric(
|
|
|
110
71
|
};
|
|
111
72
|
}
|
|
112
73
|
|
|
113
|
-
/**
|
|
114
|
-
* Format metric value based on unit
|
|
115
|
-
*
|
|
116
|
-
* @param metric - Metric object
|
|
117
|
-
* @returns Formatted value string
|
|
118
|
-
*/
|
|
119
74
|
export function formatMetricValue(metric: Metric): string {
|
|
120
75
|
const { value, unit } = metric;
|
|
121
76
|
|
|
@@ -135,37 +90,16 @@ export function formatMetricValue(metric: Metric): string {
|
|
|
135
90
|
}
|
|
136
91
|
}
|
|
137
92
|
|
|
138
|
-
/**
|
|
139
|
-
* Calculate conversion rate
|
|
140
|
-
*
|
|
141
|
-
* @param converted - Number of conversions
|
|
142
|
-
* @param total - Total number of users
|
|
143
|
-
* @returns Conversion rate percentage
|
|
144
|
-
*/
|
|
145
93
|
export function calculateConversionRate(converted: number, total: number): number {
|
|
146
94
|
if (total === 0) return 0;
|
|
147
95
|
return (converted / total) * 100;
|
|
148
96
|
}
|
|
149
97
|
|
|
150
|
-
/**
|
|
151
|
-
* Calculate drop-off rate
|
|
152
|
-
*
|
|
153
|
-
* @param current - Current step count
|
|
154
|
-
* @param previous - Previous step count
|
|
155
|
-
* @returns Drop-off rate percentage
|
|
156
|
-
*/
|
|
157
98
|
export function calculateDropOffRate(current: number, previous: number): number {
|
|
158
99
|
if (previous === 0) return 0;
|
|
159
100
|
return ((previous - current) / previous) * 100;
|
|
160
101
|
}
|
|
161
102
|
|
|
162
|
-
/**
|
|
163
|
-
* Generate date range preset
|
|
164
|
-
*
|
|
165
|
-
* @param label - Preset label
|
|
166
|
-
* @param days - Number of days
|
|
167
|
-
* @returns Date range preset with resolved `from`/`to` ISO dates
|
|
168
|
-
*/
|
|
169
103
|
export function createDateRangePreset(label: string, days: number): DateRangePreset {
|
|
170
104
|
const to = new Date();
|
|
171
105
|
const from = new Date();
|
|
@@ -180,11 +114,6 @@ export function createDateRangePreset(label: string, days: number): DateRangePre
|
|
|
180
114
|
};
|
|
181
115
|
}
|
|
182
116
|
|
|
183
|
-
/**
|
|
184
|
-
* Get common date range presets
|
|
185
|
-
*
|
|
186
|
-
* @returns Array of date range presets
|
|
187
|
-
*/
|
|
188
117
|
export function getDateRangePresets(): DateRangePreset[] {
|
|
189
118
|
return [
|
|
190
119
|
createDateRangePreset("Last 7 Days", 7),
|
|
@@ -195,13 +124,6 @@ export function getDateRangePresets(): DateRangePreset[] {
|
|
|
195
124
|
];
|
|
196
125
|
}
|
|
197
126
|
|
|
198
|
-
/**
|
|
199
|
-
* Aggregate data by time period
|
|
200
|
-
*
|
|
201
|
-
* @param data - Array of data points with date field
|
|
202
|
-
* @param period - Aggregation period (day, week, month)
|
|
203
|
-
* @returns Aggregated data
|
|
204
|
-
*/
|
|
205
127
|
export function aggregateByPeriod(
|
|
206
128
|
data: Array<{ date: string; [key: string]: number | string }>,
|
|
207
129
|
period: "day" | "week" | "month" = "day"
|
|
@@ -219,7 +141,7 @@ export function aggregateByPeriod(
|
|
|
219
141
|
weekStart.setDate(date.getDate() - date.getDay());
|
|
220
142
|
key = weekStart.toISOString().split("T")[0];
|
|
221
143
|
} else {
|
|
222
|
-
|
|
144
|
+
|
|
223
145
|
key = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
|
|
224
146
|
}
|
|
225
147
|
|
|
@@ -249,13 +171,6 @@ export function aggregateByPeriod(
|
|
|
249
171
|
});
|
|
250
172
|
}
|
|
251
173
|
|
|
252
|
-
/**
|
|
253
|
-
* Calculate moving average
|
|
254
|
-
*
|
|
255
|
-
* @param data - Array of numbers
|
|
256
|
-
* @param window - Window size
|
|
257
|
-
* @returns Array of moving averages
|
|
258
|
-
*/
|
|
259
174
|
export function calculateMovingAverage(data: number[], window: number): number[] {
|
|
260
175
|
if (window < 1) {
|
|
261
176
|
throw new RangeError(`calculateMovingAverage: window must be >= 1, received ${window}`);
|
|
@@ -273,13 +188,6 @@ export function calculateMovingAverage(data: number[], window: number): number[]
|
|
|
273
188
|
return result;
|
|
274
189
|
}
|
|
275
190
|
|
|
276
|
-
/**
|
|
277
|
-
* Detect outliers in data
|
|
278
|
-
*
|
|
279
|
-
* @param data - Array of numbers
|
|
280
|
-
* @param threshold - Standard deviation threshold (default: 2)
|
|
281
|
-
* @returns Array of outlier indices
|
|
282
|
-
*/
|
|
283
191
|
export function detectOutliers(data: number[], threshold: number = 2): number[] {
|
|
284
192
|
if (data.length === 0) return [];
|
|
285
193
|
|
|
@@ -293,37 +201,16 @@ export function detectOutliers(data: number[], threshold: number = 2): number[]
|
|
|
293
201
|
.map(({ index }) => index);
|
|
294
202
|
}
|
|
295
203
|
|
|
296
|
-
/**
|
|
297
|
-
* Round to decimal places
|
|
298
|
-
*
|
|
299
|
-
* @param num - Number to round
|
|
300
|
-
* @param decimals - Decimal places (default: 2)
|
|
301
|
-
* @returns Rounded number
|
|
302
|
-
*/
|
|
303
204
|
export function roundTo(num: number, decimals: number = 2): number {
|
|
304
205
|
const multiplier = Math.pow(10, decimals);
|
|
305
206
|
return Math.round(num * multiplier) / multiplier;
|
|
306
207
|
}
|
|
307
208
|
|
|
308
|
-
/**
|
|
309
|
-
* Generate random color
|
|
310
|
-
*
|
|
311
|
-
* @param index - Color index
|
|
312
|
-
* @param alpha - Alpha value (0-1)
|
|
313
|
-
* @returns HSL color string
|
|
314
|
-
*/
|
|
315
209
|
export function generateColor(index: number, alpha: number = 1): string {
|
|
316
|
-
const hue = (index * 137.508) % 360;
|
|
210
|
+
const hue = (index * 137.508) % 360;
|
|
317
211
|
return `hsla(${hue}, 70%, 50%, ${alpha})`;
|
|
318
212
|
}
|
|
319
213
|
|
|
320
|
-
/**
|
|
321
|
-
* Generate chart colors
|
|
322
|
-
*
|
|
323
|
-
* @param count - Number of colors
|
|
324
|
-
* @param alpha - Alpha value (0-1)
|
|
325
|
-
* @returns Array of color strings
|
|
326
|
-
*/
|
|
327
214
|
export function generateChartColors(count: number, alpha: number = 1): string[] {
|
|
328
215
|
return Array.from({ length: count }, (_, i) => generateColor(i, alpha));
|
|
329
216
|
}
|