Skip to content

Commit

Permalink
Merge pull request #34 from wanicode/master
Browse files Browse the repository at this point in the history
FEATURE: Add global error handling for prototypes.
  • Loading branch information
mficzel authored Mar 28, 2017
2 parents 994cc42 + 56ebc60 commit 2a8fd5d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import styles from './style.css';
availablePresets: state.viewportOptions.availablePresets,

path: state.styleguide.path,
prototypes: state.styleguide.prototypes
prototypes: state.styleguide.prototypes,
globalerror: state.styleguide.globalError
};
})
export default class PreviewSection extends Component {
Expand Down Expand Up @@ -40,7 +41,7 @@ export default class PreviewSection extends Component {

render() {
const {activePreset, availablePresets} = this.props;
const {path, prototypes} = this.props;
const {path, prototypes, globalerror} = this.props;
const {readyCount} = this.state;
const addReady = this.addReady;

Expand All @@ -55,6 +56,7 @@ export default class PreviewSection extends Component {
}

return <div className={styles.previewSection}>
{!!globalerror && <div style={{marginTop: '40px'}} dangerouslySetInnerHTML={{__html: globalerror}} />}
{displayPrototypes.map((item, key) => (
<PrototypeDisplay key={item} prototypeName={item} ready={addReady} visible={key <= readyCount}/>
))}
Expand Down
10 changes: 8 additions & 2 deletions Resources/Private/JavaScript/Redux/Styleguide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const SET_RENDER_PROTOTYPES_ENDPOINT = '@sitegeist/monocle-ui/Styleguide/SET_REN
const SET_IFRAME_URI = '@sitegeist/monocle-ui/Styleguide/SET_IFRAME_URI';
const SET_PREVIEW_URI = '@sitegeist/monocle-ui/Styleguide/SET_PREVIEW_URI';
const SET_FULLSCREEN_URI = '@sitegeist/monocle-ui/Styleguide/SET_FULLSCREEN_URI';
const SET_GLOBAL_ERROR = '@sitegeist/monocle-ui/Styleguide/SET_GLOBAL_ERROR';


const actionTypes = {
Expand All @@ -16,7 +17,8 @@ const actionTypes = {
SET_RENDER_PROTOTYPES_ENDPOINT,
SET_IFRAME_URI,
SET_PREVIEW_URI,
SET_FULLSCREEN_URI
SET_FULLSCREEN_URI,
SET_GLOBAL_ERROR
};

const setPath = createAction(SET_PATH, path => path);
Expand All @@ -26,6 +28,7 @@ const setRenderPrototypesEndpoint = createAction(SET_RENDER_PROTOTYPES_ENDPOINT,
const setIframeUri = createAction(SET_IFRAME_URI, uri => uri);
const setPreviewUri = createAction(SET_PREVIEW_URI, uri => uri);
const setFullscreenUri = createAction(SET_FULLSCREEN_URI, uri => uri);
const setGlobalError = createAction(SET_GLOBAL_ERROR, err => err);

const actions = {
setPath,
Expand All @@ -34,7 +37,8 @@ const actions = {
setRenderPrototypesEndpoint,
setIframeUri,
setPreviewUri,
setFullscreenUri
setFullscreenUri,
setGlobalError
};

const reducer = (state = {}, action) => {
Expand All @@ -53,6 +57,8 @@ const reducer = (state = {}, action) => {
return state.setIn(['previewUri'], action.payload);
case SET_FULLSCREEN_URI:
return state.setIn(['fullscreenUri'], action.payload);
case SET_GLOBAL_ERROR:
return state.setIn(['globalError'], action.payload);
}
return state;
};
Expand Down
14 changes: 12 additions & 2 deletions Resources/Private/JavaScript/Sagas/Prototype/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ function* boot(action) {
method: 'POST',
credentials: 'same-origin'
})
.then(response => response.json());
yield put(redux.Styleguide.actions.setPrototypes(json));
.then(response => {
if (!response.ok) {
return response.text();
}
return response.json()
});

if (typeof json === 'string') {
yield put(redux.Styleguide.actions.setGlobalError(json));
} else {
yield put(redux.Styleguide.actions.setPrototypes(json));
}
}
}

Expand Down
40 changes: 34 additions & 6 deletions Resources/Public/JavaScript/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19319,7 +19319,8 @@
availablePresets: state.viewportOptions.availablePresets,

path: state.styleguide.path,
prototypes: state.styleguide.prototypes
prototypes: state.styleguide.prototypes,
globalerror: state.styleguide.globalError
};
}), _dec(_class = (_temp = _class2 = function (_Component) {
_inherits(PreviewSection, _Component);
Expand Down Expand Up @@ -19353,6 +19354,7 @@
var _props2 = this.props;
var path = _props2.path;
var prototypes = _props2.prototypes;
var globalerror = _props2.globalerror;
var readyCount = this.state.readyCount;

var addReady = this.addReady;
Expand All @@ -19370,6 +19372,7 @@
return _react2.default.createElement(
'div',
{ className: _style2.default.previewSection },
!!globalerror && _react2.default.createElement('div', { style: { marginTop: '40px' }, dangerouslySetInnerHTML: { __html: globalerror } }),
displayPrototypes.map(function (item, key) {
return _react2.default.createElement(_index2.PrototypeDisplay, { key: item, prototypeName: item, ready: addReady, visible: key <= readyCount });
})
Expand Down Expand Up @@ -19838,6 +19841,7 @@
var SET_IFRAME_URI = '@sitegeist/monocle-ui/Styleguide/SET_IFRAME_URI';
var SET_PREVIEW_URI = '@sitegeist/monocle-ui/Styleguide/SET_PREVIEW_URI';
var SET_FULLSCREEN_URI = '@sitegeist/monocle-ui/Styleguide/SET_FULLSCREEN_URI';
var SET_GLOBAL_ERROR = '@sitegeist/monocle-ui/Styleguide/SET_GLOBAL_ERROR';

var actionTypes = {
SET_PATH: SET_PATH,
Expand All @@ -19846,7 +19850,8 @@
SET_RENDER_PROTOTYPES_ENDPOINT: SET_RENDER_PROTOTYPES_ENDPOINT,
SET_IFRAME_URI: SET_IFRAME_URI,
SET_PREVIEW_URI: SET_PREVIEW_URI,
SET_FULLSCREEN_URI: SET_FULLSCREEN_URI
SET_FULLSCREEN_URI: SET_FULLSCREEN_URI,
SET_GLOBAL_ERROR: SET_GLOBAL_ERROR
};

var setPath = (0, _reduxActions.createAction)(SET_PATH, function (path) {
Expand All @@ -19870,6 +19875,9 @@
var setFullscreenUri = (0, _reduxActions.createAction)(SET_FULLSCREEN_URI, function (uri) {
return uri;
});
var setGlobalError = (0, _reduxActions.createAction)(SET_GLOBAL_ERROR, function (err) {
return err;
});

var actions = {
setPath: setPath,
Expand All @@ -19878,7 +19886,8 @@
setRenderPrototypesEndpoint: setRenderPrototypesEndpoint,
setIframeUri: setIframeUri,
setPreviewUri: setPreviewUri,
setFullscreenUri: setFullscreenUri
setFullscreenUri: setFullscreenUri,
setGlobalError: setGlobalError
};

var reducer = function reducer() {
Expand All @@ -19900,6 +19909,8 @@
return state.setIn(['previewUri'], action.payload);
case SET_FULLSCREEN_URI:
return state.setIn(['fullscreenUri'], action.payload);
case SET_GLOBAL_ERROR:
return state.setIn(['globalError'], action.payload);
}
return state;
};
Expand Down Expand Up @@ -20081,7 +20092,7 @@
switch (_context.prev = _context.next) {
case 0:
if (!(action.payload && action.payload.prototypesEndpoint)) {
_context.next = 6;
_context.next = 11;
break;
}

Expand All @@ -20090,15 +20101,32 @@
method: 'POST',
credentials: 'same-origin'
}).then(function (response) {
if (!response.ok) {
return response.text();
}
return response.json();
});

case 3:
json = _context.sent;
_context.next = 6;

if (!(typeof json === 'string')) {
_context.next = 9;
break;
}

_context.next = 7;
return (0, _effects.put)(_index.redux.Styleguide.actions.setGlobalError(json));

case 7:
_context.next = 11;
break;

case 9:
_context.next = 11;
return (0, _effects.put)(_index.redux.Styleguide.actions.setPrototypes(json));

case 6:
case 11:
case 'end':
return _context.stop();
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/App.js.map

Large diffs are not rendered by default.

0 comments on commit 2a8fd5d

Please sign in to comment.