Skip to content

Commit 3f26e98

Browse files
Merge pull request #282 from jekyll/abstraction
Frontend Improvements
2 parents fa62f6a + 4e55ef0 commit 3f26e98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+652
-398
lines changed

docs/_frontend/components.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,51 @@ Can have [all options of SimpleMDE](https://github.com/NextStepWebs/simplemde-ma
2727
## Breadcrumbs
2828

2929
Component for generating breadcrumbs. First breadcrumb indicates the current content
30-
type and the second one which is editable is the path of current item.
30+
type and the second one which can be either an input or a label is the path of the current item.
3131

3232
### PropTypes
3333

3434
```javascript
3535
{
3636
link: String, // Link to the corresponding content type
3737
type: String, // Content type (pages, collections..)
38-
path: String, // File path
38+
content: String, // File path
39+
editable: Boolean, // can be editable or not
3940
onChange: Function // triggered when the path changes
4041
}
4142
```
4243

44+
## Errors
45+
46+
Component for listing the validation errors
47+
48+
### PropTypes
49+
50+
```javascript
51+
{
52+
errors: Array // Array of error messages
53+
}
54+
```
55+
56+
## Button
57+
58+
Generic component for button element.
59+
60+
### PropTypes
61+
62+
```javascript
63+
{
64+
type: String, // type of the button ('save', 'create', 'view', 'upload' etc.)
65+
active: Boolean, // state of the button
66+
onClick: Function, // callback function triggered when the button is clicked
67+
triggered: PropTypes.bool, // click state
68+
block: PropTypes.bool, // should the button fill the parent width
69+
thin: PropTypes.bool, // should the button be small
70+
icon: PropTypes.string, // displays icon if icon name is given
71+
to: PropTypes.string // links to the given URL. If set, onClick is disabled
72+
}
73+
```
74+
4375
## FilePreview
4476

4577
Component for previewing the uploaded file. It renders an image or a div according to

docs/_frontend/constants.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ title: Constants
66

77
Stores all of the action creators' names
88

9-
## Messages
9+
## Lang
1010

11-
Stores the following messages;
11+
Stores the language specific files. Selected language strings are exported from `index.js`.
1212

13-
* `confirm delete message`
14-
* `confirm leave message`
15-
* `confirm override static file message`
16-
* `not found message`
17-
* `notification messages`
18-
* `validation messages`
19-
20-
This allows us to control all of the messages in a single place and also will help us localize the admin panel in the future.
13+
This allows us to control all of the language specific strings in a single place and also will help us localize the admin panel in the future.
2114

2215
## API
2316

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"license": "MIT",
2626
"dependencies": {
2727
"brace": "0.9.1",
28+
"classnames": "^2.2.5",
2829
"isomorphic-fetch": "^2.2.1",
2930
"js-yaml": "^3.6.1",
3031
"lodash": "^4.13.1",

src/actions/collections.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getTitleRequiredMessage,
1010
getFilenameRequiredMessage,
1111
getFilenameNotValidMessage
12-
} from '../constants/messages';
12+
} from '../constants/lang';
1313
import {
1414
getCollectionsUrl,
1515
getCollectionUrl,

src/actions/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as ActionTypes from '../constants/actionTypes';
22
import { getConfigurationUrl, putConfigurationUrl } from '../constants/api';
3-
import { getParserErrorMessage } from '../constants/messages';
3+
import { getParserErrorMessage } from '../constants/lang';
44
import { addNotification } from './notifications';
55
import { get, put } from '../utils/fetch';
66
import { toJSON } from '../utils/helpers';

src/actions/datafiles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getParserErrorMessage,
88
getContentRequiredMessage,
99
getFilenameRequiredMessage
10-
} from '../constants/messages';
10+
} from '../constants/lang';
1111
import {
1212
getDataFilesUrl,
1313
getDataFileUrl,

src/actions/pages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getTitleRequiredMessage,
99
getFilenameRequiredMessage,
1010
getFilenameNotValidMessage
11-
} from '../constants/messages';
11+
} from '../constants/lang';
1212
import {
1313
getPagesUrl,
1414
getPageUrl,

src/actions/staticfiles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getErrorMessage,
88
getUploadSuccessMessage,
99
getUploadErrorMessage
10-
} from '../constants/messages';
10+
} from '../constants/lang';
1111
import {
1212
getStaticFilesUrl,
1313
getStaticFileUrl,

src/components/Breadcrumbs.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,30 @@ export default class Breadcrumbs extends Component {
1212
}
1313

1414
render() {
15-
const { link, type, path } = this.props;
16-
let placeholder = 'example.md';
15+
const { link, type, content, editable } = this.props;
1716

18-
if (type == 'posts') {
19-
const date = moment().format('YYYY-MM-DD');
20-
placeholder = `${date}-your-title.md`;
21-
}else if (type == 'data files') {
22-
placeholder = 'your-filename.yml';
17+
let node = null;
18+
if (editable) {
19+
let placeholder = 'example.md';
20+
if (type == 'posts') {
21+
const date = moment().format('YYYY-MM-DD');
22+
placeholder = `${date}-your-title.md`;
23+
}else if (type == 'datafiles') {
24+
placeholder = 'your-filename.yml';
25+
}
26+
node = (<input onChange={(e) => this.handleChange(e)}
27+
placeholder={placeholder}
28+
defaultValue={content}
29+
ref="input" />);
30+
} else {
31+
node = content;
2332
}
33+
2434
return (
2535
<ul className="breadcrumbs">
2636
<li><Link to={link}>{toTitleCase(type)}</Link></li>
2737
<li className="filename">
28-
<input onChange={(e) => this.handleChange(e)}
29-
ref="input"
30-
placeholder={placeholder}
31-
defaultValue={path} />
38+
{node}
3239
</li>
3340
</ul>
3441
);
@@ -38,6 +45,7 @@ export default class Breadcrumbs extends Component {
3845
Breadcrumbs.propTypes = {
3946
link: PropTypes.string.isRequired,
4047
type: PropTypes.string.isRequired,
41-
path: PropTypes.string.isRequired,
42-
onChange: PropTypes.func.isRequired
48+
content: PropTypes.string.isRequired,
49+
editable: PropTypes.bool,
50+
onChange: PropTypes.func
4351
};

src/components/Button.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import classnames from 'classnames';
3+
import { labels } from '../constants/lang';
4+
5+
export default class Button extends Component {
6+
7+
render() {
8+
const { type, active, triggered, onClick, block, thin, icon, to } = this.props;
9+
10+
const btnClass = classnames({
11+
'btn': true,
12+
'btn-active': active,
13+
'btn-success': active && (type == 'save' || type == 'create'),
14+
'btn-delete': type == 'delete',
15+
'btn-view': type == 'view',
16+
'btn-inactive': !active,
17+
'btn-fat': block,
18+
'btn-thin': thin
19+
});
20+
21+
let label = '';
22+
let triggeredLabel = '';
23+
switch (type) {
24+
case 'save':
25+
label = labels.save.label;
26+
triggeredLabel = labels.save.triggeredLabel;
27+
break;
28+
case 'create':
29+
label = labels.create.label;
30+
triggeredLabel = labels.create.triggeredLabel;
31+
break;
32+
case 'delete':
33+
label = labels.delete.label;
34+
break;
35+
case 'view':
36+
label = labels.view.label;
37+
break;
38+
case 'upload':
39+
label = labels.upload.label;
40+
break;
41+
default:
42+
}
43+
44+
const iconNode = icon ? <i className={`fa fa-${icon}`} aria-hidden="true"></i> : null;
45+
const clickEvent = !to ? onClick : null;
46+
47+
return (
48+
<a href={to}
49+
target="_blank"
50+
onClick={clickEvent}
51+
className={btnClass}>
52+
{iconNode}
53+
{triggered ? triggeredLabel : label}
54+
</a>
55+
);
56+
}
57+
58+
}
59+
60+
Button.propTypes = {
61+
type: PropTypes.string.isRequired,
62+
active: PropTypes.bool.isRequired,
63+
onClick: PropTypes.func,
64+
triggered: PropTypes.bool,
65+
block: PropTypes.bool,
66+
thin: PropTypes.bool,
67+
icon: PropTypes.string,
68+
to: PropTypes.string
69+
};

0 commit comments

Comments
 (0)