semaphor 0.0.1 → 0.0.12

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 CHANGED
@@ -0,0 +1,125 @@
1
+ Integrating dashboard into your React app is a straightforward three-step process.
2
+
3
+ ### **1) Install Semaphor Package**
4
+
5
+ Open your terminal in your project directory and run the following command. This command installs the `semaphor` package and adds it to your project dependencies.
6
+
7
+ ```markdown copy
8
+ npm i semaphor
9
+ ```
10
+
11
+ ### **2) Get Auth Token**
12
+
13
+ Before rendering the `Dashboard`, first acquire the `AuthToken`. This token enhances the security of your dashboard by restricting access to only users with the token. Make a POST fetch call as shown below.
14
+
15
+ ```jsx copy {1-3}
16
+ const DASHBOARD_ID = 'd_cf007a8b-19bc-46ad-8787-2915445b7b86'; // Replace with your actual dashboard ID
17
+ const DASHBOARD_SECRET = 'ds_f32f0b30-b7e1-40f9-ba6a-9804a5b9d635'; // Replace with your actual dashboard secret
18
+ const TOKEN_URL = 'https://semaphor.cloud/api/v1/token';
19
+
20
+ async function fetchToken() {
21
+ try {
22
+ const response = await fetch(TOKEN_URL, {
23
+ method: 'POST',
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ },
27
+ body: JSON.stringify({
28
+ dashboardId: DASHBOARD_ID,
29
+ dashboardSecret: DASHBOARD_SECRET,
30
+ }),
31
+ });
32
+ if (!response.ok) {
33
+ throw new Error(`HTTP error! status: ${response.status}`);
34
+ }
35
+
36
+ const token = await response.json();
37
+ if (token?.accessToken) {
38
+ setAuthToken(token);
39
+ }
40
+ } catch (error) {
41
+ console.error('There was an error!', error);
42
+ }
43
+ }
44
+ ```
45
+
46
+ ### **3) Initialize Dashboard**
47
+
48
+ Here is a simple example of a React component that demonstrates how to use the `Dashboard` component from the `semaphor` package. Make sure you import style.css either at the beginning of your component or in your global CSS file. This step is necessary for correctly loading your dashboard styles.
49
+
50
+ ```tsx copy {3, 11}
51
+ import { useEffect, useState } from 'react';
52
+ import { AuthToken, Dashboard } from 'semaphor';
53
+ import '../node_modules/semaphor/dist/style.css'; // IMPORTANT! Include the CSS file. This is the default style, you can customize it.
54
+
55
+ function App() {
56
+ const [authToken, setAuthToken] = useState<AuthToken>();
57
+
58
+ return (
59
+ <div>
60
+ <h2>My cool dashboard</h2>
61
+ <Dashboard authToken={authToken} id={DASHBOARD_ID} />
62
+ </div>
63
+ );
64
+ }
65
+ ```
66
+
67
+ ### **Full Code**
68
+
69
+ Here is the complete React code that uses the above steps. You can copy and paste this example into your own application.
70
+
71
+ ```tsx {3-7, 31, 43} copy filename="App.tsx"
72
+ import { useEffect, useState } from 'react';
73
+ import { AuthToken, Dashboard } from 'semaphor';
74
+ import '../node_modules/semaphor/dist/style.css'; // IMPORTANT! Include the CSS file. This is the default style, you can customize it.
75
+
76
+ const DASHBOARD_ID = 'd_cf007a8b-19bc-46ad-8787-2915445b7b86'; // Replace with your actual dashboard ID
77
+ const DASHBOARD_SECRET = 'ds_f32f0b30-b7e1-40f9-ba6a-9804a5b9d635'; // Replace with your actual dashboard secret
78
+ const TOKEN_URL = 'https://semaphor.cloud/api/v1/token';
79
+
80
+ function App() {
81
+ const [authToken, setAuthToken] = useState<AuthToken>();
82
+
83
+ useEffect(() => {
84
+ async function fetchToken() {
85
+ try {
86
+ const response = await fetch(TOKEN_URL, {
87
+ method: 'POST',
88
+ headers: {
89
+ 'Content-Type': 'application/json',
90
+ },
91
+ body: JSON.stringify({
92
+ dashboardId: DASHBOARD_ID,
93
+ dashboardSecret: DASHBOARD_SECRET,
94
+ }),
95
+ });
96
+ if (!response.ok) {
97
+ throw new Error(`HTTP error! status: ${response.status}`);
98
+ }
99
+
100
+ const token = await response.json();
101
+ if (token?.accessToken) {
102
+ setAuthToken(token);
103
+ }
104
+ } catch (error) {
105
+ console.error('There was an error!', error);
106
+ }
107
+ }
108
+ fetchToken();
109
+ }, []);
110
+
111
+ return (
112
+ <div>
113
+ <h2>My cool dashboard</h2>
114
+ <Dashboard authToken={authToken} id={DASHBOARD_ID} />
115
+ </div>
116
+ );
117
+ }
118
+
119
+ export default App;
120
+ ```
121
+
122
+ ### **Key Considerations**
123
+
124
+ - **Security Note:** Keep the `DASHBOARD_SECRET` secure and do not expose it in client-side code in production. This example is for demonstration purposes only. When deploying in production, obtain the authentication token from a secure, server-side environment.
125
+ - **Fetching the AuthToken:** Before the dashboard can be displayed, an authentication token must be fetched. The `useEffect` hook is used to perform this action when the component mounts.
@@ -10,6 +10,7 @@ declare type Actions = {
10
10
  setAuthToken: (authToken: AuthToken) => void;
11
11
  setThemeStyle: (themeStyle: StyleProps) => void;
12
12
  setIsEditorSaveEvent: (isEditorSaveEvent: boolean) => void;
13
+ setBookmarkKey: (bookmarkKey: string) => void;
13
14
  setDashboard: (dashboard: TDashboard) => void;
14
15
  setDashboardTheme: (theme: 'light' | 'dark' | 'system') => void;
15
16
  setDashboardTitle: (title: string) => void;
@@ -91,6 +92,7 @@ declare type DashboardStore = {
91
92
  authToken?: AuthToken;
92
93
  theme?: 'light' | 'dark' | 'system';
93
94
  themeStyle?: StyleProps;
95
+ bookmarkKey?: string;
94
96
  dashboard: TDashboard;
95
97
  selectedSheetId?: string | null | undefined;
96
98
  selectedCardId?: string | null;
@@ -145,6 +147,8 @@ declare type FilterForString = BaseFilter & {
145
147
  values: [string];
146
148
  };
147
149
 
150
+ export declare function getBookmarkKey(dashboardId: string): string;
151
+
148
152
  export declare function getDashbaordStateWithoutData(dashboardState: TDashboard): {
149
153
  sheets: {
150
154
  cards: TCard[] | undefined;
@@ -164,20 +168,30 @@ export declare type LoadingProps = {
164
168
  message?: string;
165
169
  };
166
170
 
171
+ /**
172
+ * Style propeerites for the dashboard
173
+ */
167
174
  export declare type StyleProps = {
175
+ /** css class for `dashboard-panel` */
168
176
  dashboardPanel?: string;
177
+ /** css class for `dashboard-tabs-container` */
169
178
  dashboardTabsContainer?: string;
179
+ /** css class for `dashboard-card` */
180
+ /** css class for `dashboard-card-container` */
181
+ dashboardCardContainer?: string;
170
182
  dashboardCard?: string;
171
- dashboardHeader?: string;
172
- dashboardTitle?: string;
173
- dashboardDescription?: string;
183
+ /** grid-layout config */
174
184
  gridLayout?: {
185
+ /** css class for `react-grid-layout` */
175
186
  className?: string;
176
187
  margin?: [number, number];
177
188
  };
189
+ /** chart config */
178
190
  chart?: {
191
+ /** chart font config */
179
192
  font?: Partial<FontSpec>;
180
193
  dataset?: any;
194
+ /** chart options */
181
195
  options?: any;
182
196
  };
183
197
  };
@@ -241,6 +255,9 @@ export declare type TSheet = {
241
255
  cards?: TCard[];
242
256
  };
243
257
 
258
+ /**
259
+ * Style for the dashboard
260
+ */
244
261
  export declare type TStyle = {
245
262
  default: StyleProps;
246
263
  dark?: StyleProps;
@@ -266,10 +283,8 @@ export declare const useDashboardStore: UseBoundStore<Omit<StoreApi<DashboardSto
266
283
  themeStyle?: {
267
284
  dashboardPanel?: string | undefined;
268
285
  dashboardTabsContainer?: string | undefined;
286
+ dashboardCardContainer?: string | undefined;
269
287
  dashboardCard?: string | undefined;
270
- dashboardHeader?: string | undefined;
271
- dashboardTitle?: string | undefined;
272
- dashboardDescription?: string | undefined;
273
288
  gridLayout?: {
274
289
  className?: string | undefined;
275
290
  margin?: [number, number] | undefined;
@@ -286,6 +301,7 @@ export declare const useDashboardStore: UseBoundStore<Omit<StoreApi<DashboardSto
286
301
  options?: any;
287
302
  } | undefined;
288
303
  } | undefined;
304
+ bookmarkKey?: string | undefined;
289
305
  dashboard: {
290
306
  id: string;
291
307
  title?: string | undefined;
@@ -335,10 +351,8 @@ export declare const useDashboardStore: UseBoundStore<Omit<StoreApi<DashboardSto
335
351
  default: {
336
352
  dashboardPanel?: string | undefined;
337
353
  dashboardTabsContainer?: string | undefined;
354
+ dashboardCardContainer?: string | undefined;
338
355
  dashboardCard?: string | undefined;
339
- dashboardHeader?: string | undefined;
340
- dashboardTitle?: string | undefined;
341
- dashboardDescription?: string | undefined;
342
356
  gridLayout?: {
343
357
  className?: string | undefined;
344
358
  margin?: [number, number] | undefined;
@@ -358,10 +372,8 @@ export declare const useDashboardStore: UseBoundStore<Omit<StoreApi<DashboardSto
358
372
  dark?: {
359
373
  dashboardPanel?: string | undefined;
360
374
  dashboardTabsContainer?: string | undefined;
375
+ dashboardCardContainer?: string | undefined;
361
376
  dashboardCard?: string | undefined;
362
- dashboardHeader?: string | undefined;
363
- dashboardTitle?: string | undefined;
364
- dashboardDescription?: string | undefined;
365
377
  gridLayout?: {
366
378
  className?: string | undefined;
367
379
  margin?: [number, number] | undefined;
@@ -474,6 +486,7 @@ export declare const useDashboardStore: UseBoundStore<Omit<StoreApi<DashboardSto
474
486
  setAuthToken: (authToken: AuthToken) => void;
475
487
  setThemeStyle: (themeStyle: StyleProps) => void;
476
488
  setIsEditorSaveEvent: (isEditorSaveEvent: boolean) => void;
489
+ setBookmarkKey: (bookmarkKey: string) => void;
477
490
  setDashboard: (dashboard: TDashboard) => void;
478
491
  setDashboardTheme: (theme: 'light' | 'dark' | 'system') => void;
479
492
  setDashboardTitle: (title: string) => void;