Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: display active alerts by default
  • Loading branch information
cryptobioz committed Jul 8, 2021
1 parent b420606 commit da31418
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/DataSource.ts
Expand Up @@ -6,7 +6,7 @@ import {
MutableDataFrame,
} from '@grafana/data';
import { getBackendSrv, getTemplateSrv } from '@grafana/runtime';
import { GenericOptions, CustomQuery, QueryRequest } from './types';
import { GenericOptions, CustomQuery, QueryRequest, defaultQuery } from './types';

export class AlertmanagerDataSource extends DataSourceApi<CustomQuery, GenericOptions> {
url: string;
Expand All @@ -27,6 +27,7 @@ export class AlertmanagerDataSource extends DataSourceApi<CustomQuery, GenericOp

async query(options: QueryRequest): Promise<DataQueryResponse> {
const promises = options.targets.map((query) => {
query = { ...defaultQuery, ...query };
if (query.hide) {
return Promise.resolve(new MutableDataFrame());
}
Expand Down
4 changes: 2 additions & 2 deletions src/QueryEditor.tsx
Expand Up @@ -4,7 +4,7 @@ import { LegacyForms } from '@grafana/ui';
import React, { ChangeEvent, PureComponent } from 'react';
import { AlertmanagerDataSource } from './DataSource';

import { GenericOptions, CustomQuery } from './types';
import { GenericOptions, CustomQuery, defaultQuery } from './types';

import './css/json-editor.css';

Expand Down Expand Up @@ -47,7 +47,7 @@ export class QueryEditor extends PureComponent<Props> {
};

render() {
const { receiver, filters, active, silenced, inhibited } = this.props.query;
const { receiver, filters, active, silenced, inhibited } = { ...defaultQuery, ...this.props.query };

return (
<>
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Expand Up @@ -15,6 +15,8 @@ export interface CustomQuery extends DataQuery {
inhibited: boolean;
}

export const defaultQuery: Partial<CustomQuery> = {};
export const defaultQuery: Partial<CustomQuery> = {
active: true,
};

export interface GenericOptions extends DataSourceJsonData {}

0 comments on commit da31418

Please sign in to comment.