mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-19 04:16:21 +00:00
Added formatted date strings to table and detail metadata values
This commit is contained in:
committed by
Jordan Pellizzari
parent
405a705943
commit
26a1d20f0d
@@ -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};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user