From ae3c464c108487f64345d20351db7576e061c07b Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Fri, 28 Apr 2023 09:32:38 +0800 Subject: [PATCH 1/4] Add filter descriptions --- engine/apps/api/views/alert_group.py | 2 ++ .../RemoteFilters/RemoteFilters.tsx | 21 ++++++++++++++++--- .../RemoteFilters/RemoteFilters.types.ts | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index 15a72f4f49..b535834713 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -609,6 +609,7 @@ def filters(self, request): "type": "options", "href": api_root + "users/?filters=true&roles=0&roles=1&roles=2", "default": {"display_name": self.request.user.username, "value": self.request.user.public_primary_key}, + "description": "This filter works only for last 1000 alert groups these users involved in.", }, { "name": "status", @@ -640,6 +641,7 @@ def filters(self, request): "name": "mine", "type": "boolean", "default": "true", + "description": "This filter works only for last 1000 alert groups you're involved in.", }, ] diff --git a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx index 2163c779de..189a407337 100644 --- a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx +++ b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx @@ -1,7 +1,17 @@ import React, { Component } from 'react'; import { SelectableValue, TimeRange } from '@grafana/data'; -import { IconButton, InlineSwitch, MultiSelect, TimeRangeInput, Select, LoadingPlaceholder, Input } from '@grafana/ui'; +import { + IconButton, + InlineSwitch, + MultiSelect, + TimeRangeInput, + Select, + LoadingPlaceholder, + Input, + Icon, + Tooltip, +} from '@grafana/ui'; import { capitalCase } from 'change-case'; import cn from 'classnames/bind'; import { debounce, isEmpty, isUndefined, omitBy, pickBy } from 'lodash-es'; @@ -114,8 +124,13 @@ class RemoteFilters extends Component {
{filters.map((filterOption: FilterOption) => (
- {filterOption.display_name || capitalCase(filterOption.name)}:{' '} - {this.renderFilterOption(filterOption)} + {filterOption.display_name || capitalCase(filterOption.name)} + {filterOption.description && ( + + + + )} + : {this.renderFilterOption(filterOption)}
))} diff --git a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.types.ts b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.types.ts index eb8bd34f4f..4b6c01a1dd 100644 --- a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.types.ts +++ b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.types.ts @@ -10,4 +10,5 @@ export interface FilterOption { options?: SelectOption[]; default?: { value: string }; global?: boolean; + description?: string; } From 9e90bc86fef7abe03cd401ada3abc2de95941084 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Fri, 28 Apr 2023 09:37:29 +0800 Subject: [PATCH 2/4] Use variable --- engine/apps/api/views/alert_group.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index d561a5cd89..78fe144798 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -84,6 +84,8 @@ class AlertGroupFilter(DateRangeFilterMixin, ByTeamModelFieldFilterMixin, ModelF Examples of possible date formats here https://docs.djangoproject.com/en/1.9/ref/settings/#datetime-input-formats """ + FILTER_BY_INVOLVED_USERS_ALERT_GROUPS_CUTOFF = 1000 + started_at_gte = filters.DateTimeFilter(field_name="started_at", lookup_expr="gte") started_at_lte = filters.DateTimeFilter(field_name="started_at", lookup_expr="lte") resolved_at_lte = filters.DateTimeFilter(field_name="resolved_at", lookup_expr="lte") @@ -186,7 +188,6 @@ def filter_invitees_are(self, queryset, name, value): return queryset def filter_by_involved_users(self, queryset, name, value): - NOTIFICATION_HISTORY_CUTOFF = 1000 users = value if not users: @@ -198,7 +199,7 @@ def filter_by_involved_users(self, queryset, name, value): UserNotificationPolicyLogRecord.objects.filter(author__in=users) .order_by("-alert_group_id") .values_list("alert_group_id", flat=True) - .distinct()[:NOTIFICATION_HISTORY_CUTOFF] + .distinct()[: self.FILTER_BY_INVOLVED_USERS_ALERT_GROUPS_CUTOFF] ) queryset = queryset.filter( @@ -620,7 +621,7 @@ def filters(self, request): "type": "options", "href": api_root + "users/?filters=true&roles=0&roles=1&roles=2", "default": {"display_name": self.request.user.username, "value": self.request.user.public_primary_key}, - "description": "This filter works only for last 1000 alert groups these users involved in.", + "description": f"This filter works only for last {AlertGroupFilter.FILTER_BY_INVOLVED_USERS_ALERT_GROUPS_CUTOFF} alert groups these users involved in.", }, { "name": "status", @@ -652,7 +653,7 @@ def filters(self, request): "name": "mine", "type": "boolean", "default": "true", - "description": "This filter works only for last 1000 alert groups you're involved in.", + "description": f"This filter works only for last {AlertGroupFilter.FILTER_BY_INVOLVED_USERS_ALERT_GROUPS_CUTOFF} alert groups you're involved in.", }, ] From b7e33132a3583da79868e22c4127a5746ad6ec3b Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Fri, 28 Apr 2023 17:52:40 +0800 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 929098b7d8..b6a470ca28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Add filter descriptions to web ui by @iskhakov ([1845](https://github.com/grafana/oncall/pull/1845)) + + ## v1.2.16 (2023-04-27) ### Added From b9577788256194de4c724e4417d96bd85f2c1cd6 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Tue, 2 May 2023 13:41:15 +0800 Subject: [PATCH 4/4] Fix lint --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6a470ca28..d17ee032bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add filter descriptions to web ui by @iskhakov ([1845](https://github.com/grafana/oncall/pull/1845)) - ## v1.2.16 (2023-04-27) ### Added