silverstripe-framework/admin/client/src/components/Preview/Preview.js

84 lines
2.5 KiB
JavaScript
Raw Normal View History

import React from 'react';
import i18n from 'i18n';
Correct naming for JS and CSS files in client/ Removed some dist/js/*.js files since they're no longer built as individual files. This was a side effect of them living in the toplevel folder of admin/client/src/, which used to have all the legacy/*.js files in there (they do need to be built). Following AirBnB convention: https://github.com/airbnb/javascript#naming--filename-matches-export While it technically allows index.js files, we found them to be bad for dev and debugging in practice: Depending on the used IDE, editor tabs all look the same. Other views like Chrome Dev Tools with sourcemaps rely on path context, and are harder to auto-complete. There's no direct rules for CSS files, but same principles apply here. Also renamed the sections/ folder to containers/, which more clearly communicates the distinction between components/ (shouldn't contain state-dependant, smart components). Renamed state/ files to follow AirBnB naming conventions https://github.com/airbnb/javascript#naming--filename-matches-export https://github.com/airbnb/javascript#naming--camelCase-default-export https://github.com/airbnb/javascript#naming--PascalCase-singleton Leaving the folder name in state/<state-key> lowercase since that's also the key to reducers in the actual state object. References: http://engineering.kapost.com/2016/01/organizing-large-react-applications/ https://github.com/erikras/react-redux-universal-hot-example/tree/master/src https://github.com/RickWong/react-isomorphic-starterkit/tree/master/src https://github.com/react-toolbox/react-toolbox/issues/98 https://github.com/react-bootstrap/react-bootstrap/tree/master/src
2016-04-21 11:59:44 +02:00
import SilverStripeComponent from 'lib/SilverStripeComponent';
/**
* Renders the right-hand collapsable change preview panel
*/
Correct naming for JS and CSS files in client/ Removed some dist/js/*.js files since they're no longer built as individual files. This was a side effect of them living in the toplevel folder of admin/client/src/, which used to have all the legacy/*.js files in there (they do need to be built). Following AirBnB convention: https://github.com/airbnb/javascript#naming--filename-matches-export While it technically allows index.js files, we found them to be bad for dev and debugging in practice: Depending on the used IDE, editor tabs all look the same. Other views like Chrome Dev Tools with sourcemaps rely on path context, and are harder to auto-complete. There's no direct rules for CSS files, but same principles apply here. Also renamed the sections/ folder to containers/, which more clearly communicates the distinction between components/ (shouldn't contain state-dependant, smart components). Renamed state/ files to follow AirBnB naming conventions https://github.com/airbnb/javascript#naming--filename-matches-export https://github.com/airbnb/javascript#naming--camelCase-default-export https://github.com/airbnb/javascript#naming--PascalCase-singleton Leaving the folder name in state/<state-key> lowercase since that's also the key to reducers in the actual state object. References: http://engineering.kapost.com/2016/01/organizing-large-react-applications/ https://github.com/erikras/react-redux-universal-hot-example/tree/master/src https://github.com/RickWong/react-isomorphic-starterkit/tree/master/src https://github.com/react-toolbox/react-toolbox/issues/98 https://github.com/react-bootstrap/react-bootstrap/tree/master/src
2016-04-21 11:59:44 +02:00
class Preview extends SilverStripeComponent {
render() {
2016-04-27 04:26:39 +02:00
// @todo - Multiple preview views with toggle slider
let body = null;
let previewUrl = null;
let previewType = '';
// Find preview url
2016-05-10 05:07:29 +02:00
if (this.props.itemLinks && this.props.itemLinks.preview) {
if (this.props.itemLinks.preview.Stage) {
previewUrl = this.props.itemLinks.preview.Stage.href;
previewType = this.props.itemLinks.preview.Stage.type;
} else if (this.props.itemLinks.preview.Live) {
previewUrl = this.props.itemLinks.preview.Live.href;
previewType = this.props.itemLinks.preview.Live.type;
}
}
// Build actions
let editUrl = null;
2016-05-09 06:00:43 +02:00
const editKey = 'edit';
let toolbarButtons = [];
2016-05-10 05:07:29 +02:00
if (this.props.itemLinks && this.props.itemLinks.edit) {
editUrl = this.props.itemLinks.edit.href;
toolbarButtons.push(
2016-05-09 06:00:43 +02:00
<a key={editKey} href={editUrl} className="btn btn-secondary-outline font-icon-edit">
<span className="btn__title">{ i18n._t('Preview.EDIT', 'Edit') }</span>
</a>
);
}
// Build body
2016-05-10 05:07:29 +02:00
if (!this.props.itemId) {
body = (
<div className="preview__overlay">
<h3 className="preview__overlay-text">No preview available.</h3>
</div>
);
} else if (!previewUrl) {
2016-04-27 04:26:39 +02:00
body = (
<div className="preview__overlay">
<h3 className="preview__overlay-text">There is no preview available for this item.</h3>
</div>
2016-04-27 04:26:39 +02:00
);
} else if (previewType && previewType.indexOf('image/') === 0) {
2016-04-28 01:41:40 +02:00
body = (
<div className="preview__file-container panel-scrollable">
<img alt={previewUrl} className="preview__file--fits-space" src={previewUrl} />
2016-04-28 01:41:40 +02:00
</div>
);
} else {
body = <iframe className="preview__iframe" src={previewUrl}></iframe>;
2016-04-27 04:26:39 +02:00
}
// Combine elements
2016-04-27 04:26:39 +02:00
return (
<div className="cms-content__right preview">
{body}
<a href="" className="cms-content__back-btn font-icon-left-open-big" />
<div className="toolbar--south">
<div className="btn-toolbar">
{toolbarButtons}
</div>
</div>
</div>
);
}
}
2016-04-28 01:41:40 +02:00
Preview.propTypes = {
2016-05-10 05:07:29 +02:00
itemLinks: React.PropTypes.object,
itemId: React.PropTypes.number,
2016-04-28 01:41:40 +02:00
};
Correct naming for JS and CSS files in client/ Removed some dist/js/*.js files since they're no longer built as individual files. This was a side effect of them living in the toplevel folder of admin/client/src/, which used to have all the legacy/*.js files in there (they do need to be built). Following AirBnB convention: https://github.com/airbnb/javascript#naming--filename-matches-export While it technically allows index.js files, we found them to be bad for dev and debugging in practice: Depending on the used IDE, editor tabs all look the same. Other views like Chrome Dev Tools with sourcemaps rely on path context, and are harder to auto-complete. There's no direct rules for CSS files, but same principles apply here. Also renamed the sections/ folder to containers/, which more clearly communicates the distinction between components/ (shouldn't contain state-dependant, smart components). Renamed state/ files to follow AirBnB naming conventions https://github.com/airbnb/javascript#naming--filename-matches-export https://github.com/airbnb/javascript#naming--camelCase-default-export https://github.com/airbnb/javascript#naming--PascalCase-singleton Leaving the folder name in state/<state-key> lowercase since that's also the key to reducers in the actual state object. References: http://engineering.kapost.com/2016/01/organizing-large-react-applications/ https://github.com/erikras/react-redux-universal-hot-example/tree/master/src https://github.com/RickWong/react-isomorphic-starterkit/tree/master/src https://github.com/react-toolbox/react-toolbox/issues/98 https://github.com/react-bootstrap/react-bootstrap/tree/master/src
2016-04-21 11:59:44 +02:00
export default Preview;