From 5a086f5ad05fe15429ef20b53ce19f140323438b Mon Sep 17 00:00:00 2001 From: Adam Janis Date: Sun, 22 Nov 2020 13:12:31 +0100 Subject: [PATCH] fix: prevent histogram render error on initial no data state --- src/components/monitorHistogram.js | 2 +- src/functions/helpers.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/monitorHistogram.js b/src/components/monitorHistogram.js index 1ee1b5b..83ce47c 100644 --- a/src/components/monitorHistogram.js +++ b/src/components/monitorHistogram.js @@ -39,7 +39,7 @@ export default function MonitorHistogram({ monitorId, kvMonitor }) { {dayInHistogramLabel} - {kvMonitor.checks.hasOwnProperty(dayInHistogram) && + {kvMonitor && kvMonitor.checks.hasOwnProperty(dayInHistogram) && Object.keys(kvMonitor.checks[dayInHistogram].res).map((key) => { return ( <> diff --git a/src/functions/helpers.js b/src/functions/helpers.js index 1df405f..74cd113 100644 --- a/src/functions/helpers.js +++ b/src/functions/helpers.js @@ -1,14 +1,16 @@ import config from '../../config.yaml' import { useEffect, useState } from 'react' +const kvDataKey = 'monitors_data_v1_1' + export async function getKVMonitors() { // trying both to see performance difference - return KV_STATUS_PAGE.get('monitors_data', 'json') - //return JSON.parse(await KV_STATUS_PAGE.get('monitors_data', 'text')) + return KV_STATUS_PAGE.get(kvDataKey, 'json') + //return JSON.parse(await KV_STATUS_PAGE.get(kvDataKey, 'text')) } export async function setKVMonitors(data) { - return setKV('monitors_data', JSON.stringify(data)) + return setKV(kvDataKey, JSON.stringify(data)) } export async function setKV(key, value, metadata, expirationTtl) {