From 696aca2d803cef38b7fffa03825c195af9677b65 Mon Sep 17 00:00:00 2001 From: Vadim Stepanov Date: Mon, 22 Jul 2024 11:30:28 +0100 Subject: [PATCH] Make it clear alert groups can't be searched (#4713) # What this PR does * Make the filter input say `Filter results...` instead of `Search or filter results...` on the alert group page; disallow custom input there so it's only possible to choose among existing filters * Remove outdated `/filters?search=` functionality from internal API ## Which issue(s) this PR closes Related to https://github.com/grafana/oncall-private/issues/2679 ## 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. --- engine/apps/api/views/alert_group.py | 4 +++- engine/apps/api/views/alert_receive_channel.py | 1 + engine/apps/api/views/escalation_chain.py | 5 +---- engine/apps/api/views/schedule.py | 5 +---- engine/apps/api/views/user.py | 5 +---- engine/apps/api/views/webhooks.py | 5 +---- grafana-plugin/e2e-tests/utils/alertGroup.ts | 2 +- .../src/containers/RemoteFilters/RemoteFilters.tsx | 2 +- grafana-plugin/src/models/filters/filters.ts | 5 ----- 9 files changed, 10 insertions(+), 24 deletions(-) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index 96d49ade..95afdba1 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -747,7 +747,6 @@ class AlertGroupView( "href": api_root + "teams/", "global": True, }, - {"name": "search", "type": "search"}, {"name": "integration", "type": "options", "href": api_root + "alert_receive_channels/?filters=true"}, {"name": "escalation_chain", "type": "options", "href": api_root + "escalation_chains/?filters=true"}, { @@ -811,6 +810,9 @@ class AlertGroupView( }, ] + if settings.FEATURE_ALERT_GROUP_SEARCH_ENABLED: + filter_options = [{"name": "search", "type": "search"}] + filter_options + if is_labels_feature_enabled(self.request.auth.organization): filter_options.append( { diff --git a/engine/apps/api/views/alert_receive_channel.py b/engine/apps/api/views/alert_receive_channel.py index 21ea9209..c4103e9d 100644 --- a/engine/apps/api/views/alert_receive_channel.py +++ b/engine/apps/api/views/alert_receive_channel.py @@ -474,6 +474,7 @@ class AlertReceiveChannelView( api_root = "/api/internal/v1/" filter_options = [ + {"name": "search", "type": "search"}, { "name": "team", "type": "team_select", diff --git a/engine/apps/api/views/escalation_chain.py b/engine/apps/api/views/escalation_chain.py index af670c2d..952da922 100644 --- a/engine/apps/api/views/escalation_chain.py +++ b/engine/apps/api/views/escalation_chain.py @@ -183,10 +183,10 @@ class EscalationChainViewSet( @action(methods=["get"], detail=False) def filters(self, request): - filter_name = request.query_params.get("search", None) api_root = "/api/internal/v1/" filter_options = [ + {"name": "search", "type": "search"}, { "name": "team", "type": "team_select", @@ -195,7 +195,4 @@ class EscalationChainViewSet( }, ] - if filter_name is not None: - filter_options = list(filter(lambda f: filter_name in f["name"], filter_options)) - return Response(filter_options) diff --git a/engine/apps/api/views/schedule.py b/engine/apps/api/views/schedule.py index a14fc427..261851d6 100644 --- a/engine/apps/api/views/schedule.py +++ b/engine/apps/api/views/schedule.py @@ -577,10 +577,10 @@ class ScheduleView( @action(methods=["get"], detail=False) def filters(self, request): - filter_name = request.query_params.get("search", None) api_root = "/api/internal/v1/" filter_options = [ + {"name": "search", "type": "search"}, { "name": "team", "type": "team_select", @@ -610,7 +610,4 @@ class ScheduleView( }, ] - if filter_name is not None: - filter_options = list(filter(lambda f: filter_name in f["name"], filter_options)) - return Response(filter_options) diff --git a/engine/apps/api/views/user.py b/engine/apps/api/views/user.py index 85b81825..3bbc50ac 100644 --- a/engine/apps/api/views/user.py +++ b/engine/apps/api/views/user.py @@ -870,10 +870,10 @@ class UserView( ) @action(methods=["get"], detail=False) def filters(self, request): - filter_name = request.query_params.get("search", None) api_root = "/api/internal/v1/" filter_options = [ + {"name": "search", "type": "search"}, { "name": "team", "type": "team_select", @@ -882,9 +882,6 @@ class UserView( }, ] - if filter_name is not None: - filter_options = list(filter(lambda f: filter_name in f["name"], filter_options)) - return Response(filter_options) diff --git a/engine/apps/api/views/webhooks.py b/engine/apps/api/views/webhooks.py index 0deb30dd..f32b31ff 100644 --- a/engine/apps/api/views/webhooks.py +++ b/engine/apps/api/views/webhooks.py @@ -140,10 +140,10 @@ class WebhooksView(TeamFilteringMixin, PublicPrimaryKeyMixin[Webhook], ModelView @action(methods=["get"], detail=False) def filters(self, request): - filter_name = request.query_params.get("search", None) api_root = "/api/internal/v1/" filter_options = [ + {"name": "search", "type": "search"}, { "name": "team", "type": "team_select", @@ -161,9 +161,6 @@ class WebhooksView(TeamFilteringMixin, PublicPrimaryKeyMixin[Webhook], ModelView } ) - if filter_name is not None: - filter_options = list(filter(lambda f: filter_name in f["name"], filter_options)) - return Response(filter_options) @action(methods=["get"], detail=True) diff --git a/grafana-plugin/e2e-tests/utils/alertGroup.ts b/grafana-plugin/e2e-tests/utils/alertGroup.ts index 77696e55..b346da71 100644 --- a/grafana-plugin/e2e-tests/utils/alertGroup.ts +++ b/grafana-plugin/e2e-tests/utils/alertGroup.ts @@ -49,7 +49,7 @@ export const filterAlertGroupsTableByIntegrationAndGoToDetailPage = async ( const selectElement = await selectDropdownValue({ page, selectType: 'grafanaSelect', - placeholderText: 'Search or filter results...', + placeholderText: 'Filter results...', value: 'Integration', }); await selectElement.type(integrationName); diff --git a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx index 416bbcfd..61a83f9f 100644 --- a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx +++ b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx @@ -173,7 +173,7 @@ class _RemoteFilters extends Component {