Skip to content

Commit 37c4b31

Browse files
Copilothotlong
andcommitted
refactor: extract isObjectProvider to shared utils, rename _dropped to _data
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 1f93088 commit 37c4b31

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

packages/plugin-dashboard/src/DashboardGridLayout.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { cn, Card, CardHeader, CardTitle, CardContent, Button } from '@object-ui
55
import { Edit, GripVertical, Save, X, RefreshCw } from 'lucide-react';
66
import { SchemaRenderer, useHasDndProvider, useDnd } from '@object-ui/react';
77
import type { DashboardSchema, DashboardWidgetSchema } from '@object-ui/types';
8+
import { isObjectProvider } from './utils';
89

910
/** Bridges editMode transitions to the ObjectUI DnD system when a DndProvider is present. */
1011
function DndEditModeBridge({ editMode }: { editMode: boolean }) {
@@ -30,16 +31,6 @@ const CHART_COLORS = [
3031
'hsl(var(--chart-5))',
3132
];
3233

33-
/** Returns true when the widget data config uses provider: 'object' (async data source). */
34-
function isObjectProvider(widgetData: unknown): widgetData is { provider: 'object'; object?: string; aggregate?: any } {
35-
return (
36-
widgetData != null &&
37-
typeof widgetData === 'object' &&
38-
!Array.isArray(widgetData) &&
39-
(widgetData as any).provider === 'object'
40-
);
41-
}
42-
4334
export interface DashboardGridLayoutProps {
4435
schema: DashboardSchema;
4536
className?: string;
@@ -176,7 +167,7 @@ export const DashboardGridLayout: React.FC<DashboardGridLayoutProps> = ({
176167

177168
// provider: 'object' — pass through object config for async data loading
178169
if (isObjectProvider(widgetData)) {
179-
const { data: _dropped, ...restOptions } = options;
170+
const { data: _data, ...restOptions } = options;
180171
return {
181172
type: 'data-table',
182173
...restOptions,
@@ -204,7 +195,7 @@ export const DashboardGridLayout: React.FC<DashboardGridLayoutProps> = ({
204195

205196
// provider: 'object' — pass through object config for async data loading
206197
if (isObjectProvider(widgetData)) {
207-
const { data: _dropped, ...restOptions } = options;
198+
const { data: _data, ...restOptions } = options;
208199
return {
209200
type: 'pivot',
210201
...restOptions,

packages/plugin-dashboard/src/DashboardRenderer.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { SchemaRenderer } from '@object-ui/react';
1111
import { cn, Card, CardHeader, CardTitle, CardContent, Button } from '@object-ui/components';
1212
import { forwardRef, useState, useEffect, useCallback, useRef } from 'react';
1313
import { RefreshCw } from 'lucide-react';
14+
import { isObjectProvider } from './utils';
1415

1516
// Color palette for charts
1617
const CHART_COLORS = [
@@ -21,16 +22,6 @@ const CHART_COLORS = [
2122
'hsl(var(--chart-5))',
2223
];
2324

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-
3425
export interface DashboardRendererProps {
3526
schema: DashboardSchema;
3627
className?: string;
@@ -164,7 +155,7 @@ export const DashboardRenderer = forwardRef<HTMLDivElement, DashboardRendererPro
164155

165156
// provider: 'object' — pass through object config for async data loading
166157
if (isObjectProvider(widgetData)) {
167-
const { data: _dropped, ...restOptions } = options;
158+
const { data: _data, ...restOptions } = options;
168159
return {
169160
type: 'data-table',
170161
...restOptions,
@@ -192,7 +183,7 @@ export const DashboardRenderer = forwardRef<HTMLDivElement, DashboardRendererPro
192183

193184
// provider: 'object' — pass through object config for async data loading
194185
if (isObjectProvider(widgetData)) {
195-
const { data: _dropped, ...restOptions } = options;
186+
const { data: _data, ...restOptions } = options;
196187
return {
197188
type: 'pivot',
198189
...restOptions,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/** Returns true when the widget data config uses provider: 'object' (async data source). */
10+
export function isObjectProvider(widgetData: unknown): widgetData is { provider: 'object'; object?: string; aggregate?: any } {
11+
return (
12+
widgetData != null &&
13+
typeof widgetData === 'object' &&
14+
!Array.isArray(widgetData) &&
15+
(widgetData as any).provider === 'object'
16+
);
17+
}

0 commit comments

Comments
 (0)