piral-dashboard 1.0.0-pre.2296 → 1.0.1-beta.5640
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 +28 -8
- 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/lib/create.js
CHANGED
|
@@ -1,56 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDashboardApi = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function getPreferences(defaultPreferences, customPreferences) {
|
|
9
|
-
if (customPreferences === void 0) { customPreferences = {}; }
|
|
10
|
-
return tslib_1.__assign(tslib_1.__assign({}, defaultPreferences), customPreferences);
|
|
11
|
-
}
|
|
12
|
-
function getTiles(items, defaultPreferences) {
|
|
13
|
-
var tiles = {};
|
|
14
|
-
var i = 0;
|
|
15
|
-
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
16
|
-
var _a = items_1[_i], component = _a.component, preferences = _a.preferences;
|
|
17
|
-
tiles["global-" + i++] = {
|
|
18
|
-
pilet: undefined,
|
|
19
|
-
component: component,
|
|
20
|
-
preferences: getPreferences(defaultPreferences, preferences),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return tiles;
|
|
24
|
-
}
|
|
4
|
+
const actions = require("./actions");
|
|
5
|
+
const piral_core_1 = require("piral-core");
|
|
6
|
+
const Dashboard_1 = require("./Dashboard");
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
25
8
|
/**
|
|
26
9
|
* Creates the Pilet API extension for activating dashboard support.
|
|
27
10
|
*/
|
|
28
|
-
function createDashboardApi(config) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return function (context) {
|
|
11
|
+
function createDashboardApi(config = {}) {
|
|
12
|
+
const { tiles = [], defaultPreferences = {}, routes = ['/'] } = config;
|
|
13
|
+
return (context) => {
|
|
32
14
|
context.defineActions(actions);
|
|
33
|
-
context.dispatch(
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
15
|
+
context.dispatch((0, piral_core_1.withAll)((0, helpers_1.withTiles)((0, helpers_1.getTiles)(tiles, defaultPreferences)), (0, piral_core_1.withRootExtension)('piral-dashboard', Dashboard_1.Dashboard), (0, helpers_1.withRoutes)(routes)));
|
|
16
|
+
return (api, target) => {
|
|
17
|
+
const pilet = target.name;
|
|
18
|
+
let next = 0;
|
|
37
19
|
return {
|
|
38
|
-
registerTile
|
|
20
|
+
registerTile(name, arg, preferences) {
|
|
39
21
|
if (typeof name !== 'string') {
|
|
40
22
|
preferences = arg;
|
|
41
23
|
arg = name;
|
|
42
24
|
name = next++;
|
|
43
25
|
}
|
|
44
|
-
|
|
26
|
+
const id = (0, piral_core_1.buildName)(pilet, name);
|
|
45
27
|
context.registerTile(id, {
|
|
46
|
-
pilet
|
|
47
|
-
component: piral_core_1.withApi(context, arg, api, 'tile'),
|
|
48
|
-
preferences: getPreferences(defaultPreferences, preferences),
|
|
28
|
+
pilet,
|
|
29
|
+
component: (0, piral_core_1.withApi)(context, arg, api, 'tile'),
|
|
30
|
+
preferences: (0, helpers_1.getPreferences)(defaultPreferences, preferences),
|
|
49
31
|
});
|
|
50
|
-
return
|
|
32
|
+
return () => api.unregisterTile(name);
|
|
51
33
|
},
|
|
52
|
-
unregisterTile
|
|
53
|
-
|
|
34
|
+
unregisterTile(name) {
|
|
35
|
+
const id = (0, piral_core_1.buildName)(pilet, name);
|
|
54
36
|
context.unregisterTile(id);
|
|
55
37
|
},
|
|
56
38
|
};
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACrC,2CAAyF;AACzF,2CAAwC;AAExC,uCAA4E;AAuB5E;;GAEG;AACH,SAAgB,kBAAkB,CAAC,SAA0B,EAAE;IAC7D,MAAM,EAAE,KAAK,GAAG,EAAE,EAAE,kBAAkB,GAAG,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC;IAEvE,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE/B,OAAO,CAAC,QAAQ,CACd,IAAA,oBAAO,EACL,IAAA,mBAAS,EAAC,IAAA,kBAAQ,EAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAC9C,IAAA,8BAAiB,EAAC,iBAAiB,EAAE,qBAAS,CAAC,EAC/C,IAAA,oBAAU,EAAC,MAAM,CAAC,CACnB,CACF,CAAC;QAEF,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YACrB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;YAC1B,IAAI,IAAI,GAAG,CAAC,CAAC;YAEb,OAAO;gBACL,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,WAAY;oBAClC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;wBAC5B,WAAW,GAAG,GAAG,CAAC;wBAClB,GAAG,GAAG,IAAI,CAAC;wBACX,IAAI,GAAG,IAAI,EAAE,CAAC;qBACf;oBAED,MAAM,EAAE,GAAG,IAAA,sBAAS,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;oBAClC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE;wBACvB,KAAK;wBACL,SAAS,EAAE,IAAA,oBAAO,EAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC;wBAC7C,WAAW,EAAE,IAAA,wBAAc,EAAC,kBAAkB,EAAE,WAAW,CAAC;qBAC7D,CAAC,CAAC;oBACH,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBACxC,CAAC;gBACD,cAAc,CAAC,IAAI;oBACjB,MAAM,EAAE,GAAG,IAAA,sBAAS,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;oBAClC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;gBAC7B,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAzCD,gDAyCC"}
|
package/lib/default.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultTile = exports.DefaultContainer = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const piral_core_1 = require("piral-core");
|
|
6
|
+
const DefaultContainer = (props) => (React.createElement(piral_core_1.ExtensionSlot, { name: "dashboard", params: props, empty: () => (0, piral_core_1.defaultRender)(props.children, 'default_dashboard') }));
|
|
7
|
+
exports.DefaultContainer = DefaultContainer;
|
|
8
|
+
const DefaultTile = (props) => (0, piral_core_1.defaultRender)(props.children);
|
|
9
|
+
exports.DefaultTile = DefaultTile;
|
|
8
10
|
//# sourceMappingURL=default.js.map
|
package/lib/default.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAA0D;AAGnD,MAAM,gBAAgB,GAAsC,CAAC,KAAK,EAAE,EAAE,CAAC,CAC5E,oBAAC,0BAAa,IAAC,IAAI,EAAC,WAAW,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAA,0BAAa,EAAC,KAAK,CAAC,QAAQ,EAAE,mBAAmB,CAAC,GAAI,CACnH,CAAC;AAFW,QAAA,gBAAgB,oBAE3B;AAEK,MAAM,WAAW,GAAiC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,0BAAa,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAArF,QAAA,WAAW,eAA0E"}
|
package/lib/helpers.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Dict, GlobalState } from 'piral-core';
|
|
2
|
+
import { InitialTile, TilePreferences, TileRegistration } from './types';
|
|
3
|
+
export declare function getPreferences(defaultPreferences: TilePreferences, customPreferences?: TilePreferences): {
|
|
4
|
+
initialColumns?: number;
|
|
5
|
+
initialRows?: number;
|
|
6
|
+
resizable?: boolean;
|
|
7
|
+
customProperties?: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare function getTiles(items: Array<InitialTile>, defaultPreferences: TilePreferences): Dict<TileRegistration>;
|
|
10
|
+
export declare function withTiles(tiles: Dict<TileRegistration>): (state: GlobalState) => GlobalState;
|
|
11
|
+
export declare function withRoutes(routes: Array<string>): (state: GlobalState) => GlobalState;
|
package/lib/helpers.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withRoutes = exports.withTiles = exports.getTiles = exports.getPreferences = void 0;
|
|
4
|
+
const default_1 = require("./default");
|
|
5
|
+
const Dashboard_1 = require("./Dashboard");
|
|
6
|
+
function getPreferences(defaultPreferences, customPreferences = {}) {
|
|
7
|
+
return Object.assign(Object.assign({}, defaultPreferences), customPreferences);
|
|
8
|
+
}
|
|
9
|
+
exports.getPreferences = getPreferences;
|
|
10
|
+
function getTiles(items, defaultPreferences) {
|
|
11
|
+
const tiles = {};
|
|
12
|
+
let i = 0;
|
|
13
|
+
for (const { component, preferences } of items) {
|
|
14
|
+
tiles[`global-${i++}`] = {
|
|
15
|
+
pilet: undefined,
|
|
16
|
+
component,
|
|
17
|
+
preferences: getPreferences(defaultPreferences, preferences),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return tiles;
|
|
21
|
+
}
|
|
22
|
+
exports.getTiles = getTiles;
|
|
23
|
+
function withTiles(tiles) {
|
|
24
|
+
return (state) => (Object.assign(Object.assign({}, state), { components: Object.assign({ DashboardTile: default_1.DefaultTile, DashboardContainer: default_1.DefaultContainer }, state.components), registry: Object.assign(Object.assign({}, state.registry), { tiles }) }));
|
|
25
|
+
}
|
|
26
|
+
exports.withTiles = withTiles;
|
|
27
|
+
function withRoutes(routes) {
|
|
28
|
+
return (state) => (Object.assign(Object.assign({}, state), { routes: Object.assign(Object.assign({}, state.routes), routes.reduce((newRoutes, route) => {
|
|
29
|
+
newRoutes[route] = Dashboard_1.Dashboard;
|
|
30
|
+
return newRoutes;
|
|
31
|
+
}, {})) }));
|
|
32
|
+
}
|
|
33
|
+
exports.withRoutes = withRoutes;
|
|
34
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AACA,uCAA0D;AAC1D,2CAAwC;AAGxC,SAAgB,cAAc,CAAC,kBAAmC,EAAE,oBAAqC,EAAE;IACzG,uCACK,kBAAkB,GAClB,iBAAiB,EACpB;AACJ,CAAC;AALD,wCAKC;AAED,SAAgB,QAAQ,CAAC,KAAyB,EAAE,kBAAmC;IACrF,MAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,KAAK,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,KAAK,EAAE;QAC9C,KAAK,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG;YACvB,KAAK,EAAE,SAAS;YAChB,SAAS;YACT,WAAW,EAAE,cAAc,CAAC,kBAAkB,EAAE,WAAW,CAAC;SAC7D,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAbD,4BAaC;AAED,SAAgB,SAAS,CAAC,KAA6B;IACrD,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,UAAU,kBACR,aAAa,EAAE,qBAAW,EAC1B,kBAAkB,EAAE,0BAAgB,IACjC,KAAK,CAAC,UAAU,GAErB,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,KAAK,OAEP,CAAC;AACL,CAAC;AAbD,8BAaC;AAED,SAAgB,UAAU,CAAC,MAAqB;IAC9C,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,MAAM,kCACD,KAAK,CAAC,MAAM,GACZ,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YACpC,SAAS,CAAC,KAAK,CAAC,GAAG,qBAAS,CAAC;YAC7B,OAAO,SAAS,CAAC;QACnB,CAAC,EAAE,EAAE,CAAC,KAER,CAAC;AACL,CAAC;AAXD,gCAWC"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./create"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./components"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./Dashboard"), exports);
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
import { RouteComponentProps } from 'react-router-dom';
|
|
3
|
-
import { Dict, WrappedComponent, BaseComponentProps, AnyComponent, BaseRegistration, RegistrationDisposer } from 'piral-core';
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import type { RouteComponentProps } from 'react-router-dom';
|
|
3
|
+
import type { Dict, WrappedComponent, BaseComponentProps, AnyComponent, BaseRegistration, RegistrationDisposer } from 'piral-core';
|
|
4
4
|
declare module 'piral-core/lib/types/custom' {
|
|
5
5
|
interface PiletCustomApi extends PiletDashboardApi {
|
|
6
6
|
}
|
|
@@ -39,7 +39,21 @@ declare module 'piral-core/lib/types/custom' {
|
|
|
39
39
|
DashboardTile: ComponentType<DashboardTileProps>;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
export interface InitialTile {
|
|
43
|
+
/**
|
|
44
|
+
* Defines the component to be used for the tile.
|
|
45
|
+
*/
|
|
46
|
+
component: ComponentType<BareTileComponentProps>;
|
|
47
|
+
/**
|
|
48
|
+
* Optionally sets the preferences for the tile.
|
|
49
|
+
*/
|
|
50
|
+
preferences?: TilePreferences;
|
|
51
|
+
}
|
|
42
52
|
export interface DashboardContainerProps extends RouteComponentProps {
|
|
53
|
+
/**
|
|
54
|
+
* The tiles to display.
|
|
55
|
+
*/
|
|
56
|
+
children?: ReactNode;
|
|
43
57
|
}
|
|
44
58
|
export interface DashboardTileProps {
|
|
45
59
|
/**
|
|
@@ -58,6 +72,10 @@ export interface DashboardTileProps {
|
|
|
58
72
|
* The provided tile preferences.
|
|
59
73
|
*/
|
|
60
74
|
meta: TilePreferences;
|
|
75
|
+
/**
|
|
76
|
+
* The content of the tile to display.
|
|
77
|
+
*/
|
|
78
|
+
children?: ReactNode;
|
|
61
79
|
}
|
|
62
80
|
export interface TileErrorInfoProps {
|
|
63
81
|
/**
|
|
@@ -76,6 +94,10 @@ export interface TileErrorInfoProps {
|
|
|
76
94
|
* The currently used number of rows.
|
|
77
95
|
*/
|
|
78
96
|
rows: number;
|
|
97
|
+
/**
|
|
98
|
+
* The name of the pilet emitting the error.
|
|
99
|
+
*/
|
|
100
|
+
pilet?: string;
|
|
79
101
|
}
|
|
80
102
|
export interface BareTileComponentProps {
|
|
81
103
|
/**
|
|
@@ -87,7 +109,7 @@ export interface BareTileComponentProps {
|
|
|
87
109
|
*/
|
|
88
110
|
rows: number;
|
|
89
111
|
}
|
|
90
|
-
export
|
|
112
|
+
export type TileComponentProps = BaseComponentProps & BareTileComponentProps;
|
|
91
113
|
export interface PiralCustomTilePreferences {
|
|
92
114
|
}
|
|
93
115
|
export interface TilePreferences extends PiralCustomTilePreferences {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-dashboard",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta.5640",
|
|
4
4
|
"description": "Plugin for creating a centralized dashboard in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -20,11 +20,29 @@
|
|
|
20
20
|
"module": "esm/index.js",
|
|
21
21
|
"main": "lib/index.js",
|
|
22
22
|
"typings": "lib/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./esm/index.js",
|
|
26
|
+
"require": "./lib/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./esm/*": {
|
|
29
|
+
"import": "./esm/*"
|
|
30
|
+
},
|
|
31
|
+
"./lib/*": {
|
|
32
|
+
"require": "./lib/*"
|
|
33
|
+
},
|
|
34
|
+
"./_/*": {
|
|
35
|
+
"import": "./esm/*.js",
|
|
36
|
+
"require": "./lib/*.js"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
23
40
|
"sideEffects": false,
|
|
24
41
|
"files": [
|
|
25
42
|
"esm",
|
|
26
43
|
"lib",
|
|
27
|
-
"src"
|
|
44
|
+
"src",
|
|
45
|
+
"piral-dashboard.min.js"
|
|
28
46
|
],
|
|
29
47
|
"repository": {
|
|
30
48
|
"type": "git",
|
|
@@ -34,17 +52,19 @@
|
|
|
34
52
|
"url": "https://github.com/smapiot/piral/issues"
|
|
35
53
|
},
|
|
36
54
|
"scripts": {
|
|
37
|
-
"
|
|
55
|
+
"cleanup": "rimraf esm lib piral-dashboard.min.js",
|
|
56
|
+
"build": "yarn build:bundle && yarn build:commonjs && yarn build:esnext",
|
|
57
|
+
"build:bundle": "esbuild src/index.ts --outfile=piral-dashboard.min.js --bundle --external:piral-core --external:react --minify --global-name=piralDashboard",
|
|
38
58
|
"build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
|
|
39
59
|
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
40
60
|
"typedoc": "typedoc --json ../../../docs/types/piral-dashboard.json src --exclude \"src/**/*.test.*\"",
|
|
41
61
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
42
62
|
},
|
|
43
63
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
64
|
+
"@types/react": "^18.0.0",
|
|
65
|
+
"@types/react-router-dom": "^5.1.6",
|
|
66
|
+
"piral-core": "1.0.1-beta.5640",
|
|
67
|
+
"react": "^18.0.0"
|
|
48
68
|
},
|
|
49
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "fa0a72b28fd0a20afec7ef491ec19e93c090fc72"
|
|
50
70
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var piralDashboard=(()=>{var q=Object.create;var h=Object.defineProperty,v=Object.defineProperties,B=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyDescriptors,J=Object.getOwnPropertyNames,S=Object.getOwnPropertySymbols,L=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var I=(e,r,t)=>r in e?h(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,i=(e,r)=>{for(var t in r||(r={}))G.call(r,t)&&I(e,t,r[t]);if(S)for(var t of S(r))M.call(r,t)&&I(e,t,r[t]);return e},s=(e,r)=>v(e,H(r)),F=e=>h(e,"__esModule",{value:!0});var p=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(r,t)=>(typeof require!="undefined"?require:r)[t]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+e+'" is not supported')});var k=(e,r)=>{F(e);for(var t in r)h(e,t,{get:r[t],enumerable:!0})},Q=(e,r,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of J(r))!G.call(e,o)&&o!=="default"&&h(e,o,{get:()=>r[o],enumerable:!(t=B(r,o))||t.enumerable});return e},c=e=>Q(F(h(e!=null?q(L(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var X={};k(X,{Dashboard:()=>d,PiralDashboardContainer:()=>C,PiralDashboardTile:()=>R,createDashboardApi:()=>W});var y={};k(y,{registerTile:()=>U,unregisterTile:()=>V});var D=c(p("piral-core"));function U(e,r,t){e.dispatch(o=>s(i({},o),{registry:s(i({},o.registry),{tiles:(0,D.withKey)(o.registry.tiles,r,t)})}))}function V(e,r){e.dispatch(t=>s(i({},t),{registry:s(i({},t.registry),{tiles:(0,D.withoutKey)(t.registry.tiles,r)})}))}var l=c(p("piral-core"));var P=c(p("react")),z=c(p("piral-core"));var x=c(p("piral-core")),C=(0,x.getPiralComponent)("DashboardContainer"),R=(0,x.getPiralComponent)("DashboardTile");var d=e=>{let r=(0,z.useGlobalState)(a=>a.registry.tiles),{filter:t=()=>!0}=e,o=Object.keys(r).filter(a=>t(r[a])).map(a=>{let{component:f,preferences:T}=r[a],{initialColumns:m=1,initialRows:g=1,resizable:n=!1}=T;return P.createElement(R,{key:a,columns:m,rows:g,resizable:n,meta:T},P.createElement(f,{columns:m,rows:g}))});return P.createElement(C,s(i({},e),{children:o}))};d.displayName="Dashboard";var E=c(p("react")),b=c(p("piral-core")),K=e=>E.createElement(b.ExtensionSlot,{name:"dashboard",params:e,empty:()=>(0,b.defaultRender)(e.children,"default_dashboard")}),N=e=>(0,b.defaultRender)(e.children);function w(e,r={}){return i(i({},e),r)}function j(e,r){let t={},o=0;for(let{component:a,preferences:f}of e)t[`global-${o++}`]={pilet:void 0,component:a,preferences:w(r,f)};return t}function O(e){return r=>s(i({},r),{components:i({DashboardTile:N,DashboardContainer:K},r.components),registry:s(i({},r.registry),{tiles:e})})}function _(e){return r=>s(i({},r),{routes:i(i({},r.routes),e.reduce((t,o)=>(t[o]=d,t),{}))})}function W(e={}){let{tiles:r=[],defaultPreferences:t={},routes:o=["/"]}=e;return a=>(a.defineActions(y),a.dispatch((0,l.withAll)(O(j(r,t)),(0,l.withRootExtension)("piral-dashboard",d),_(o))),(f,T)=>{let m=T.name,g=0;return{registerTile(n,u,A){typeof n!="string"&&(A=u,u=n,n=g++);let $=(0,l.buildName)(m,n);return a.registerTile($,{pilet:m,component:(0,l.withApi)(a,u,f,"tile"),preferences:w(t,A)}),()=>f.unregisterTile(n)},unregisterTile(n){let u=(0,l.buildName)(m,n);a.unregisterTile(u)}}})}return X;})();
|
package/src/Dashboard.test.tsx
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import create from 'zustand';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
3
4
|
import { StateContext } from 'piral-core';
|
|
4
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
5
5
|
import { Dashboard } from './Dashboard';
|
|
6
6
|
|
|
7
|
-
const MockDbContainer: React.FC = ({ children }) => <
|
|
7
|
+
const MockDbContainer: React.FC<any> = ({ children }) => <ul>{children}</ul>;
|
|
8
8
|
MockDbContainer.displayName = 'MockDbContainer';
|
|
9
|
-
const MockDbTile: React.FC = ({ children }) => <
|
|
9
|
+
const MockDbTile: React.FC<any> = ({ children }) => <li>{children}</li>;
|
|
10
10
|
MockDbTile.displayName = 'MockDbTile';
|
|
11
11
|
|
|
12
12
|
function createMockContainer(tiles = {}) {
|
|
13
|
-
const state =
|
|
13
|
+
const state = create(() => ({
|
|
14
14
|
components: {
|
|
15
15
|
DashboardContainer: MockDbContainer,
|
|
16
16
|
DashboardTile: MockDbTile,
|
|
@@ -18,7 +18,7 @@ function createMockContainer(tiles = {}) {
|
|
|
18
18
|
registry: {
|
|
19
19
|
tiles,
|
|
20
20
|
},
|
|
21
|
-
});
|
|
21
|
+
}));
|
|
22
22
|
return {
|
|
23
23
|
context: {
|
|
24
24
|
on: jest.fn(),
|
|
@@ -27,10 +27,10 @@ function createMockContainer(tiles = {}) {
|
|
|
27
27
|
defineActions() {},
|
|
28
28
|
state,
|
|
29
29
|
readState(read) {
|
|
30
|
-
return read(
|
|
30
|
+
return read(state.getState());
|
|
31
31
|
},
|
|
32
32
|
dispatch(update) {
|
|
33
|
-
|
|
33
|
+
state.setState(update(state.getState()));
|
|
34
34
|
},
|
|
35
35
|
} as any,
|
|
36
36
|
api: {} as any,
|
|
@@ -41,13 +41,13 @@ describe('Piral-Dashboard Dashboard component', () => {
|
|
|
41
41
|
it('uses container for a connected dashboard', () => {
|
|
42
42
|
const fake: any = {};
|
|
43
43
|
const { context } = createMockContainer();
|
|
44
|
-
const node =
|
|
44
|
+
const node = render(
|
|
45
45
|
<StateContext.Provider value={context}>
|
|
46
46
|
<Dashboard {...fake} />
|
|
47
47
|
</StateContext.Provider>,
|
|
48
48
|
);
|
|
49
|
-
expect(node.
|
|
50
|
-
expect(node.
|
|
49
|
+
expect(node.getAllByRole('list').length).toBe(1);
|
|
50
|
+
expect(node.queryByRole('listitem')).toBe(null);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
it('uses container and tile for each tile of a connected dashboard', () => {
|
|
@@ -62,12 +62,12 @@ describe('Piral-Dashboard Dashboard component', () => {
|
|
|
62
62
|
preferences: {},
|
|
63
63
|
},
|
|
64
64
|
});
|
|
65
|
-
const node =
|
|
65
|
+
const node = render(
|
|
66
66
|
<StateContext.Provider value={context}>
|
|
67
67
|
<Dashboard {...fake} />
|
|
68
68
|
</StateContext.Provider>,
|
|
69
69
|
);
|
|
70
|
-
expect(node.
|
|
71
|
-
expect(node.
|
|
70
|
+
expect(node.getAllByRole('list').length).toBe(1);
|
|
71
|
+
expect(node.getAllByRole('listitem').length).toBe(2);
|
|
72
72
|
});
|
|
73
73
|
});
|
package/src/Dashboard.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { RouteComponentProps } from 'react-router-dom';
|
|
2
|
+
import type { RouteComponentProps } from 'react-router-dom';
|
|
3
3
|
import { useGlobalState } from 'piral-core';
|
|
4
4
|
import { PiralDashboardContainer, PiralDashboardTile } from './components';
|
|
5
5
|
import { TileRegistration } from './types';
|
|
@@ -8,6 +8,10 @@ export interface DashboardProps extends RouteComponentProps {
|
|
|
8
8
|
filter?(tile: TileRegistration): boolean;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The dashboard component. Integrate this as a page or in a component
|
|
13
|
+
* where dashboard information (tiles) should be shown.
|
|
14
|
+
*/
|
|
11
15
|
export const Dashboard: React.FC<DashboardProps> = (props) => {
|
|
12
16
|
const tiles = useGlobalState((s) => s.registry.tiles);
|
|
13
17
|
const { filter = () => true } = props;
|
package/src/actions.test.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
|
+
import { createListener } from 'piral-base';
|
|
3
|
+
import { createActions } from 'piral-core';
|
|
2
4
|
import { registerTile, unregisterTile } from './actions';
|
|
3
|
-
import { createActions, createListener } from 'piral-core';
|
|
4
5
|
|
|
5
6
|
describe('Dashboard Actions Module', () => {
|
|
6
7
|
it('registerTile and unregisterTile', () => {
|
|
7
|
-
const state =
|
|
8
|
+
const state: any = create(() => ({
|
|
8
9
|
foo: 5,
|
|
9
10
|
registry: {
|
|
10
11
|
foo: 5,
|
|
11
12
|
tiles: {},
|
|
12
13
|
},
|
|
13
|
-
});
|
|
14
|
+
}));
|
|
14
15
|
const ctx = createActions(state, createListener({}));
|
|
15
16
|
registerTile(ctx, 'foo', 10);
|
|
16
|
-
expect(
|
|
17
|
+
expect((state.getState())).toEqual({
|
|
17
18
|
foo: 5,
|
|
18
19
|
registry: {
|
|
19
20
|
foo: 5,
|
|
@@ -23,7 +24,7 @@ describe('Dashboard Actions Module', () => {
|
|
|
23
24
|
},
|
|
24
25
|
});
|
|
25
26
|
unregisterTile(ctx, 'foo');
|
|
26
|
-
expect(
|
|
27
|
+
expect((state.getState())).toEqual({
|
|
27
28
|
foo: 5,
|
|
28
29
|
registry: {
|
|
29
30
|
foo: 5,
|
package/src/components.tsx
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { getPiralComponent } from 'piral-core';
|
|
3
|
-
import { DashboardContainerProps, DashboardTileProps } from './types';
|
|
4
2
|
|
|
5
|
-
export const PiralDashboardContainer
|
|
6
|
-
|
|
7
|
-
);
|
|
8
|
-
export const PiralDashboardTile: React.ComponentType<DashboardTileProps> = getPiralComponent('DashboardTile');
|
|
3
|
+
export const PiralDashboardContainer = getPiralComponent('DashboardContainer');
|
|
4
|
+
export const PiralDashboardTile = getPiralComponent('DashboardTile');
|
package/src/create.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { createElement, FC } from 'react';
|
|
3
3
|
import { createDashboardApi } from './create';
|
|
4
4
|
|
|
@@ -6,7 +6,11 @@ const StubComponent: FC = (props) => createElement('div', props);
|
|
|
6
6
|
StubComponent.displayName = 'StubComponent';
|
|
7
7
|
|
|
8
8
|
function createMockContainer() {
|
|
9
|
-
const state =
|
|
9
|
+
const state = create(() => ({
|
|
10
|
+
registry: {
|
|
11
|
+
extensions: {},
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
10
14
|
return {
|
|
11
15
|
context: {
|
|
12
16
|
on: jest.fn(),
|
|
@@ -19,7 +23,7 @@ function createMockContainer() {
|
|
|
19
23
|
},
|
|
20
24
|
state,
|
|
21
25
|
dispatch(update) {
|
|
22
|
-
|
|
26
|
+
state.setState(update(state.getState()));
|
|
23
27
|
},
|
|
24
28
|
} as any,
|
|
25
29
|
api: {} as any,
|
package/src/create.ts
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import * as actions from './actions';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export interface InitialTile {
|
|
8
|
-
/**
|
|
9
|
-
* Defines the component to be used for the tile.
|
|
10
|
-
*/
|
|
11
|
-
component: ComponentType<BareTileComponentProps>;
|
|
12
|
-
/**
|
|
13
|
-
* Optionally sets the preferences for the tile.
|
|
14
|
-
*/
|
|
15
|
-
preferences?: TilePreferences;
|
|
16
|
-
}
|
|
2
|
+
import { buildName, withApi, PiralPlugin, withRootExtension, withAll } from 'piral-core';
|
|
3
|
+
import { Dashboard } from './Dashboard';
|
|
4
|
+
import { InitialTile, PiletDashboardApi, TilePreferences } from './types';
|
|
5
|
+
import { getPreferences, getTiles, withRoutes, withTiles } from './helpers';
|
|
17
6
|
|
|
18
7
|
/**
|
|
19
8
|
* Available configuration options for the dashboard plugin.
|
|
20
9
|
*/
|
|
21
10
|
export interface DashboardConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Sets the routes where a dashboard should be displayed.
|
|
13
|
+
* @default ['/']
|
|
14
|
+
*/
|
|
15
|
+
routes?: Array<string>;
|
|
22
16
|
/**
|
|
23
17
|
* Sets the tiles to be given by the app shell.
|
|
24
18
|
* @default []
|
|
@@ -31,49 +25,22 @@ export interface DashboardConfig {
|
|
|
31
25
|
defaultPreferences?: TilePreferences;
|
|
32
26
|
}
|
|
33
27
|
|
|
34
|
-
function getPreferences(defaultPreferences: TilePreferences, customPreferences: TilePreferences = {}) {
|
|
35
|
-
return {
|
|
36
|
-
...defaultPreferences,
|
|
37
|
-
...customPreferences,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getTiles(items: Array<InitialTile>, defaultPreferences: TilePreferences) {
|
|
42
|
-
const tiles: Dict<TileRegistration> = {};
|
|
43
|
-
let i = 0;
|
|
44
|
-
|
|
45
|
-
for (const { component, preferences } of items) {
|
|
46
|
-
tiles[`global-${i++}`] = {
|
|
47
|
-
pilet: undefined,
|
|
48
|
-
component,
|
|
49
|
-
preferences: getPreferences(defaultPreferences, preferences),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return tiles;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
28
|
/**
|
|
57
29
|
* Creates the Pilet API extension for activating dashboard support.
|
|
58
30
|
*/
|
|
59
31
|
export function createDashboardApi(config: DashboardConfig = {}): PiralPlugin<PiletDashboardApi> {
|
|
60
|
-
const { tiles = [], defaultPreferences = {} } = config;
|
|
32
|
+
const { tiles = [], defaultPreferences = {}, routes = ['/'] } = config;
|
|
61
33
|
|
|
62
34
|
return (context) => {
|
|
63
35
|
context.defineActions(actions);
|
|
64
36
|
|
|
65
|
-
context.dispatch(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
registry: {
|
|
73
|
-
...state.registry,
|
|
74
|
-
tiles: getTiles(tiles, defaultPreferences),
|
|
75
|
-
},
|
|
76
|
-
}));
|
|
37
|
+
context.dispatch(
|
|
38
|
+
withAll(
|
|
39
|
+
withTiles(getTiles(tiles, defaultPreferences)),
|
|
40
|
+
withRootExtension('piral-dashboard', Dashboard),
|
|
41
|
+
withRoutes(routes),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
77
44
|
|
|
78
45
|
return (api, target) => {
|
|
79
46
|
const pilet = target.name;
|
package/src/default.test.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
3
|
import { DefaultContainer } from './default';
|
|
4
4
|
|
|
5
5
|
jest.mock('piral-core', () => ({
|
|
@@ -35,10 +35,10 @@ const state = {
|
|
|
35
35
|
|
|
36
36
|
(React as any).useMemo = (cb) => cb();
|
|
37
37
|
|
|
38
|
-
const StubDashboard: React.FC = () => <div />;
|
|
38
|
+
const StubDashboard: React.FC = () => <div role="dashboard" />;
|
|
39
39
|
StubDashboard.displayName = 'StubDashboard';
|
|
40
40
|
|
|
41
|
-
const StubTile: React.FC = () => <div />;
|
|
41
|
+
const StubTile: React.FC = () => <div role="tile" />;
|
|
42
42
|
StubTile.displayName = 'StubTile';
|
|
43
43
|
|
|
44
44
|
describe('Default Dashboard Component', () => {
|
|
@@ -47,13 +47,13 @@ describe('Default Dashboard Component', () => {
|
|
|
47
47
|
component: StubTile,
|
|
48
48
|
preferences: {},
|
|
49
49
|
};
|
|
50
|
-
const node =
|
|
51
|
-
<DefaultContainer
|
|
50
|
+
const node = render(
|
|
51
|
+
<DefaultContainer>
|
|
52
52
|
<StubTile />
|
|
53
53
|
</DefaultContainer>,
|
|
54
54
|
);
|
|
55
|
-
expect(node.
|
|
56
|
-
expect(node.
|
|
55
|
+
expect(node.queryByRole("dashboard")).toBe(null);
|
|
56
|
+
expect(node.getAllByRole("tile").length).toBe(1);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
it('renders the provided extension in the default case', () => {
|
|
@@ -62,12 +62,12 @@ describe('Default Dashboard Component', () => {
|
|
|
62
62
|
component: StubDashboard,
|
|
63
63
|
},
|
|
64
64
|
];
|
|
65
|
-
const node =
|
|
66
|
-
<DefaultContainer
|
|
65
|
+
const node = render(
|
|
66
|
+
<DefaultContainer>
|
|
67
67
|
<StubTile />
|
|
68
68
|
</DefaultContainer>,
|
|
69
69
|
);
|
|
70
|
-
expect(node.
|
|
71
|
-
expect(node.
|
|
70
|
+
expect(node.queryByRole("tile")).toBe(null);
|
|
71
|
+
expect(node.getAllByRole("dashboard").length).toBe(1);
|
|
72
72
|
});
|
|
73
73
|
});
|