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 objects = Object.keys(object) if (order) { const grouped = objects.reduce((a, b) => { const index = order.indexOf(b) if (index !== -1) { a.order.push([index, b]) } else { a.alpha.push(b) } return a }, { order: [], alpha: [] }) objects = grouped.order .sort((a, b) => a[0] - b[0]) .map(([i, s]) => s) if (!summary) { objects = objects // .concat([__HR__]) .concat(grouped.alpha.sort()) } } else { objects = objects.sort() } return (
{tag &&

{tag}

} {objects.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} ) }