Skip to content

Commit e1f9d31

Browse files
Merge pull request #248 from jekyll/messages
Separate frontend messages into a file
2 parents 8b3b738 + c079dcc commit e1f9d31

File tree

20 files changed

+169
-182
lines changed

20 files changed

+169
-182
lines changed

docs/frontend/constants.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ permalink: /frontend/constants/
77

88
Stores all of the action creators' names
99

10+
## Messages
11+
12+
Stores the following messages;
13+
14+
* confirm delete message
15+
* confirm leave message
16+
* confirm override static file message
17+
* not found message
18+
* notification messages
19+
* validation messages
20+
21+
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.
22+
1023
## API
1124

1225
Stores all of the API endpoints

lib/jekyll-admin/server/static_file.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def static_files
5050
site.static_files
5151
end
5252

53-
def file_list_dir(path)
54-
end
53+
def file_list_dir(path) end
5554

5655
def static_file
5756
static_files.find { |f| f.path == static_file_path }

src/actions/collections.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as ActionTypes from '../constants/actionTypes';
22
import _ from 'underscore';
33
import moment from 'moment';
4-
4+
import { validationError } from '../actions/utils';
5+
import { get, put, del } from '../utils/fetch';
6+
import { validator } from '../utils/validation';
7+
import { slugify } from '../utils/helpers';
58
import {
69
getCollectionsUrl,
710
getCollectionUrl,
@@ -10,18 +13,16 @@ import {
1013
putCollectionDocumentUrl,
1114
deleteCollectionDocumentUrl
1215
} from '../constants/api';
13-
1416
import {
1517
getCollections,
1618
getCollection,
1719
getCollectionDocuments
1820
} from '../constants/api';
19-
20-
import { validationError } from '../actions/utils';
21-
22-
import { get, put, del } from '../utils/fetch';
23-
import { validator } from '../utils/validation';
24-
import { slugify } from '../utils/helpers';
21+
import {
22+
getTitleRequiredMessage,
23+
getFilenameRequiredMessage,
24+
getFilenameNotValidMessage
25+
} from '../constants/messages';
2526

2627
export function fetchCollections() {
2728
return dispatch => {
@@ -76,15 +77,15 @@ export function putDocument(id, collection) {
7677
'path': 'required'
7778
};
7879
let messages = {
79-
'title.required': 'The title is required.',
80-
'path.required': 'The filename is required.'
80+
'title.required': getTitleRequiredMessage(),
81+
'path.required': getFilenameRequiredMessage()
8182
};
8283
if (collection == 'posts') {
8384
validations['path'] = 'required|date';
84-
messages['path.date'] = 'The filename is not valid.';
85+
messages['path.date'] = getFilenameNotValidMessage();
8586
}else {
8687
validations['path'] = 'required|filename';
87-
messages['path.filename'] = 'The filename is not valid.';
88+
messages['path.filename'] = getFilenameNotValidMessage();
8889
}
8990
const errors = validator(metadata, validations, messages);
9091
if(errors.length) {
@@ -101,7 +102,6 @@ export function putDocument(id, collection) {
101102
}),
102103
raw_content
103104
});
104-
// TODO dispatch({type: ActionTypes.PUT_DOCUMENT_REQUEST, doc});
105105
return put(
106106
putCollectionDocumentUrl(
107107
collection, id || path.substring(path.lastIndexOf('/') + 1)

src/actions/config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as ActionTypes from '../constants/actionTypes';
22
import { getConfigurationUrl, putConfigurationUrl } from '../constants/api';
3-
3+
import { getParserErrorMessage } from '../constants/messages';
44
import { addNotification } from './notifications';
5-
65
import { get, put } from '../utils/fetch';
76
import { toJSON } from '../utils/helpers';
87

@@ -24,7 +23,7 @@ export function putConfig(config) {
2423
try {
2524
json = toJSON(config);
2625
} catch (e) {
27-
return dispatch(addNotification('Parse Error', e.message, 'error'));
26+
return dispatch(addNotification(getParserErrorMessage(), e.message, 'error'));
2827
}
2928
return put(
3029
putConfigurationUrl(),

src/actions/datafiles.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import * as ActionTypes from '../constants/actionTypes';
22
import _ from 'underscore';
3-
3+
import { getParserErrorMessage } from '../constants/messages';
4+
import { validationError } from './utils';
5+
import { addNotification } from './notifications';
6+
import { get, put, del } from '../utils/fetch';
7+
import { toJSON } from '../utils/helpers';
8+
import { validator } from '../utils/validation';
49
import {
510
getDataFilesUrl,
611
getDataFileUrl,
712
putDataFileUrl,
813
deleteDataFileUrl
914
} from '../constants/api';
1015

11-
import { validationError } from './utils';
12-
import { addNotification } from './notifications';
13-
14-
import { get, put, del } from '../utils/fetch';
15-
import { toJSON } from '../utils/helpers';
16-
import { validator } from '../utils/validation';
17-
1816
export function fetchDataFiles() {
1917
return (dispatch) => {
2018
dispatch({ type: ActionTypes.FETCH_DATAFILES_REQUEST});
@@ -60,7 +58,7 @@ export function putDataFile(filename, data) {
6058
try {
6159
json = toJSON(data);
6260
} catch (e) {
63-
return dispatch(addNotification('Parse Error', e.message, 'error'));
61+
return dispatch(addNotification(getParserErrorMessage(), e.message, 'error'));
6462
}
6563
return put(
6664
putDataFileUrl(filename),

src/actions/pages.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import * as ActionTypes from '../constants/actionTypes';
22
import _ from 'underscore';
3-
3+
import { validationError } from '../actions/utils';
4+
import { get, put, del } from '../utils/fetch';
5+
import { validator } from '../utils/validation';
6+
import { slugify } from '../utils/helpers';
47
import {
58
getPagesUrl,
69
getPageUrl,
710
putPageUrl,
811
deletePageUrl
912
} from '../constants/api';
10-
11-
import { validationError } from '../actions/utils';
12-
13-
import { get, put, del } from '../utils/fetch';
14-
import { validator } from '../utils/validation';
15-
import { slugify } from '../utils/helpers';
13+
import {
14+
getTitleRequiredMessage,
15+
getFilenameRequiredMessage,
16+
getFilenameNotValidMessage
17+
} from '../constants/messages';
1618

1719
export function fetchPages() {
1820
return (dispatch) => {
@@ -49,8 +51,8 @@ export function putPage(name) {
4951
metadata,
5052
{ 'path': 'required|filename' },
5153
{
52-
'path.required': 'The filename is required.',
53-
'path.filename': 'The filename is not valid.'
54+
'path.required': getTitleRequiredMessage(),
55+
'path.filename': getFilenameNotValidMessage()
5456
}
5557
);
5658
if (errors.length) {
@@ -67,7 +69,6 @@ export function putPage(name) {
6769
}),
6870
raw_content
6971
});
70-
// TODO dispatch({type: ActionTypes.PUT_PAGE_REQUEST, page});
7172
return put(
7273
putPageUrl(name || path),
7374
page,

src/actions/staticfiles.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import * as ActionTypes from '../constants/actionTypes';
22
import _ from 'underscore';
3-
3+
import { get, put, del } from '../utils/fetch';
4+
import { addNotification } from './notifications';
5+
import {
6+
getSuccessMessage,
7+
getErrorMessage,
8+
getUploadSuccessMessage,
9+
getUploadErrorMessage
10+
} from '../constants/messages';
411
import {
512
getStaticFilesUrl,
613
getStaticFileUrl,
714
putStaticFileUrl,
815
deleteStaticFileUrl
916
} from '../constants/api';
1017

11-
import { get, put, del } from '../utils/fetch';
12-
13-
import { addNotification } from './notifications';
14-
1518
export function fetchStaticFiles() {
1619
return dispatch => {
1720
dispatch({ type: ActionTypes.FETCH_STATICFILES_REQUEST});
@@ -47,8 +50,8 @@ export function uploadStaticFiles(files) {
4750
});
4851
dispatch(fetchStaticFiles());
4952
dispatch(addNotification(
50-
'Success',
51-
`${file.name} uploaded successfully`,
53+
getSuccessMessage(),
54+
getUploadSuccessMessage(file.name),
5255
'success'
5356
));
5457
})
@@ -58,8 +61,8 @@ export function uploadStaticFiles(files) {
5861
error
5962
});
6063
dispatch(addNotification(
61-
'Upload Error',
62-
`Error occurred uploading the file.`,
64+
getErrorMessage(),
65+
getUploadErrorMessage(),
6366
'error'
6467
));
6568
});

src/constants/messages.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// inline messages
2+
export const getDeleteMessage = (filename) =>
3+
`Are you sure that you want to delete "${filename}" ?`;
4+
5+
export const getLeaveMessage = () =>
6+
"You have unsaved changes on this page. Are you sure you want to leave?";
7+
8+
export const getNotFoundMessage = (type) =>
9+
`No ${type} found.`;
10+
11+
export const getOverrideMessage = (filename) =>
12+
`${filename} will be overwritten. Continue anyway?`;
13+
14+
// notification messages
15+
export const getParserErrorMessage = () => "Parse Error";
16+
17+
export const getSuccessMessage = () => "Success";
18+
19+
export const getErrorMessage = () => "Error";
20+
21+
export const getUploadSuccessMessage = (filename) =>
22+
`${filename} uploaded successfully`;
23+
24+
export const getUploadErrorMessage = () =>
25+
`Error occurred uploading the file.`;
26+
27+
export const getFetchErrorMessage = (filename) =>
28+
`Could not fetch the ${filename}`;
29+
30+
export const getUpdateErrorMessage = (filename) =>
31+
`Could not update the ${filename}`;
32+
33+
export const getDeleteErrorMessage = (filename) =>
34+
`Could not delete the ${filename}`;
35+
36+
// validation messages
37+
export const getTitleRequiredMessage = () =>
38+
"The title is required.";
39+
40+
export const getFilenameRequiredMessage = () =>
41+
"The filename is required.";
42+
43+
export const getFilenameNotValidMessage = () =>
44+
"The filename is not valid.";

src/containers/views/Configuration.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import React, { Component, PropTypes } from 'react';
22
import { connect } from 'react-redux';
33
import { bindActionCreators } from 'redux';
44
import { withRouter } from 'react-router';
5-
6-
// Components
75
import Editor from '../../components/Editor';
8-
9-
// Actions
106
import { putConfig, onEditorChange } from '../../actions/config';
7+
import { getLeaveMessage } from '../../constants/messages';
118

129
export class Configuration extends Component {
1310

@@ -17,9 +14,9 @@ export class Configuration extends Component {
1714
}
1815

1916
routerWillLeave(nextLocation) {
20-
const { editorChanged } = this.props;
21-
if (editorChanged)
22-
return 'You have unsaved changes on this page. Are you sure you want to leave?';
17+
if (this.props.editorChanged) {
18+
return getLeaveMessage();
19+
}
2320
}
2421

2522
handleSaveClick() {

src/containers/views/DataFileEdit.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ import { bindActionCreators } from 'redux';
44
import { browserHistory, withRouter } from 'react-router';
55
import { Link } from 'react-router';
66
import _ from 'underscore';
7-
8-
// Constants
9-
import { ADMIN_PREFIX } from '../../constants';
10-
11-
// Components
127
import Splitter from '../../components/Splitter';
138
import Editor from '../../components/Editor';
14-
15-
// Actions
169
import { fetchDataFile, putDataFile, deleteDataFile, onDataFileChanged } from '../../actions/datafiles';
1710
import { clearErrors } from '../../actions/utils';
11+
import { ADMIN_PREFIX } from '../../constants';
12+
import { getLeaveMessage, getDeleteMessage, getNotFoundMessage } from '../../constants/messages';
1813

1914
export class DataFileEdit extends Component {
2015

@@ -30,9 +25,9 @@ export class DataFileEdit extends Component {
3025
}
3126

3227
routerWillLeave(nextLocation) {
33-
const { datafileChanged } = this.props;
34-
if (datafileChanged)
35-
return 'You have unsaved changes on this page. Are you sure you want to leave?';
28+
if (this.props.datafileChanged) {
29+
return getLeaveMessage();
30+
}
3631
}
3732

3833
handleClickSave() {
@@ -45,7 +40,7 @@ export class DataFileEdit extends Component {
4540

4641
handleClickDelete(filename) {
4742
const { deleteDataFile } = this.props;
48-
const confirm = window.confirm(`Are you sure that you want to delete "${filename}" ?`);
43+
const confirm = window.confirm(getDeleteMessage(filename));
4944
if (confirm) {
5045
deleteDataFile(filename);
5146
browserHistory.push(`${ADMIN_PREFIX}/datafiles`);
@@ -60,7 +55,7 @@ export class DataFileEdit extends Component {
6055
}
6156

6257
if (_.isEmpty(datafile)) {
63-
return <h1>{`Could not find the data file.`}</h1>;
58+
return <h1>{getNotFoundMessage("data file")}</h1>;
6459
}
6560

6661
const { slug, ext, raw_content, content } = datafile;

0 commit comments

Comments
 (0)