Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Alert page breaks when target query returns null result #4250

Merged
merged 2 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/app/pages/alert/components/Criteria.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use head and not resultValues[0]?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use head and not resultValues[0]?

const invalidMessage = (() => {
// bail if condition is valid for strings
if (includes(VALID_STRING_CONDITIONS, alertOptions.op)) {
Expand Down
6 changes: 3 additions & 3 deletions client/app/pages/alert/components/NotificationTemplate.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { head } from 'lodash';
import { head, isEmpty, isNull, isUndefined } from 'lodash';
import Mustache from 'mustache';

import { HelpTrigger } from '@/components/HelpTrigger';
Expand All @@ -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',
Expand All @@ -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: isNull(topValue) || isUndefined(topValue) ? 'UNKNOWN' : topValue,
QUERY_RESULT_ROWS: resultValues,
QUERY_RESULT_COLS: columnNames,
};
Expand Down