begins refactoring frontend into src, moves babel-register to src

This commit is contained in:
James
2019-10-04 16:07:06 -04:00
parent 08c112bdaa
commit 69f8ef881a
149 changed files with 288 additions and 894 deletions

72
components.js Normal file
View File

@@ -0,0 +1,72 @@
export { default as App } from './src/client/components/App';
// Controls
export { default as Button } from './src/client/components/controls/Button';
// Data
export { default as withListData } from './src/client/components/data/list';
export { default as withEditData } from './src/client/components/data/edit';
// Field Types
export { default as fieldType } from './src/client/components/field-types/fieldType';
export { default as Group } from './src/client/components/field-types/Group';
export { default as Repeater } from './src/client/components/field-types/Repeater';
export { default as Input } from './src/client/components/field-types/Input';
export { default as Media } from './src/client/components/field-types/Media';
export { default as Email } from './src/client/components/field-types/Email';
export { default as Password } from './src/client/components/field-types/Password';
export { default as Textarea } from './src/client/components/field-types/Textarea';
export { default as HiddenInput } from './src/client/components/field-types/HiddenInput';
// Forms
export { default as Form, FormContext } from './src/client/components/forms/Form';
export { default as FormSubmit } from './src/client/components/forms/Submit';
// Graphics
export { default as PayloadIcon } from './src/client/components/graphics/PayloadIcon';
export { default as PayloadLogo } from './src/client/components/graphics/PayloadLogo';
export { default as Arrow } from './src/client/components/graphics/Arrow';
export { default as Close } from './src/client/components/graphics/Close';
// Layout
export { default as DefaultTemplate } from './src/client/components/layout/DefaultTemplate';
export { default as Sticky } from './src/client/components/layout/Sticky';
export { default as Sidebar } from './src/client/components/layout/Sidebar';
export { default as ContentBlock } from './src/client/components/layout/ContentBlock';
export { default as Table } from './src/client/components/layout/Table';
export { default as Section } from './src/client/components/layout/Section';
// Modals
export { default as asModal } from './src/client/components/modals/asModal';
// Modules
export { default as Status } from './src/client/components/modules/Status';
export { default as StickyHeader } from './src/client/components/modules/StickyHeader';
export { default as HeadingButton } from './src/client/components/modules/HeadingButton';
export { default as Filter } from './src/client/components/modules/Filter';
export { default as APIUrl } from './src/client/components/modules/APIUrl';
export { default as StepNav } from './src/client/components/modules/StepNav';
export { default as Tooltip } from './src/client/components/modules/Tooltip';
export { default as SearchableTable } from './src/client/components/modules/SearchableTable';
export { default as Localizer } from './src/client/components/modules/Localizer';
export { default as UploadMedia } from './src/client/components/modules/UploadMedia';
// Routes
export { default as CollectionRoutes } from './src/client/components/routes/Collections';
// Utilities
export { default as MeasureWindow } from './src/client/components/utilities/MeasureWindow';
export { default as MeasureScroll } from './src/client/components/utilities/MeasureScroll';
export { default as SetStepNav } from './src/client/components/utilities/SetStepNav';
export { default as LoadGlobals } from './src/client/components/utilities/LoadGlobals';
export { default as SetLocale } from './src/client/components/utilities/SetLocale';
export { default as SetSearchParams } from './src/client/components/utilities/SetSearchParams';
// Views
export { default as Dashboard } from './src/client/components/views/Dashboard';
export { default as Login } from './src/client/components/views/Login';
export { default as CreateUser } from './src/client/components/views/CreateUser';
export { default as MediaLibrary } from './src/client/components/views/MediaLibrary';
export { default as ListView } from './src/client/components/views/collections/List';
export { default as EditView } from './src/client/components/views/collections/Edit';

View File

@@ -1,43 +0,0 @@
export default {
slug: 'orders',
label: 'Orders',
singular: 'Order',
plural: 'Orders',
fields: [
{
name: 'metaInfo',
type: 'group',
fields: {
title: {
type: 'string',
maxLength: 100
},
description: { type: 'textarea',
wysiwyg: false,
height: 100
},
keywords: { type: 'text' }
}
},
{
name: 'content',
type: 'group',
fields: [
{
name: 'exampleField1',
type: 'textarea',
wysiwyg: true,
height: 400
},
{
name: 'flexibleContentExample',
type: 'flex',
availableLayouts: [
'layout1',
'layout5'
]
}
]
}
]
};

View File

@@ -1,31 +0,0 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { EditView } from 'payload/components';
const mapStateToProps = state => ({
collections: state.collections.all
});
class Edit extends Component {
constructor(props) {
super(props);
this.slug = 'orders';
this.collection = this.props.collections.find(collection => {
return collection.slug === this.slug;
});
}
render() {
return (
<EditView
id={this.props.match.params.id}
slug={this.slug}
collection={this.collection}>
<h1>Edit Order {this.props.match.params.id}</h1>
</EditView>
);
}
}
export default connect(mapStateToProps)(Edit);

