mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Add support for Users objects to cards & datatables
This commit is contained in:
parent
8e27870bf0
commit
582dc2010b
1 changed files with 33 additions and 12 deletions
|
@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import Button from 'react-bootstrap/lib/Button';
|
import Button from 'react-bootstrap/lib/Button';
|
||||||
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
const getLabel = (field, fieldName, collection, intl) => {
|
const getLabel = (field, fieldName, collection, intl) => {
|
||||||
const schema = collection.simpleSchema()._schema;
|
const schema = collection.simpleSchema()._schema;
|
||||||
|
@ -71,18 +72,7 @@ export const getFieldValue = (value, typeName) => {
|
||||||
|
|
||||||
case 'Object':
|
case 'Object':
|
||||||
case 'object':
|
case 'object':
|
||||||
return (
|
return getObject(value);
|
||||||
<table className="table table-bordered">
|
|
||||||
<tbody>
|
|
||||||
{_.map(value, (value, key) =>
|
|
||||||
<tr key={key}>
|
|
||||||
<td><strong>{key}</strong></td>
|
|
||||||
<td>{getFieldValue(value, typeof value)}</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
)
|
|
||||||
|
|
||||||
case 'Date':
|
case 'Date':
|
||||||
return moment(new Date(value)).format('dddd, MMMM Do YYYY, h:mm:ss');
|
return moment(new Date(value)).format('dddd, MMMM Do YYYY, h:mm:ss');
|
||||||
|
@ -92,6 +82,37 @@ export const getFieldValue = (value, typeName) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getObject = object => {
|
||||||
|
|
||||||
|
if (object.__typename === 'User') {
|
||||||
|
|
||||||
|
const user = object;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="dashboard-user" style={{ whiteSpace: 'nowrap' }}>
|
||||||
|
<Components.Avatar size="small" user={user} link />
|
||||||
|
<Link to={user.pageUrl}>{user.displayName}</Link>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<table className="table table-bordered">
|
||||||
|
<tbody>
|
||||||
|
{_.map(object, (value, key) =>
|
||||||
|
<tr key={key}>
|
||||||
|
<td><strong>{key}</strong></td>
|
||||||
|
<td>{getFieldValue(value, typeof value)}</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const CardItem = ({label, value, typeName}) =>
|
const CardItem = ({label, value, typeName}) =>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="datacard-label"><strong>{label}</strong></td>
|
<td className="datacard-label"><strong>{label}</strong></td>
|
||||||
|
|
Loading…
Add table
Reference in a new issue