@object-ui/plugin-charts 0.3.1 → 2.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/src/index.tsx CHANGED
@@ -6,49 +6,19 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
 
9
- import React, { Suspense } from 'react';
10
9
  import { ComponentRegistry } from '@object-ui/core';
11
- import { Skeleton } from '@object-ui/components';
12
- import type { ChartConfig } from './ChartContainerImpl';
10
+ import { ChartBarRenderer, ChartRenderer } from './ChartRenderer';
11
+ import { ObjectChart } from './ObjectChart';
13
12
 
14
13
  // Export types for external use
15
14
  export type { BarChartSchema } from './types';
15
+ export { ChartBarRenderer, ChartRenderer };
16
+ export { ObjectChart } from './ObjectChart';
16
17
 
17
- // 🚀 Lazy load the implementation files
18
- // This ensures Recharts is only loaded when the component is actually rendered
19
- const LazyChart = React.lazy(() => import('./ChartImpl'));
20
- const LazyAdvancedChart = React.lazy(() => import('./AdvancedChartImpl'));
21
-
22
- export interface ChartBarRendererProps {
23
- schema: {
24
- type: string;
25
- id?: string;
26
- className?: string;
27
- data?: Array<Record<string, any>>;
28
- dataKey?: string;
29
- xAxisKey?: string;
30
- height?: number;
31
- color?: string;
32
- };
33
- }
34
-
35
- /**
36
- * ChartBarRenderer - The public API for the bar chart component
37
- * This wrapper handles lazy loading internally using React.Suspense
38
- */
39
- export const ChartBarRenderer: React.FC<ChartBarRendererProps> = ({ schema }) => {
40
- return (
41
- <Suspense fallback={<Skeleton className="w-full h-[400px]" />}>
42
- <LazyChart
43
- data={schema.data}
44
- dataKey={schema.dataKey}
45
- xAxisKey={schema.xAxisKey}
46
- height={schema.height}
47
- className={schema.className}
48
- color={schema.color}
49
- />
50
- </Suspense>
51
- );
18
+ // Standard Export Protocol - for manual integration
19
+ export const chartComponents = {
20
+ 'bar-chart': ChartBarRenderer,
21
+ 'chart': ChartRenderer,
52
22
  };
53
23
 
54
24
  // Register the component with the ComponentRegistry
@@ -56,6 +26,7 @@ ComponentRegistry.register(
56
26
  'bar-chart',
57
27
  ChartBarRenderer,
58
28
  {
29
+ namespace: 'plugin-charts',
59
30
  label: 'Bar Chart',
60
31
  category: 'plugin',
61
32
  inputs: [
@@ -80,88 +51,24 @@ ComponentRegistry.register(
80
51
  },
81
52
  }
82
53
  );
83
-
84
- // Advanced Chart Renderer with multiple chart types
85
- export interface ChartRendererProps {
86
- schema: {
87
- type: string;
88
- id?: string;
89
- className?: string;
90
- chartType?: 'bar' | 'line' | 'area';
91
- data?: Array<Record<string, any>>;
92
- config?: Record<string, any>;
93
- xAxisKey?: string;
94
- series?: Array<{ dataKey: string }>;
95
- };
96
- }
97
-
98
- /**
99
- * ChartRenderer - The public API for the advanced chart component
100
- * Supports multiple chart types (bar, line, area) with full configuration
101
- */
102
- export const ChartRenderer: React.FC<ChartRendererProps> = ({ schema }) => {
103
- // ⚡️ Adapter: Normalize JSON schema to Recharts Props
104
- const props = React.useMemo(() => {
105
- // 1. Defaults
106
- let series = schema.series;
107
- let xAxisKey = schema.xAxisKey;
108
- let config = schema.config;
109
-
110
- // 2. Adapt Tremor/Simple format (categories -> series, index -> xAxisKey)
111
- if (!xAxisKey) {
112
- if ((schema as any).index) xAxisKey = (schema as any).index;
113
- else if ((schema as any).category) xAxisKey = (schema as any).category; // Support Pie/Donut category
114
- }
115
-
116
- if (!series) {
117
- if ((schema as any).categories) {
118
- series = (schema as any).categories.map((cat: string) => ({ dataKey: cat }));
119
- } else if ((schema as any).value) {
120
- // Single value adapter (for Pie/Simple charts)
121
- series = [{ dataKey: (schema as any).value }];
122
- }
123
- }
124
-
125
- // 3. Auto-generate config/colors if missing
126
- if (!config && series) {
127
- const colors = (schema as any).colors || ['hsl(var(--chart-1))', 'hsl(var(--chart-2))', 'hsl(var(--chart-3))'];
128
- const newConfig: ChartConfig = {};
129
- series.forEach((s: any, idx: number) => {
130
- newConfig[s.dataKey] = { label: s.dataKey, color: colors[idx % colors.length] };
131
- });
132
- config = newConfig;
133
- }
134
-
135
- return {
136
- chartType: schema.chartType,
137
- data: schema.data,
138
- config,
139
- xAxisKey,
140
- series,
141
- className: schema.className
142
- };
143
- }, [schema]);
144
-
145
- return (
146
- <Suspense fallback={<Skeleton className="w-full h-[400px]" />}>
147
- <LazyAdvancedChart
148
- // Pass adapted props
149
- chartType={props.chartType}
150
- data={props.data}
151
- config={props.config}
152
- xAxisKey={props.xAxisKey}
153
- series={props.series}
154
- className={props.className}
155
- />
156
- </Suspense>
157
- );
158
- };
159
-
54
+ // Alias for generic view
55
+ ComponentRegistry.register('chart', ObjectChart, {
56
+ namespace: 'view',
57
+ category: 'view',
58
+ label: 'Chart',
59
+ inputs: [
60
+ { name: 'objectName', type: 'string', label: 'Object Name', required: true },
61
+ { name: 'type', type: 'string', label: 'Chart Type' },
62
+ { name: 'categoryField', type: 'string', label: 'Category Field' },
63
+ { name: 'valueField', type: 'string', label: 'Value Field' },
64
+ ]
65
+ });
160
66
  // Register the advanced chart component
161
67
  ComponentRegistry.register(
162
68
  'chart',
163
69
  ChartRenderer,
164
70
  {
71
+ namespace: 'plugin-charts',
165
72
  label: 'Chart',
166
73
  category: 'plugin',
167
74
  inputs: [
@@ -172,7 +79,11 @@ ComponentRegistry.register(
172
79
  enum: [
173
80
  { label: 'Bar', value: 'bar' },
174
81
  { label: 'Line', value: 'line' },
175
- { label: 'Area', value: 'area' }
82
+ { label: 'Area', value: 'area' },
83
+ { label: 'Pie', value: 'pie' },
84
+ { label: 'Donut', value: 'donut' },
85
+ { label: 'Radar', value: 'radar' },
86
+ { label: 'Scatter', value: 'scatter' }
176
87
  ],
177
88
  defaultValue: 'bar'
178
89
  },
@@ -204,8 +115,58 @@ ComponentRegistry.register(
204
115
  }
205
116
  );
206
117
 
207
- // Standard Export Protocol - for manual integration
208
- export const chartComponents = {
209
- 'bar-chart': ChartBarRenderer,
210
- 'chart': ChartRenderer,
211
- };
118
+ // Alias for CRM App compatibility
119
+ ComponentRegistry.register(
120
+ 'chart:bar',
121
+ ChartRenderer,
122
+ {
123
+ namespace: 'plugin-charts',
124
+ label: 'Bar Chart (Alias)',
125
+ category: 'plugin',
126
+ defaultProps: { chartType: 'bar' }
127
+ }
128
+ );
129
+
130
+ ComponentRegistry.register(
131
+ 'pie-chart',
132
+ ChartRenderer,
133
+ {
134
+ namespace: 'plugin-charts',
135
+ label: 'Pie Chart',
136
+ category: 'plugin',
137
+ defaultProps: { chartType: 'pie' }
138
+ }
139
+ );
140
+
141
+ ComponentRegistry.register(
142
+ 'donut-chart',
143
+ ChartRenderer,
144
+ {
145
+ namespace: 'plugin-charts',
146
+ label: 'Donut Chart',
147
+ category: 'plugin',
148
+ defaultProps: { chartType: 'donut' }
149
+ }
150
+ );
151
+
152
+ ComponentRegistry.register(
153
+ 'radar-chart',
154
+ ChartRenderer,
155
+ {
156
+ namespace: 'plugin-charts',
157
+ label: 'Radar Chart',
158
+ category: 'plugin',
159
+ defaultProps: { chartType: 'radar' }
160
+ }
161
+ );
162
+
163
+ ComponentRegistry.register(
164
+ 'scatter-chart',
165
+ ChartRenderer,
166
+ {
167
+ namespace: 'plugin-charts',
168
+ label: 'Scatter Chart',
169
+ category: 'plugin',
170
+ defaultProps: { chartType: 'scatter' }
171
+ }
172
+ );
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { describe, it, expect, vi, beforeAll } from 'vitest';
4
+ import { ComponentRegistry } from '@object-ui/core';
5
+
6
+ describe('Plugin Charts Registration', () => {
7
+ beforeAll(async () => {
8
+ await import('./index');
9
+ }, 30000);
10
+
11
+ it('registers bar-chart component', () => {
12
+ const config = ComponentRegistry.get('bar-chart');
13
+ expect(config).toBeDefined();
14
+ });
15
+
16
+ it('registers chart component types', () => {
17
+ expect(ComponentRegistry.get('chart')).toBeDefined(); // Assuming base
18
+ // Verify aliases if they exist
19
+ expect(ComponentRegistry.get('pie-chart')).toBeDefined();
20
+ expect(ComponentRegistry.get('donut-chart')).toBeDefined();
21
+ });
22
+ });
package/vite.config.ts CHANGED
@@ -24,6 +24,13 @@ export default defineConfig({
24
24
  resolve: {
25
25
  alias: {
26
26
  '@': resolve(__dirname, './src'),
27
+ '@object-ui/core': resolve(__dirname, '../core/src'),
28
+ '@object-ui/types': resolve(__dirname, '../types/src'),
29
+ '@object-ui/react': resolve(__dirname, '../react/src'),
30
+ '@object-ui/components': resolve(__dirname, '../components/src'),
31
+ '@object-ui/fields': resolve(__dirname, '../fields/src'),
32
+ '@object-ui/plugin-dashboard': resolve(__dirname, '../plugin-dashboard/src'),
33
+ '@object-ui/plugin-grid': resolve(__dirname, '../plugin-grid/src'),
27
34
  },
28
35
  },
29
36
  build: {
@@ -45,4 +52,10 @@ export default defineConfig({
45
52
  },
46
53
  },
47
54
  },
55
+ test: {
56
+ globals: true,
57
+ environment: 'happy-dom',
58
+ setupFiles: ['../../vitest.setup.tsx'],
59
+ passWithNoTests: true,
60
+ },
48
61
  });
@@ -0,0 +1,13 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from 'vite';
3
+ import react from '@vitejs/plugin-react';
4
+ import path from 'path';
5
+
6
+ export default defineConfig({
7
+ plugins: [react()],
8
+ test: {
9
+ environment: 'happy-dom',
10
+ globals: true,
11
+ setupFiles: ['./vitest.setup.ts'],
12
+ },
13
+ });
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';