Fix alert group table default filter being ignored, add 1 week window as default time range (#4080)
# What this PR does - Default filters were being ignored on the alerts group page (Only show acknowledged and firing). This was because the object contained an empty array for the team field so it was never considered empty, now all fields are checked. - Added a 1 week window for `started_at` as a default. This should give more useful behavior in larger instances so we won't have long queries counting all alert groups since the beginning. ## Which issue(s) this PR closes Closes https://github.com/grafana/oncall-private/issues/2520 <!-- *Note*: if you have more than one GitHub issue that this PR closes, be sure to preface each issue link with a [closing keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue). This ensures that the issue(s) are auto-closed once the PR has been merged. --> ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
This commit is contained in:
parent
5fd35b61b8
commit
626aa88d62
5 changed files with 18 additions and 5 deletions
|
|
@ -101,6 +101,6 @@ export const verifyThatAlertGroupIsTriggered = async (
|
|||
|
||||
export const resolveFiringAlert = async (page: Page) => {
|
||||
await goToOnCallPage(page, 'alert-groups');
|
||||
await page.getByText('Firing').nth(1).click();
|
||||
await page.getByText('Firing').nth(2).click({force: true});
|
||||
await page.getByLabel('Context menu').getByText('Resolve').click();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export function parseFilters(
|
|||
filterOptions: FilterOption[],
|
||||
query: { [key: string]: any }
|
||||
) {
|
||||
const dataWithPredefinedTeams = { ...data, team: data.team || [] };
|
||||
const dataWithPredefinedTeams = { ...data, team: data?.team || [] };
|
||||
const filters = filterOptions.filter((filterOption: FilterOption) => filterOption.name in dataWithPredefinedTeams);
|
||||
|
||||
const values = filters.reduce((memo: any, filterOption: FilterOption) => {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import {
|
|||
} from '@grafana/ui';
|
||||
import { capitalCase } from 'change-case';
|
||||
import cn from 'classnames/bind';
|
||||
import { debounce, isEmpty, isUndefined, omitBy, pickBy } from 'lodash-es';
|
||||
import { debounce, isUndefined, omitBy, pickBy } from 'lodash-es';
|
||||
import { observer } from 'mobx-react';
|
||||
import moment from 'moment-timezone';
|
||||
import Emoji from 'react-emoji-render';
|
||||
|
|
@ -29,6 +29,7 @@ import { SelectOption, WithStoreProps } from 'state/types';
|
|||
import { withMobXProviderContext } from 'state/withStore';
|
||||
import { LocationHelper } from 'utils/LocationHelper';
|
||||
import { PAGE } from 'utils/consts';
|
||||
import { allFieldsEmpty } from 'utils/utils';
|
||||
|
||||
import { parseFilters } from './RemoteFilters.helpers';
|
||||
import { FilterOption } from './RemoteFilters.types';
|
||||
|
|
@ -102,7 +103,7 @@ class _RemoteFilters extends Component<RemoteFiltersProps, RemoteFiltersState> {
|
|||
|
||||
let { filters, values } = parseFilters({ ...query, ...filtersStore.globalValues }, filterOptions, query);
|
||||
|
||||
if (isEmpty(values)) {
|
||||
if (allFieldsEmpty(values)) {
|
||||
({ filters, values } = parseFilters(defaultFilters, filterOptions, query));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -304,6 +304,8 @@ class _IncidentsPage extends React.Component<IncidentsPageProps, IncidentsPageSt
|
|||
|
||||
renderIncidentFilters() {
|
||||
const { query, store } = this.props;
|
||||
const defaultStart = moment().subtract(7, 'days');
|
||||
const defaultEnd = moment().add(1, 'days');
|
||||
return (
|
||||
<div className={cx('filters')}>
|
||||
<RemoteFilters
|
||||
|
|
@ -318,6 +320,7 @@ class _IncidentsPage extends React.Component<IncidentsPageProps, IncidentsPageSt
|
|||
team: [],
|
||||
status: [IncidentStatus.Firing, IncidentStatus.Acknowledged],
|
||||
mine: false,
|
||||
started_at: `${defaultStart.format('YYYY-MM-DDTHH:mm:ss')}/${defaultEnd.format('YYYY-MM-DDTHH:mm:ss')}`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { AxiosError } from 'axios';
|
|||
import { sentenceCase } from 'change-case';
|
||||
// @ts-ignore
|
||||
import appEvents from 'grafana/app/core/app_events';
|
||||
import { isArray, concat, isPlainObject, flatMap, map, keys } from 'lodash-es';
|
||||
import { isArray, concat, every, isEmpty, isObject, isPlainObject, flatMap, map, keys } from 'lodash-es';
|
||||
|
||||
import { isNetworkError } from 'network/network';
|
||||
import { getGrafanaVersion } from 'plugin/GrafanaPluginRootPage.helpers';
|
||||
|
|
@ -107,3 +107,12 @@ export function isUseProfileExtensionPointEnabled(): boolean {
|
|||
|
||||
return isRequiredGrafanaVersion;
|
||||
}
|
||||
|
||||
function isFieldEmpty(value: any): boolean {
|
||||
if (isObject(value)) {
|
||||
return isEmpty(value);
|
||||
}
|
||||
return value === '' || value === null || value === undefined;
|
||||
}
|
||||
|
||||
export const allFieldsEmpty = (obj: any) => every(obj, isFieldEmpty);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue