From 5fcb05d10ce330ebae6039385edf7c5b891ced05 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Wed, 16 Oct 2019 10:24:26 +0300 Subject: [PATCH 1/2] Fix: Alert page breaks when target query returns null result --- client/app/pages/alert/components/Criteria.jsx | 4 ++-- client/app/pages/alert/components/NotificationTemplate.jsx | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/app/pages/alert/components/Criteria.jsx b/client/app/pages/alert/components/Criteria.jsx index 3971499a77..57516fd899 100644 --- a/client/app/pages/alert/components/Criteria.jsx +++ b/client/app/pages/alert/components/Criteria.jsx @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { head, includes, toString } from 'lodash'; +import { head, includes, toString, isEmpty } from 'lodash'; import Input from 'antd/lib/input'; import Icon from 'antd/lib/icon'; @@ -34,7 +34,7 @@ DisabledInput.propTypes = { }; export default function Criteria({ columnNames, resultValues, alertOptions, onChange, editMode }) { - const columnValue = resultValues && head(resultValues)[alertOptions.column]; + const columnValue = !isEmpty(resultValues) ? head(resultValues)[alertOptions.column] : null; const invalidMessage = (() => { // bail if condition is valid for strings if (includes(VALID_STRING_CONDITIONS, alertOptions.op)) { diff --git a/client/app/pages/alert/components/NotificationTemplate.jsx b/client/app/pages/alert/components/NotificationTemplate.jsx index d3c1178436..d11bb45d30 100644 --- a/client/app/pages/alert/components/NotificationTemplate.jsx +++ b/client/app/pages/alert/components/NotificationTemplate.jsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; -import { head } from 'lodash'; +import { head, isEmpty } from 'lodash'; import Mustache from 'mustache'; import { HelpTrigger } from '@/components/HelpTrigger'; @@ -15,7 +15,7 @@ import './NotificationTemplate.less'; function normalizeCustomTemplateData(alert, query, columnNames, resultValues) { - const topValue = resultValues && head(resultValues)[alert.options.column]; + const topValue = !isEmpty(resultValues) ? head(resultValues)[alert.options.column] : null; return { ALERT_STATUS: 'TRIGGERED', @@ -25,7 +25,7 @@ function normalizeCustomTemplateData(alert, query, columnNames, resultValues) { ALERT_URL: `${window.location.origin}/alerts/${alert.id}`, QUERY_NAME: query.name, QUERY_URL: `${window.location.origin}/queries/${query.id}`, - QUERY_RESULT_VALUE: topValue, + QUERY_RESULT_VALUE: topValue || 'UNKNOWN', QUERY_RESULT_ROWS: resultValues, QUERY_RESULT_COLS: columnNames, }; From cf0780660098a730a07a6aff055843ca141d7792 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Wed, 16 Oct 2019 10:42:56 +0300 Subject: [PATCH 2/2] Better handling of topValue value --- client/app/pages/alert/components/NotificationTemplate.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/app/pages/alert/components/NotificationTemplate.jsx b/client/app/pages/alert/components/NotificationTemplate.jsx index d11bb45d30..31e10bdc12 100644 --- a/client/app/pages/alert/components/NotificationTemplate.jsx +++ b/client/app/pages/alert/components/NotificationTemplate.jsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; -import { head, isEmpty } from 'lodash'; +import { head, isEmpty, isNull, isUndefined } from 'lodash'; import Mustache from 'mustache'; import { HelpTrigger } from '@/components/HelpTrigger'; @@ -25,7 +25,7 @@ function normalizeCustomTemplateData(alert, query, columnNames, resultValues) { ALERT_URL: `${window.location.origin}/alerts/${alert.id}`, QUERY_NAME: query.name, QUERY_URL: `${window.location.origin}/queries/${query.id}`, - QUERY_RESULT_VALUE: topValue || 'UNKNOWN', + QUERY_RESULT_VALUE: isNull(topValue) || isUndefined(topValue) ? 'UNKNOWN' : topValue, QUERY_RESULT_ROWS: resultValues, QUERY_RESULT_COLS: columnNames, };