;
}
const LimitedString = ({ string }) =>
{string.indexOf(' ') === -1 && string.length > 30 ?
{string.substr(0,30)}… :
{(string)}
}
export const getFieldValue = (value, typeName) => {
if (typeof value === 'undefined' || value === null) {
return ''
}
// JSX element
if (React.isValidElement(value)) {
return value;
}
if (Array.isArray(value)) {
typeName = 'Array';
}
if (typeof typeName === 'undefined') {
typeName = typeof value;
}
switch (typeName) {
case 'Boolean':
case 'boolean':
case 'Number':
case 'number':
case 'SimpleSchema.Integer':
return {value.toString()}
;
case 'Array':
return {value.map((item, index) => - {getFieldValue(item, typeof item)}
)}
case 'Object':
case 'object':
return getObject(value);
case 'Date':
return moment(new Date(value)).format('dddd, MMMM Do YYYY, h:mm:ss');
case 'String':
case 'string':
return parseImageUrl(value);
default:
return value.toString();
}
}
const getObject = object => {
if (object.__typename === 'User') {
const user = object;
return (
{user.displayName}
)
} else {
return (
{_.without(Object.keys(object), '__typename').map(key =>
{key} |
{getFieldValue(object[key], typeof object[key])} |
)}
)
}
}
const CardItem = ({label, value, typeName}) =>
{label} |
{getFieldValue(value, typeName)} |
const CardEdit = (props, context) =>
}>
|
CardEdit.contextTypes = { intl: intlShape };
const CardEditForm = ({ collection, document, closeModal }) =>
{
closeModal();
}}
/>
const Card = ({title, className, collection, document, currentUser, fields, showEdit = true}, {intl}) => {
const fieldNames = fields ? fields : _.without(_.keys(document), '__typename');
const canEdit = showEdit && currentUser && collection && collection.options.mutations.update.check(currentUser, document);
return (
{title &&
{title}
}
{canEdit ? : null}
{fieldNames.map((fieldName, index) =>
)}
);
};
Card.displayName = 'Card';
Card.propTypes = {
className: PropTypes.string,
collection: PropTypes.object,
document: PropTypes.object,
currentUser: PropTypes.object,
fields: PropTypes.array,
showEdit: PropTypes.bool
}
Card.contextTypes = {
intl: intlShape
}
registerComponent('Card', Card);