piral-dashboard 1.0.0-pre.2296 → 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.
Files changed (48) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +34 -10
  3. package/esm/Dashboard.d.ts +5 -1
  4. package/esm/Dashboard.js +13 -10
  5. package/esm/Dashboard.js.map +1 -1
  6. package/esm/actions.js +2 -3
  7. package/esm/actions.js.map +1 -1
  8. package/esm/components.d.ts +3 -4
  9. package/esm/components.js +2 -2
  10. package/esm/components.js.map +1 -1
  11. package/esm/create.d.ts +6 -12
  12. package/esm/create.js +16 -34
  13. package/esm/create.js.map +1 -1
  14. package/esm/default.js +2 -2
  15. package/esm/default.js.map +1 -1
  16. package/esm/helpers.d.ts +11 -0
  17. package/esm/helpers.js +27 -0
  18. package/esm/helpers.js.map +1 -0
  19. package/esm/types.d.ts +26 -4
  20. package/lib/Dashboard.d.ts +5 -1
  21. package/lib/Dashboard.js +17 -13
  22. package/lib/Dashboard.js.map +1 -1
  23. package/lib/actions.js +3 -4
  24. package/lib/actions.js.map +1 -1
  25. package/lib/components.d.ts +3 -4
  26. package/lib/components.js +3 -3
  27. package/lib/components.js.map +1 -1
  28. package/lib/create.d.ts +6 -12
  29. package/lib/create.js +19 -37
  30. package/lib/create.js.map +1 -1
  31. package/lib/default.js +6 -4
  32. package/lib/default.js.map +1 -1
  33. package/lib/helpers.d.ts +11 -0
  34. package/lib/helpers.js +34 -0
  35. package/lib/helpers.js.map +1 -0
  36. package/lib/index.js +1 -1
  37. package/lib/types.d.ts +26 -4
  38. package/package.json +30 -6
  39. package/piral-dashboard.min.js +1 -0
  40. package/src/Dashboard.test.tsx +14 -14
  41. package/src/Dashboard.tsx +5 -1
  42. package/src/actions.test.ts +7 -6
  43. package/src/components.tsx +2 -6
  44. package/src/create.test.ts +7 -3
  45. package/src/create.ts +17 -50
  46. package/src/default.test.tsx +11 -11
  47. package/src/helpers.ts +54 -0
  48. 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
- var tslib_1 = require("tslib");
5
- var actions = require("./actions");
6
- var piral_core_1 = require("piral-core");
7
- var default_1 = require("./default");
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
- if (config === void 0) { config = {}; }
30
- var _a = config.tiles, tiles = _a === void 0 ? [] : _a, _b = config.defaultPreferences, defaultPreferences = _b === void 0 ? {} : _b;
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(function (state) { return (tslib_1.__assign(tslib_1.__assign({}, state), { components: tslib_1.__assign({ DashboardTile: default_1.DefaultTile, DashboardContainer: default_1.DefaultContainer }, state.components), registry: tslib_1.__assign(tslib_1.__assign({}, state.registry), { tiles: getTiles(tiles, defaultPreferences) }) })); });
34
- return function (api, target) {
35
- var pilet = target.name;
36
- var next = 0;
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: function (name, arg, preferences) {
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
- var id = piral_core_1.buildName(pilet, name);
26
+ const id = (0, piral_core_1.buildName)(pilet, name);
45
27
  context.registerTile(id, {
46
- pilet: 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 function () { return api.unregisterTile(name); };
32
+ return () => api.unregisterTile(name);
51
33
  },
52
- unregisterTile: function (name) {
53
- var id = piral_core_1.buildName(pilet, name);
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":";;;;AAAA,mCAAqC;AAErC,yCAAmE;AACnE,qCAA0D;AA8B1D,SAAS,cAAc,CAAC,kBAAmC,EAAE,iBAAuC;IAAvC,kCAAA,EAAA,sBAAuC;IAClG,6CACK,kBAAkB,GAClB,iBAAiB,EACpB;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAyB,EAAE,kBAAmC;IAC9E,IAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,KAAyC,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK,EAAE;QAArC,IAAA,gBAA0B,EAAxB,SAAS,eA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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
- var React = require("react");
5
- var piral_core_1 = require("piral-core");
6
- exports.DefaultContainer = function (props) { return (React.createElement(piral_core_1.ExtensionSlot, { name: "dashboard", params: props, empty: function () { return piral_core_1.defaultRender(props.children, 'default_dashboard'); } })); };
7
- exports.DefaultTile = function (props) { return piral_core_1.defaultRender(props.children); };
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
@@ -1 +1 @@
1
- {"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":";;;AAAA,6BAA+B;AAC/B,yCAA0D;AAG7C,QAAA,gBAAgB,GAAsC,UAAC,KAAK,IAAK,OAAA,CAC5E,oBAAC,0BAAa,IAAC,IAAI,EAAC,WAAW,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,cAAM,OAAA,0BAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,mBAAmB,CAAC,EAAlD,CAAkD,GAAI,CACnH,EAF6E,CAE7E,CAAC;AAEW,QAAA,WAAW,GAAiC,UAAC,KAAK,IAAK,OAAA,0BAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,EAA7B,CAA6B,CAAC"}
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"}
@@ -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
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,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
- var tslib_1 = require("tslib");
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 declare type TileComponentProps = BaseComponentProps & BareTileComponentProps;
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.0-pre.2296",
3
+ "version": "1.0.0",
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,23 @@
34
52
  "url": "https://github.com/smapiot/piral/issues"
35
53
  },
36
54
  "scripts": {
37
- "build": "yarn build:commonjs && yarn build:esnext",
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
- "piral-core": "^1.0.0-pre.2296"
64
+ "@types/react": "^18.0.0",
65
+ "@types/react-router-dom": "^5.1.6",
66
+ "piral-core": "^1.0.0",
67
+ "react": "^18.0.0"
45
68
  },
46
69
  "peerDependencies": {
47
- "piral-core": "0.13.x"
70
+ "piral-core": "0.14.x || 0.15.x",
71
+ "react": ">=16.8.0"
48
72
  },
49
- "gitHead": "8dc47ff93be1eefcc3e226a1e7dd4d58615b4e0c"
73
+ "gitHead": "67d9a2920bd5231baf10bc87ae8985666b18fa3a"
50
74
  }
@@ -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;})();
@@ -1,16 +1,16 @@
1
1
  import * as React from 'react';
