piral-dashboard 0.14.9 → 0.15.0-alpha.3549
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 +25 -7
- package/esm/create.d.ts +6 -12
- package/esm/create.js +3 -21
- package/esm/create.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 +10 -0
- package/lib/create.d.ts +6 -12
- package/lib/create.js +4 -22
- package/lib/create.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/types.d.ts +10 -0
- package/package.json +3 -3
- package/src/create.ts +14 -54
- package/src/helpers.ts +54 -0
- package/src/types.ts +11 -0
package/README.md
CHANGED
|
@@ -116,17 +116,35 @@ const instance = createInstance({
|
|
|
116
116
|
});
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
By default, the dashboard is located at the homepage (`/`). You can change this via the `routes` setting:
|
|
120
120
|
|
|
121
|
-
```
|
|
122
|
-
|
|
121
|
+
```ts
|
|
122
|
+
const instance = createInstance({
|
|
123
|
+
// important part
|
|
124
|
+
plugins: [createDashboardApi({
|
|
125
|
+
routes: ['/dashboard'],
|
|
126
|
+
})],
|
|
127
|
+
// ...
|
|
128
|
+
});
|
|
123
129
|
```
|
|
124
130
|
|
|
125
|
-
|
|
131
|
+
Or alternatively, don't use any route for it and just reference the `Dashboard` component on any page or within the layout.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
// for the instance
|
|
135
|
+
const instance = createInstance({
|
|
136
|
+
// important part
|
|
137
|
+
plugins: [createDashboardApi({
|
|
138
|
+
routes: [],
|
|
139
|
+
})],
|
|
140
|
+
// ...
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
// in some component, maybe even in the layout
|
|
145
|
+
import { Dashboard } from 'piral-dashboard';
|
|
126
146
|
|
|
127
|
-
|
|
128
|
-
<SetRoute path="/dashboard1" component={props => <Dashboard {...props} filter={tile => tile.preferences.category === 'self'} />} />
|
|
129
|
-
<SetRoute path="/dashboard2" component={props => <Dashboard {...props} filter={tile => tile.preferences.category === 'group'} />} />
|
|
147
|
+
// then use: <Dashboard />
|
|
130
148
|
```
|
|
131
149
|
|
|
132
150
|
### Customizing
|
package/esm/create.d.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
1
|
import { PiralPlugin } from 'piral-core';
|
|
3
|
-
import { PiletDashboardApi, TilePreferences
|
|
4
|
-
export interface InitialTile {
|
|
5
|
-
/**
|
|
6
|
-
* Defines the component to be used for the tile.
|
|
7
|
-
*/
|
|
8
|
-
component: ComponentType<BareTileComponentProps>;
|
|
9
|
-
/**
|
|
10
|
-
* Optionally sets the preferences for the tile.
|
|
11
|
-
*/
|
|
12
|
-
preferences?: TilePreferences;
|
|
13
|
-
}
|
|
2
|
+
import { InitialTile, PiletDashboardApi, TilePreferences } from './types';
|
|
14
3
|
/**
|
|
15
4
|
* Available configuration options for the dashboard plugin.
|
|
16
5
|
*/
|
|
17
6
|
export interface DashboardConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Sets the routes where a dashboard should be displayed.
|
|
9
|
+
* @default ['/']
|
|
10
|
+
*/
|
|
11
|
+
routes?: Array<string>;
|
|
18
12
|
/**
|
|
19
13
|
* Sets the tiles to be given by the app shell.
|
|
20
14
|
* @default []
|
package/esm/create.js
CHANGED
|
@@ -1,33 +1,15 @@
|
|
|
1
1
|
import * as actions from './actions';
|
|
2
2
|
import { buildName, withApi, withRootExtension, withAll } from 'piral-core';
|
|
3
|
-
import { DefaultTile, DefaultContainer } from './default';
|
|
4
3
|
import { Dashboard } from './Dashboard';
|
|
5
|
-
|
|
6
|
-
return Object.assign(Object.assign({}, defaultPreferences), customPreferences);
|
|
7
|
-
}
|
|
8
|
-
function getTiles(items, defaultPreferences) {
|
|
9
|
-
const tiles = {};
|
|
10
|
-
let i = 0;
|
|
11
|
-
for (const { component, preferences } of items) {
|
|
12
|
-
tiles[`global-${i++}`] = {
|
|
13
|
-
pilet: undefined,
|
|
14
|
-
component,
|
|
15
|
-
preferences: getPreferences(defaultPreferences, preferences),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
return tiles;
|
|
19
|
-
}
|
|
20
|
-
function withTiles(tiles) {
|
|
21
|
-
return (state) => (Object.assign(Object.assign({}, state), { components: Object.assign({ DashboardTile: DefaultTile, DashboardContainer: DefaultContainer }, state.components), registry: Object.assign(Object.assign({}, state.registry), { tiles }) }));
|
|
22
|
-
}
|
|
4
|
+
import { getPreferences, getTiles, withRoutes, withTiles } from './helpers';
|
|
23
5
|
/**
|
|
24
6
|
* Creates the Pilet API extension for activating dashboard support.
|
|
25
7
|
*/
|
|
26
8
|
export function createDashboardApi(config = {}) {
|
|
27
|
-
const { tiles = [], defaultPreferences = {} } = config;
|
|
9
|
+
const { tiles = [], defaultPreferences = {}, routes = ['/'] } = config;
|
|
28
10
|
return (context) => {
|
|
29
11
|
context.defineActions(actions);
|
|
30
|
-
context.dispatch(withAll(withTiles(getTiles(tiles, defaultPreferences)), withRootExtension('piral-dashboard', Dashboard)));
|
|
12
|
+
context.dispatch(withAll(withTiles(getTiles(tiles, defaultPreferences)), withRootExtension('piral-dashboard', Dashboard), withRoutes(routes)));
|
|
31
13
|
return (api, target) => {
|
|
32
14
|
const pilet = target.name;
|
|
33
15
|
let next = 0;
|
package/esm/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS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c,CAAC,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,SAAS,CAAC,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"}
|
package/esm/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/esm/helpers.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DefaultTile, DefaultContainer } from './default';
|
|
2
|
+
import { Dashboard } from './Dashboard';
|
|
3
|
+
export function getPreferences(defaultPreferences, customPreferences = {}) {
|
|
4
|
+
return Object.assign(Object.assign({}, defaultPreferences), customPreferences);
|
|
5
|
+
}
|
|
6
|
+
export function getTiles(items, defaultPreferences) {
|
|
7
|
+
const tiles = {};
|
|
8
|
+
let i = 0;
|
|
9
|
+
for (const { component, preferences } of items) {
|
|
10
|
+
tiles[`global-${i++}`] = {
|
|
11
|
+
pilet: undefined,
|
|
12
|
+
component,
|
|
13
|
+
preferences: getPreferences(defaultPreferences, preferences),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return tiles;
|
|
17
|
+
}
|
|
18
|
+
export function withTiles(tiles) {
|
|
19
|
+
return (state) => (Object.assign(Object.assign({}, state), { components: Object.assign({ DashboardTile: DefaultTile, DashboardContainer: DefaultContainer }, state.components), registry: Object.assign(Object.assign({}, state.registry), { tiles }) }));
|
|
20
|
+
}
|
|
21
|
+
export function withRoutes(routes) {
|
|
22
|
+
return (state) => (Object.assign(Object.assign({}, state), { routes: Object.assign(Object.assign({}, state.routes), routes.reduce((newRoutes, route) => {
|
|
23
|
+
newRoutes[route] = Dashboard;
|
|
24
|
+
return newRoutes;
|
|
25
|
+
}, {})) }));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,UAAU,cAAc,CAAC,kBAAmC,EAAE,oBAAqC,EAAE;IACzG,uCACK,kBAAkB,GAClB,iBAAiB,EACpB;AACJ,CAAC;AAED,MAAM,UAAU,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;AAED,MAAM,UAAU,SAAS,CAAC,KAA6B;IACrD,OAAO,CAAC,KAAkB,EAAe,EAAE,CAAC,iCACvC,KAAK,KACR,UAAU,kBACR,aAAa,EAAE,WAAW,EAC1B,kBAAkB,EAAE,gBAAgB,IACjC,KAAK,CAAC,UAAU,GAErB,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,KAAK,OAEP,CAAC;AACL,CAAC;AAED,MAAM,UAAU,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,SAAS,CAAC;YAC7B,OAAO,SAAS,CAAC;QACnB,CAAC,EAAE,EAAE,CAAC,KAER,CAAC;AACL,CAAC"}
|
package/esm/types.d.ts
CHANGED
|
@@ -39,6 +39,16 @@ 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 {
|
|
43
53
|
}
|
|
44
54
|
export interface DashboardTileProps {
|
package/lib/create.d.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
1
|
import { PiralPlugin } from 'piral-core';
|
|
3
|
-
import { PiletDashboardApi, TilePreferences
|
|
4
|
-
export interface InitialTile {
|
|
5
|
-
/**
|
|
6
|
-
* Defines the component to be used for the tile.
|
|
7
|
-
*/
|
|
8
|
-
component: ComponentType<BareTileComponentProps>;
|
|
9
|
-
/**
|
|
10
|
-
* Optionally sets the preferences for the tile.
|
|
11
|
-
*/
|
|
12
|
-
preferences?: TilePreferences;
|
|
13
|
-
}
|
|
2
|
+
import { InitialTile, PiletDashboardApi, TilePreferences } from './types';
|
|
14
3
|
/**
|
|
15
4
|
* Available configuration options for the dashboard plugin.
|
|
16
5
|
*/
|
|
17
6
|
export interface DashboardConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Sets the routes where a dashboard should be displayed.
|
|
9
|
+
* @default ['/']
|
|
10
|
+
*/
|
|
11
|
+
routes?: Array<string>;
|
|
18
12
|
/**
|
|
19
13
|
* Sets the tiles to be given by the app shell.
|
|
20
14
|
* @default []
|
package/lib/create.js
CHANGED
|
@@ -3,34 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createDashboardApi = void 0;
|
|
4
4
|
const actions = require("./actions");
|
|
5
5
|
const piral_core_1 = require("piral-core");
|
|
6
|
-
const default_1 = require("./default");
|
|
7
6
|
const Dashboard_1 = require("./Dashboard");
|
|
8
|
-
|
|
9
|
-
return Object.assign(Object.assign({}, defaultPreferences), customPreferences);
|
|
10
|
-
}
|
|
11
|
-
function getTiles(items, defaultPreferences) {
|
|
12
|
-
const tiles = {};
|
|
13
|
-
let i = 0;
|
|
14
|
-
for (const { component, preferences } of items) {
|
|
15
|
-
tiles[`global-${i++}`] = {
|
|
16
|
-
pilet: undefined,
|
|
17
|
-
component,
|
|
18
|
-
preferences: getPreferences(defaultPreferences, preferences),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
return tiles;
|
|
22
|
-
}
|
|
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
|
-
}
|
|
7
|
+
const helpers_1 = require("./helpers");
|
|
26
8
|
/**
|
|
27
9
|
* Creates the Pilet API extension for activating dashboard support.
|
|
28
10
|
*/
|
|
29
11
|
function createDashboardApi(config = {}) {
|
|
30
|
-
const { tiles = [], defaultPreferences = {} } = config;
|
|
12
|
+
const { tiles = [], defaultPreferences = {}, routes = ['/'] } = config;
|
|
31
13
|
return (context) => {
|
|
32
14
|
context.defineActions(actions);
|
|
33
|
-
context.dispatch((0, piral_core_1.withAll)(withTiles(getTiles(tiles, defaultPreferences)), (0, piral_core_1.withRootExtension)('piral-dashboard', Dashboard_1.Dashboard)));
|
|
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)));
|
|
34
16
|
return (api, target) => {
|
|
35
17
|
const pilet = target.name;
|
|
36
18
|
let next = 0;
|
|
@@ -45,7 +27,7 @@ function createDashboardApi(config = {}) {
|
|
|
45
27
|
context.registerTile(id, {
|
|
46
28
|
pilet,
|
|
47
29
|
component: (0, piral_core_1.withApi)(context, arg, api, 'tile'),
|
|
48
|
-
preferences: getPreferences(defaultPreferences, preferences),
|
|
30
|
+
preferences: (0, helpers_1.getPreferences)(defaultPreferences, preferences),
|
|
49
31
|
});
|
|
50
32
|
return () => api.unregisterTile(name);
|
|
51
33
|
},
|
package/lib/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;
|
|
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,SAA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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/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/types.d.ts
CHANGED
|
@@ -39,6 +39,16 @@ 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 {
|
|
43
53
|
}
|
|
44
54
|
export interface DashboardTileProps {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-dashboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0-alpha.3549",
|
|
4
4
|
"description": "Plugin for creating a centralized dashboard in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"piral-core": "
|
|
44
|
+
"piral-core": "0.15.0-alpha.3549"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"piral-core": "0.14.x"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "2edf7bbcee6a7e931348198d14139c7f958877e7"
|
|
50
50
|
}
|
package/src/create.ts
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
import * as actions from './actions';
|
|
2
|
-
import {
|
|
3
|
-
import { buildName, withApi, PiralPlugin, Dict, withRootExtension, withAll, GlobalState } from 'piral-core';
|
|
4
|
-
import { DefaultTile, DefaultContainer } from './default';
|
|
2
|
+
import { buildName, withApi, PiralPlugin, withRootExtension, withAll } from 'piral-core';
|
|
5
3
|
import { Dashboard } from './Dashboard';
|
|
6
|
-
import { PiletDashboardApi, TilePreferences
|
|
7
|
-
|
|
8
|
-
export interface InitialTile {
|
|
9
|
-
/**
|
|
10
|
-
* Defines the component to be used for the tile.
|
|
11
|
-
*/
|
|
12
|
-
component: ComponentType<BareTileComponentProps>;
|
|
13
|
-
/**
|
|
14
|
-
* Optionally sets the preferences for the tile.
|
|
15
|
-
*/
|
|
16
|
-
preferences?: TilePreferences;
|
|
17
|
-
}
|
|
4
|
+
import { InitialTile, PiletDashboardApi, TilePreferences } from './types';
|
|
5
|
+
import { getPreferences, getTiles, withRoutes, withTiles } from './helpers';
|
|
18
6
|
|
|
19
7
|
/**
|
|
20
8
|
* Available configuration options for the dashboard plugin.
|
|
21
9
|
*/
|
|
22
10
|
export interface DashboardConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Sets the routes where a dashboard should be displayed.
|
|
13
|
+
* @default ['/']
|
|
14
|
+
*/
|
|
15
|
+
routes?: Array<string>;
|
|
23
16
|
/**
|
|
24
17
|
* Sets the tiles to be given by the app shell.
|
|
25
18
|
* @default []
|
|
@@ -32,54 +25,21 @@ export interface DashboardConfig {
|
|
|
32
25
|
defaultPreferences?: TilePreferences;
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
function getPreferences(defaultPreferences: TilePreferences, customPreferences: TilePreferences = {}) {
|
|
36
|
-
return {
|
|
37
|
-
...defaultPreferences,
|
|
38
|
-
...customPreferences,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function getTiles(items: Array<InitialTile>, defaultPreferences: TilePreferences) {
|
|
43
|
-
const tiles: Dict<TileRegistration> = {};
|
|
44
|
-
let i = 0;
|
|
45
|
-
|
|
46
|
-
for (const { component, preferences } of items) {
|
|
47
|
-
tiles[`global-${i++}`] = {
|
|
48
|
-
pilet: undefined,
|
|
49
|
-
component,
|
|
50
|
-
preferences: getPreferences(defaultPreferences, preferences),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return tiles;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function withTiles(tiles: Dict<TileRegistration>) {
|
|
58
|
-
return (state: GlobalState): GlobalState => ({
|
|
59
|
-
...state,
|
|
60
|
-
components: {
|
|
61
|
-
DashboardTile: DefaultTile,
|
|
62
|
-
DashboardContainer: DefaultContainer,
|
|
63
|
-
...state.components,
|
|
64
|
-
},
|
|
65
|
-
registry: {
|
|
66
|
-
...state.registry,
|
|
67
|
-
tiles,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
28
|
/**
|
|
73
29
|
* Creates the Pilet API extension for activating dashboard support.
|
|
74
30
|
*/
|
|
75
31
|
export function createDashboardApi(config: DashboardConfig = {}): PiralPlugin<PiletDashboardApi> {
|
|
76
|
-
const { tiles = [], defaultPreferences = {} } = config;
|
|
32
|
+
const { tiles = [], defaultPreferences = {}, routes = ['/'] } = config;
|
|
77
33
|
|
|
78
34
|
return (context) => {
|
|
79
35
|
context.defineActions(actions);
|
|
80
36
|
|
|
81
37
|
context.dispatch(
|
|
82
|
-
withAll(
|
|
38
|
+
withAll(
|
|
39
|
+
withTiles(getTiles(tiles, defaultPreferences)),
|
|
40
|
+
withRootExtension('piral-dashboard', Dashboard),
|
|
41
|
+
withRoutes(routes),
|
|
42
|
+
),
|
|
83
43
|
);
|
|
84
44
|
|
|
85
45
|
return (api, target) => {
|
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
|
@@ -51,6 +51,17 @@ declare module 'piral-core/lib/types/custom' {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
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
|
+
|
|
54
65
|
export interface DashboardContainerProps extends RouteComponentProps {}
|
|
55
66
|
|
|
56
67
|
export interface DashboardTileProps {
|