piral-dashboard 1.0.0-pre.2217 → 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/LICENSE +1 -1
- package/README.md +34 -10
- package/esm/Dashboard.d.ts +5 -1
- package/esm/Dashboard.js +13 -10
- package/esm/Dashboard.js.map +1 -1
- package/esm/actions.js +2 -3
- package/esm/actions.js.map +1 -1
- package/esm/components.d.ts +3 -4
- package/esm/components.js +2 -2
- package/esm/components.js.map +1 -1
- package/esm/create.d.ts +6 -12
- package/esm/create.js +16 -34
- package/esm/create.js.map +1 -1
- package/esm/default.js +2 -2
- package/esm/default.js.map +1 -1
- package/esm/helpers.d.ts +11 -0
- package/esm/helpers.js +27 -0
- package/esm/helpers.js.map +1 -0
- package/esm/types.d.ts +26 -4
- package/lib/Dashboard.d.ts +5 -1
- package/lib/Dashboard.js +17 -13
- package/lib/Dashboard.js.map +1 -1
- package/lib/actions.js +3 -4
- package/lib/actions.js.map +1 -1
- package/lib/components.d.ts +3 -4
- package/lib/components.js +3 -3
- package/lib/components.js.map +1 -1
- package/lib/create.d.ts +6 -12
- package/lib/create.js +19 -37
- package/lib/create.js.map +1 -1
- package/lib/default.js +6 -4
- package/lib/default.js.map +1 -1
- package/lib/helpers.d.ts +11 -0
- package/lib/helpers.js +34 -0
- package/lib/helpers.js.map +1 -0
- package/lib/index.js +1 -1
- package/lib/types.d.ts +26 -4
- package/package.json +30 -6
- package/piral-dashboard.min.js +1 -0
- package/src/Dashboard.test.tsx +14 -14
- package/src/Dashboard.tsx +5 -1
- package/src/actions.test.ts +7 -6
- package/src/components.tsx +2 -6
- package/src/create.test.ts +7 -3
- package/src/create.ts +17 -50
- package/src/default.test.tsx +11 -11
- package/src/helpers.ts +54 -0
- package/src/types.ts +28 -4
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Dict, GlobalState } from 'piral-core';
|
|
2
|
+
import { DefaultTile, DefaultContainer } from './default';
|
|
3
|
+
import { Dashboard } from './Dashboard';
|
|
4
|
+
import { InitialTile, TilePreferences, TileRegistration } from './types';
|
|
5
|
+
|
|
6
|
+
export function getPreferences(defaultPreferences: TilePreferences, customPreferences: TilePreferences = {}) {
|
|
7
|
+
return {
|
|
8
|
+
...defaultPreferences,
|
|
9
|
+
...customPreferences,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getTiles(items: Array<InitialTile>, defaultPreferences: TilePreferences) {
|
|
14
|
+
const tiles: Dict<TileRegistration> = {};
|
|
15
|
+
let i = 0;
|
|
16
|
+
|
|
17
|
+
for (const { component, preferences } of items) {
|
|
18
|
+
tiles[`global-${i++}`] = {
|
|
19
|
+
pilet: undefined,
|
|
20
|
+
component,
|
|
21
|
+
preferences: getPreferences(defaultPreferences, preferences),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return tiles;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function withTiles(tiles: Dict<TileRegistration>) {
|
|
29
|
+
return (state: GlobalState): GlobalState => ({
|
|
30
|
+
...state,
|
|
31
|
+
components: {
|
|
32
|
+
DashboardTile: DefaultTile,
|
|
33
|
+
DashboardContainer: DefaultContainer,
|
|
34
|
+
...state.components,
|
|
35
|
+
},
|
|
36
|
+
registry: {
|
|
37
|
+
...state.registry,
|
|
38
|
+
tiles,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function withRoutes(routes: Array<string>) {
|
|
44
|
+
return (state: GlobalState): GlobalState => ({
|
|
45
|
+
...state,
|
|
46
|
+
routes: {
|
|
47
|
+
...state.routes,
|
|
48
|
+
...routes.reduce((newRoutes, route) => {
|
|
49
|
+
newRoutes[route] = Dashboard;
|
|
50
|
+
return newRoutes;
|
|
51
|
+
}, {}),
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
import { RouteComponentProps } from 'react-router-dom';
|
|
3
|
-
import {
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import type { RouteComponentProps } from 'react-router-dom';
|
|
3
|
+
import type {
|
|
4
4
|
Dict,
|
|
5
5
|
WrappedComponent,
|
|
6
6
|
BaseComponentProps,
|
|
@@ -51,7 +51,23 @@ declare module 'piral-core/lib/types/custom' {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export interface
|
|
54
|
+
export interface InitialTile {
|
|
55
|
+
/**
|
|
56
|
+
* Defines the component to be used for the tile.
|
|
57
|
+
*/
|
|
58
|
+
component: ComponentType<BareTileComponentProps>;
|
|
59
|
+
/**
|
|
60
|
+
* Optionally sets the preferences for the tile.
|
|
61
|
+
*/
|
|
62
|
+
preferences?: TilePreferences;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface DashboardContainerProps extends RouteComponentProps {
|
|
66
|
+
/**
|
|
67
|
+
* The tiles to display.
|
|
68
|
+
*/
|
|
69
|
+
children?: ReactNode;
|
|
70
|
+
}
|
|
55
71
|
|
|
56
72
|
export interface DashboardTileProps {
|
|
57
73
|
/**
|
|
@@ -70,6 +86,10 @@ export interface DashboardTileProps {
|
|
|
70
86
|
* The provided tile preferences.
|
|
71
87
|
*/
|
|
72
88
|
meta: TilePreferences;
|
|
89
|
+
/**
|
|
90
|
+
* The content of the tile to display.
|
|
91
|
+
*/
|
|
92
|
+
children?: ReactNode;
|
|
73
93
|
}
|
|
74
94
|
|
|
75
95
|
export interface TileErrorInfoProps {
|
|
@@ -89,6 +109,10 @@ export interface TileErrorInfoProps {
|
|
|
89
109
|
* The currently used number of rows.
|
|
90
110
|
*/
|
|
91
111
|
rows: number;
|
|
112
|
+
/**
|
|
113
|
+
* The name of the pilet emitting the error.
|
|
114
|
+
*/
|
|
115
|
+
pilet?: string;
|
|
92
116
|
}
|
|
93
117
|
|
|
94
118
|
export interface BareTileComponentProps {
|