Skip to content

Commit 7cab248

Browse files
committed
setup validation messages
1 parent 745197c commit 7cab248

File tree

16 files changed

+105
-63
lines changed

16 files changed

+105
-63
lines changed

lib/actions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var editor_paths_1 = require('./modules/editor-paths');
2222
exports.editorMarkdownOpen = editor_paths_1.editorMarkdownOpen;
2323
exports.editorTestOpen = editor_paths_1.editorTestOpen;
2424
exports.editorPjOpen = editor_paths_1.editorPjOpen;
25+
var validation_1 = require('./modules/validation');
26+
exports.validatePj = validation_1.validatePj;
2527
var core_coderoad_1 = require('core-coderoad');
2628
exports.alertOpen = core_coderoad_1.alertOpen;
2729
exports.alertClose = core_coderoad_1.alertClose;

lib/components/Publish/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ var styles = {
3030
margin: '30px 10px 20px 10px',
3131
},
3232
};
33-
var fields = [{
34-
name: 'author(s)',
35-
example: 'Shawn McKay <[email protected]>',
36-
status: true,
37-
}, {
38-
name: 'keywords',
39-
example: '["CodeRoad", "JS", "React"]',
40-
status: false,
41-
}];
4233
var TutorialPublish = (function (_super) {
4334
__extends(TutorialPublish, _super);
4435
function TutorialPublish() {
@@ -52,23 +43,32 @@ var TutorialPublish = (function (_super) {
5243
TopPanel_1.topElement.toggle(false);
5344
};
5445
TutorialPublish.prototype.render = function () {
46+
var _a = this.props, validation = _a.validation, validatePj = _a.validatePj;
5547
return (React.createElement(Card_1.Card, {style: styles.card},
5648
React.createElement(Card_1.CardHeader, {title: 'Tutorial Info'}),
5749
React.createElement(Table_1.Table, {fixedHeader: true, selectable: false},
5850
React.createElement(Table_1.TableHeader, {displaySelectAll: false, adjustForCheckbox: false},
5951
React.createElement(Table_1.TableRow, null,
52+
React.createElement(Table_1.TableHeaderColumn, null, "Status"),
6053
React.createElement(Table_1.TableHeaderColumn, null, "Field"),
6154
React.createElement(Table_1.TableHeaderColumn, null, "Description"))
6255
),
63-
React.createElement(Table_1.TableBody, {displayRowCheckbox: false}, fields.map(function (field, index) { return (React.createElement(Table_1.TableRow, {key: index},
64-
React.createElement(Table_1.TableRowColumn, null, field.name),
65-
React.createElement(Table_1.TableRowColumn, null, field.example))); }))),
66-
React.createElement(RaisedButton_1.default, {style: styles.button, label: 'Publish', secondary: true, disabled: true, onTouchTap: function () { return alert('Publish not yet implemented'); }})));
56+
React.createElement(Table_1.TableBody, {displayRowCheckbox: false},
57+
validation.errors.map(function (field, index) { return (React.createElement(Table_1.TableRow, {key: index},
58+
React.createElement(Table_1.TableRowColumn, null, "Error"),
59+
React.createElement(Table_1.TableRowColumn, null, field.name),
60+
React.createElement(Table_1.TableRowColumn, null, field.example))); }),
61+
validation.warnings.map(function (field, index) { return (React.createElement(Table_1.TableRow, {key: index},
62+
React.createElement(Table_1.TableRowColumn, null, "Warning"),
63+
React.createElement(Table_1.TableRowColumn, null, field.name),
64+
React.createElement(Table_1.TableRowColumn, null, field.example))); }))),
65+
React.createElement(RaisedButton_1.default, {style: styles.button, label: 'Validate', primary: true, onTouchTap: validatePj}),
66+
React.createElement(RaisedButton_1.default, {style: styles.button, label: 'Publish', secondary: true, disabled: validation.errors.length === 0, onTouchTap: function () { return alert('Publish not yet implemented'); }})));
6767
};
6868
TutorialPublish = __decorate([
6969
react_redux_1.connect(function (state) { return ({
70-
packageJson: state.packageJson,
71-
}); }, { pjLoad: actions_1.pjLoad, pjSave: actions_1.pjSave, editorPjOpen: actions_1.editorPjOpen }),
70+
validation: state.validation,
71+
}); }, { pjLoad: actions_1.pjLoad, pjSave: actions_1.pjSave, editorPjOpen: actions_1.editorPjOpen, validatePj: actions_1.validatePj }),
7272
__metadata('design:paramtypes', [])
7373
], TutorialPublish);
7474
return TutorialPublish;

lib/modules/validation/actions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
function validatePj() {
4+
return { type: types_1.VALIDATE_PJ };
5+
}
6+
exports.validatePj = validatePj;

lib/modules/validation/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
var actions_1 = require('./actions');
3+
exports.validatePj = actions_1.validatePj;
4+
var reducer_1 = require('./reducer');
5+
exports.reducer = reducer_1.default;

lib/modules/validation/reducer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
var coderoad_cli_1 = require('coderoad-cli');
4+
var _v = {
5+
errors: [],
6+
warnings: [],
7+
};
8+
function validation(v, action) {
9+
if (v === void 0) { v = _v; }
10+
switch (action.type) {
11+
case types_1.VALIDATE_PJ:
12+
return coderoad_cli_1.validatePackageJson();
13+
default:
14+
return v;
15+
}
16+
}
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
exports.default = validation;

