Merge pull request #2177 from Apollinaire/debugLayout

Debug & Admin layouts
This commit is contained in:
Apollinaire Lecocq 2019-01-10 12:36:37 +01:00 committed by GitHub
commit ccdbce037d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 133 additions and 45 deletions

View file

@ -0,0 +1,33 @@
/**
* @Author: Apollinaire Lecocq <apollinaire>
* @Date: 08-01-19
* @Last modified by: apollinaire
* @Last modified time: 09-01-19
*/
import React from 'react';
import {registerComponent, Components, withAccess} from 'meteor/vulcan:core';
// we need a component to wrap the `withAccess` hoc around something
function EmptyComponent({children}) {
return children;
}
EmptyComponent.displayName = 'EmptyComponent';
const RestrictToAdmins = withAccess({groups: ['admins']})(EmptyComponent);
/**
* A simple component that renders the existing layout and checks wether the currentUser is an admin or not.
*/
function AdminLayout({children}) {
return (
<Components.Layout>
<RestrictToAdmins>{children}</RestrictToAdmins>
</Components.Layout>
);
}
registerComponent({
name: 'AdminLayout',
component: AdminLayout,
});

View file

@ -1,3 +1,4 @@
import './fragments.js';
import './routes.js';
import './i18n.js';
import '../components/AdminLayout';

View file

@ -1,5 +1,14 @@
import { addRoute, getDynamicComponent } from 'meteor/vulcan:core';
import {addRoute, getDynamicComponent} from 'meteor/vulcan:core';
import React from 'react';
addRoute({ name: 'admin', path: '/admin', component: () => getDynamicComponent(import('../components/AdminHome.jsx'))});
addRoute({ name: 'admin2', path: '/admin/users', component: () => getDynamicComponent(import('../components/AdminHome.jsx'))});
addRoute({
name: 'admin',
path: '/admin',
component: () => getDynamicComponent(import('../components/AdminHome.jsx')),
layoutName: 'AdminLayout',
});
addRoute({
name: 'admin2',
path: '/admin/users',
component: () => getDynamicComponent(import('../components/AdminHome.jsx')),
});

View file

@ -1,10 +0,0 @@
import React from 'react';
import { Components, registerComponent } from 'meteor/vulcan:lib';
const adminStyles = {
padding: '20px'
};
const AdminLayout = props => <div className="admin-layout" style={adminStyles}>{props.children}</div>;
registerComponent('AdminLayout', AdminLayout);

View file

@ -0,0 +1,10 @@
import React from 'react';
import { Components, registerComponent } from 'meteor/vulcan:lib';
const debugStyles = {
padding: '20px'
};
const DebugLayout = props => <div className="debug-layout" style={debugStyles}>{props.children}</div>;
registerComponent('DebugLayout', DebugLayout);

View file

@ -1,26 +1,31 @@
import React from 'react';
import { registerComponent, Components, Routes } from 'meteor/vulcan:lib';
import { Link } from 'react-router';
import {registerComponent, Components, Routes} from 'meteor/vulcan:lib';
import {Link} from 'react-router';
const RoutePath = ({ document }) =>
<Link to={document.path}>{document.path}</Link>;
const RoutePath = ({document}) => (
<Link to={document.path}>{document.path}</Link>
);
const RoutesDashboard = props =>
<div className="routes">
<Components.Datatable
showSearch={false}
showNew={false}
showEdit={false}
data={Object.values(Routes)}
columns={[
'name',
{
name: 'path',
component: RoutePath
},
'componentName',
]}
/>
</div>;
const RoutesDashboard = props => {
return (
<div className="routes">
<Components.Datatable
showSearch={false}
showNew={false}
showEdit={false}
data={Object.values(Routes)}
columns={[
'name',
{
name: 'path',
component: RoutePath,
},
'componentName',
'layoutName'
]}
/>
</div>
);
};
registerComponent('Routes', RoutesDashboard);
registerComponent('Routes', RoutesDashboard);

View file

@ -1,4 +1,4 @@
import '../components/AdminLayout.jsx';
import '../components/DebugLayout.jsx';
import '../components/Emails.jsx';
import '../components/Groups.jsx';

View file

@ -1,14 +1,54 @@
import { addRoute, getDynamicComponent } from 'meteor/vulcan:lib';
import {addRoute, getDynamicComponent} from 'meteor/vulcan:lib';
addRoute([
// {name: 'cheatsheet', path: '/cheatsheet', component: import('./components/Cheatsheet.jsx')},
{ name: 'debug', path: '/debug', componentName: 'DebugDashboard', layoutName: 'AdminLayout' },
{ name: 'debugGroups', path: '/debug/groups', component: () => getDynamicComponent(import('../components/Groups.jsx')), layoutName: 'AdminLayout' },
{ name: 'debugSettings', path: '/debug/settings', componentName: 'Settings', layoutName: 'AdminLayout' },
{ name: 'debugCallbacks', path: '/debug/callbacks', componentName: 'Callbacks', layoutName: 'AdminLayout' },
{
name: 'debug',
path: '/debug',
componentName: 'DebugDashboard',
layoutName: 'DebugLayout',
},
{
name: 'debugGroups',
path: '/debug/groups',
component: () => getDynamicComponent(import('../components/Groups.jsx')),
layoutName: 'DebugLayout',
},
{
name: 'debugSettings',
path: '/debug/settings',
componentName: 'Settings',
layoutName: 'DebugLayout',
},
{
name: 'debugCallbacks',
path: '/debug/callbacks',
componentName: 'Callbacks',
layoutName: 'DebugLayout',
},
// {name: 'emails', path: '/emails', component: () => getDynamicComponent(import('./components/Emails.jsx'))},
{ name: 'debugEmails', path: '/debug/emails', componentName: 'Emails', layoutName: 'AdminLayout' },
{ name: 'debugRoutes', path: '/debug/routes', componentName: 'Routes', layoutName: 'AdminLayout' },
{ name: 'debugComponents', path: '/debug/components', componentName: 'Components', layoutName: 'AdminLayout' },
{ name: 'debugI18n', path: '/debug/i18n', componentName: 'I18n', layoutName: 'AdminLayout' },
{
name: 'debugEmails',
path: '/debug/emails',
componentName: 'Emails',
layoutName: 'DebugLayout',
},
{
name: 'debugRoutes',
path: '/debug/routes',
componentName: 'Routes',
layoutName: 'DebugLayout',
},
{
name: 'debugComponents',
path: '/debug/components',
componentName: 'Components',
layoutName: 'DebugLayout',
},
{
name: 'debugI18n',
path: '/debug/i18n',
componentName: 'I18n',
layoutName: 'DebugLayout',
},
]);