Fix AG date range based filters default values (#4354)

# What this PR does

Fix AG date range based filters default values

## Which issue(s) this PR closes


## Checklist

- [ ] 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.

---------

Co-authored-by: Michael Derynck <michael.derynck@grafana.com>
This commit is contained in:
Maxim Mordasov 2024-05-22 13:02:56 +01:00 committed by GitHub
parent 721375e3fa
commit a2859553ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 12 deletions

View file

@ -1,9 +1,7 @@
import typing
from datetime import timedelta
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Count, Max, Q
from django.utils import timezone
from django_filters import rest_framework as filters
from drf_spectacular.utils import extend_schema, inline_serializer
from rest_framework import mixins, serializers, status, viewsets
@ -729,14 +727,9 @@ class AlertGroupView(
Retrieve a list of valid filter options that can be used to filter alert groups
"""
api_root = "/api/internal/v1/"
default_day_range = 30
now = timezone.now()
week_ago = now - timedelta(days=7)
default_datetime_range = "{}_{}".format(
week_ago.strftime(DateRangeFilterMixin.DATE_FORMAT),
now.strftime(DateRangeFilterMixin.DATE_FORMAT),
)
default_datetime_range = f"now-{default_day_range}d_now"
filter_options = [
{

View file

@ -307,8 +307,6 @@ 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
@ -323,7 +321,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')}`,
started_at: 'now-30d_now',
}}
/>
</div>