View File

@@ -1,33 +0,0 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { ListView, HeadingButton, Filter } from 'payload/components';
const mapStateToProps = state => ({
collections: state.collections.all
});
class List extends Component {
constructor(props) {
super(props);
this.slug = 'orders';
this.collection = this.props.collections.find(collection => {
return collection.slug === this.slug;
});
}
render() {
return (
<ListView slug={this.slug} collection={this.collection}>
<HeadingButton
heading="Orders"
buttonLabel="Add New"
buttonUrl={`/collections/${this.slug}/create`}
buttonType="link" />
<Filter />
</ListView>
);
}
}
export default connect(mapStateToProps)(List);

View File

@@ -1,7 +0,0 @@
import List from './List';
import Edit from './Edit';
export default {
List: List,
Edit: Edit
};

View File

@@ -1,8 +1,8 @@
import validate from 'express-validation';
import Joi from 'joi';
const validate = require('express-validation');
const Joi = require('joi');
// TODO: move field specific validations to the config
export default {
module.exports = {
post: validate({
body: {
email: Joi.string().email().required(),

View File

@@ -1,32 +0,0 @@
import express from 'express';
import Payload from '../src';
import payloadConfig from './payload.config';
import User from './config/User';
import Page from './config/Page';
import Category from './config/Category';
const router = express.Router({}); // eslint-disable-line new-cap
export const app = express();
new Payload({
models: [
User,
Page,
Category,
],
config: payloadConfig,
app: app,
router: router,
});
if (process.env.NODE_ENV !== 'production') {
router.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
next();
});
}
app.listen(payloadConfig.port, () => {
console.log(`listening on ${payloadConfig.port}...`);
});

View File

@@ -1,33 +0,0 @@
import React from 'react';
import { render } from 'react-dom';
import { App } from 'payload/components';
import Routes from './components/Routes';
import store from './store';
import config from '../payload.config.js';
import Page from '../Page/Page.config';
import pageViews from '../Page/components';
import Order from '../Order/Order.config';
import orderViews from '../Order/components';
const views = {
orders: orderViews,
pages: pageViews
};
const collections = {
orders: Order,
pages: Page
}
const Index = () => {
return (
<App store={store} collections={collections} config={config}>
<Routes views={views} />
</App>
);
};
render(<Index />, document.getElementById('app'));

View File

@@ -1,4 +1,4 @@
export default {
module.exports = {
slug: 'categories',
label: 'Categories',
labels: {

100
demo/config/Header.js Normal file
View File

@@ -0,0 +1,100 @@
module.exports = {
slug: 'header',
labels: {
singular: 'Header',
},
policies: {
create: (req, res, next) => {
return next();
},
read: (req, res, next) => {
return next();
},
update: (req, res, next) => {
return next();
},
destroy: (req, res, next) => {
return next();
},
},
fields: [
{
name: 'title',
label: 'Page Title',
type: 'input',
unique: true,
localized: true,
maxLength: 100,
required: true,
},
{
name: 'content',
label: 'Content',
type: 'textarea',
localized: true,
height: 100,
required: true
},
{
name: 'categories',
label: 'Categories',
type: 'relationship',
relationType: 'reference',
relationTo: 'Category',
},
{
name: 'image',
label: 'Image',
type: 'media',
required: true
},
{
name: 'author',
label: 'Written by:',
type: 'reference',
reference: {
to: 'Author',
nested: true,
relationship: 'oneToMany'
}
},
{
name: 'slides',
label: 'Slides',
type: 'repeater',
fields: [
{
name: 'content',
type: 'textarea',
label: 'Content'
}
]
},
{
label: 'Meta Information',
type: 'group',
fields: [
{
name: 'metaTitle',
type: 'input',
maxLength: 100,
label: 'Meta Title',
width: 50
},
{
name: 'metaKeywords',
type: 'input',
maxLength: 100,
label: 'Meta Keywords',
width: 50
},
{
name: 'metaDesc',
type: 'textarea',
label: 'Meta Description',
height: 100
}
]
}
],
};

View File

@@ -1,4 +1,4 @@
export default {
module.exports = {
slug: 'pages',
labels: {
singular: 'Page',

View File

@@ -1,8 +1,8 @@
import passportLocalMongoose from 'passport-local-mongoose';
import payloadConfig from '../payload.config';
import userValidate from '../User/User.validate';
const passportLocalMongoose = require('passport-local-mongoose');
const payloadConfig = require('../payload.config');
const userValidate = require('../User/User.validate');
export default {
module.exports = {
slug: 'users',
labels: {
singular: 'User',
@@ -29,7 +29,7 @@ export default {
registration: true,
registrationValidation: userValidate.post,
},
plugins: [{plugin: passportLocalMongoose, options: {usernameField: 'email'}}],
plugins: [{ plugin: passportLocalMongoose, options: { usernameField: 'email' } }],
fields: [
{
name: 'email',

View File

@@ -1,7 +0,0 @@
import { makeExecutableSchema } from 'graphql-tools';
import typeDefs from './types';
import resolvers from './resolvers';
const schema = makeExecutableSchema({ typeDefs, resolvers });
export default schema;

View File

@@ -1,11 +0,0 @@
import { mergeResolvers } from 'merge-graphql-schemas';
import Page from '../Page/Page.resolvers';
import Category from '../Category/Category.resolvers';
const resolvers = [
Page,
Category
];
export default mergeResolvers(resolvers);

View File

@@ -1,10 +0,0 @@
import { mergeTypes } from 'merge-graphql-schemas';
import Page from '../Page/Page.types';
import Category from '../Category/Category.types';
const types = [
Page,
Category
];
export default mergeTypes(types, { all: true });

View File

@@ -1,5 +1,24 @@
require('@babel/register')({
ignore: [/(node_modules)/]
const express = require('express');
const Payload = require('../');
const config = require('./payload.config');
const router = express.Router({}); // eslint-disable-line new-cap
const app = express();
new Payload({
config,
app,
router,
});
require('./app');
if (process.env.NODE_ENV !== 'production') {
router.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
next();
});
}
app.listen(config.port, () => {
console.log(`listening on ${config.port}...`);
});

View File

@@ -1,4 +1,13 @@
export default {
const User = require('./config/User');
const Page = require('./config/Page');
const Category = require('./config/Category');
module.exports = {
models: {
User,
Page,
Category,
},
port: 3000,
serverUrl: 'http://localhost:3000',
cors: ['http://localhost', 'http://localhost:8080', 'http://localhost:8081'],

View File

@@ -1,110 +0,0 @@
{
"variables": [],
"info": {
"name": "Payload",
"_postman_id": "2ea79fc9-1b0a-1b6c-d7e6-6f8cf8d73cb9",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "Public Domain Check",
"request": {
"url": "https://jyiixvked0.execute-api.us-east-1.amazonaws.com/dev/call",
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\"domain\": \"http://localhost:8000\"}"
},
"description": ""
},
"response": []
},
{
"name": "Get Page",
"request": {
"url": "http://localhost:3000/pages",
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"title\": \"sup dog\",\n\t\"content\": \"some shit\"\n}"
},
"description": "\t"
},
"response": []
},
{
"name": "Post Page",
"request": {
"url": "http://localhost:3000/pages",
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"title\": \"sup dog\",\n\t\"content\": \"some shit\"\n}"
},
"description": "\t"
},
"response": []
},
{
"name": "Delete Post",
"request": {
"url": "http://localhost:3000/pages/5bf498411a69cf1b718c730b",
"method": "DELETE",
"header": [],
"body": {},
"description": "Deletes a post with a specific _id"
},
"response": []
},
{
"name": "Update Page",
"request": {
"url": "http://localhost:3000/pages/5bf498411a69cf1b718c730b",
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"title\": \"hey dog\",\n\t\"content\": \"updated shit\"\n}"
},
"description": "\t"
},
"response": []
},
{
"name": "Find Page",
"request": {
"url": "http://localhost:3000/pages/5bf498411a69cf1b718c730b",
"method": "GET",
"header": [],
"body": {},
"description": ""
},
"response": []
}
]
}

View File

@@ -1,399 +0,0 @@
{
"info": {
"name": "Payload",
"_postman_id": "027b80cb-1244-c4b7-01f4-2a0ccf32e0a3",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Roles",
"description": "",
"item": [
{
"name": "At Least",
"description": "",
"item": [
{
"name": "Role - At least admin",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "JWT {{token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:3000/role/admin/atleast",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"role",
"admin",
"atleast"
]
},
"description": "\tThis is to test that the JWT comes through properly. "
},
"response": []
},
{
"name": "Role - At least viewer",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "JWT {{token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:3000/role/viewer/atleast",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"role",
"viewer",
"atleast"
]
},
"description": "\tThis is to test that the JWT comes through properly. "
},
"response": []
},
{
"name": "Role - At least user",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "JWT {{token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:3000/role/user/atleast",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"role",
"user",
"atleast"
]
},
"description": "\tThis is to test that the JWT comes through properly. "
},
"response": []
}
],
"_postman_isSubFolder": true
},
{
"name": "Exact",
"description": "",
"item": [
{
"name": "Role - Admin only",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "JWT {{token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:3000/role/admin/only",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"role",
"admin",
"only"
]
},
"description": "\tThis is to test that the JWT comes through properly. "
},
"response": []
},
{
"name": "Role - User only",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "JWT {{token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:3000/role/user/only",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"role",
"user",
"only"
]
},
"description": "\tThis is to test that the JWT comes through properly. "
},
"response": []
}
],
"_postman_isSubFolder": true
}
]
},
{
"name": "Public Domain Check",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\"domain\": \"http://localhost:8000\"}"
},
"url": {
"raw": "https://jyiixvked0.execute-api.us-east-1.amazonaws.com/dev/call",
"protocol": "https",
"host": [
"jyiixvked0",
"execute-api",
"us-east-1",
"amazonaws",
"com"
],
"path": [
"dev",
"call"
]
}
},
"response": []
},
{
"name": "Get Page",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"title\": \"sup dog\",\n\t\"content\": \"some shit\"\n}"
},
"url": {
"raw": "http://localhost:3000/pages",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"pages"
]
},
"description": "\t"
},
"response": []
},
{
"name": "Post Page",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"title\": \"sup dog\",\n\t\"content\": \"some shit\"\n}"
},
"url": {
"raw": "http://localhost:3000/pages",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"pages"
]
},
"description": "\t"
},
"response": []
},
{
"name": "Post User",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"title\": \"sup dog\",\n\t\"content\": \"some shit\"\n}"
},
"url": {
"raw": "http://localhost:3000/users",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"users"
]
},
"description": "\t"
},
"response": []
},
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"id": "78a4a2f8-716e-4b01-802a-be1d9c915829",
"type": "text/javascript",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setGlobalVariable(\"token\", jsonData.token);"
]
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"email\": \"test@test.com\",\n\t\"password\": \"test123\"\n}"
},
"url": {
"raw": "http://localhost:3000/login",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"login"
]
},
"description": "\t"
},
"response": []
},
{
"name": "Me",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "JWT {{token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:3000/me",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"me"
]
},
"description": "\tThis is to test that the JWT comes through properly. "
},
"response": []
}
]
}

