piral-dashboard
Version:
Plugin for creating a centralized dashboard in Piral.
39 lines • 1.64 kB
JavaScript
import * as actions from './actions';
import { buildName, withApi, withRootExtension, withAll } from 'piral-core';
import { Dashboard } from './Dashboard';
import { getPreferences, getTiles, withRoutes, withTiles } from './helpers';
/**
* Creates the Pilet API extension for activating dashboard support.
*/
export function createDashboardApi(config = {}) {
const { tiles = [], defaultPreferences = {}, routes = ['/'] } = config;
return (context) => {
context.defineActions(actions);
context.dispatch(withAll(withTiles(getTiles(tiles, defaultPreferences)), withRootExtension('piral-dashboard', Dashboard), withRoutes(routes)));
return (api, target) => {
const pilet = target.name;
let next = 0;
return {
registerTile(name, arg, preferences) {
if (typeof name !== 'string') {
preferences = arg;
arg = name;
name = next++;
}
const id = buildName(pilet, name);
context.registerTile(id, {
pilet,
component: withApi(context, arg, api, 'tile'),
preferences: getPreferences(defaultPreferences, preferences),
});
return () => api.unregisterTile(name);
},
unregisterTile(name) {
const id = buildName(pilet, name);
context.unregisterTile(id);
},
};
};
};
}
//# sourceMappingURL=create.js.map