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

Alert group column/label selector #3281

Merged
merged 82 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
11e8623
Merge branch 'dev' into rares/columns-selector
teodosii Nov 1, 2023
bd6fb2e
wip columns selector
teodosii Nov 2, 2023
84ac125
Merge branch 'dev' into rares/columns-selector
teodosii Nov 2, 2023
8070b0d
WIP drag&drop on the columns
teodosii Nov 2, 2023
505b36a
wip draggable columns
teodosii Nov 3, 2023
c2fcde5
WIP columns
teodosii Nov 6, 2023
36fc9b2
added wrapper to show Modal outside of Toggletip component
teodosii Nov 6, 2023
e8141cf
lint
teodosii Nov 6, 2023
841388d
removed react-dnd
teodosii Nov 6, 2023
50e49fd
Merge branch 'dev' into rares/columns-selector
teodosii Nov 6, 2023
35f9dd3
removed unused references
teodosii Nov 6, 2023
e402f6a
reverted version to 17.0.2
teodosii Nov 7, 2023
2a75d2c
removed unused menuDisplay
teodosii Nov 7, 2023
219f852
Merge branch 'dev' into rares/columns-selector
teodosii Nov 7, 2023
c0dcdc5
snapshots
teodosii Nov 7, 2023
5e44221
mock ResizeObserver, updated packages, updated snapshots
teodosii Nov 7, 2023
f8f89f5
Merge branch 'dev' into rares/columns-selector
teodosii Nov 7, 2023
8d13a3d
Merge branch 'dev' into rares/columns-selector
teodosii Nov 7, 2023
64c90b9
Merge branch 'dev' into rares/columns-selector
teodosii Nov 8, 2023
d7ec3e0
call api, add transtiongroup wrapper to list elements
teodosii Nov 8, 2023
20eb2d6
tweaks
teodosii Nov 8, 2023
a6d81ea
fix
teodosii Nov 8, 2023
41f8307
tweaks
teodosii Nov 9, 2023
c3e1b45
add new columns from modal actions
teodosii Nov 9, 2023
9c14a89
readjust table on column change
teodosii Nov 10, 2023
4d77aeb
Merge branch 'dev' into rares/columns-selector
teodosii Nov 10, 2023
e3ac6b7
allow showing custom column (hardcoded for now)
teodosii Nov 10, 2023
972a45f
Merge branch 'dev' into rares/columns-selector
teodosii Nov 13, 2023
723a6bf
show label cols
teodosii Nov 13, 2023
e258ea6
table formatting tweaks
teodosii Nov 13, 2023
333f210
removed log
teodosii Nov 13, 2023
1a8c23a
smoother animation
teodosii Nov 13, 2023
bf45275
horizontal scrolling, fixed resetting data
teodosii Nov 14, 2023
cc86fe1
Merge branch 'dev' into rares/columns-selector
teodosii Nov 14, 2023
855927d
lint
teodosii Nov 14, 2023
75b8f36
Add endpoint for alert group columns selector
Ferril Nov 16, 2023
fced3ff
changes wip
teodosii Nov 16, 2023
317e972
Add validation for columns settings endpoint
Ferril Nov 16, 2023
3c99bb4
connected endpoints
teodosii Nov 17, 2023
0f8d107
lint
teodosii Nov 17, 2023
f0dc47b
refactored modal to separate file
teodosii Nov 17, 2023
cf6826a
linter
teodosii Nov 17, 2023
3811608
Merge branch 'dev' into rares/columns-selector
teodosii Nov 17, 2023
b7d687e
changed renderLabels to arrow function
teodosii Nov 17, 2023
4ed0caa
lint
teodosii Nov 17, 2023
7b61417
Update validation for columns settings endpoint
Ferril Nov 20, 2023
6af37d0
a few more improvements
teodosii Nov 20, 2023
a4812ad
Merge remote-tracking branch 'origin/rares/columns-selector' into rar…
Ferril Nov 20, 2023
895387c
Add tests
Ferril Nov 20, 2023
3d89fce
show key values in the add modal
teodosii Nov 20, 2023
3a3d938
more tweaks
teodosii Nov 20, 2023
737f1a9
admin permission + table calculation horizontal scrolling
teodosii Nov 21, 2023
9714fde
Check labels feature flag for alert group columns settings endpoints
Ferril Nov 21, 2023
1f3bc0c
Fix migration lint
Ferril Nov 21, 2023
1e75884
updates on hard reset
teodosii Nov 21, 2023
f7b262d
sorting + labels check
teodosii Nov 21, 2023
67d4d37
emotionjs usages, tweaks, changed Floating Menu display component
teodosii Nov 22, 2023
36cc709
linter
teodosii Nov 22, 2023
f369a75
table cols sizing
teodosii Nov 22, 2023
7c3c350
Update typing
Ferril Nov 23, 2023
da31e00
review
teodosii Nov 23, 2023
a87f3f3
Merge branch 'dev' into rares/columns-selector
teodosii Nov 23, 2023
f8bb5aa
build fix
teodosii Nov 23, 2023
032fed6
increase table horizontal size
teodosii Nov 23, 2023
6100116
e2e fix
teodosii Nov 23, 2023
f9ab3cd
attempt to fix e2e failing case
teodosii Nov 23, 2023
463c43b
review
teodosii Nov 23, 2023
7948371
Add endpoint to reset columns settings, after review fixes
Ferril Nov 27, 2023
8d9ae1a
Fix columns settings validation, add tests
Ferril Nov 27, 2023
07ddacf
reorginize utils for alert group columns settings
Ferril Nov 28, 2023
ca68f05
Update alert group table settings field for organization, add lazy up…
Ferril Nov 28, 2023
adc96f0
call reset on backend
teodosii Nov 28, 2023
43ee175
Add flag to columns endpoint to show if user has default settings
Ferril Nov 28, 2023
61532b9
use default flag from backend
teodosii Nov 29, 2023
fdd1ddf
Merge branch 'dev' into rares/columns-selector
teodosii Nov 29, 2023
4a32c87
after merge
teodosii Nov 29, 2023
c0f22db
build fix
teodosii Nov 29, 2023
1621dd6
build fix after using new typed auto generated interfaces
teodosii Nov 29, 2023
9d35c38
linter
teodosii Nov 29, 2023
e2583d1
labels version bump
teodosii Nov 29, 2023
b19a9d3
Merge branch 'dev' into rares/columns-selector
teodosii Nov 29, 2023
4a2f197
pr feedback rename var
teodosii Nov 29, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Add options to customize table columns in AlertGroup page ([3281](https://github.com/grafana/oncall/pull/3281))

### Fixed

- User profile UI tweaks ([#3443](https://github.com/grafana/oncall/pull/3443))
Expand Down
31 changes: 31 additions & 0 deletions engine/apps/api/alert_group_table_columns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import typing

from apps.user_management.constants import AlertGroupTableColumns, default_columns

if typing.TYPE_CHECKING:
from apps.user_management.models import User


def alert_group_table_user_settings(user: "User") -> AlertGroupTableColumns:
"""
Returns user settings for alert group table columns. The flag "default" shows that user has default settings for
visible columns. It's used by frontend to enable/disable `reset` button.
This function uses lazy update to update columns settings for organization and for user.
"""
default_organization_columns = default_columns()
if not user.organization.alert_group_table_columns:
user.organization.update_alert_group_table_columns(default_organization_columns)
organization_columns = user.organization.alert_group_table_columns
if user.alert_group_table_selected_columns:
visible_columns = [
column for column in user.alert_group_table_selected_columns if column in organization_columns
]
else:
visible_columns = default_organization_columns
user.update_alert_group_table_selected_columns(visible_columns)
hidden_columns = [column for column in organization_columns if column not in visible_columns]
return {
"visible": visible_columns,
"hidden": hidden_columns,
"default": visible_columns == default_organization_columns,
}
60 changes: 60 additions & 0 deletions engine/apps/api/serializers/alert_group_table_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from apps.user_management.constants import (
AlertGroupTableColumnTypeChoices,
AlertGroupTableDefaultColumnChoices,
default_columns,
)


class AlertGroupTableColumnSerializer(serializers.Serializer):
name = serializers.CharField(max_length=200)
id = serializers.CharField(max_length=200)
type = serializers.ChoiceField(choices=AlertGroupTableColumnTypeChoices.choices)

def validate(self, data):
self._validate_id(data)
return data

def _validate_id(self, data):
"""Validate if `id` of column with `default` type is in the list of available default columns"""
if (
Ferril marked this conversation as resolved.
Show resolved Hide resolved
data["type"] == AlertGroupTableColumnTypeChoices.DEFAULT.value
and data["id"] not in AlertGroupTableDefaultColumnChoices.values
):
raise ValidationError("Invalid column id format")


class AlertGroupTableColumnsOrganizationSerializer(serializers.Serializer):
visible = AlertGroupTableColumnSerializer(many=True)
hidden = AlertGroupTableColumnSerializer(many=True)

def validate(self, data):
"""
Validate that at least one column is selected as visible and that all default columns are in the list.
"""
columns = data["visible"] + data["hidden"]
request_columns_ids = [column["id"] for column in columns]
if len(data["visible"]) == 0:
raise ValidationError("At least one column should be selected as visible")
elif not set(request_columns_ids) >= set(AlertGroupTableDefaultColumnChoices.values):
raise ValidationError("Default column cannot be removed")
elif len(request_columns_ids) > len(set(request_columns_ids)):
raise ValidationError("Duplicate column")
return data


class AlertGroupTableColumnsUserSerializer(AlertGroupTableColumnsOrganizationSerializer):
def validate(self, data):
"""
Validate that all columns exist in organization alert group table columns list.
"""
data = super().validate(data)
columns = data["visible"] + data["hidden"]
request_columns_ids = [column["id"] for column in columns]
organization_columns = self.context["request"].auth.organization.alert_group_table_columns or default_columns()
organization_columns_ids = [column["id"] for column in organization_columns]
if set(organization_columns_ids) != set(request_columns_ids):
raise ValidationError("Invalid settings")
return data
Loading
Loading