builds collection editor, builds stepnav

This commit is contained in:
James
2018-08-01 16:11:20 -04:00
parent 648ee44d95
commit 6723dee304
16 changed files with 241 additions and 31 deletions

View File

@@ -61,7 +61,7 @@ module.exports = exports = {
"no-labels": WARN, "no-labels": WARN,
"no-lone-blocks": WARN, "no-lone-blocks": WARN,
"no-loop-func": ERROR, "no-loop-func": ERROR,
"no-magic-numbers": [ WARN, { "ignore": [0] } ], "no-magic-numbers": [ WARN, { "ignore": [-1, 0, 1] } ],
"no-multi-spaces": ERROR, "no-multi-spaces": ERROR,
"no-multi-str": WARN, "no-multi-str": WARN,
"no-native-reassign": ERROR, "no-native-reassign": ERROR,

View File

@@ -1,6 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Route, Switch, Link, withRouter } from 'react-router-dom'; import { Route, Switch, withRouter } from 'react-router-dom';
import DefaultTemplate from 'payload/client/components/layout/DefaultTemplate'; import DefaultTemplate from 'payload/client/components/layout/DefaultTemplate';
import Dashboard from 'payload/client/components/views/Dashboard'; import Dashboard from 'payload/client/components/views/Dashboard';
@@ -21,11 +21,10 @@ class Routes extends Component {
<DefaultTemplate> <DefaultTemplate>
<Route path="/" exact component={Dashboard} /> <Route path="/" exact component={Dashboard} />
{this.props.collections.map((collection) => { {this.props.collections.map((collection) => {
return ( return (
<React.Fragment key={collection.slug}> <React.Fragment key={collection.attrs.slug}>
<Route path={`/collections/${collection.slug}`} exact component={collection.archive} /> <Route path={`/collections/${collection.attrs.slug}`} exact component={collection.components.archive} />
<Route path={`/collections/${collection.slug}/:id`} component={collection.edit} /> <Route path={`/collections/${collection.attrs.slug}/:id`} component={collection.components.edit} />
</React.Fragment> </React.Fragment>
); );
})} })}

View File

@@ -1,9 +1,16 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import SetStepNav from 'payload/client/components/utilities/SetStepNav';
class PagesArchive extends Component { class PagesArchive extends Component {
render() { render() {
return ( return (
<div> <div>
<SetStepNav nav={ [
{
url: '/collections/pages',
label: 'Pages'
}
] } />
<h1>Pages</h1> <h1>Pages</h1>
</div> </div>
); );

View File

@@ -1,11 +1,12 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import CollectionEdit from 'payload/client/components/views/CollectionEdit';
class PagesEdit extends Component { class PagesEdit extends Component {
render() { render() {
return ( return (
<div> <CollectionEdit id={this.props.match.params.id}>
<h1>Edit page {this.props.match.params.id}</h1> <h1>Edit page {this.props.match.params.id}</h1>
</div> </CollectionEdit>
); );
} }
} }

View File

@@ -6,19 +6,98 @@ import OrdersEdit from './client/components/collections/Orders/Edit';
export default [ export default [
{ {
slug: 'pages', attrs: {
label: 'Pages', slug: 'pages',
singular: 'Page', label: 'Pages',
plural: 'Pages', singular: 'Page',
archive: PagesArchive, plural: 'Pages',
edit: PagesEdit },
fields: {
metaInfo: {
type: 'group',
fields: {
title: {
type: 'string',
maxLength: 100
},
description: { type: 'textarea',
wysiwyg: false,
height: 100
},
keywords: { type: 'text' }
}
},
content: {
type: 'group',
fields: {
exampleField1: {
type: 'textarea',
wysiwyg: true,
height: 400
},
flexibleContentExample: {
type: 'flex',
availableLayouts: [
'layout1',
'layout5'
]
}
}
}
},
components: {
archive: PagesArchive,
edit: PagesEdit
}
}, },
{ {
slug: 'orders', attrs: {
label: 'Orders', slug: 'orders',
singular: 'Order', label: 'Orders',
plural: 'Orders', singular: 'Order',
archive: OrdersArchive, plural: 'Orders',
edit: OrdersEdit },
}
fields: {
metaInfo: {
type: 'group',
fields: {
title: {
type: 'string',
maxLength: 100
},
description: { type: 'textarea',
wysiwyg: false,
height: 100
},
keywords: { type: 'text' }
}
},
content: {
type: 'group',
fields: {
exampleField1: {
type: 'textarea',
wysiwyg: true,
height: 400
},
flexibleContentExample: {
type: 'flex',
availableLayouts: [
'layout1',
'layout5'
]
}
}
}
},
components: {
archive: OrdersArchive,
edit: OrdersEdit
}
},
]; ];

View File

@@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import Sidebar from '../Sidebar'; import Sidebar from '../Sidebar';
import StepNav from '../StepNav';
import './index.css'; import './index.css';
@@ -7,7 +8,8 @@ export default props => {
return ( return (
<div className="default-template"> <div className="default-template">
<Sidebar /> <Sidebar />
<StepNav />
{props.children} {props.children}
</div> </div>
); );
} };

View File

@@ -1,6 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Link } from 'react-router-dom'; import { NavLink, Link } from 'react-router-dom';
import Icon from 'demo/client/components/graphics/Icon'; import Icon from 'demo/client/components/graphics/Icon';
import Label from '../../type/Label'; import Label from '../../type/Label';
@@ -20,14 +20,21 @@ class Sidebar extends Component {
<Label>Collections</Label> <Label>Collections</Label>
<nav> <nav>
{this.props.collections.map((collection, i) => { {this.props.collections.map((collection, i) => {
const href = `/collections/${collection.attrs.slug}`;
return ( return (
<Link key={i} to={`/collections/${collection.slug}`}>{collection.plural}</Link> <NavLink activeClassName="active" key={i} to={href}>{collection.attrs.plural}</NavLink>
); );
})} })}
</nav> </nav>
<Label>Globals</Label>
<nav>
<NavLink activeClassName="active" to="/components">Components</NavLink>
<NavLink activeClassName="active" to="/settings">Settings</NavLink>
</nav>
</aside> </aside>
); );
} }
}; }
export default connect(mapStateToProps)(Sidebar); export default connect(mapStateToProps)(Sidebar);

