@optifye/dashboard-core 1.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/README.md ADDED
@@ -0,0 +1,244 @@
1
+ # @optifye/dashboard-core
2
+
3
+ A reusable React component library and utility toolkit for building dashboard functionalities, tailored for Optifye applications.
4
+
5
+ This package provides a set of configurable services, hooks, context providers, and utility functions to interact with a Supabase backend and manage dashboard-specific logic.
6
+
7
+ ## Features
8
+
9
+ - **Configurable**: Highly configurable via a central `DashboardConfig` object.
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.
14
+
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @optifye/dashboard-core
20
+ # or
21
+ yarn add @optifye/dashboard-core
22
+ ```
23
+
24
+ ## Quick Start & Usage
25
+
26
+ The primary way to integrate `@optifye/dashboard-core` into your application is by using the `DashboardProvider` at the root of your component tree (or a relevant section).
27
+
28
+ ```tsx
29
+ // Example: pages/_app.tsx in a Next.js application
30
+
31
+ import type { AppProps } from 'next/app';
32
+ import {
33
+ DashboardProvider,
34
+ DashboardConfig,
35
+ AuthProvider,
36
+ DashboardOverridesProvider
37
+ } from '@optifye/dashboard-core';
38
+
39
+ // 1. Define your application-specific dashboard configuration
40
+ const appConfig: Partial<DashboardConfig> = {
41
+ supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
42
+ supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
43
+ entityConfig: {
44
+ companyId: process.env.NEXT_PUBLIC_COMPANY_ID!,
45
+ // ... other entity-specific IDs like factoryId, defaultLineId etc.
46
+ },
47
+ // ... other configurations like theme, analytics, dateTimeConfig etc.
48
+ };
49
+
50
+ function MyApp({ Component, pageProps }: AppProps) {
51
+ return (
52
+ <DashboardProvider config={appConfig}>
53
+ <AuthProvider> { /* For authentication */ }
54
+ <DashboardOverridesProvider overrides={{ /* your component overrides */ }}>
55
+ <Component {...pageProps} />
56
+ </DashboardOverridesProvider>
57
+ </AuthProvider>
58
+ </DashboardProvider>
59
+ );
60
+ }
61
+
62
+ export default MyApp;
63
+ ```
64
+
65
+ ### Configuration (`DashboardConfig`)
66
+
67
+ The `DashboardConfig` object is crucial for tailoring the package to your specific application instance. It allows you to define:
68
+
69
+ - Supabase credentials (`supabaseUrl`, `supabaseKey` - **required**)
70
+ - Entity identifiers (`entityConfig` - e.g., `companyId`, `factoryId`, line IDs - **often required for services/hooks**)
71
+ - API endpoints (`apiBaseUrl`, `endpoints`)
72
+ - Theme overrides (`theme`)
73
+ - Date/time preferences (`dateTimeConfig`)
74
+ - Database table names and schema (`databaseConfig`)
75
+ - And more...
76
+
77
+ Refer to the `DashboardConfig` interface definition within the package (exported from `lib/types/dashboardConfig`) for all available options and their types. For a detailed setup guide, see the [Application Configuration Setup Guide](../../migration_outputs/14_app_configuration_setup.md).
78
+
79
+ ## Core Modules
80
+
81
+ This package is organized into several core modules:
82
+
83
+ - **`lib/types`**: Contains all TypeScript interface and type definitions.
84
+ - **`lib/constants`**: Provides default configurations and other constant values.
85
+ - **`lib/contexts`**: Includes React Context providers and hooks for global state.
86
+ - **`lib/hooks`**: Custom React hooks for fetching and managing data.
87
+ - **`lib/services`**: Service factories for data interaction.
88
+ - **`lib/utils`**: Utility functions for common tasks.
89
+ - **`lib/supabaseClient`**: Supabase client utilities.
90
+
91
+ ## Utility Hooks
92
+
93
+ - **`useNavigation`**: Abstracted navigation API.
94
+ - **`useDateFormatter`**: Configured date/time formatting.
95
+ - **`useWorkspaceNavigation`**: Utilities for workspace navigation parameters.
96
+ - **`useFormatNumber`**: Configured number formatting.
97
+
98
+ ## UI Components
99
+
100
+ `@optifye/dashboard-core` provides a suite of reusable UI components.
101
+
102
+ ### Common Components
103
+
104
+ - **`MetricCard`**: Displays a key metric, value, unit, and trend.
105
+ - **Location**: `packages/dashboard-core/src/components/common/MetricCard.tsx`
106
+ - **`DateTimeDisplay`**: Shows current date/time, formatted via `DateTimeConfig`.
107
+ - **Location**: `packages/dashboard-core/src/components/common/DateTimeDisplay.tsx`
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`
114
+
115
+ ### Dashboard Components
116
+
117
+ #### Line Components
118
+
119
+ - **`LinePdfExportButton`**: Captures a DOM element and exports as PDF.
120
+ - **Location**: `packages/dashboard-core/src/components/dashboard/line/LinePdfExportButton.tsx`
121
+ - **`LineHistoryCalendar`**: Displays monthly history for a line using `BaseHistoryCalendar`.
122
+ - **Location**: `packages/dashboard-core/src/components/dashboard/line/LineHistoryCalendar.tsx`
123
+ - **`LineMonthlyHistory`**: Monthly historical overview for a line, using `LineHistoryCalendar`.
124
+ - **Location**: `packages/dashboard-core/src/components/dashboard/line/LineMonthlyHistory.tsx`
125
+
126
+ #### Workspace Components
127
+
128
+ - **`WorkspacePdfExportButton`**: Similar to `LinePdfExportButton` for workspace data.
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`
138
+
139
+ #### Grid Components
140
+
141
+ - **`WorkspaceGrid`**: Layout for arranging `WorkspaceCard` components.
142
+ - **Location**: `packages/dashboard-core/src/components/dashboard/grid/WorkspaceGrid.tsx`
143
+
144
+ ### Chart Components
145
+
146
+ - **`BarChart`**: Generic wrapper for Recharts `BarChart`.
147
+ - **Location**: `packages/dashboard-core/src/components/charts/BarChart.tsx`
148
+ - **`LineChart`**: Flexible wrapper for Recharts `LineChart`.
149
+ - **Location**: `packages/dashboard-core/src/components/charts/LineChart.tsx`
150
+
151
+ ### KPI Components
152
+
153
+ - **`KPICard`**: Displays KPI metrics with trends, secondary metrics, status indicators.
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`
161
+
162
+ ### Navigation Components
163
+
164
+ - **`SideNavBar`**: Configurable side navigation bar.
165
+ - **Location**: `packages/dashboard-core/src/components/navigation/SideNavBar.tsx`
166
+
167
+ ### Layout Components
168
+
169
+ - **`PageHeader`**: Responsive header for dashboard pages.
170
+ - **Location**: `packages/dashboard-core/src/components/layouts/PageHeader.tsx`
171
+ - **`DashboardLayout`**: Main layout component for dashboard pages.
172
+ - **Location**: `packages/dashboard-core/src/components/layouts/DashboardLayout.tsx`
173
+
174
+
175
+ ### Leaderboard Components
176
+
177
+ Location: `src/components/dashboard/leaderboard/`
178
+
179
+ * **`LeaderboardTable`**: A flexible and sortable table component designed to display leaderboard rankings. It supports custom column definitions, row click handlers, loading/error/empty states, and styling for highlighting top/bottom entries.
180
+ * **Key Props**: `data: LeaderboardRowData[]`, `columns?: ColumnDefinitionUnion[]`, `title?: string`, `onRowClick?: (row: LeaderboardRowData) => void`.
181
+ * **Usage**: Ideal for presenting ranked lists based on performance metrics.
182
+
183
+ ## Usage
184
+
185
+ To use the `@optifye/dashboard-core` service factory in your application:
186
+
187
+ 1. **Ensure you have a Supabase client instance initialized in your application.**
188
+
189
+ 2. **Prepare a configuration object.** The service factory `createDashboardService` expects a configuration object that can include:
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.
195
+
196
+ 3. **Create the service instance:**
197
+
198
+ ```typescript
199
+ import { createDashboardService } from '@optifye/dashboard-core';
200
+ import type { DashboardConfig } from '@optifye/dashboard-core';
201
+ import { supabase } from '../path/to/your/supabaseClient'; // Your app's Supabase client
202
+
203
+ // Example application-specific configuration
204
+ const appDashboardConfig: Partial<DashboardConfig> = {
205
+ entityConfig: {
206
+ companyId: 'YOUR_COMPANY_UUID',
207
+ defaultLineId: 'YOUR_DEFAULT_LINE_UUID',
208
+ // ... other entity properties
209
+ },
210
+ supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL,
211
+ supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
212
+ apiBaseUrl: process.env.NEXT_PUBLIC_API_URL,
213
+ endpoints: {
214
+ worstPerformingWorkspaces: '/functions/v1/worst-performing-workspaces' // Or your specific endpoint path
215
+ }
216
+ };
217
+
218
+ export const dashboardService = createDashboardService(appDashboardConfig, supabase);
219
+ ```
220
+
221
+ Now you can use `dashboardService.getLineInfo()`, `dashboardService.getWorkspacesData()`, etc., throughout your application.
222
+
223
+ ## Development
224
+
225
+ (Information about local development, building, and contributing to this package would go here.)
226
+
227
+ ## Publishing to npm
228
+
229
+ This package is published to npm as `@optifye/dashboard-core` and follows semantic versioning. New releases are automatically published when a PR with "RELEASE" in the title is merged to the main branch.
230
+
231
+ ### How to trigger a new release
232
+
233
+ 1. Create a changeset for your changes: `pnpm changeset`
234
+ 2. Choose the appropriate version bump (patch, minor, major)
235
+ 3. Create a PR with "RELEASE" in the title
236
+ 4. When merged, the GitHub Actions workflow will automatically publish the package to npm
237
+
238
+ ### Package Repository
239
+
240
+ The package repository field has been properly formatted for npm publishing standards.
241
+
242
+ ## License
243
+
244
+ (License information, e.g., MIT, would go here.)