Skip to content

Commit

Permalink
Add filter descriptions (#1845)
Browse files Browse the repository at this point in the history
# What this PR does
<img width="954" alt="Screenshot 2023-04-28 at 9 33 16 AM"
src="https://user-images.githubusercontent.com/2262529/235033175-6a94ffb2-3a39-4730-b855-5b1c5dff8fda.png">


## Which issue(s) this PR fixes

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
  • Loading branch information
iskhakov authored May 2, 2023
1 parent 6a08fdc commit bb34ba4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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
Expand Down
7 changes: 5 additions & 2 deletions engine/apps/api/views/alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -620,6 +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": f"This filter works only for last {AlertGroupFilter.FILTER_BY_INVOLVED_USERS_ALERT_GROUPS_CUTOFF} alert groups these users involved in.",
},
{
"name": "status",
Expand Down Expand Up @@ -651,6 +653,7 @@ def filters(self, request):
"name": "mine",
"type": "boolean",
"default": "true",
"description": f"This filter works only for last {AlertGroupFilter.FILTER_BY_INVOLVED_USERS_ALERT_GROUPS_CUTOFF} alert groups you're involved in.",
},
]

Expand Down
21 changes: 18 additions & 3 deletions grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -114,8 +124,13 @@ class RemoteFilters extends Component<RemoteFiltersProps, RemoteFiltersState> {
<div className={cx('filters')}>
{filters.map((filterOption: FilterOption) => (
<div key={filterOption.name} className={cx('filter')}>
<Text type="secondary">{filterOption.display_name || capitalCase(filterOption.name)}:</Text>{' '}
{this.renderFilterOption(filterOption)}
<Text type="secondary">{filterOption.display_name || capitalCase(filterOption.name)}</Text>
{filterOption.description && (
<Tooltip content={filterOption.description}>
<Icon name="info-circle" />
</Tooltip>
)}
<Text type="secondary">:</Text> {this.renderFilterOption(filterOption)}
<IconButton size="sm" name="times" onClick={this.getDeleteFilterClickHandler(filterOption.name)} />
</div>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface FilterOption {
options?: SelectOption[];
default?: { value: string };
global?: boolean;
description?: string;
}

0 comments on commit bb34ba4

Please sign in to comment.