Skip to content

Commit e4667f1

Browse files
committed
Graph updates now automatically on regex change
After changing a "Hostname Regex", the graph was not automatically updated, but Grafanas "Refresh dashboard" button on the upper right had to be clicked. Now the graph should update automatically. In order to limit the load on the checkmk server, the update is delayed by 500ms for text fields. This affects: * Hostname regex * Service Regex * Host is in Group * Service is in Group
1 parent cea0df7 commit e4667f1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/components/filters.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { SelectableValue } from '@grafana/data';
1414
import { EditorProps } from './types';
1515
import { AsyncAutocomplete, vsAutocomplete } from './fields';
16-
import { get, update } from 'lodash';
16+
import { get, update, debounce } from 'lodash';
1717
import { ResponseDataAutocompleteLabel } from 'types';
1818

1919
export const SiteFilter = (props: EditorProps): JSX.Element => {
@@ -46,17 +46,23 @@ export const HostFilter = (props: EditorProps): JSX.Element => {
4646
);
4747
};
4848

49+
const debouncedOnRunQuery = debounce((props: EditorProps) => {
50+
props.onRunQuery();
51+
}, 500);
52+
4953
export const HostRegExFilter = (props: EditorProps): JSX.Element => {
5054
const onHostChange = (event: ChangeEvent<HTMLInputElement>) => {
5155
const { onChange, query } = props;
5256
update(query, 'context.hostregex.host_regex', () => event.target.value);
5357
onChange(query);
58+
debouncedOnRunQuery(props);
5459
};
5560

5661
const onNegateChange = (event: ChangeEvent<HTMLInputElement>) => {
57-
const { onChange, query } = props;
62+
const { onChange, onRunQuery, query } = props;
5863
update(query, 'context.hostregex.neg_host_regex', () => (event.target.checked ? 'on' : ''));
5964
onChange(query);
65+
onRunQuery();
6066
};
6167

6268
const hostRegEx = get(props, 'query.context.hostregex', {});
@@ -92,12 +98,14 @@ export const ServiceRegExFilter = (props: EditorProps): JSX.Element => {
9298
const { onChange, query } = props;
9399
update(query, 'context.serviceregex.service_regex', () => event.target.value);
94100
onChange(query);
101+
debouncedOnRunQuery(props);
95102
};
96103

97104
const onNegateChange = (event: ChangeEvent<HTMLInputElement>) => {
98-
const { onChange, query } = props;
105+
const { onChange, onRunQuery, query } = props;
99106
update(query, 'context.serviceregex.neg_service_regex', () => (event.target.checked ? 'on' : ''));
100107
onChange(query);
108+
onRunQuery();
101109
};
102110

103111
const serviceRegEx = get(props, 'query.context.serviceregex.service_regex', '');
@@ -152,9 +160,10 @@ export const HostLabelsFilter = ({ datasource, onChange, query, onRunQuery }: Ed
152160

153161
export const HostGroupFilter = (props: EditorProps): JSX.Element => {
154162
const onNegateChange = (event: ChangeEvent<HTMLInputElement>) => {
155-
const { onChange, query } = props;
163+
const { onChange, onRunQuery, query } = props;
156164
update(query, 'context.opthostgroup.neg_opthost_group', () => (event.target.checked ? 'on' : ''));
157165
onChange(query);
166+
onRunQuery();
158167
};
159168

160169
const groupVS = {
@@ -183,9 +192,10 @@ export const HostGroupFilter = (props: EditorProps): JSX.Element => {
183192

184193
export const ServiceGroupFilter = (props: EditorProps): JSX.Element => {
185194
const onNegateChange = (event: ChangeEvent<HTMLInputElement>) => {
186-
const { onChange, query } = props;
195+
const { onChange, onRunQuery, query } = props;
187196
update(query, 'context.optservicegroup.neg_optservice_group', () => (event.target.checked ? 'on' : ''));
188197
onChange(query);
198+
onRunQuery();
189199
};
190200

191201
const groupVS = {

0 commit comments

Comments
 (0)