Skip to content

Commit

Permalink
Move snapshot count in monitor status alert to callout.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Jun 5, 2020
1 parent 18846c9 commit abc7e07
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { useState } from 'react';
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
import { EuiCallOut, EuiLoadingSpinner, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { DataPublicPluginSetup } from 'src/plugins/data/public';
import * as labels from './translations';
Expand All @@ -25,6 +25,8 @@ interface AlertMonitorStatusProps {
hasFilters: boolean;
isOldAlert: boolean;
locations: string[];
snapshotCount: number;
snapshotLoading: boolean;
numTimes: number;
setAlertParams: (key: string, value: any) => void;
timerange: {
Expand All @@ -34,7 +36,14 @@ interface AlertMonitorStatusProps {
}

export const AlertMonitorStatusComponent: React.FC<AlertMonitorStatusProps> = (props) => {
const { alertParams, hasFilters, isOldAlert, setAlertParams } = props;
const {
alertParams,
hasFilters,
isOldAlert,
setAlertParams,
snapshotCount,
snapshotLoading,
} = props;

const alertFilters = alertParams?.filters ?? {};
const [newFilters, setNewFilters] = useState<string[]>(
Expand All @@ -50,7 +59,7 @@ export const AlertMonitorStatusComponent: React.FC<AlertMonitorStatusProps> = (p
size="s"
title={
<FormattedMessage
id="xpack.uptime.alerts.monitorStatus.oldAlertCallout.Title"
id="xpack.uptime.alerts.monitorStatus.oldAlertCallout.title"
defaultMessage="You are editing an older alert, some fields may not auto-populate."
/>
}
Expand Down Expand Up @@ -108,6 +117,24 @@ export const AlertMonitorStatusComponent: React.FC<AlertMonitorStatusProps> = (p
/>

<EuiSpacer size="m" />

{!snapshotLoading ? (
<EuiCallOut
size="s"
title={
<FormattedMessage
id="xpack.uptime.alerts.monitorStatus.monitorCallOut.title"
defaultMessage="This alert will apply to approximately {snapshotCount} monitors."
values={{ snapshotCount }}
/>
}
iconType="iInCircle"
/>
) : (
<EuiLoadingSpinner size="m" />
)}

<EuiSpacer size="m" />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { DataPublicPluginSetup } from 'src/plugins/data/public';
import { isRight } from 'fp-ts/lib/Either';
import { selectMonitorStatusAlert, overviewFiltersSelector } from '../../../../state/selectors';
import {
selectMonitorStatusAlert,
overviewFiltersSelector,
snapshotDataSelector,
esKuerySelector,
} from '../../../../state/selectors';
import { AlertMonitorStatusComponent } from '../index';
import {
fetchOverviewFilters,
setSearchTextAction,
setEsKueryString,
getSnapshotCountAction,
} from '../../../../state/actions';
import { AtomicStatusCheckParamsType } from '../../../../../common/runtime_types';
import { useIndexPattern } from '../../kuery_bar/use_index_pattern';
Expand Down Expand Up @@ -43,7 +49,7 @@ export const AlertMonitorStatus: React.FC<Props> = ({
useEffect(() => {
dispatch(
fetchOverviewFilters({
dateRangeStart: 'now-15m',
dateRangeStart: 'now-24h',
dateRangeEnd: 'now',
locations: alertParams.filters?.['observer.geo.name'] ?? [],
ports: alertParams.filters?.['url.port'] ?? [],
Expand All @@ -62,12 +68,16 @@ export const AlertMonitorStatus: React.FC<Props> = ({
}, [alertParams, dispatch]);

const { index_pattern: indexPattern } = useIndexPattern();

const { count, loading } = useSelector(snapshotDataSelector);
const esKuery = useSelector(esKuerySelector);
const [esFilters] = useUpdateKueryString(
indexPattern,
alertParams.search,
typeof alertParams.filters === 'string' ? {} : alertParams.filters
alertParams.filters === undefined || typeof alertParams.filters === 'string'
? ''
: JSON.stringify(Array.from(Object.entries(alertParams.filters)))
);

useEffect(() => {
dispatch(setEsKueryString(esFilters ?? ''));
}, [dispatch, esFilters]);
Expand All @@ -76,6 +86,11 @@ export const AlertMonitorStatus: React.FC<Props> = ({
() => !isRight(AtomicStatusCheckParamsType.decode(alertParams)),
[alertParams]
);
useEffect(() => {
dispatch(
getSnapshotCountAction({ dateRangeStart: 'now-24h', dateRangeEnd: 'now', filters: esKuery })
);
}, [dispatch, esKuery]);

return (
<AlertMonitorStatusComponent
Expand All @@ -87,6 +102,8 @@ export const AlertMonitorStatus: React.FC<Props> = ({
locations={locations}
numTimes={numTimes}
setAlertParams={setAlertParams}
snapshotCount={count.total}
snapshotLoading={loading}
timerange={timerange}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner, EuiText } from '@elastic/eui';
import { snapshotDataSelector, esKuerySelector } from '../../state/selectors';
import { getSnapshotCountAction } from '../../state/actions';

export const MonitorStatusTitle = () => {
const { count, loading } = useSelector(snapshotDataSelector);
const esKuery = useSelector(esKuerySelector);
const dispatch = useDispatch();
useEffect(() => {
dispatch(
getSnapshotCountAction({ dateRangeStart: 'now-15m', dateRangeEnd: 'now', filters: esKuery })
);
}, [dispatch, esKuery]);

return (
<EuiFlexGroup>
<EuiFlexItem>
<FormattedMessage
id="xpack.uptime.alerts.monitorStatus.title.label"
defaultMessage="Uptime monitor status"
/>{' '}
</EuiFlexItem>
<EuiFlexItem grow={false} style={{ alignSelf: 'center' }}>
{!loading ? (
<EuiText size="s" color="subdued">
{count.total} monitors
</EuiText>
) : (
<EuiLoadingSpinner size="m" />
)}
</EuiFlexItem>
</EuiFlexGroup>
<FormattedMessage
id="xpack.uptime.alerts.monitorStatus.title.label"
defaultMessage="Uptime monitor status"
/>
);
};

0 comments on commit abc7e07

Please sign in to comment.