@optifye/dashboard-core 1.0.0 → 2.0.1
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/README.md +562 -151
- package/dist/index.js +19753 -4398
- package/dist/index.mjs +19593 -4237
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -1,228 +1,639 @@
|
|
|
1
1
|
# @optifye/dashboard-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @optifye/dashboard-core
|
|
4
|
+
|
|
5
|
+
A comprehensive React component library and core utilities package for building enterprise-grade operational dashboards with real-time metrics, visualizations, and interactive views.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The **@optifye/dashboard-core** package provides a complete solution for building data-rich, real-time operational dashboards for manufacturing, production lines, and industrial workspaces. It includes a comprehensive set of UI components, data hooks, services, utilities, and fully-composed view components that can be used to build complete dashboard applications with minimal effort.
|
|
10
|
+
|
|
11
|
+
This package has been designed with a focus on:
|
|
12
|
+
|
|
13
|
+
- **Component Reusability**: All UI components from atomic elements to complete page views
|
|
14
|
+
- **Data Abstraction**: Hooks and services for clean data fetching and management
|
|
15
|
+
- **Configurability**: Extensive prop-based configuration for all components
|
|
16
|
+
- **Type Safety**: Comprehensive TypeScript types throughout
|
|
17
|
+
- **Performance**: Optimized rendering and data fetching strategies
|
|
18
|
+
- **Enterprise Readiness**: Authentication, real-time data, and role-based access controls
|
|
19
|
+
|
|
20
|
+
## Package Structure
|
|
21
|
+
|
|
22
|
+
### Core Architecture
|
|
23
|
+
|
|
24
|
+
The package is organized into the following key directories:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
@optifye/dashboard-core/
|
|
28
|
+
├── src/
|
|
29
|
+
│ ├── components/ # UI Components from atomic to composite
|
|
30
|
+
│ ├── lib/ # Core logic, utilities, hooks, services
|
|
31
|
+
│ ├── views/ # Complete page-level view components
|
|
32
|
+
│ └── index.ts # Main export file
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Component Architecture
|
|
36
|
+
|
|
37
|
+
Components follow a hierarchical organization:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
components/
|
|
41
|
+
├── auth/ # Authentication components
|
|
42
|
+
├── charts/ # Data visualization components
|
|
43
|
+
├── common/ # Shared components across domains
|
|
44
|
+
├── dashboard/ # Domain-specific dashboard components
|
|
45
|
+
│ ├── grid/ # Workspace grid components
|
|
46
|
+
│ ├── kpis/ # KPI visualization components
|
|
47
|
+
│ ├── line/ # Production line components
|
|
48
|
+
│ ├── video/ # Video streaming components
|
|
49
|
+
│ └── workspace/ # Workspace detail components
|
|
50
|
+
├── data/ # Data display and transformation components
|
|
51
|
+
├── layouts/ # Layout components and structure
|
|
52
|
+
├── navigation/ # Navigation components and menus
|
|
53
|
+
├── ui/ # Fundamental UI components (buttons, cards, etc.)
|
|
54
|
+
└── views/ # View-specific components
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Core Library Structure
|
|
58
|
+
|
|
59
|
+
The core logic follows a clean separation of concerns:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
lib/
|
|
63
|
+
├── constants/ # Application constants and configuration values
|
|
64
|
+
├── contexts/ # React context providers and consumers
|
|
65
|
+
├── hooks/ # Custom React hooks for data and UI
|
|
66
|
+
├── internal/ # Internal utilities (not exported)
|
|
67
|
+
├── services/ # Data services and API clients
|
|
68
|
+
│ └── factories/ # Service factory functions
|
|
69
|
+
├── supabase/ # Supabase client configuration
|
|
70
|
+
├── types/ # TypeScript type definitions
|
|
71
|
+
└── utils/ # Utility functions by domain
|
|
72
|
+
└── dev/ # Development utilities
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Key Features
|
|
76
|
+
|
|
77
|
+
### 1. UI Component System
|
|
78
|
+
|
|
79
|
+
The package provides a complete UI component system for building operational dashboards:
|
|
80
|
+
|
|
81
|
+
#### Foundational UI Components
|
|
82
|
+
|
|
83
|
+
- **Button**: Versatile button component with multiple variants (primary, secondary, outline, ghost)
|
|
84
|
+
- **Card**: Card components with header, body, and footer sections
|
|
85
|
+
- **Select**: Form select components with dropdown options
|
|
86
|
+
- **LoadingSpinner, LoadingOverlay, LoadingPage**: Loading indicators at various levels
|
|
87
|
+
- **DateDisplay, TimeDisplay**: Timezone-aware date and time components
|
|
88
|
+
- **Skeleton**: Loading skeleton placeholders
|
|
89
|
+
- **EmptyStateMessage**: Consistent empty state messaging
|
|
90
|
+
|
|
91
|
+
#### Data Visualization
|
|
92
|
+
|
|
93
|
+
- **KPICard**: Key Performance Indicator display cards
|
|
94
|
+
- **MetricCard**: General metric display cards
|
|
95
|
+
- **LineChart, BarChart**: Chart components for data visualization
|
|
96
|
+
- **HourlyOutputChart**: Specialized chart for hourly production data
|
|
97
|
+
- **WorkspaceHistoryCalendar**: Calendar visualization for workspace metrics history
|
|
98
|
+
- **OutputProgressChart**: Progress visualization for production output
|
|
99
|
+
|
|
100
|
+
#### Video & Real-Time Components
|
|
101
|
+
|
|
102
|
+
- **LiveView**: Real-time HLS video streaming component
|
|
103
|
+
- **BottlenecksContent**: Video clip management for bottleneck analysis
|
|
104
|
+
|
|
105
|
+
#### Navigation & Layout
|
|
106
|
+
|
|
107
|
+
- **MainLayout**: Main application layout with sidebar
|
|
108
|
+
- **DashboardLayout**: Full dashboard layout with header and sidebar
|
|
109
|
+
- **SideNavBar**: Navigation sidebar with configurable items
|
|
110
|
+
- **PageHeader**: Page header with breadcrumbs and user profile
|
|
111
|
+
|
|
112
|
+
### 2. Data Services
|
|
4
113
|
|
|
5
|
-
|
|
114
|
+
The package includes ready-to-use data services for common dashboard operations:
|
|
6
115
|
|
|
7
|
-
|
|
116
|
+
- **dashboardService**: Core dashboard data operations
|
|
117
|
+
- **workspaceService**: Workspace management and configuration
|
|
118
|
+
- **actionService**: Action tracking and management
|
|
119
|
+
- **whatsAppService**: WhatsApp integration for notifications
|
|
120
|
+
- **realtimeService**: Real-time data streaming and subscriptions
|
|
121
|
+
- **qualityService**: Quality metrics and analysis
|
|
122
|
+
- **mixpanelService**: Event tracking and analytics
|
|
8
123
|
|
|
9
|
-
|
|
10
|
-
- **React Hooks**: A rich set of hooks for accessing data, managing state, and handling metrics.
|
|
11
|
-
- **Services**: Modular services for interacting with backend data (e.g., dashboard metrics, line info, user actions).
|
|
12
|
-
- **Context Providers**: For managing global state like authentication, configuration, and component overrides.
|
|
13
|
-
- **Type-Safe**: Written in TypeScript for improved developer experience and safety.
|
|
124
|
+
### 3. Custom Hooks
|
|
14
125
|
|
|
126
|
+
Specialized hooks for data fetching and UI interactions:
|
|
127
|
+
|
|
128
|
+
- **useDashboardMetrics**: Dashboard-level metrics and KPIs
|
|
129
|
+
- **useMetrics**: General metrics management
|
|
130
|
+
- **useRealtimeLineMetrics**: Real-time line metrics with subscriptions
|
|
131
|
+
- **useLineDetailedMetrics**: Detailed metrics for production lines
|
|
132
|
+
- **useWorkspaceDetailedMetrics**: Detailed metrics for workspaces
|
|
133
|
+
- **useLineWorkspaceMetrics**: Combined line and workspace metrics
|
|
134
|
+
- **useHistoricWorkspaceMetrics**: Historical data for workspaces
|
|
135
|
+
- **useLeaderboardMetrics**: Leaderboard and ranking metrics
|
|
136
|
+
- **useFactoryOverviewMetrics**: Factory-level overview metrics
|
|
137
|
+
- **useTargets**: Production targets management
|
|
138
|
+
- **useWorkspaceOperators**: Operator assignment and management
|
|
139
|
+
- **useShifts**: Shift schedule management
|
|
140
|
+
- **useDateFormatter**: Date formatting utilities
|
|
141
|
+
- **useFormatNumber**: Number formatting utilities
|
|
142
|
+
- **useNavigation**: Navigation helpers
|
|
143
|
+
|
|
144
|
+
### 4. Complete Views
|
|
145
|
+
|
|
146
|
+
Full page-level view components that can be directly used in applications:
|
|
147
|
+
|
|
148
|
+
- **HomeView**: Main dashboard overview
|
|
149
|
+
- **FactoryView**: Factory-level overview with multiple lines
|
|
150
|
+
- **KPIDetailView**: Detailed KPI view for a specific line
|
|
151
|
+
- **WorkspaceDetailView**: Detailed view for a specific workspace
|
|
152
|
+
- **TargetsView**: Production targets management view
|
|
153
|
+
- **ShiftsView**: Shift scheduling and management view
|
|
15
154
|
|
|
16
155
|
## Installation
|
|
17
156
|
|
|
18
157
|
```bash
|
|
19
158
|
npm install @optifye/dashboard-core
|
|
20
|
-
# or
|
|
21
|
-
yarn add @optifye/dashboard-core
|
|
22
159
|
```
|
|
23
160
|
|
|
24
|
-
|
|
161
|
+
### Peer Dependencies
|
|
162
|
+
|
|
163
|
+
This package requires the following peer dependencies to be installed in your project:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
npm install react@^18 react-dom@^18 next@^13 tailwindcss@^3 @supabase/supabase-js@^2 date-fns@^4 date-fns-tz@^3
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Or if using Yarn:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
yarn add react@^18 react-dom@^18 next@^13 tailwindcss@^3 @supabase/supabase-js@^2 date-fns@^4 date-fns-tz@^3
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Integration Guide
|
|
176
|
+
|
|
177
|
+
### Basic Setup
|
|
178
|
+
|
|
179
|
+
1. Install the package:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
npm install @optifye/dashboard-core
|
|
183
|
+
```
|
|
25
184
|
|
|
26
|
-
|
|
185
|
+
2. Wrap your application with the required providers:
|
|
27
186
|
|
|
28
187
|
```tsx
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
import type { AppProps } from 'next/app';
|
|
32
|
-
import {
|
|
33
|
-
DashboardProvider,
|
|
34
|
-
DashboardConfig,
|
|
35
|
-
AuthProvider,
|
|
36
|
-
DashboardOverridesProvider
|
|
37
|
-
} from '@optifye/dashboard-core';
|
|
188
|
+
import { SupabaseProvider, DashboardProvider } from '@optifye/dashboard-core';
|
|
189
|
+
import { createClient } from '@supabase/supabase-js';
|
|
38
190
|
|
|
39
|
-
//
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
191
|
+
// Initialize Supabase client
|
|
192
|
+
const supabaseClient = createClient(
|
|
193
|
+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
194
|
+
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
// Dashboard configuration
|
|
198
|
+
const dashboardConfig = {
|
|
43
199
|
entityConfig: {
|
|
44
|
-
|
|
45
|
-
|
|
200
|
+
lineId: 'your-line-id',
|
|
201
|
+
factoryViewId: 'factory',
|
|
202
|
+
companyId: 'your-company-id'
|
|
46
203
|
},
|
|
47
|
-
|
|
204
|
+
supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
|
205
|
+
apiUrl: process.env.NEXT_PUBLIC_API_URL!,
|
|
206
|
+
timezone: 'Asia/Kolkata',
|
|
207
|
+
// ... other configuration options
|
|
48
208
|
};
|
|
49
209
|
|
|
50
|
-
function MyApp({ Component, pageProps }
|
|
210
|
+
function MyApp({ Component, pageProps }) {
|
|
51
211
|
return (
|
|
52
|
-
<
|
|
53
|
-
<
|
|
54
|
-
<DashboardOverridesProvider overrides={{ /* your component overrides */ }}>
|
|
212
|
+
<SupabaseProvider client={supabaseClient}>
|
|
213
|
+
<DashboardProvider config={dashboardConfig}>
|
|
55
214
|
<Component {...pageProps} />
|
|
56
|
-
</DashboardOverridesProvider>
|
|
57
|
-
</AuthProvider>
|
|
58
215
|
</DashboardProvider>
|
|
216
|
+
</SupabaseProvider>
|
|
59
217
|
);
|
|
60
218
|
}
|
|
61
219
|
|
|
62
220
|
export default MyApp;
|
|
63
221
|
```
|
|
64
222
|
|
|
65
|
-
###
|
|
223
|
+
### Using Individual Components
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
import {
|
|
227
|
+
KPICard,
|
|
228
|
+
Button,
|
|
229
|
+
Card,
|
|
230
|
+
DateDisplay,
|
|
231
|
+
useLineKPIs
|
|
232
|
+
} from '@optifye/dashboard-core';
|
|
233
|
+
|
|
234
|
+
function MyDashboardComponent() {
|
|
235
|
+
const { kpis, isLoading, error } = useLineKPIs('line-id');
|
|
236
|
+
|
|
237
|
+
if (isLoading) return <LoadingSpinner />;
|
|
238
|
+
if (error) return <div>Error loading KPIs</div>;
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
<Card>
|
|
242
|
+
<Card.Header>
|
|
243
|
+
<Card.Title>Line Performance</Card.Title>
|
|
244
|
+
<DateDisplay date={new Date()} />
|
|
245
|
+
</Card.Header>
|
|
246
|
+
<Card.Content>
|
|
247
|
+
<div className="grid grid-cols-3 gap-4">
|
|
248
|
+
<KPICard
|
|
249
|
+
title="Efficiency"
|
|
250
|
+
value={kpis.efficiency}
|
|
251
|
+
changeValue={kpis.efficiencyChange}
|
|
252
|
+
variant="percentage"
|
|
253
|
+
/>
|
|
254
|
+
<KPICard
|
|
255
|
+
title="Output"
|
|
256
|
+
value={kpis.output}
|
|
257
|
+
changeValue={kpis.outputChange}
|
|
258
|
+
variant="number"
|
|
259
|
+
/>
|
|
260
|
+
<KPICard
|
|
261
|
+
title="PPH"
|
|
262
|
+
value={kpis.pph}
|
|
263
|
+
changeValue={kpis.pphChange}
|
|
264
|
+
variant="number"
|
|
265
|
+
/>
|
|
266
|
+
</div>
|
|
267
|
+
</Card.Content>
|
|
268
|
+
<Card.Footer>
|
|
269
|
+
<Button>View Details</Button>
|
|
270
|
+
</Card.Footer>
|
|
271
|
+
</Card>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Using Complete Views
|
|
66
277
|
|
|
67
|
-
|
|
278
|
+
```tsx
|
|
279
|
+
import { FactoryView } from '@optifye/dashboard-core';
|
|
280
|
+
import { withAuth } from '@optifye/dashboard-core';
|
|
68
281
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
-
|
|
282
|
+
// Factory view with authentication protection
|
|
283
|
+
function FactoryPage() {
|
|
284
|
+
return (
|
|
285
|
+
<FactoryView
|
|
286
|
+
lineIds={['line-1-id', 'line-2-id']}
|
|
287
|
+
productIdMap={{
|
|
288
|
+
'line-1-id': 'product-1-id',
|
|
289
|
+
'line-2-id': 'product-2-id'
|
|
290
|
+
}}
|
|
291
|
+
showEfficiency={true}
|
|
292
|
+
showOutput={true}
|
|
293
|
+
showUnderperforming={true}
|
|
294
|
+
/>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
76
297
|
|
|
77
|
-
|
|
298
|
+
export default withAuth(FactoryPage);
|
|
299
|
+
```
|
|
78
300
|
|
|
79
|
-
##
|
|
301
|
+
## Authentication and Security
|
|
80
302
|
|
|
81
|
-
|
|
303
|
+
The package includes a comprehensive authentication system:
|
|
82
304
|
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
- **`lib/services`**: Service factories for data interaction.
|
|
88
|
-
- **`lib/utils`**: Utility functions for common tasks.
|
|
89
|
-
- **`lib/supabaseClient`**: Supabase client utilities.
|
|
305
|
+
- **withAuth**: Higher-order component for route protection
|
|
306
|
+
- **useAuth**: Hook for accessing authentication state and user data
|
|
307
|
+
- **AuthContext**: Context provider for authentication state
|
|
308
|
+
- **Authentication-Ready Views**: All view components have authentication built-in
|
|
90
309
|
|
|
91
|
-
##
|
|
310
|
+
## Performance Optimizations
|
|
92
311
|
|
|
93
|
-
|
|
94
|
-
- **`useDateFormatter`**: Configured date/time formatting.
|
|
95
|
-
- **`useWorkspaceNavigation`**: Utilities for workspace navigation parameters.
|
|
96
|
-
- **`useFormatNumber`**: Configured number formatting.
|
|
312
|
+
The package includes several performance optimizations:
|
|
97
313
|
|
|
98
|
-
|
|
314
|
+
- **Component Memoization**: React.memo with custom comparison functions
|
|
315
|
+
- **Data Caching**: SWR-based data caching and revalidation
|
|
316
|
+
- **Lazy Loading**: Dynamic imports for heavy components
|
|
317
|
+
- **Tree Shaking**: Proper module exports for better tree shaking
|
|
318
|
+
- **Render Optimizations**: Proper useMemo and useCallback hooks
|
|
99
319
|
|
|
100
|
-
|
|
320
|
+
## AWS Integration for Video
|
|
101
321
|
|
|
102
|
-
|
|
322
|
+
The package includes AWS S3 integration for video clips:
|
|
103
323
|
|
|
104
|
-
-
|
|
105
|
-
|
|
106
|
-
-
|
|
107
|
-
|
|
108
|
-
- **`EmptyStateMessage`**: For displaying messages when content is unavailable.
|
|
109
|
-
- **Location**: `packages/dashboard-core/src/components/common/EmptyStateMessage.tsx`
|
|
110
|
-
- **`WhatsAppShareButton`**: Opens a WhatsApp share link.
|
|
111
|
-
- **Location**: `packages/dashboard-core/src/components/common/WhatsAppShareButton.tsx`
|
|
112
|
-
- **`BaseHistoryCalendar`**: Foundational calendar using `react-day-picker`.
|
|
113
|
-
- **Location**: `packages/dashboard-core/src/components/common/BaseHistoryCalendar.tsx`
|
|
324
|
+
- **Direct S3 Integration**: No API endpoints required
|
|
325
|
+
- **Signed URL Generation**: Secure access to video content
|
|
326
|
+
- **Configurable Integration**: Custom fetch functions and credentials
|
|
327
|
+
- **Fallback Mode**: Simulated mode when credentials are not available
|
|
114
328
|
|
|
115
|
-
|
|
329
|
+
## Configuration Reference
|
|
116
330
|
|
|
117
|
-
|
|
331
|
+
### DashboardConfig
|
|
118
332
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
333
|
+
```typescript
|
|
334
|
+
interface DashboardConfig {
|
|
335
|
+
// Entity configuration
|
|
336
|
+
entityConfig: {
|
|
337
|
+
lineId: string;
|
|
338
|
+
factoryViewId: string;
|
|
339
|
+
companyId: string;
|
|
340
|
+
// Optional additional line IDs
|
|
341
|
+
lineIds?: Record<string, string>;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// API configuration
|
|
345
|
+
supabaseKey: string;
|
|
346
|
+
apiUrl: string;
|
|
347
|
+
|
|
348
|
+
// Time configuration
|
|
349
|
+
timezone: string;
|
|
350
|
+
|
|
351
|
+
// Feature flags
|
|
352
|
+
features?: {
|
|
353
|
+
enableRealtime?: boolean;
|
|
354
|
+
enableVideoStreaming?: boolean;
|
|
355
|
+
enableWhatsAppShare?: boolean;
|
|
356
|
+
enablePdfExport?: boolean;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// Theme configuration
|
|
360
|
+
theme?: {
|
|
361
|
+
primaryColor?: string;
|
|
362
|
+
secondaryColor?: string;
|
|
363
|
+
accentColor?: string;
|
|
364
|
+
errorColor?: string;
|
|
365
|
+
warningColor?: string;
|
|
366
|
+
successColor?: string;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// Other configuration options
|
|
370
|
+
options?: {
|
|
371
|
+
refreshInterval?: number;
|
|
372
|
+
dateFormat?: string;
|
|
373
|
+
timeFormat?: string;
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
```
|
|
125
377
|
|
|
126
|
-
|
|
378
|
+
## Working with Supabase
|
|
127
379
|
|
|
128
|
-
|
|
129
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/workspace/WorkspacePdfExportButton.tsx`
|
|
130
|
-
- **`WorkspaceCard`**: Presentational card for workspace information and metrics.
|
|
131
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/workspace/WorkspaceCard.tsx`
|
|
132
|
-
- **`LiveView`**: Displays HLS video streams for workspace cameras.
|
|
133
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/workspace/LiveView.tsx`
|
|
134
|
-
- **`OperatorsDisplay`**: Displays a list/row of operator avatars/names.
|
|
135
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/workspace/OperatorsDisplay.tsx`
|
|
136
|
-
- **`WorkspaceHistoryCalendar`**: Displays monthly history for a workspace, using `BaseHistoryCalendar`.
|
|
137
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/workspace/WorkspaceHistoryCalendar.tsx`
|
|
380
|
+
The package is designed to work with Supabase for data storage and real-time capabilities:
|
|
138
381
|
|
|
139
|
-
|
|
382
|
+
1. The `SupabaseProvider` component must be configured with a Supabase client.
|
|
383
|
+
2. All data services will use this client for data operations.
|
|
384
|
+
3. Real-time subscriptions use Supabase's real-time capabilities.
|
|
140
385
|
|
|
141
|
-
|
|
142
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/grid/WorkspaceGrid.tsx`
|
|
386
|
+
### Supabase Schema
|
|
143
387
|
|
|
144
|
-
|
|
388
|
+
The package expects the following Supabase tables and structure:
|
|
145
389
|
|
|
146
|
-
-
|
|
147
|
-
|
|
148
|
-
-
|
|
149
|
-
|
|
390
|
+
- **metrics_current**: Current metrics for lines and workspaces
|
|
391
|
+
- **metrics_hourly**: Hourly aggregated metrics
|
|
392
|
+
- **metrics_daily**: Daily aggregated metrics
|
|
393
|
+
- **line_operating_hours**: Shift configuration for lines
|
|
394
|
+
- **workspaces**: Workspace definitions and configuration
|
|
395
|
+
- **workspace_actions**: Action configurations for workspaces
|
|
396
|
+
- **workspace_operators**: Operator assignments to workspaces
|
|
150
397
|
|
|
151
|
-
|
|
398
|
+
## Integration Examples
|
|
152
399
|
|
|
153
|
-
|
|
154
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/kpis/KPICard.tsx`
|
|
155
|
-
- **`KPIGrid`**: Layout for KPI cards (row or grid).
|
|
156
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/kpis/KPIGrid.tsx`
|
|
157
|
-
- **`KPIHeader`**: Header for KPI sections with title, subtitle, actions.
|
|
158
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/kpis/KPIHeader.tsx`
|
|
159
|
-
- **`KPISection`**: Displays a collection of KPIs using `KPICard`s and `KPIGrid`.
|
|
160
|
-
- **Location**: `packages/dashboard-core/src/components/dashboard/kpis/KPISection.tsx`
|
|
400
|
+
### Next.js Integration
|
|
161
401
|
|
|
162
|
-
|
|
402
|
+
For Next.js applications, a common pattern is to use the dynamic catch-all routing to render the appropriate view:
|
|
163
403
|
|
|
164
|
-
|
|
165
|
-
|
|
404
|
+
```tsx
|
|
405
|
+
// pages/[[...dashboard]].tsx
|
|
406
|
+
import { useRouter } from 'next/router';
|
|
407
|
+
import dynamic from 'next/dynamic';
|
|
408
|
+
|
|
409
|
+
// Dynamic imports with loading fallbacks
|
|
410
|
+
const HomeView = dynamic(() => import('@optifye/dashboard-core/views/HomeView'), {
|
|
411
|
+
loading: () => <div className="flex h-screen w-full items-center justify-center">Loading...</div>,
|
|
412
|
+
ssr: false
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
const FactoryView = dynamic(() => import('@optifye/dashboard-core/views/FactoryView'), {
|
|
416
|
+
loading: () => <div className="flex h-screen w-full items-center justify-center">Loading...</div>,
|
|
417
|
+
ssr: false
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
// ... other view imports
|
|
421
|
+
|
|
422
|
+
export default function DashboardPage() {
|
|
423
|
+
const router = useRouter();
|
|
424
|
+
const { dashboard } = router.query;
|
|
425
|
+
|
|
426
|
+
// Determine which view to render based on the route
|
|
427
|
+
const renderView = () => {
|
|
428
|
+
if (!dashboard || dashboard.length === 0) {
|
|
429
|
+
return <HomeView />;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const [main, id] = dashboard as string[];
|
|
433
|
+
|
|
434
|
+
switch (main) {
|
|
435
|
+
case 'factory-view':
|
|
436
|
+
return <FactoryView />;
|
|
437
|
+
case 'kpis':
|
|
438
|
+
return <KPIDetailView lineId={id} />;
|
|
439
|
+
case 'workspace':
|
|
440
|
+
return <WorkspaceDetailView workspaceId={id} />;
|
|
441
|
+
case 'targets':
|
|
442
|
+
return <TargetsView />;
|
|
443
|
+
case 'shifts':
|
|
444
|
+
return <ShiftsView />;
|
|
445
|
+
default:
|
|
446
|
+
return <div>Page not found</div>;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
return (
|
|
451
|
+
<MainLayout>
|
|
452
|
+
{renderView()}
|
|
453
|
+
</MainLayout>
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### React SPA Integration
|
|
166
459
|
|
|
167
|
-
|
|
460
|
+
For React SPA applications, you can use React Router:
|
|
461
|
+
|
|
462
|
+
```tsx
|
|
463
|
+
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
|
464
|
+
import {
|
|
465
|
+
HomeView,
|
|
466
|
+
FactoryView,
|
|
467
|
+
KPIDetailView,
|
|
468
|
+
WorkspaceDetailView,
|
|
469
|
+
TargetsView,
|
|
470
|
+
ShiftsView
|
|
471
|
+
} from '@optifye/dashboard-core';
|
|
168
472
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
473
|
+
export default function App() {
|
|
474
|
+
return (
|
|
475
|
+
<BrowserRouter>
|
|
476
|
+
<Routes>
|
|
477
|
+
<Route path="/" element={<HomeView />} />
|
|
478
|
+
<Route path="/factory-view" element={<FactoryView />} />
|
|
479
|
+
<Route path="/kpis/:lineId" element={<KPIDetailView />} />
|
|
480
|
+
<Route path="/workspace/:id" element={<WorkspaceDetailView />} />
|
|
481
|
+
<Route path="/targets" element={<TargetsView />} />
|
|
482
|
+
<Route path="/shifts" element={<ShiftsView />} />
|
|
483
|
+
</Routes>
|
|
484
|
+
</BrowserRouter>
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
```
|
|
173
488
|
|
|
489
|
+
## Available Services
|
|
174
490
|
|
|
175
|
-
###
|
|
491
|
+
### dashboardService
|
|
176
492
|
|
|
177
|
-
|
|
493
|
+
The core service for dashboard data operations.
|
|
178
494
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
495
|
+
```typescript
|
|
496
|
+
// Key Methods
|
|
497
|
+
dashboardService.getUnderperformingWorkspaces(lineId: string): Promise<WorkspaceMetrics[]>
|
|
498
|
+
dashboardService.getLineInfo(lineId: string): Promise<LineInfo>
|
|
499
|
+
dashboardService.getLineMetrics(lineId: string): Promise<LineMetrics>
|
|
500
|
+
dashboardService.getWorkspacesForLine(lineId: string): Promise<Workspace[]>
|
|
501
|
+
dashboardService.getHistoricalMetrics(params: HistoricalMetricsParams): Promise<HistoricalMetrics>
|
|
502
|
+
```
|
|
182
503
|
|
|
183
|
-
|
|
504
|
+
### workspaceService
|
|
184
505
|
|
|
185
|
-
|
|
506
|
+
Service for workspace management and configuration.
|
|
186
507
|
|
|
187
|
-
|
|
508
|
+
```typescript
|
|
509
|
+
// Key Methods
|
|
510
|
+
workspaceService.getWorkspace(workspaceId: string): Promise<Workspace>
|
|
511
|
+
workspaceService.getWorkspaceMetrics(workspaceId: string): Promise<WorkspaceDetailedMetrics>
|
|
512
|
+
workspaceService.updateWorkspaceAction(params: WorkspaceActionUpdate): Promise<void>
|
|
513
|
+
workspaceService.bulkUpdateWorkspaceActions(params: BulkWorkspaceActionUpdate): Promise<void>
|
|
514
|
+
workspaceService.getLineWorkspaceThresholds(lineId: string): Promise<LineThreshold[]>
|
|
515
|
+
```
|
|
188
516
|
|
|
189
|
-
|
|
190
|
-
* `entityConfig`: Specifies `companyId`, `factoryId`, `defaultLineId`, `secondaryLineId`, `lineNames`, and `factoryViewId`.
|
|
191
|
-
* `supabaseUrl`, `supabaseKey`: Required by certain internal parts of the service (e.g., Edge Function calls) even if a client is passed.
|
|
192
|
-
* `apiBaseUrl`: Base URL for API calls, used by features like `getUnderperformingWorkspaces` if its endpoint is relative.
|
|
193
|
-
* `endpoints`: Configuration for specific service endpoints, e.g., `worstPerformingWorkspaces`.
|
|
194
|
-
* Other configurations like `databaseConfig`, `shiftConfig`, `dateTimeConfig` can be provided to override package defaults.
|
|
517
|
+
### actionService
|
|
195
518
|
|
|
196
|
-
|
|
519
|
+
Service for action tracking and management.
|
|
197
520
|
|
|
198
521
|
```typescript
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
522
|
+
// Key Methods
|
|
523
|
+
actionService.getActionForWorkspace(workspaceId: string): Promise<Action>
|
|
524
|
+
actionService.updateAction(params: ActionUpdate): Promise<void>
|
|
525
|
+
actionService.addAction(params: ActionCreate): Promise<Action>
|
|
526
|
+
actionService.deleteAction(actionId: string): Promise<void>
|
|
527
|
+
```
|
|
202
528
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
endpoints: {
|
|
214
|
-
worstPerformingWorkspaces: '/functions/v1/worst-performing-workspaces' // Or your specific endpoint path
|
|
215
|
-
}
|
|
216
|
-
};
|
|
529
|
+
### whatsAppService
|
|
530
|
+
|
|
531
|
+
WhatsApp integration for notifications.
|
|
532
|
+
|
|
533
|
+
```typescript
|
|
534
|
+
// Key Methods
|
|
535
|
+
whatsAppService.shareWorkspaceMetrics(params: ShareWorkspaceParams): Promise<string>
|
|
536
|
+
whatsAppService.shareLineMetrics(params: ShareLineParams): Promise<string>
|
|
537
|
+
whatsAppService.shareFactoryMetrics(params: ShareFactoryParams): Promise<string>
|
|
538
|
+
```
|
|
217
539
|
|
|
218
|
-
|
|
540
|
+
### realtimeService
|
|
541
|
+
|
|
542
|
+
Real-time data streaming and subscriptions.
|
|
543
|
+
|
|
544
|
+
```typescript
|
|
545
|
+
// Key Methods
|
|
546
|
+
realtimeService.subscribeToLineMetrics(lineId: string, callback: Callback): Subscription
|
|
547
|
+
realtimeService.subscribeToWorkspaceMetrics(workspaceId: string, callback: Callback): Subscription
|
|
548
|
+
realtimeService.unsubscribe(subscription: Subscription): void
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
## Extension and Customization
|
|
552
|
+
|
|
553
|
+
The package supports several extension mechanisms:
|
|
554
|
+
|
|
555
|
+
### DashboardOverrides
|
|
556
|
+
|
|
557
|
+
The `DashboardOverridesContext` allows overriding specific components:
|
|
558
|
+
|
|
559
|
+
```tsx
|
|
560
|
+
import { DashboardOverridesProvider } from '@optifye/dashboard-core';
|
|
561
|
+
|
|
562
|
+
// Custom components for overrides
|
|
563
|
+
const CustomKPICard = (props) => <div>Custom KPI Card: {props.title}</div>;
|
|
564
|
+
const CustomWorkspaceCard = (props) => <div>Custom Workspace: {props.name}</div>;
|
|
565
|
+
|
|
566
|
+
function MyApp({ Component, pageProps }) {
|
|
567
|
+
const overrides = {
|
|
568
|
+
components: {
|
|
569
|
+
KPICard: CustomKPICard,
|
|
570
|
+
WorkspaceCard: CustomWorkspaceCard
|
|
571
|
+
},
|
|
572
|
+
hooks: {
|
|
573
|
+
// Hook overrides
|
|
574
|
+
},
|
|
575
|
+
views: {
|
|
576
|
+
// View overrides
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
return (
|
|
581
|
+
<DashboardOverridesProvider overrides={overrides}>
|
|
582
|
+
<Component {...pageProps} />
|
|
583
|
+
</DashboardOverridesProvider>
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### View Customization
|
|
589
|
+
|
|
590
|
+
All view components accept extensive prop-based customization:
|
|
591
|
+
|
|
592
|
+
```tsx
|
|
593
|
+
<FactoryView
|
|
594
|
+
lineIds={['line1', 'line2']}
|
|
595
|
+
showEfficiency={true}
|
|
596
|
+
showOutput={true}
|
|
597
|
+
showPPH={true}
|
|
598
|
+
refreshInterval={30000}
|
|
599
|
+
onLineSelect={(lineId) => console.log(`Selected line: ${lineId}`)}
|
|
600
|
+
customHeader={<MyCustomHeader />}
|
|
601
|
+
customFooter={<MyCustomFooter />}
|
|
602
|
+
/>
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
## Troubleshooting
|
|
606
|
+
|
|
607
|
+
### Common Issues
|
|
608
|
+
|
|
609
|
+
1. **React Version Compatibility**
|
|
610
|
+
|
|
611
|
+
If you encounter React type compatibility issues between the package and your application, use type casting:
|
|
612
|
+
|
|
613
|
+
```tsx
|
|
614
|
+
import ComponentOriginal from '@optifye/dashboard-core/components/path/Component';
|
|
615
|
+
const Component = ComponentOriginal as any;
|
|
219
616
|
```
|
|
220
617
|
|
|
221
|
-
|
|
618
|
+
2. **Supabase Client Not Initialized**
|
|
222
619
|
|
|
223
|
-
|
|
620
|
+
Error: "Supabase client not initialized in @optifye/dashboard-core. Use SupabaseProvider."
|
|
621
|
+
|
|
622
|
+
Solution: Ensure your application is wrapped with `SupabaseProvider` and a valid Supabase client is provided.
|
|
623
|
+
|
|
624
|
+
3. **Missing Dashboard Configuration**
|
|
625
|
+
|
|
626
|
+
Error: "Dashboard configuration not found. Use DashboardProvider."
|
|
627
|
+
|
|
628
|
+
Solution: Ensure your application is wrapped with `DashboardProvider` and valid configuration is provided.
|
|
629
|
+
|
|
630
|
+
## Contributing
|
|
631
|
+
|
|
632
|
+
This package is continuously evolving. For contributions, please follow the established code patterns and ensure all tests pass.
|
|
633
|
+
|
|
634
|
+
## License
|
|
224
635
|
|
|
225
|
-
|
|
636
|
+
Proprietary - All rights reserved. This package is for internal use only.
|
|
226
637
|
|
|
227
638
|
## Publishing to npm
|
|
228
639
|
|