2a2497072d
* infer card title * Infer entry body & image * infer image * Better terminology: EntryListing accept a single Collection * remove log * Refactored Collections VO into selectors * use selectors when showning card * fixed size cards * Added 'bio' and 'biography' to collection description inference synonyms * Removed unused card file * throw error instance * bugfix for file based collections * lint * moved components with css to own folder * Search Bugfix: More than one collection might be returned * Changed sidebar implementation. Closes #104 & #152 * Show spinning loading for unpublished entries * Refactored Sidebar into a separate container * Make preview widgets more robust
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
import React, { Component, PropTypes } from 'react';
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
import { resolveWidget } from '../Widgets';
|
|
import styles from './ControlPane.css';
|
|
|
|
function isHidden(field) {
|
|
return field.get('widget') === 'hidden';
|
|
}
|
|
|
|
export default class ControlPane extends Component {
|
|
|
|
controlFor(field) {
|
|
const { entry, fields, getMedia, onChange, onAddMedia, onRemoveMedia } = this.props;
|
|
const widget = resolveWidget(field.get('widget'));
|
|
const fieldName = field.get('name');
|
|
const value = entry.getIn(['data', fieldName]);
|
|
if (entry.size === 0 || entry.get('partial') === true) return null;
|
|
return (
|
|
<div className={styles.control}>
|
|
<label className={styles.label} htmlFor={fieldName}>{field.get('label')}</label>
|
|
{
|
|
React.createElement(widget.control, {
|
|
field,
|
|
value,
|
|
onChange: val => onChange(entry.setIn(['data', fieldName], val)),
|
|
onAddMedia,
|
|
onRemoveMedia,
|
|
getMedia,
|
|
})
|
|
}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
render() {
|
|
const { collection, fields } = this.props;
|
|
if (!collection || !fields) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
{
|
|
fields.map(field =>
|
|
isHidden(field) ? null : <div
|
|
key={field.get('name')}
|
|
className={styles.widget}
|
|
>
|
|
{this.controlFor(field)}
|
|
</div>
|
|
)
|
|
}
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
ControlPane.propTypes = {
|
|
collection: ImmutablePropTypes.map.isRequired,
|
|
entry: ImmutablePropTypes.map.isRequired,
|
|
fields: ImmutablePropTypes.list.isRequired,
|
|
getMedia: PropTypes.func.isRequired,
|
|
onAddMedia: PropTypes.func.isRequired,
|
|
onChange: PropTypes.func.isRequired,
|
|
onRemoveMedia: PropTypes.func.isRequired,
|
|
};
|