Skip to content

Commit 0747f70

Browse files
Copilothotlong
andcommitted
refactor: extract isObjectProvider() helper, fix test comment per code review
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 73083fb commit 0747f70

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

packages/plugin-charts/src/__tests__/ObjectChart.aggregation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ describe('aggregateRecords', () => {
121121
});
122122

123123
expect(result).toHaveLength(1);
124-
expect(result[0].amount).toBe(100); // NaN coerced to 0, then 0 + 100
124+
expect(result[0].amount).toBe(100); // non-numeric value coerced to 0, sum is 0 + 100
125125
});
126126
});

packages/plugin-dashboard/src/DashboardRenderer.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ const CHART_COLORS = [
2121
'hsl(var(--chart-5))',
2222
];
2323

24+
/** Returns true when the widget data config uses provider: 'object' (async data source). */
25+
function isObjectProvider(widgetData: unknown): widgetData is { provider: 'object'; object?: string; aggregate?: any } {
26+
return (
27+
widgetData != null &&
28+
typeof widgetData === 'object' &&
29+
!Array.isArray(widgetData) &&
30+
(widgetData as any).provider === 'object'
31+
);
32+
}
33+
2434
export interface DashboardRendererProps {
2535
schema: DashboardSchema;
2636
className?: string;
@@ -118,7 +128,7 @@ export const DashboardRenderer = forwardRef<HTMLDivElement, DashboardRendererPro
118128
const yField = options.yField || 'value';
119129

120130
// provider: 'object' — delegate to ObjectChart for async data loading
121-
if (widgetData && typeof widgetData === 'object' && !Array.isArray(widgetData) && widgetData.provider === 'object') {
131+
if (isObjectProvider(widgetData)) {
122132
return {
123133
type: 'object-chart',
124134
chartType: widgetType,
@@ -149,7 +159,7 @@ export const DashboardRenderer = forwardRef<HTMLDivElement, DashboardRendererPro
149159
const widgetData = (widget as any).data || options.data;
150160

151161
// provider: 'object' — pass through object config for async data loading
152-
if (widgetData && typeof widgetData === 'object' && !Array.isArray(widgetData) && widgetData.provider === 'object') {
162+
if (isObjectProvider(widgetData)) {
153163
return {
154164
type: 'data-table',
155165
...options,
@@ -175,7 +185,7 @@ export const DashboardRenderer = forwardRef<HTMLDivElement, DashboardRendererPro
175185
const widgetData = (widget as any).data || options.data;
176186

177187
// provider: 'object' — pass through object config for async data loading
178-
if (widgetData && typeof widgetData === 'object' && !Array.isArray(widgetData) && widgetData.provider === 'object') {
188+
if (isObjectProvider(widgetData)) {
179189
return {
180190
type: 'pivot',
181191
...options,

0 commit comments

Comments
 (0)