lib/modules/validation/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
exports.VALIDATE_PJ = 'VALIDATE_PJ';

lib/reducers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ var setup_1 = require('./modules/setup');
66
var package_json_1 = require('./modules/package-json');
77
var tutorial_1 = require('./modules/tutorial');
88
var window_1 = require('./modules/window');
9+
var validation_1 = require('./modules/validation');
910
var core_coderoad_1 = require('core-coderoad');
1011
Object.defineProperty(exports, "__esModule", { value: true });
1112
exports.default = redux_1.combineReducers({
1213
alert: core_coderoad_1.alertReducer, checks: setup_1.reducer, editor: core_coderoad_1.editorReducer, dir: core_coderoad_1.dirReducer,
1314
packageJson: package_json_1.reducer, pagePosition: page_position_1.reducer, route: core_coderoad_1.routeReducer,
14-
tutorial: tutorial_1.reducer, windowToggle: window_1.reducer, form: redux_form_1.reducer
15+
tutorial: tutorial_1.reducer, windowToggle: window_1.reducer, form: redux_form_1.reducer, validation: validation_1.reducer,
1516
});

src/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
} from './modules/tutorial';
88
export {windowToggle, quit} from './modules/window';
99
export {editorMarkdownOpen, editorTestOpen, editorPjOpen} from './modules/editor-paths';
10+
export {validatePj} from './modules/validation';
1011

1112
export {
1213
alertOpen, alertClose, alertReplay,

src/components/Publish/index.tsx

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Table, TableBody, TableHeader, TableHeaderColumn, TableRow, TableRowColu
44
import MenuItem from 'material-ui/MenuItem';
55
import {Card, CardHeader} from 'material-ui/Card';
66
import RaisedButton from 'material-ui/RaisedButton';
7-
import {pjSave, pjLoad, routeSet, editorPjOpen} from '../../actions';
7+
import {validatePj, pjSave, pjLoad, routeSet, editorPjOpen} from '../../actions';
88
import {topElement} from '../TopPanel';
99
import textField from '../Form/textField';
1010

@@ -19,22 +19,14 @@ const styles = {
1919
},
2020
};
2121

22-
const fields = [{
23-
name: 'author(s)',
24-
example: 'Shawn McKay <[email protected]>',
25-
status: true,
26-
}, {
27-
name: 'keywords',
28-
example: '["CodeRoad", "JS", "React"]',
29-
status: false,
30-
}];
31-
3222
@connect(state => ({
33-
packageJson: state.packageJson,
34-
}), {pjLoad, pjSave, editorPjOpen})
23+
validation: state.validation,
24+
}), {pjLoad, pjSave, editorPjOpen, validatePj})
3525
export default class TutorialPublish extends React.Component<{
36-
packageJson?: any, pjSave?: (pj: PackageJson) => any,
26+
validation?: Validation.Object,
27+
pjSave?: (pj: PackageJson) => any,
3728
pjLoad?: () => Redux.ActionCreator,
29+
validatePj?: () => Redux.ActionCreator,
3830
editorPjOpen?: () => Redux.ActionCreator,
3931
}, {}> {
4032
componentWillMount() {
@@ -45,6 +37,7 @@ export default class TutorialPublish extends React.Component<{
4537
topElement.toggle(false);
4638
}
4739
render() {
40+
const {validation, validatePj} = this.props;
4841
return (
4942
<Card style={styles.card}>
5043
<CardHeader
@@ -59,26 +52,41 @@ export default class TutorialPublish extends React.Component<{
5952
adjustForCheckbox={false}
6053
>
6154
<TableRow>
55+
<TableHeaderColumn>Status</TableHeaderColumn>
6256
<TableHeaderColumn>Field</TableHeaderColumn>
6357
<TableHeaderColumn>Description</TableHeaderColumn>
6458
</TableRow>
6559
</TableHeader>
6660
<TableBody
6761
displayRowCheckbox={false}
6862
>
69-
{fields.map((field, index) => (
63+
{validation.errors.map((field, index) => (
7064
<TableRow key={index}>
65+
<TableRowColumn>Error</TableRowColumn>
66+
<TableRowColumn>{field.name}</TableRowColumn>
67+
<TableRowColumn>{field.example}</TableRowColumn>
68+
</TableRow>
69+
))}
70+
{validation.warnings.map((field, index) => (
71+
<TableRow key={index}>
72+
<TableRowColumn>Warning</TableRowColumn>
7173
<TableRowColumn>{field.name}</TableRowColumn>
7274
<TableRowColumn>{field.example}</TableRowColumn>
7375
</TableRow>
7476
))}
7577
</TableBody>
7678
</Table>
79+
<RaisedButton
80+
style={styles.button}
81+
label='Validate'
82+
primary={true}
83+
onTouchTap={validatePj}
84+
/>
7785
<RaisedButton
7886
style={styles.button}
7987
label='Publish'
8088
secondary={true}
81-
disabled={true}
89+
disabled={validation.errors.length === 0}
8290
onTouchTap={() => alert('Publish not yet implemented')}
8391
/>
8492
</Card>

src/components/Publish/validate.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)