View File

@@ -8,8 +8,11 @@
padding: rem(1); padding: rem(1);
.icon-wrap { .icon-wrap {
@include m; margin: 0 0 rem(.5);
width: $base;
> * {
height: $base;
}
} }
label { label {
@@ -17,7 +20,7 @@
} }
nav { nav {
margin: rem(.5) 0; margin: rem(.25) 0 $base;
a { a {
display: block; display: block;
padding: rem(.33) 0; padding: rem(.33) 0;

View File

@@ -0,0 +1,36 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import Label from '../../type/Label';
import './index.css';
const mapStateToProps = state => ({
nav: state.common.stepNav
});
class StepNav extends Component {
render() {
const dashboardLabel = <Label>Dashboard</Label>;
return (
<nav className="current-view-nav">
{this.props.nav.length > 0
? <Link to="/">{dashboardLabel}</Link>
: dashboardLabel
}
{this.props.nav.map((item, i) => {
const StepLabel = <Label key={i}>{item.label}</Label>;
const Step = this.props.nav.length === i + 1
? StepLabel
: <Link to={item.url} key={i}>{StepLabel}</Link>;
return Step;
})}
</nav>
);
}
}
export default connect(mapStateToProps)(StepNav);

View File

@@ -0,0 +1,22 @@
@import '_styles';
.current-view-nav {
@include m;
display: flex;
* {
display: block;
}
a {
border: 0;
}
> * {
margin-right: rem(.25);
}
> label {
color: $gray;
}
}

View File

@@ -0,0 +1,16 @@
import { Component } from 'react';
import { connect } from 'react-redux';
const mapDispatchToProps = dispatch => ({
set: nav => dispatch({ type: 'SET_STEP_NAV', payload: nav })
});
class SetStepNav extends Component {
componentDidMount() {
this.props.set(this.props.nav);
}
render() { return null; }
}
export default connect(null, mapDispatchToProps)(SetStepNav);

View File

@@ -0,0 +1,28 @@
import React, { Component } from 'react';
import SetStepNav from 'payload/client/components/utilities/SetStepNav';
class CollectionEdit extends Component {
constructor(props) {
super(props);
}
render() {
return (
<article className="collection-edit">
<SetStepNav nav={ [
{
url: '/collections/pages',
label: 'Pages'
},
{
url: `/collections/pages/${this.props.id}`,
label: this.props.id
}
] } />
{this.props.children}
</article>
);
}
}
export default CollectionEdit;

View File

@@ -1,11 +1,13 @@
import React from 'react'; import React from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import SetStepNav from 'payload/client/components/utilities/SetStepNav';
import './index.css'; import './index.css';
export default () => { export default () => {
return ( return (
<article className="dashboard"> <article className="dashboard">
<SetStepNav nav={ [] } />
<h1>Dashboard</h1> <h1>Dashboard</h1>
<Link to="/login">Login</Link> <Link to="/login">Login</Link>
<br /> <br />

View File

@@ -1,5 +1,5 @@
.login { .login {
.logo { .logo-wrap {
display: block; display: block;
margin: 0 auto; margin: 0 auto;
max-width: 200px; max-width: 200px;

View File

@@ -5,7 +5,8 @@ const defaultState = {
windowHeight: 900, windowHeight: 900,
viewWidth: false, viewWidth: false,
viewHeight: false, viewHeight: false,
modalState: false modalState: false,
stepNav: []
}; };
export default (state = defaultState, action) => { export default (state = defaultState, action) => {
@@ -46,6 +47,13 @@ export default (state = defaultState, action) => {
modalStatus: action.payload modalStatus: action.payload
}; };
case 'SET_STEP_NAV':
return {
...state,
stepNav: action.payload
};
default: default:
// //
} }

View File

@@ -38,7 +38,7 @@ $green : #3bffaa;
$dark-green : #0FCE84; $dark-green : #0FCE84;
$light-gray : #f5f5f5; $light-gray : #f5f5f5;
$gray : #B1B1B1; $gray : #909090;
$black : rgb(60, 60, 60); $black : rgb(60, 60, 60);
$pink : #ff8efc; $pink : #ff8efc;