import React from 'react' import { formatName } from '../util' const __HR__ = '__HR__' export function TableObject({ tag, object, order, summary }) { if (!object) return null if (object === 'loading') { return
{tag}{': Loading'}
} if (object.err) { return
{tag}{' Error: '}{object.err}
} let keys = Object.keys(object) if (order) { const grouped = keys.reduce((a, b) => { if (summary && !object[b].trim().length) { return a } const index = order.indexOf(b) if (index !== -1) { a.order.push([index, b]) } else { a.alpha.push(b) } return a }, { order: [], alpha: [] }) keys = grouped.order .sort((a, b) => a[0] - b[0]) .map(([i, s]) => s) if (!summary) { keys = keys // .concat([__HR__]) .concat(grouped.alpha.sort()) } } else { keys = keys.sort() } return (
{tag &&

{tag}

} {keys.map((key, i) => ( ))}
) } export function TableArray({ tag, list }) { if (!list) return null return (
{tag &&

{tag}

} {list.map((value, i) => ( ))}
) } export function TableTuples({ tag, list }) { if (!list) return null return (
{tag &&

{tag}

} {list.map(([key, ...values], i) => ( {values.map((value, j) => ( ))} ))}
{formatName(key)}
) } export function TableRow({ name, value }) { if (name === __HR__) { return (
) } return ( {formatName(name)} ) } export function TableCell({ value }) { if (value && typeof value === 'object') { if (value._raw) { value = value.value } else if (value.length) { value = } else { value = } } return ( {value} ) }