From 8d7d0bd254de45965c9616cf02f42ff84291f470 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Thu, 5 Oct 2017 16:25:10 -0700 Subject: [PATCH] Add number as valid type of bound --- ui/spec/normalizers/dashboardTimeSpec.js | 4 ++-- ui/src/normalizers/dashboardTime.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/spec/normalizers/dashboardTimeSpec.js b/ui/spec/normalizers/dashboardTimeSpec.js index d918c2f6bc..25921a8fdb 100644 --- a/ui/spec/normalizers/dashboardTimeSpec.js +++ b/ui/spec/normalizers/dashboardTimeSpec.js @@ -48,8 +48,8 @@ describe.only('Normalizers.DashboardTime', () => { }) it('can remove a timeRange when upper and lower bounds are of the wrong type', () => { - const badTime = {dashboardID, upper: 2017, lower} - const reallyBadTime = {dashboardID, upper, lower: {foo: 'bar'}} + const badTime = {dashboardID, upper: [], lower} + const reallyBadTime = {dashboardID, upper, lower: {bad: 'time'}} const ranges = [timeRange, badTime, reallyBadTime] const actual = normalizer(ranges) diff --git a/ui/src/normalizers/dashboardTime.js b/ui/src/normalizers/dashboardTime.js index e8e0d02a7f..2f374c6fd9 100644 --- a/ui/src/normalizers/dashboardTime.js +++ b/ui/src/normalizers/dashboardTime.js @@ -1,3 +1,5 @@ +import _ from 'lodash' + const dashtime = ranges => { if (!Array.isArray(ranges)) { return [] @@ -27,7 +29,8 @@ const dashtime = ranges => { return false } - const isCorrectType = bound => typeof bound === 'string' || bound === null + const isCorrectType = bound => + _.isString(bound) || _.isNull(bound) || _.isInteger(bound) if (!isCorrectType(lower) || !isCorrectType(upper)) { return false