Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter descriptions #1845

Merged
merged 6 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}