Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Commit 78e28cc

Browse files
committed
merge
2 parents c398e8f + cf02b2c commit 78e28cc

File tree

7 files changed

+113
-76
lines changed

7 files changed

+113
-76
lines changed

docs/canner.schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const postColumns = [{
3131
dataIndex: 'title'
3232
}];
3333

34-
export default <root connector={connector}>
34+
export default <root>
3535
<object keyName="overview"
3636
title="Components Overview"
3737
storage={storage}

docs/index.js

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,14 @@ import { Link, BrowserRouter as Router, Route } from 'react-router-dom';
44
import CMS from '../src/components';
55
import schema from './canner.schema';
66
import {Layout, Menu} from 'antd';
7-
import firebase from 'firebase';
8-
import {FirebaseRtdbClientConnector} from 'canner-graphql-interface';
7+
// eslint-disable-next-line
98
console.log(schema);
109

1110
class CMSExample extends React.Component {
1211
constructor(props) {
1312
super(props);
14-
// try {
15-
// firebase.app();
16-
// } catch (e) {
17-
// firebase.initializeApp({
18-
// apiKey: "AIzaSyDXsFofZTaEk6SIhDj0Ot4YuPidKAfY750",
19-
// authDomain: "test-new-qa.firebaseapp.com",
20-
// databaseURL: "https://test-new-qa.firebaseio.com",
21-
// projectId: "test-new-qa",
22-
// storageBucket: "test-new-qa.appspot.com",
23-
// messagingSenderId: "983887338585"
24-
// });
25-
// }
26-
// const defaultApp = firebase.app()
27-
// this.connector = new FirebaseRtdbClientConnector({
28-
// database: defaultApp.database()
29-
// });
30-
this.state = {
31-
login: true,
32-
dataChanged: {}
33-
};
3413
}
3514

36-
// auth = () => new Promise((resolve, reject) => {
37-
// firebase.auth().onAuthStateChanged(user => {
38-
// if (user) {
39-
// resolve(user);
40-
// }
41-
// });
42-
// firebase.auth().signInAnonymously().catch(error => {
43-
// reject(error);
44-
// });
45-
// });
46-
47-
// componentDidMount() {
48-
// this.auth().then(() => {
49-
// this.setState({
50-
// login: true
51-
// });
52-
// });
53-
// }
54-
5515
dataDidChange = (dataChanged) => {
5616
// eslint-disable-next-line
5717
console.log(dataChanged);
@@ -64,7 +24,6 @@ class CMSExample extends React.Component {
6424

6525
render() {
6626
const baseUrl = "/docs";
67-
const {login} = this.state;
6827
// eslint-disable-next-line
6928
return (
7029
<Router>
@@ -84,17 +43,13 @@ class CMSExample extends React.Component {
8443
</Menu>
8544
</Layout.Sider>
8645
<Layout.Content>
87-
{
88-
login ?
89-
<CMS
90-
schema={schema}
91-
baseUrl={baseUrl}
92-
history={history}
93-
afterDeploy={this.afterDeploy}
94-
dataDidChange={this.dataDidChange}
95-
/> :
96-
null
97-
}
46+
<CMS
47+
schema={schema}
48+
baseUrl={baseUrl}
49+
history={history}
50+
afterDeploy={this.afterDeploy}
51+
dataDidChange={this.dataDidChange}
52+
/>
9853
</Layout.Content>
9954
</Layout>;
10055
}}/>

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "canner",
3-
"version": "1.1.11",
3+
4+
"version": "1.2.0",
45
"description": "Build CMS in few lines of code for different data sources",
56
"main": "lib/index.js",
67
"scripts": {
@@ -46,7 +47,10 @@
4647
"babel-preset-react": "^6.24.1",
4748
"babel-preset-stage-0": "^6.24.1",
4849
"babel-register": "^6.26.0",
50+
<<<<<<< HEAD
4951
"canner-graphql-interface": "^1.15.0",
52+
=======
53+
>>>>>>> opt-cli
5054
"canner-schema-loader": "^1.2.2",
5155
"canner-script": "^1.1.5",
5256
"cross-env": "^5.1.3",
@@ -100,10 +104,17 @@
100104
"react-intl": "^2.4.0",
101105
"react-loadable": "^5.3.1",
102106
"react-spinners": "^0.2.6",
107+
<<<<<<< HEAD
103108
"styled-components": "^3.2.1"
109+
=======
110+
"styled-components": "^3.2.1",
111+
"canner-helpers": "^0.1.15",
112+
"canner-graphql-interface": "^1.15.0"
113+
>>>>>>> opt-cli
104114
},
105115
"peerDependencies": {
106116
"canner-helpers": "^0.1.15",
117+
"canner-graphql-interface": "^1.15.0",
107118
"react": ">=16.3",
108119
"react-dom": ">=16.3"
109120
}

src/action/types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type Action<T> = {
2020
}
2121

2222

23-
export interface Pattern<T> {
23+
export type Pattern<T> = {
2424
actions: Array<T>;
2525

2626
addAction(action: T): void;
@@ -36,7 +36,7 @@ export type ActionManagerStore = {
3636
}>
3737
}
3838

39-
export interface ActionManagerDef {
39+
export type ActionManagerDef = {
4040
store: ActionManagerStore;
4141

4242
addAction(action: Action<ActionType>): void;

src/components/Generator.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import get from 'lodash/get';
1818
import isUndefined from 'lodash/isUndefined';
1919
import mapValues from 'lodash/mapValues';
2020
import RefId from 'canner-ref-id';
21-
import dynamic, {SameLoopPromise} from 'next/dynamic';
21+
import Layouts from 'canner-layouts';
2222

2323
function defaultHoc(Component) {
2424
return Component;
@@ -142,27 +142,19 @@ export default class Generator extends React.PureComponent<Props, State> {
142142
const copyNode = {...node};
143143
let component;
144144
if (isLayout(copyNode)) {
145+
if (typeof copyNode.component === 'string') {
146+
copyNode.component = Layouts[copyNode.component]
147+
}
145148
component = this.wrapByHOC(copyNode.component, (copyNode.hocs || ['containerRouter']).slice() || []);
146149
} else if (isComponent(copyNode)) { // TODO: need to fix, turn plugins to components in compiler
147150

148151
if (isFieldset(copyNode)) {
149152
component = () => <Item />;
150153
} else {
151-
// if using next.js framework dynamic route should use next.js's dynmic function.
152-
if (process.env.ENGINE === 'nextjs') {
153-
component = dynamic(new SameLoopPromise((resolve, reject) => copyNode.loader.then(resolve).catch(reject)),
154-
{
155-
// Since we don't know whether the components are supporting SSR, so we are not going to SSR components.
156-
ssr: false,
157-
loading: Loading
158-
}
159-
)
160-
} else {
161-
component = Loadable({
162-
loader: () => copyNode.loader || Promise.reject(`There is no loader in ${copyNode.path}`),
163-
loading: Loading,
164-
});
165-
}
154+
component = Loadable({
155+
loader: () => copyNode.loader || Promise.reject(`There is no loader in ${copyNode.path}`),
156+
loading: Loading,
157+
});
166158
}
167159
component = this.wrapByHOC(component, ['title', 'onDeploy', 'deploy', 'request', 'query', 'cache', 'route', 'id', 'context'] || []);
168160
}

src/components/index.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import queryString from 'query-string';
55
import Provider from './Provider';
66
import Generator from './Generator';
77
import hocs from '../hocs';
8+
import {createEmptyData} from 'canner-helpers';
89
import {Parser, Traverser} from 'canner-compiler';
9-
10+
import {createClient, MemoryConnector} from 'canner-graphql-interface';
11+
import {isEmpty, isPlainObject} from 'lodash';
1012
// i18n
1113
import en from 'react-intl/locale-data/en';
1214
import zh from 'react-intl/locale-data/zh';
@@ -83,6 +85,7 @@ class CannerCMS extends React.Component<Props, State> {
8385
result[key] = v;
8486
return result;
8587
}, {});
88+
this.client = genClient({...props.schema, schema: schema});
8689
}
8790

8891
deploy = (key: string, id?: string): Promise<*> => {
@@ -108,7 +111,7 @@ class CannerCMS extends React.Component<Props, State> {
108111
afterDeploy,
109112
intl = {},
110113
hideButtons,
111-
schema: {client, storages}
114+
schema: {storages}
112115
} = this.props;
113116
const {location, push} = history;
114117
const {pathname} = location;
@@ -126,7 +129,7 @@ class CannerCMS extends React.Component<Props, State> {
126129
>
127130
<Provider
128131
ref={provider => this.provider = provider}
129-
client={client}
132+
client={this.client}
130133
schema={this.schema}
131134
dataDidChange={dataDidChange}
132135
afterDeploy={afterDeploy}
@@ -167,4 +170,47 @@ function compile(schema, visitors) {
167170
return componentTree;
168171
}
169172

173+
export function genClient(schema) {
174+
const {
175+
resolvers,
176+
connector,
177+
graphqlClient,
178+
} = schema;
179+
180+
const options: Object = {
181+
schema: schema.schema
182+
};
183+
184+
if (connector) {
185+
if (isPlainObject(connector)) {
186+
if (!isEmpty(connector)) {
187+
options.connectors = connector
188+
}
189+
} else {
190+
options.connector = connector;
191+
}
192+
}
193+
194+
if (graphqlClient) {
195+
if (isPlainObject(graphqlClient)) {
196+
if (!isEmpty(connector)) {
197+
options.graphqlClients = graphqlClient;
198+
}
199+
} else {
200+
options.graphqlClient = graphqlClient;
201+
}
202+
}
203+
204+
if (isEmpty(connector) && isEmpty(graphqlClient)) {
205+
options.connector = new MemoryConnector({
206+
defaultData: createEmptyData(schema.schema).toJS()
207+
});
208+
}
209+
210+
if (!isEmpty(resolvers)) {
211+
options.resolvers = resolvers
212+
}
213+
return createClient(options);
214+
}
215+
170216
export default CannerCMS;

src/components/types.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// @flow
2+
import type {ApolloClient} from 'apollo-boost';
3+
export type Connector = any;
4+
export type CannerSchema = {[key: string]: Object};
5+
export type LoadedSchema = {
6+
schema: CannerSchema,
7+
client: ApolloClient,
8+
connectors: {[string]: Connector};
9+
}
10+
export interface CannerProps {
11+
schema: {
12+
13+
},
14+
dataDidChange: Object => void,
15+
afterDeploy: Object => void,
16+
children: React.ChildrenArray<React.Node>,
17+
client: ApolloClient,
18+
imageServiceConfigs: Object,
19+
hocs: {[string]: React.ComponentType<*>},
20+
goTo: (path: string) => void,
21+
baseUrl: string,
22+
23+
history: {
24+
push: (path: string) => void,
25+
location: Object
26+
},
27+
intl: {
28+
locale: string,
29+
defaultLocale: string,
30+
message: Object
31+
},
32+
hideButtons: boolean
33+
}

0 commit comments

Comments
 (0)