Skip to content

Commit

Permalink
Make monitor counter function while editing alerts.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Jun 4, 2020
1 parent 86baf2c commit dcce253
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import { DataPublicPluginSetup } from 'src/plugins/data/public';
import { isRight } from 'fp-ts/lib/Either';
import { selectMonitorStatusAlert, overviewFiltersSelector } from '../../../../state/selectors';
import { AlertMonitorStatusComponent } from '../index';
import { fetchOverviewFilters, setSearchTextAction } from '../../../../state/actions';
import {
fetchOverviewFilters,
setSearchTextAction,
setEsKueryString,
} from '../../../../state/actions';
import { AtomicStatusCheckParamsType } from '../../../../../common/runtime_types';
import { useIndexPattern } from '../../kuery_bar/use_index_pattern';
import { useUpdateKueryString } from '../../../../hooks';

interface Props {
alertParams: { [key: string]: any };
Expand Down Expand Up @@ -54,6 +60,18 @@ export const AlertMonitorStatus: React.FC<Props> = ({
dispatch(setSearchTextAction(alertParams.search));
}
}, [alertParams, dispatch]);

const { index_pattern: indexPattern } = useIndexPattern();
const [esFilters] = useUpdateKueryString(
indexPattern,
alertParams.search,
typeof alertParams.filters === 'string' ? {} : alertParams.filters
);

useEffect(() => {
dispatch(setEsKueryString(esFilters ?? ''));
}, [dispatch, esFilters]);

const isOldAlert = React.useMemo(
() => !isRight(AtomicStatusCheckParamsType.decode(alertParams)),
[alertParams]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,9 @@ export function KueryBar({
return;
}

updateSearchText(inputValue);

setIsLoadingSuggestions(true);
setState({ ...state, suggestions: [] });

if (updateDefaultKuery) {
updateDefaultKuery(inputValue);
}

const currentRequest = uniqueId();
currentRequestCheck = currentRequest;

Expand Down Expand Up @@ -125,6 +119,10 @@ export function KueryBar({
if (shouldUpdateUrl !== false) {
updateUrlParams({ search: inputValue.trim() });
}
updateSearchText(inputValue);
if (updateDefaultKuery) {
updateDefaultKuery(inputValue);
}
} catch (e) {
console.log('Invalid kuery syntax'); // eslint-disable-line no-console
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { useSelector } from 'react-redux';
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner, EuiText } from '@elastic/eui';
import { snapshotDataSelector } from '../../state/selectors';
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>
Expand Down

0 comments on commit dcce253

Please sign in to comment.