5
index.js Normal file
View File

@@ -0,0 +1,5 @@
require('@babel/register')({
ignore: [/(node_modules)/]
});
module.exports = require('./src');

View File

@@ -13,7 +13,7 @@
"test": "jest --config src/tests/jest.config.js",
"test:int": "jest --config src/tests/jest.config.integration.js",
"cov": "npm run core:build && node ./node_modules/jest/bin/jest.js src/tests --coverage",
"webpack": "webpack-dev-server --mode development --config config/webpack.dev.config.js --open --hot --history-api-fallback",
"webpack": "webpack-dev-server --mode development --config src/config/webpack.dev.config.js --open --hot --history-api-fallback",
"demo-server": "nodemon demo/init.js",
"debug": "nodemon --inspect ./demo/init.js",
"dev": "npm-run-all -p webpack demo-server"

View File

Before

Width:  |  Height:  |  Size: 200 KiB

After

Width:  |  Height:  |  Size: 200 KiB

View File

Before

Width:  |  Height:  |  Size: 193 KiB

After

Width:  |  Height:  |  Size: 193 KiB

View File

Before

Width:  |  Height:  |  Size: 604 KiB

After

Width:  |  Height:  |  Size: 604 KiB

View File

Before

Width:  |  Height:  |  Size: 859 KiB

