From e0b0b2f976c61225a178c7715caf2656a1f6741f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 15 Dec 2018 21:32:51 +0100 Subject: moving stuff --- client/common/table.component.js | 121 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 client/common/table.component.js (limited to 'client/common/table.component.js') diff --git a/client/common/table.component.js b/client/common/table.component.js new file mode 100644 index 00000000..76a1d57c --- /dev/null +++ b/client/common/table.component.js @@ -0,0 +1,121 @@ +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} + ) +} -- cgit v1.2.3-70-g09d2