@pagamio/frontend-commons-lib 0.8.213 → 0.8.214

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.
Files changed (105) hide show
  1. package/lib/api/TanstackQueryProvider.d.ts +146 -0
  2. package/lib/api/TanstackQueryProvider.js +140 -0
  3. package/lib/api/index.d.ts +2 -0
  4. package/lib/api/index.js +2 -0
  5. package/lib/api/tanstackQuery.d.ts +249 -0
  6. package/lib/api/tanstackQuery.js +299 -0
  7. package/lib/components/layout/Sidebar.js +47 -24
  8. package/lib/components/ui/Sheet.d.ts +1 -1
  9. package/lib/context/SidebarContext.d.ts +10 -0
  10. package/lib/dashboard-visuals-v2/DashboardWrapperV2.d.ts +81 -0
  11. package/lib/dashboard-visuals-v2/DashboardWrapperV2.js +217 -0
  12. package/lib/dashboard-visuals-v2/cards/CardGrid.d.ts +22 -0
  13. package/lib/dashboard-visuals-v2/cards/CardGrid.js +27 -0
  14. package/lib/dashboard-visuals-v2/cards/InfoCard.d.ts +7 -0
  15. package/lib/dashboard-visuals-v2/cards/InfoCard.js +26 -0
  16. package/lib/dashboard-visuals-v2/cards/MetricCard.d.ts +7 -0
  17. package/lib/dashboard-visuals-v2/cards/MetricCard.js +37 -0
  18. package/lib/dashboard-visuals-v2/cards/StatCard.d.ts +7 -0
  19. package/lib/dashboard-visuals-v2/cards/StatCard.js +92 -0
  20. package/lib/dashboard-visuals-v2/cards/TopItemsCard.d.ts +7 -0
  21. package/lib/dashboard-visuals-v2/cards/TopItemsCard.js +34 -0
  22. package/lib/dashboard-visuals-v2/cards/TransactionListCard.d.ts +7 -0
  23. package/lib/dashboard-visuals-v2/cards/TransactionListCard.js +24 -0
  24. package/lib/dashboard-visuals-v2/cards/index.d.ts +9 -0
  25. package/lib/dashboard-visuals-v2/cards/index.js +9 -0
  26. package/lib/dashboard-visuals-v2/charts/AreaChart.d.ts +7 -0
  27. package/lib/dashboard-visuals-v2/charts/AreaChart.js +124 -0
  28. package/lib/dashboard-visuals-v2/charts/BarChart.d.ts +7 -0
  29. package/lib/dashboard-visuals-v2/charts/BarChart.js +106 -0
  30. package/lib/dashboard-visuals-v2/charts/BaseChart.d.ts +61 -0
  31. package/lib/dashboard-visuals-v2/charts/BaseChart.js +173 -0
  32. package/lib/dashboard-visuals-v2/charts/DonutChart.d.ts +7 -0
  33. package/lib/dashboard-visuals-v2/charts/DonutChart.js +108 -0
  34. package/lib/dashboard-visuals-v2/charts/HeatmapChart.d.ts +7 -0
  35. package/lib/dashboard-visuals-v2/charts/HeatmapChart.js +101 -0
  36. package/lib/dashboard-visuals-v2/charts/LineChart.d.ts +7 -0
  37. package/lib/dashboard-visuals-v2/charts/LineChart.js +109 -0
  38. package/lib/dashboard-visuals-v2/charts/MixedChart.d.ts +7 -0
  39. package/lib/dashboard-visuals-v2/charts/MixedChart.js +106 -0
  40. package/lib/dashboard-visuals-v2/charts/PieChart.d.ts +7 -0
  41. package/lib/dashboard-visuals-v2/charts/PieChart.js +10 -0
  42. package/lib/dashboard-visuals-v2/charts/RadialChart.d.ts +7 -0
  43. package/lib/dashboard-visuals-v2/charts/RadialChart.js +72 -0
  44. package/lib/dashboard-visuals-v2/charts/index.d.ts +12 -0
  45. package/lib/dashboard-visuals-v2/charts/index.js +12 -0
  46. package/lib/dashboard-visuals-v2/components/DataFetchingVisual.d.ts +0 -0
  47. package/lib/dashboard-visuals-v2/components/DataFetchingVisual.js +1 -0
  48. package/lib/dashboard-visuals-v2/components/index.d.ts +0 -0
  49. package/lib/dashboard-visuals-v2/components/index.js +1 -0
  50. package/lib/dashboard-visuals-v2/hooks/index.d.ts +4 -0
  51. package/lib/dashboard-visuals-v2/hooks/index.js +4 -0
  52. package/lib/dashboard-visuals-v2/hooks/useChartData.d.ts +72 -0
  53. package/lib/dashboard-visuals-v2/hooks/useChartData.js +122 -0
  54. package/lib/dashboard-visuals-v2/index.d.ts +10 -0
  55. package/lib/dashboard-visuals-v2/index.js +16 -0
  56. package/lib/dashboard-visuals-v2/types/card.types.d.ts +237 -0
  57. package/lib/dashboard-visuals-v2/types/card.types.js +30 -0
  58. package/lib/dashboard-visuals-v2/types/chart.types.d.ts +308 -0
  59. package/lib/dashboard-visuals-v2/types/chart.types.js +25 -0
  60. package/lib/dashboard-visuals-v2/types/index.d.ts +6 -0
  61. package/lib/dashboard-visuals-v2/types/index.js +6 -0
  62. package/lib/dashboard-visuals-v2/utils/index.d.ts +0 -0
  63. package/lib/dashboard-visuals-v2/utils/index.js +1 -0
  64. package/lib/dashboard-visuals-v2/utils/propsTransformer.d.ts +0 -0
  65. package/lib/dashboard-visuals-v2/utils/propsTransformer.js +1 -0
  66. package/lib/dashboard-visuals-v2/visualRegistry.d.ts +59 -0
  67. package/lib/dashboard-visuals-v2/visualRegistry.js +110 -0
  68. package/lib/data-table-v2/DataTable.d.ts +7 -0
  69. package/lib/data-table-v2/DataTable.js +206 -0
  70. package/lib/data-table-v2/components/DataTableBody.d.ts +19 -0
  71. package/lib/data-table-v2/components/DataTableBody.js +20 -0
  72. package/lib/data-table-v2/components/DataTableEmpty.d.ts +17 -0
  73. package/lib/data-table-v2/components/DataTableEmpty.js +13 -0
  74. package/lib/data-table-v2/components/DataTableError.d.ts +16 -0
  75. package/lib/data-table-v2/components/DataTableError.js +14 -0
  76. package/lib/data-table-v2/components/DataTableHeader.d.ts +15 -0
  77. package/lib/data-table-v2/components/DataTableHeader.js +31 -0
  78. package/lib/data-table-v2/components/DataTableLoading.d.ts +14 -0
  79. package/lib/data-table-v2/components/DataTableLoading.js +19 -0
  80. package/lib/data-table-v2/components/DataTablePagination.d.ts +36 -0
  81. package/lib/data-table-v2/components/DataTablePagination.js +20 -0
  82. package/lib/data-table-v2/components/DataTableRowActions.d.ts +13 -0
  83. package/lib/data-table-v2/components/DataTableRowActions.js +57 -0
  84. package/lib/data-table-v2/components/DataTableSearch.d.ts +19 -0
  85. package/lib/data-table-v2/components/DataTableSearch.js +33 -0
  86. package/lib/data-table-v2/components/DataTableToolbar.d.ts +54 -0
  87. package/lib/data-table-v2/components/DataTableToolbar.js +28 -0
  88. package/lib/data-table-v2/components/index.d.ts +12 -0
  89. package/lib/data-table-v2/components/index.js +12 -0
  90. package/lib/data-table-v2/hooks/index.d.ts +4 -0
  91. package/lib/data-table-v2/hooks/index.js +4 -0
  92. package/lib/data-table-v2/hooks/useTableData.d.ts +118 -0
  93. package/lib/data-table-v2/hooks/useTableData.js +210 -0
  94. package/lib/data-table-v2/index.d.ts +9 -0
  95. package/lib/data-table-v2/index.js +12 -0
  96. package/lib/data-table-v2/types/index.d.ts +296 -0
  97. package/lib/data-table-v2/types/index.js +1 -0
  98. package/lib/data-table-v2/utils/export.d.ts +26 -0
  99. package/lib/data-table-v2/utils/export.js +92 -0
  100. package/lib/data-table-v2/utils/index.d.ts +4 -0
  101. package/lib/data-table-v2/utils/index.js +4 -0
  102. package/lib/index.d.ts +4 -0
  103. package/lib/index.js +23 -0
  104. package/lib/styles.css +212 -0
  105. package/package.json +7 -1