2
- import { mount } from 'enzyme';
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 }) => <div>{children}</div>;
7
+ const MockDbContainer: React.FC<any> = ({ children }) => <ul>{children}</ul>;
8
8
  MockDbContainer.displayName = 'MockDbContainer';
9
- const MockDbTile: React.FC = ({ children }) => <div>{children}</div>;
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 = Atom.of({
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(deref(state));
30
+ return read(state.getState());
31
31
  },
32
32
  dispatch(update) {
33
- swap(state, update);
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 = mount(
44
+ const node = render(
45
45
  <StateContext.Provider value={context}>
46
46
  <Dashboard {...fake} />
47
47
  </StateContext.Provider>,
48
48
  );
49
- expect(node.find(MockDbContainer).length).toBe(1);
50
- expect(node.find(MockDbTile).length).toBe(0);
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 = mount(
65
+ const node = render(
66
66
  <StateContext.Provider value={context}>
67
67
  <Dashboard {...fake} />
68
68
  </StateContext.Provider>,
69
69
  );
70
- expect(node.find(MockDbContainer).length).toBe(1);
71
- expect(node.find(MockDbTile).length).toBe(2);
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;
@@ -1,19 +1,20 @@
1
- import { Atom, deref } from '@dbeining/react-atom';
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 = Atom.of({
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(deref(state)).toEqual({
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(deref(state)).toEqual({
27
+ expect((state.getState())).toEqual({
27
28
  foo: 5,
28
29
  registry: {
29
30
  foo: 5,
@@ -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: React.ComponentType<DashboardContainerProps> = getPiralComponent(
6
- 'DashboardContainer',
7
- );
8
- export const PiralDashboardTile: React.ComponentType<DashboardTileProps> = getPiralComponent('DashboardTile');
3
+ export const PiralDashboardContainer = getPiralComponent('DashboardContainer');
4
+ export const PiralDashboardTile = getPiralComponent('DashboardTile');
@@ -1,4 +1,4 @@
1
- import { Atom, swap } from '@dbeining/react-atom';
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 = Atom.of({});
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
- swap(state, update);
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 { ComponentType } from 'react';
3
- import { buildName, withApi, PiralPlugin, Dict } from 'piral-core';
4
- import { DefaultTile, DefaultContainer } from './default';
5
- import { PiletDashboardApi, TilePreferences, BareTileComponentProps, TileRegistration } from './types';
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((state) => ({
66
- ...state,
67
- components: {
68
- DashboardTile: DefaultTile,
69
- DashboardContainer: DefaultContainer,
70
- ...state.components,
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;
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { mount } from 'enzyme';
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 = mount(
51
- <DefaultContainer history={undefined} location={undefined} match={undefined}>
50
+ const node = render(
51
+ <DefaultContainer>
52
52
  <StubTile />
53
53
  </DefaultContainer>,
54
54
  );
55
- expect(node.find(StubDashboard).length).toBe(0);
56
- expect(node.find(StubTile).length).toBe(1);
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 = mount(
66
- <DefaultContainer history={undefined} location={undefined} match={undefined}>
65
+ const node = render(
66
+ <DefaultContainer>
67
67
  <StubTile />
68
68
  </DefaultContainer>,
69
69
  );
70
- expect(node.find(StubTile).length).toBe(0);
71
- expect(node.find(StubDashboard).length).toBe(1);
70
+ expect(node.queryByRole("tile")).toBe(null);
71
+ expect(node.getAllByRole("dashboard").length).toBe(1);
72
72
  });
73
73
  });