Added formatted date strings to table and detail metadata values

This commit is contained in:
Jordan Pellizzari
2016-10-24 09:22:59 -07:00
committed by Jordan Pellizzari
parent 405a705943
commit 26a1d20f0d
5 changed files with 45 additions and 20 deletions
+20
View File
@@ -2,6 +2,7 @@ import React from 'react';
import filesize from 'filesize';
import d3 from 'd3';
import LCP from 'lcp';
import moment from 'moment';
const formatLargeValue = d3.format('s');
@@ -73,3 +74,22 @@ export function slugify(label) {
export function longestCommonPrefix(strArr) {
return (new LCP(strArr)).lcp();
}
// Formats metadata values. Add a key to the `formatters` obj
// that matches the `dataType` of the field. You must return an Object
// with the keys `value` and `title` defined.
export function formatDataType(field) {
const formatters = {
datetime(dateString) {
const date = moment(new Date(dateString));
return {
value: date.fromNow(),
title: date.format('YYYY-MM-DD HH:mm:ss.SSS')
};
}
};
const format = formatters[field.dataType];
return format
? format(field.value)
: {value: field.value, title: field.value};
}