After

Width:  |  Height:  |  Size: 859 KiB

View File

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 150 KiB

View File

@@ -2,10 +2,12 @@ import React from 'react';
import { PayloadIcon } from 'payload/components';
export default () => {
const Icon = () => {
return (
<div className="icon-wrap">
<PayloadIcon />
</div>
);
};
export default Icon;

View File

@@ -2,10 +2,12 @@ import React from 'react';
import { PayloadLogo } from 'payload/components';
export default () => {
const Logo = () => {
return (
<div className="logo-wrap">
<PayloadLogo />
</div>
);
};
export default Logo;

View File

Before

Width:  |  Height:  |  Size: 943 B

After

Width:  |  Height:  |  Size: 943 B

View File

@@ -0,0 +1,28 @@
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'react-redux';
import Routes from './routes';
import store from '../store';
import LoadConfig from './utilities/LoadConfig';
import MeasureWindow from './utilities/MeasureWindow';
import MeasureScroll from './utilities/MeasureScroll';
import SetLocale from './utilities/SetLocale';
import SetSearchParams from './utilities/SetSearchParams';
const Index = () => {
return (
<Provider store={store}>
<Router>
<MeasureScroll />
<MeasureWindow />
<LoadConfig />
<SetLocale />
<SetSearchParams />
<Routes />
</Router>
</Provider>
);
};
render(<Index />, document.getElementById('app'));

Some files were not shown because too many files have changed in this diff Show More