@@ -0,0 +1,101 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { BaseChart } from './BaseChart';
4
+ /**
5
+ * Heatmap Chart component
6
+ * Grid-based visualization with color intensity
7
+ */
8
+ export function HeatmapChart({ data = [], series: providedSeries, categories: providedCategories, xKey = 'x', yKey = 'y', valueKey = 'value', colorScale, showValue = true, style, tooltip, xAxis, yAxis, apexOptions, onDataPointClick, ...baseProps }) {
9
+ // Transform data into heatmap series format
10
+ const chartSeries = useMemo(() => {
11
+ if (providedSeries) {
12
+ return providedSeries.map((s) => ({
13
+ name: s.name,
14
+ data: s.data.map((value, index) => ({
15
+ x: providedCategories?.[index] ?? index.toString(),
16
+ y: value,
17
+ })),
18
+ }));
19
+ }
20
+ // Group data by yKey to create series
21
+ const grouped = data.reduce((acc, item) => {
22
+ const yValue = String(item[yKey] ?? '');
23
+ if (!acc[yValue]) {
24
+ acc[yValue] = [];
25
+ }
26
+ acc[yValue].push({
27
+ x: String(item[xKey] ?? ''),
28
+ y: Number(item[valueKey]) || 0,
29
+ });
30
+ return acc;
31
+ }, {});
32
+ return Object.entries(grouped).map(([name, values]) => ({
33
+ name,
34
+ data: values,
35
+ }));
36
+ }, [providedSeries, providedCategories, data, xKey, yKey, valueKey]);
37
+ const isEmpty = chartSeries.length === 0;
38
+ const options = useMemo(() => ({
39
+ chart: {
40
+ events: onDataPointClick
41
+ ? {
42
+ dataPointSelection: (event, chartContext, config) => {
43
+ void event;
44
+ void chartContext;
45
+ const { dataPointIndex, seriesIndex } = config;
46
+ onDataPointClick(dataPointIndex, seriesIndex, data[dataPointIndex]);
47
+ },
48
+ }
49
+ : undefined,
50
+ },
51
+ plotOptions: {
52
+ heatmap: {
53
+ shadeIntensity: 0.5,
54
+ radius: 4,
55
+ useFillColorAsStroke: false,
56
+ colorScale: colorScale ?? {
57
+ ranges: [
58
+ { from: 0, to: 25, color: '#FEF3C7', name: 'Low' },
59
+ { from: 26, to: 50, color: '#FCD34D', name: 'Medium' },
60
+ { from: 51, to: 75, color: '#F59E0B', name: 'High' },
61
+ { from: 76, to: 100, color: '#D97706', name: 'Very High' },
62
+ ],
63
+ },
64
+ },
65
+ },
66
+ dataLabels: {
67
+ enabled: showValue,
68
+ style: {
69
+ fontSize: '12px',
70
+ fontWeight: 500,
71
+ },
72
+ },
73
+ stroke: {
74
+ width: 2,
75
+ colors: ['#fff'],
76
+ },
77
+ xaxis: {
78
+ title: xAxis?.title ? { text: xAxis.title } : undefined,
79
+ labels: {
80
+ show: xAxis?.show !== false,
81
+ formatter: xAxis?.formatter,
82
+ },
83
+ },
84
+ yaxis: {
85
+ title: yAxis?.title ? { text: yAxis.title } : undefined,
86
+ labels: {
87
+ show: yAxis?.show !== false,
88
+ formatter: yAxis?.formatter,
89
+ },
90
+ },
91
+ tooltip: {
92
+ enabled: tooltip?.enabled !== false,
93
+ y: {
94
+ formatter: tooltip?.valueFormatter ?? ((val) => val?.toString() ?? ''),
95
+ },
96
+ },
97
+ ...apexOptions,
98
+ }), [colorScale, showValue, xAxis, yAxis, tooltip, apexOptions, onDataPointClick, data]);
99
+ return (_jsx(BaseChart, { type: "heatmap", options: options, series: chartSeries, isEmpty: isEmpty, style: style, ...baseProps }));
100
+ }
101
+ export default HeatmapChart;
@@ -0,0 +1,7 @@
1
+ import type { ChartDataPoint, LineChartProps } from '../types';
2
+ /**
3
+ * Line Chart component
4
+ * Supports single/multi-series lines with markers
5
+ */
6
+ export declare function LineChart<TData extends ChartDataPoint = ChartDataPoint>({ data, series: providedSeries, categories: providedCategories, xKey, yKey, yKeys, seriesNames, curve, strokeWidth, showMarkers, markerSize, style, tooltip, xAxis, yAxis, apexOptions, onDataPointClick, ...baseProps }: LineChartProps<TData>): import("react/jsx-runtime").JSX.Element;
7
+ export default LineChart;
@@ -0,0 +1,109 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { BaseChart } from './BaseChart';
4
+ /**
5
+ * Line Chart component
6
+ * Supports single/multi-series lines with markers
7
+ */
8
+ export function LineChart({ data = [], series: providedSeries, categories: providedCategories, xKey = 'label', yKey = 'value', yKeys, seriesNames, curve = 'smooth', strokeWidth = 3, showMarkers = true, markerSize = 5, style, tooltip, xAxis, yAxis, apexOptions, onDataPointClick, ...baseProps }) {
9
+ // Build series from data
10
+ const chartSeries = useMemo(() => {
11
+ if (providedSeries) {
12
+ return providedSeries.map((s) => ({
13
+ name: s.name,
14
+ data: s.data,
15
+ }));
16
+ }
17
+ if (yKeys && yKeys.length > 0) {
18
+ return yKeys.map((key, index) => ({
19
+ name: seriesNames?.[index] ?? String(key),
20
+ data: data.map((item) => Number(item[key]) || 0),
21
+ }));
22
+ }
23
+ return [
24
+ {
25
+ name: seriesNames?.[0] ?? String(yKey),
26
+ data: data.map((item) => Number(item[yKey]) || 0),
27
+ },
28
+ ];
29
+ }, [providedSeries, data, yKey, yKeys, seriesNames]);
30
+ // Build categories from data
31
+ const categories = useMemo(() => {
32
+ if (providedCategories)
33
+ return providedCategories;
34
+ return data.map((item) => String(item[xKey] ?? ''));
35
+ }, [providedCategories, data, xKey]);
36
+ const isEmpty = chartSeries.every((s) => s.data.length === 0);
37
+ // Map curve type to ApexCharts
38
+ const curveMap = {
39
+ smooth: 'smooth',
40
+ straight: 'straight',
41
+ stepline: 'stepline',
42
+ };
43
+ const options = useMemo(() => ({
44
+ chart: {
45
+ events: onDataPointClick
46
+ ? {
47
+ markerClick: (event, chartContext, config) => {
48
+ void event;
49
+ void chartContext;
50
+ const { dataPointIndex, seriesIndex } = config;
51
+ onDataPointClick(dataPointIndex, seriesIndex, data[dataPointIndex]);
52
+ },
53
+ }
54
+ : undefined,
55
+ },
56
+ stroke: {
57
+ curve: curveMap[curve] ?? 'smooth',
58
+ width: strokeWidth,
59
+ },
60
+ markers: {
61
+ size: showMarkers ? markerSize : 0,
62
+ strokeWidth: 2,
63
+ hover: {
64
+ size: markerSize + 2,
65
+ },
66
+ },
67
+ xaxis: {
68
+ categories,
69
+ title: xAxis?.title ? { text: xAxis.title } : undefined,
70
+ labels: {
71
+ show: xAxis?.show !== false,
72
+ formatter: xAxis?.formatter,
73
+ },
74
+ type: xAxis?.type,
75
+ },
76
+ yaxis: {
77
+ title: yAxis?.title ? { text: yAxis.title } : undefined,
78
+ labels: {
79
+ show: yAxis?.show !== false,
80
+ formatter: yAxis?.formatter,
81
+ },
82
+ min: yAxis?.min,
83
+ max: yAxis?.max,
84
+ tickAmount: yAxis?.tickAmount,
85
+ },
86
+ tooltip: {
87
+ enabled: tooltip?.enabled !== false,
88
+ shared: tooltip?.shared ?? true,
89
+ y: {
90
+ formatter: tooltip?.valueFormatter,
91
+ },
92
+ },
93
+ ...apexOptions,
94
+ }), [
95
+ curve,
96
+ strokeWidth,
97
+ showMarkers,
98
+ markerSize,
99
+ categories,
100
+ xAxis,
101
+ yAxis,
102
+ tooltip,
103
+ apexOptions,
104
+ onDataPointClick,
105
+ data,
106
+ ]);
107
+ return (_jsx(BaseChart, { type: "line", options: options, series: chartSeries, isEmpty: isEmpty, style: style, ...baseProps }));
108
+ }
109
+ export default LineChart;
@@ -0,0 +1,7 @@
1
+ import type { ChartDataPoint, MixedChartProps } from '../types';
2
+ /**
3
+ * Mixed Chart component
4
+ * Combines bar, line, and area charts in one visualization
5
+ */
6
+ export declare function MixedChart<TData extends ChartDataPoint = ChartDataPoint>({ data, categories: providedCategories, xKey, seriesConfig, style, tooltip, xAxis, yAxis, apexOptions, onDataPointClick, ...baseProps }: MixedChartProps<TData>): import("react/jsx-runtime").JSX.Element;
7
+ export default MixedChart;
@@ -0,0 +1,106 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { BaseChart } from './BaseChart';
4
+ /**
5
+ * Mixed Chart component
6
+ * Combines bar, line, and area charts in one visualization
7
+ */
8
+ export function MixedChart({ data = [], categories: providedCategories, xKey = 'label', seriesConfig, style, tooltip, xAxis, yAxis, apexOptions, onDataPointClick, ...baseProps }) {
9
+ // Build series from seriesConfig
10
+ const chartSeries = useMemo(() => {
11
+ return seriesConfig.map((config) => ({
12
+ name: config.name,
13
+ type: config.type,
14
+ data: data.map((item) => Number(item[config.dataKey]) || 0),
15
+ }));
16
+ }, [data, seriesConfig]);
17
+ // Build categories from data
18
+ const categories = useMemo(() => {
19
+ if (providedCategories)
20
+ return providedCategories;
21
+ return data.map((item) => String(item[xKey] ?? ''));
22
+ }, [providedCategories, data, xKey]);
23
+ // Extract colors from seriesConfig
24
+ const colors = useMemo(() => {
25
+ return seriesConfig.map((config) => config.color).filter(Boolean);
26
+ }, [seriesConfig]);
27
+ const isEmpty = chartSeries.every((s) => s.data.length === 0);
28
+ const options = useMemo(() => ({
29
+ chart: {
30
+ stacked: false,
31
+ events: onDataPointClick
32
+ ? {
33
+ dataPointSelection: (event, chartContext, config) => {
34
+ void event;
35
+ void chartContext;
36
+ const { dataPointIndex, seriesIndex } = config;
37
+ onDataPointClick(dataPointIndex, seriesIndex, data[dataPointIndex]);
38
+ },
39
+ }
40
+ : undefined,
41
+ },
42
+ colors: colors.length > 0 ? colors : undefined,
43
+ stroke: {
44
+ width: seriesConfig.map((config) => (config.type === 'line' ? 3 : 0)),
45
+ curve: 'smooth',
46
+ },
47
+ plotOptions: {
48
+ bar: {
49
+ columnWidth: '50%',
50
+ borderRadius: 4,
51
+ },
52
+ },
53
+ fill: {
54
+ opacity: seriesConfig.map((config) => (config.type === 'area' ? 0.3 : 1)),
55
+ type: seriesConfig.map((config) => (config.type === 'area' ? 'gradient' : 'solid')),
56
+ },
57
+ markers: {
58
+ size: seriesConfig.map((config) => (config.type === 'line' ? 4 : 0)),
59
+ },
60
+ xaxis: {
61
+ categories,
62
+ title: xAxis?.title ? { text: xAxis.title } : undefined,
63
+ labels: {
64
+ show: xAxis?.show !== false,
65
+ formatter: xAxis?.formatter,
66
+ },
67
+ type: xAxis?.type,
68
+ },
69
+ yaxis: Array.isArray(yAxis)
70
+ ? yAxis.map((axis) => ({
71
+ title: axis?.title ? { text: axis.title } : undefined,
72
+ labels: {
73
+ show: axis?.show !== false,
74
+ formatter: axis?.formatter,
75
+ },
76
+ min: axis?.min,
77
+ max: axis?.max,
78
+ tickAmount: axis?.tickAmount,
79
+ }))
80
+ : {
81
+ title: yAxis?.title ? { text: yAxis.title } : undefined,
82
+ labels: {
83
+ show: yAxis?.show !== false,
84
+ formatter: yAxis?.formatter,
85
+ },
86
+ min: yAxis?.min,
87
+ max: yAxis?.max,
88
+ tickAmount: yAxis?.tickAmount,
89
+ },
90
+ tooltip: {
91
+ enabled: tooltip?.enabled !== false,
92
+ shared: tooltip?.shared ?? true,
93
+ y: {
94
+ formatter: tooltip?.valueFormatter,
95
+ },
96
+ },
97
+ legend: {
98
+ position: 'top',
99
+ horizontalAlign: 'left',
100
+ },
101
+ ...apexOptions,
102
+ }), [colors, seriesConfig, categories, xAxis, yAxis, tooltip, apexOptions, onDataPointClick, data]);
103
+ return (_jsx(BaseChart, { type: "line" // ApexCharts uses the individual series types
104
+ , options: options, series: chartSeries, isEmpty: isEmpty, style: style, ...baseProps }));
105
+ }
106
+ export default MixedChart;
@@ -0,0 +1,7 @@
1
+ import type { ChartDataPoint, PieChartProps } from '../types';
2
+ /**
3
+ * Pie Chart component
4
+ * Standard pie chart (donut with no hole)
5
+ */
6
+ export declare function PieChart<TData extends ChartDataPoint = ChartDataPoint>(props: PieChartProps<TData>): import("react/jsx-runtime").JSX.Element;
7
+ export default PieChart;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { DonutChart } from './DonutChart';
3
+ /**
4
+ * Pie Chart component
5
+ * Standard pie chart (donut with no hole)
6
+ */
7
+ export function PieChart(props) {
8
+ return _jsx(DonutChart, { ...props, donutSize: "0%", showTotal: false });
9
+ }
10
+ export default PieChart;
@@ -0,0 +1,7 @@
1
+ import type { RadialChartProps } from '../types';
2
+ /**
3
+ * Radial Chart component
4
+ * Circular gauge/progress visualization
5
+ */
6
+ export declare function RadialChart({ values, labels, showValue, valueFormatter, trackBackground, hollowSize, startAngle, endAngle, style, tooltip, apexOptions, ...baseProps }: RadialChartProps): import("react/jsx-runtime").JSX.Element;
7
+ export default RadialChart;
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import { BaseChart } from './BaseChart';
4
+ /**
5
+ * Radial Chart component
6
+ * Circular gauge/progress visualization
7
+ */
8
+ export function RadialChart({ values, labels, showValue = true, valueFormatter, trackBackground = '#E5E7EB', hollowSize = '65%', startAngle = -135, endAngle = 135, style, tooltip, apexOptions, ...baseProps }) {
9
+ const isEmpty = values.length === 0 || values.every((v) => v === 0);
10
+ const options = useMemo(() => ({
11
+ chart: {
12
+ type: 'radialBar',
13
+ },
14
+ labels,
15
+ plotOptions: {
16
+ radialBar: {
17
+ startAngle,
18
+ endAngle,
19
+ hollow: {
20
+ size: hollowSize,
21
+ background: 'transparent',
22
+ },
23
+ track: {
24
+ background: trackBackground,
25
+ strokeWidth: '100%',
26
+ margin: 5,
27
+ },
28
+ dataLabels: {
29
+ show: showValue,
30
+ name: {
31
+ show: true,
32
+ fontSize: '14px',
33
+ fontWeight: 600,
34
+ color: '#6B7280',
35
+ offsetY: -10,
36
+ },
37
+ value: {
38
+ show: true,
39
+ fontSize: '24px',
40
+ fontWeight: 700,
41
+ color: '#111827',
42
+ offsetY: 5,
43
+ formatter: valueFormatter ?? ((val) => `${val}%`),
44
+ },
45
+ total: {
46
+ show: labels.length > 1,
47
+ label: 'Average',
48
+ fontSize: '14px',
49
+ fontWeight: 600,
50
+ color: '#6B7280',
51
+ formatter: (w) => {
52
+ const avg = Math.round(w.globals.seriesTotals.reduce((a, b) => a + b, 0) / w.globals.series.length);
53
+ return valueFormatter ? valueFormatter(avg) : `${avg}%`;
54
+ },
55
+ },
56
+ },
57
+ },
58
+ },
59
+ stroke: {
60
+ lineCap: 'round',
61
+ },
62
+ tooltip: {
63
+ enabled: tooltip?.enabled !== false,
64
+ y: {
65
+ formatter: tooltip?.valueFormatter ?? valueFormatter ?? ((val) => `${val}%`),
66
+ },
67
+ },
68
+ ...apexOptions,
69
+ }), [labels, startAngle, endAngle, hollowSize, trackBackground, showValue, valueFormatter, tooltip, apexOptions]);
70
+ return (_jsx(BaseChart, { type: "radialBar", options: options, series: values, isEmpty: isEmpty, style: style, ...baseProps }));
71
+ }
72
+ export default RadialChart;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview Charts index - Export all chart components
3
+ */
4
+ export { BaseChart, type BaseChartComponentProps } from './BaseChart';
5
+ export { BarChart } from './BarChart';
6
+ export { LineChart } from './LineChart';
7
+ export { AreaChart } from './AreaChart';
8
+ export { DonutChart } from './DonutChart';
9
+ export { PieChart } from './PieChart';
10
+ export { HeatmapChart } from './HeatmapChart';
11
+ export { RadialChart } from './RadialChart';
12
+ export { MixedChart } from './MixedChart';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview Charts index - Export all chart components
3
+ */
4
+ export { BaseChart } from './BaseChart';
5
+ export { BarChart } from './BarChart';
6
+ export { LineChart } from './LineChart';
7
+ export { AreaChart } from './AreaChart';
8
+ export { DonutChart } from './DonutChart';
9
+ export { PieChart } from './PieChart';
10
+ export { HeatmapChart } from './HeatmapChart';
11
+ export { RadialChart } from './RadialChart';
12
+ export { MixedChart } from './MixedChart';
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @fileoverview Dashboard Visuals V2 Hooks
3
+ */
4
+ export { useChartData, useChartQueryData, type UseChartDataOptions, type UseChartDataResult } from './useChartData';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @fileoverview Dashboard Visuals V2 Hooks
3
+ */
4
+ export { useChartData, useChartQueryData } from './useChartData';
@@ -0,0 +1,72 @@
1
+ import type { ChartQueryProps } from '../types';
2
+ export interface UseChartDataOptions<TData> {
3
+ /** URL to fetch data from */
4
+ url?: string;
5
+ /** HTTP method */
6
+ method?: 'GET' | 'POST';
7
+ /** Request body for POST requests */
8
+ body?: Record<string, unknown>;
9
+ /** Query parameters */
10
+ params?: Record<string, string>;
11
+ /** Transform function for response data */
12
+ transform?: (data: unknown) => TData[];
13
+ /** Whether to enable the query */
14
+ enabled?: boolean;
15
+ /** Stale time in milliseconds (how long data is considered fresh) */
16
+ staleTime?: number;
17
+ /** Garbage collection time in milliseconds */
18
+ gcTime?: number;
19
+ /** Refetch interval in milliseconds (0 = disabled) */
20
+ refetchInterval?: number;
21
+ /** Refetch on window focus */
22
+ refetchOnWindowFocus?: boolean;
23
+ /** Initial data */
24
+ initialData?: TData[];
25
+ /** Query key prefix for cache management */
26
+ queryKeyPrefix?: string;
27
+ }
28
+ export interface UseChartDataResult<TData> {
29
+ /** The fetched and transformed data */
30
+ data: TData[];
31
+ /** Whether the initial fetch is in progress */
32
+ isLoading: boolean;
33
+ /** Whether a background refetch is in progress */
34
+ isFetching: boolean;
35
+ /** Whether there was an error */
36
+ isError: boolean;
37
+ /** The error object if any */
38
+ error: Error | null;
39
+ /** Function to manually refetch data */
40
+ refetch: () => void;
41
+ }
42
+ /**
43
+ * Hook for fetching chart data using TanStack Query
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * const { data, isLoading, error, refetch } = useChartData({
48
+ * url: '/api/sales/monthly',
49
+ * params: { year: '2024' },
50
+ * transform: (raw) => raw.data.map(item => ({
51
+ * name: item.month,
52
+ * value: item.total
53
+ * })),
54
+ * staleTime: 5 * 60 * 1000, // 5 minutes
55
+ * });
56
+ * ```
57
+ */
58
+ export declare function useChartData<TData = unknown>(options: UseChartDataOptions<TData>): UseChartDataResult<TData>;
59
+ /**
60
+ * Props adapter for using ChartQueryProps with useChartData
61
+ *
62
+ * @example
63
+ * ```tsx
64
+ * // In your chart component
65
+ * const { data, isLoading, error } = useChartQueryData(
66
+ * queryProps,
67
+ * staticData // fallback data if no query
68
+ * );
69
+ * ```
70
+ */
71
+ export declare function useChartQueryData<TData>(queryProps: ChartQueryProps | undefined, staticData?: TData[]): UseChartDataResult<TData>;
72
+ export default useChartData;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @fileoverview useChartData hook - Data fetching for V2 charts
3
+ * Uses TanStack Query for declarative, cache-aware data fetching
4
+ */
5
+ import { useCallback, useMemo } from 'react';
6
+ import { useApiQuery } from '../../api/tanstackQuery';
7
+ /**
8
+ * Hook for fetching chart data using TanStack Query
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const { data, isLoading, error, refetch } = useChartData({
13
+ * url: '/api/sales/monthly',
14
+ * params: { year: '2024' },
15
+ * transform: (raw) => raw.data.map(item => ({
16
+ * name: item.month,
17
+ * value: item.total
18
+ * })),
19
+ * staleTime: 5 * 60 * 1000, // 5 minutes
20
+ * });
21
+ * ```
22
+ */
23
+ export function useChartData(options) {
24
+ const { url, method = 'GET', body, params, transform, enabled = true, staleTime, gcTime, refetchInterval, refetchOnWindowFocus, initialData = [], queryKeyPrefix = 'chart', } = options;
25
+ // Build query string for GET requests
26
+ const queryString = useMemo(() => {
27
+ if (!params || Object.keys(params).length === 0)
28
+ return '';
29
+ return '?' + new URLSearchParams(params).toString();
30
+ }, [params]);
31
+ const fullUrl = url ? `${url}${queryString}` : '';
32
+ // Build stable query key
33
+ const queryKey = useMemo(() => [queryKeyPrefix, url, method, params, body].filter(Boolean), [queryKeyPrefix, url, method, params, body]);
34
+ // Use TanStack Query for data fetching
35
+ const { data: rawData, isLoading, isFetching, isError, error, refetch: queryRefetch, } = useApiQuery({
36
+ queryKey,
37
+ endpoint: fullUrl,
38
+ requestConfig: {
39
+ method,
40
+ ...(method === 'POST' && body ? { body: JSON.stringify(body) } : {}),
41
+ },
42
+ enabled: enabled && !!url,
43
+ staleTime,
44
+ gcTime,
45
+ refetchInterval: refetchInterval || false,
46
+ refetchOnWindowFocus: refetchOnWindowFocus ?? false,
47
+ });
48
+ // Transform data if transform function provided
49
+ const transformedData = useMemo(() => {
50
+ if (!rawData)
51
+ return initialData;
52
+ if (transform) {
53
+ try {
54
+ return transform(rawData);
55
+ }
56
+ catch (e) {
57
+ console.error('Error transforming chart data:', e);
58
+ return initialData;
59
+ }
60
+ }
61
+ // Default: assume data is array or has data property
62
+ if (Array.isArray(rawData))
63
+ return rawData;
64
+ if (rawData && typeof rawData === 'object' && 'data' in rawData) {
65
+ return rawData.data;
66
+ }
67
+ return initialData;
68
+ }, [rawData, transform, initialData]);
69
+ // Memoized refetch function
70
+ const refetch = useCallback(() => {
71
+ queryRefetch();
72
+ }, [queryRefetch]);
73
+ return {
74
+ data: transformedData,
75
+ isLoading,
76
+ isFetching,
77
+ isError,
78
+ error: error,
79
+ refetch,
80
+ };
81
+ }
82
+ /**
83
+ * Props adapter for using ChartQueryProps with useChartData
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * // In your chart component
88
+ * const { data, isLoading, error } = useChartQueryData(
89
+ * queryProps,
90
+ * staticData // fallback data if no query
91
+ * );
92
+ * ```
93
+ */
94
+ export function useChartQueryData(queryProps, staticData) {
95
+ const result = useChartData({
96
+ url: queryProps?.url,
97
+ method: queryProps?.method,
98
+ body: queryProps?.body,
99
+ params: queryProps?.params,
100
+ transform: queryProps?.transform,
101
+ enabled: queryProps?.enabled ?? !!queryProps?.url,
102
+ staleTime: queryProps?.staleTime,
103
+ gcTime: queryProps?.gcTime,
104
+ refetchInterval: queryProps?.refetchInterval,
105
+ refetchOnWindowFocus: queryProps?.refetchOnWindowFocus,
106
+ initialData: staticData,
107
+ queryKeyPrefix: queryProps?.queryKey?.[0]?.toString() ?? 'chart',
108
+ });
109
+ // If no query props, return static data
110
+ if (!queryProps?.url) {
111
+ return {
112
+ data: staticData || [],
113
+ isLoading: false,
114
+ isFetching: false,
115
+ isError: false,
116
+ error: null,
117
+ refetch: () => { },
118
+ };
119
+ }
120
+ return result;
121
+ }
122
+ export default useChartData;