import React, { Component } from 'react' import { Link } from 'react-router-dom' import { connect } from 'react-redux' import { formatDateTime } from 'app/utils' import { Loader, Swatch, Dot } from 'app/common' /* '/collection/' + row.id + '/show/' }, { name: 'username', type: 'string' }, { name: 'date', type: 'date' }, { name: 'notes', type: 'text' }, ]} /> */ export default class TableIndex extends Component { componentDidMount() { this.props.actions && this.props.actions.index() } render() { const { data, els, title, fields, noHeadings, notFoundMessage } = this.props if (data.loading) { return } if (!els && (!data.lookup || !data.order.length)) { return (

{title}

{notFoundMessage || ("No " + title)}

) } return (

{title}

{!noHeadings && } {els ? els.map(el => ) : data.order.map(id => ) }
) } } const RowHeadings = ({fields}) => { return (
{fields.map(field => { if (field.type === 'gallery') return let css = {} if (field.width) { css = { width: field.width, maxWidth: 'none', flex: 'none', } } if (field.flex) { css.flex = field.flex } return
{(field.title || field.name).replace(/_/g, ' ')}
})}
) } const Row = ({ row, fields }) => { return (
{fields.map(field => { let value = field.valueFn ? field.valueFn(row) : row[field.name] let css = {} if (field.type === 'date' && (row.updated_at || row.created_at || value)) { // value = (value || "").split('.')[0] value = formatDateTime(row.updated_at || row.created_at || value) } else if (field.type === 'text') { value = String(value || "").trim().split('\n')[0].replace(/^#+/, '').substr(0, 100) } else if (field.type === 'color') { value = } else if (field.type === 'bool') { value = } else if (field.type === 'str') { value = String(value || "").replace(/_/g, ' ') } else if (field.type === 'gallery') { return } if (field.width) { css = { width: field.width, maxWidth: 'none', flex: 'none', } } if (field.flex) { css.flex = field.flex } let className if (field.style) { className = field.type + ' ' + field.style } else { className = field.type } value =
{value}
if (field.link) { return {value} } return value })}
) } const GalleryRow = ({ media }) => { return (
{media.map(img => ( ))}
) }