Use static propTypes class property

This commit is contained in:
Andrey Okonetchnikov 2016-10-03 14:33:48 +02:00
parent 382b1537b0
commit 4010a16a76
8 changed files with 72 additions and 71 deletions

View File

@ -8,6 +8,16 @@ export const SEARCH = 'SEARCH';
const PLACEHOLDER = 'Search or enter a command'; const PLACEHOLDER = 'Search or enter a command';
class FindBar extends Component { class FindBar extends Component {
static propTypes = {
commands: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
pattern: PropTypes.string.isRequired
})).isRequired,
defaultCommands: PropTypes.arrayOf(PropTypes.string),
runCommand: PropTypes.func.isRequired,
};
constructor() { constructor() {
super(); super();
this._compiledCommands = []; this._compiledCommands = [];
@ -352,14 +362,4 @@ class FindBar extends Component {
} }
} }
FindBar.propTypes = {
commands: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
pattern: PropTypes.string.isRequired
})).isRequired,
defaultCommands: PropTypes.arrayOf(PropTypes.string),
runCommand: PropTypes.func.isRequired,
};
export default FindBar; export default FindBar;

View File

@ -6,6 +6,12 @@ import { resolveWidget } from './Widgets';
import styles from './PreviewPane.css'; import styles from './PreviewPane.css';
class Preview extends React.Component { class Preview extends React.Component {
static propTypes = {
collection: ImmutablePropTypes.map.isRequired,
entry: ImmutablePropTypes.map.isRequired,
getMedia: PropTypes.func.isRequired,
};
previewFor(field) { previewFor(field) {
const { entry, getMedia } = this.props; const { entry, getMedia } = this.props;
const widget = resolveWidget(field.get('widget')); const widget = resolveWidget(field.get('widget'));
@ -26,12 +32,6 @@ class Preview extends React.Component {
} }
} }
Preview.propTypes = {
collection: ImmutablePropTypes.map.isRequired,
entry: ImmutablePropTypes.map.isRequired,
getMedia: PropTypes.func.isRequired,
};
export default class PreviewPane extends React.Component { export default class PreviewPane extends React.Component {
componentDidUpdate() { componentDidUpdate() {
this.renderPreview(); this.renderPreview();

View File

@ -69,6 +69,12 @@ class UnpublishedListing extends React.Component {
} }
}; };
static propTypes = {
entries: ImmutablePropTypes.orderedMap,
handleChangeStatus: PropTypes.func.isRequired,
handlePublish: PropTypes.func.isRequired,
};
render() { render() {
const columns = this.renderColumns(this.props.entries); const columns = this.renderColumns(this.props.entries);
return ( return (
@ -82,10 +88,4 @@ class UnpublishedListing extends React.Component {
} }
} }
UnpublishedListing.propTypes = {
entries: ImmutablePropTypes.orderedMap,
handleChangeStatus: PropTypes.func.isRequired,
handlePublish: PropTypes.func.isRequired,
};
export default HTML5DragDrop(UnpublishedListing); export default HTML5DragDrop(UnpublishedListing);

View File

@ -7,6 +7,19 @@ import { connect } from 'react-redux';
import { switchVisualMode } from '../../actions/editor'; import { switchVisualMode } from '../../actions/editor';
class MarkdownControl extends React.Component { class MarkdownControl extends React.Component {
static propTypes = {
editor: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
onAddMedia: PropTypes.func.isRequired,
getMedia: PropTypes.func.isRequired,
switchVisualMode: PropTypes.func.isRequired,
value: PropTypes.node,
};
static contextTypes = {
plugins: PropTypes.object,
};
componentWillMount() { componentWillMount() {
this.useRawEditor(); this.useRawEditor();
processEditorPlugins(registry.getEditorComponents()); processEditorPlugins(registry.getEditorComponents());
@ -60,19 +73,6 @@ class MarkdownControl extends React.Component {
} }
} }
MarkdownControl.propTypes = {
editor: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
onAddMedia: PropTypes.func.isRequired,
getMedia: PropTypes.func.isRequired,
switchVisualMode: PropTypes.func.isRequired,
value: PropTypes.node,
};
MarkdownControl.contextTypes = {
plugins: PropTypes.object,
};
export default connect( export default connect(
state => ({ editor: state.editor }), state => ({ editor: state.editor }),
{ switchVisualMode } { switchVisualMode }

View File

@ -18,6 +18,14 @@ const EditorComponent = Record({
class Plugin extends Component { class Plugin extends Component {
static propTypes = {
children: PropTypes.element.isRequired
};
static childContextTypes = {
plugins: PropTypes.object
};
getChildContext() { getChildContext() {
return { plugins: plugins }; return { plugins: plugins };
} }
@ -27,13 +35,6 @@ class Plugin extends Component {
} }
} }
Plugin.propTypes = {
children: PropTypes.element.isRequired
};
Plugin.childContextTypes = {
plugins: PropTypes.object
};
export function newEditorPlugin(config) { export function newEditorPlugin(config) {
const configObj = new EditorComponent({ const configObj = new EditorComponent({
id: config.id || config.label.replace(/[^A-Z0-9]+/ig, '_'), id: config.id || config.label.replace(/[^A-Z0-9]+/ig, '_'),

View File

@ -9,6 +9,13 @@ import styles from './CollectionPage.css';
import CollectionPageHOC from './editorialWorkflow/CollectionPageHOC'; import CollectionPageHOC from './editorialWorkflow/CollectionPageHOC';
class DashboardPage extends React.Component { class DashboardPage extends React.Component {
static propTypes = {
collection: ImmutablePropTypes.map.isRequired,
collections: ImmutablePropTypes.orderedMap.isRequired,
dispatch: PropTypes.func.isRequired,
entries: ImmutablePropTypes.list,
};
componentDidMount() { componentDidMount() {
const { collection, dispatch } = this.props; const { collection, dispatch } = this.props;
if (collection) { if (collection) {
@ -39,12 +46,6 @@ class DashboardPage extends React.Component {
</div>; </div>;
} }
} }
DashboardPage.propTypes = {
collection: ImmutablePropTypes.map.isRequired,
collections: ImmutablePropTypes.orderedMap.isRequired,
dispatch: PropTypes.func.isRequired,
entries: ImmutablePropTypes.list,
};
/* /*
* Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff, * Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff,

View File

@ -15,6 +15,23 @@ import EntryEditor from '../components/EntryEditor';
import EntryPageHOC from './editorialWorkflow/EntryPageHOC'; import EntryPageHOC from './editorialWorkflow/EntryPageHOC';
class EntryPage extends React.Component { class EntryPage extends React.Component {
static propTypes = {
addMedia: PropTypes.func.isRequired,
boundGetMedia: PropTypes.func.isRequired,
changeDraft: PropTypes.func.isRequired,
collection: ImmutablePropTypes.map.isRequired,
createDraftFromEntry: PropTypes.func.isRequired,
createEmptyDraft: PropTypes.func.isRequired,
discardDraft: PropTypes.func.isRequired,
entry: ImmutablePropTypes.map,
entryDraft: ImmutablePropTypes.map.isRequired,
loadEntry: PropTypes.func.isRequired,
persistEntry: PropTypes.func.isRequired,
removeMedia: PropTypes.func.isRequired,
slug: PropTypes.string,
newEntry: PropTypes.bool.isRequired,
};
componentDidMount() { componentDidMount() {
if (!this.props.newEntry) { if (!this.props.newEntry) {
this.props.loadEntry(this.props.collection, this.props.slug); this.props.loadEntry(this.props.collection, this.props.slug);
@ -69,23 +86,6 @@ class EntryPage extends React.Component {
} }
} }
EntryPage.propTypes = {
addMedia: PropTypes.func.isRequired,
boundGetMedia: PropTypes.func.isRequired,
changeDraft: PropTypes.func.isRequired,
collection: ImmutablePropTypes.map.isRequired,
createDraftFromEntry: PropTypes.func.isRequired,
createEmptyDraft: PropTypes.func.isRequired,
discardDraft: PropTypes.func.isRequired,
entry: ImmutablePropTypes.map,
entryDraft: ImmutablePropTypes.map.isRequired,
loadEntry: PropTypes.func.isRequired,
persistEntry: PropTypes.func.isRequired,
removeMedia: PropTypes.func.isRequired,
slug: PropTypes.string,
newEntry: PropTypes.bool.isRequired,
};
function mapStateToProps(state, ownProps) { function mapStateToProps(state, ownProps) {
const { collections, entryDraft } = state; const { collections, entryDraft } = state;
const collection = collections.get(ownProps.params.name); const collection = collections.get(ownProps.params.name);

View File

@ -10,6 +10,11 @@ import styles from '../CollectionPage.css';
export default function CollectionPageHOC(CollectionPage) { export default function CollectionPageHOC(CollectionPage) {
class CollectionPageHOC extends CollectionPage { class CollectionPageHOC extends CollectionPage {
static propTypes = {
dispatch: PropTypes.func.isRequired,
isEditorialWorkflow: PropTypes.bool.isRequired,
unpublishedEntries: ImmutablePropTypes.map,
};
componentDidMount() { componentDidMount() {
const { dispatch, isEditorialWorkflow } = this.props; const { dispatch, isEditorialWorkflow } = this.props;
@ -36,12 +41,6 @@ export default function CollectionPageHOC(CollectionPage) {
} }
} }
CollectionPageHOC.propTypes = {
dispatch: PropTypes.func.isRequired,
isEditorialWorkflow: PropTypes.bool.isRequired,
unpublishedEntries: ImmutablePropTypes.map,
};
function mapStateToProps(state) { function mapStateToProps(state) {
const publish_mode = state.config.get('publish_mode'); const publish_mode = state.config.get('publish_mode');
const isEditorialWorkflow = (publish_mode === EDITORIAL_WORKFLOW); const isEditorialWorkflow = (publish_mode === EDITORIAL_WORKFLOW);