mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-17 10:22:36 +00:00
Resolve "Aggregations for last modified by fields"
This commit is contained in:
parent
6560ca13d3
commit
bad0b863b2
5 changed files with 103 additions and 0 deletions
backend
src/baserow/contrib/database/views
tests/baserow/contrib/database/field
changelog/entries/unreleased/feature
web-frontend/modules/database
|
@ -20,12 +20,14 @@ from baserow.contrib.database.db.aggregations import Percentile
|
|||
from baserow.contrib.database.fields.field_types import (
|
||||
AutonumberFieldType,
|
||||
BooleanFieldType,
|
||||
CreatedByFieldType,
|
||||
CreatedOnFieldType,
|
||||
DateFieldType,
|
||||
DurationFieldType,
|
||||
EmailFieldType,
|
||||
FileFieldType,
|
||||
FormulaFieldType,
|
||||
LastModifiedByFieldType,
|
||||
LastModifiedFieldType,
|
||||
LinkRowFieldType,
|
||||
LongTextFieldType,
|
||||
|
@ -87,7 +89,9 @@ class EmptyCountViewAggregationType(ViewAggregationType):
|
|||
DateFieldType.type,
|
||||
DurationFieldType.type,
|
||||
LastModifiedFieldType.type,
|
||||
LastModifiedByFieldType.type,
|
||||
CreatedOnFieldType.type,
|
||||
CreatedByFieldType.type,
|
||||
LinkRowFieldType.type,
|
||||
EmailFieldType.type,
|
||||
FileFieldType.type,
|
||||
|
@ -170,7 +174,9 @@ class UniqueCountViewAggregationType(ViewAggregationType):
|
|||
RatingFieldType.type,
|
||||
DateFieldType.type,
|
||||
LastModifiedFieldType.type,
|
||||
LastModifiedByFieldType.type,
|
||||
CreatedOnFieldType.type,
|
||||
CreatedByFieldType.type,
|
||||
EmailFieldType.type,
|
||||
PhoneNumberFieldType.type,
|
||||
SingleSelectFieldType.type,
|
||||
|
|
|
@ -466,3 +466,44 @@ def test_created_by_field_type_sorting(data_fixture):
|
|||
rows = view_handler.apply_sorting(grid_view, model.objects.all())
|
||||
row_ids = [row.id for row in rows]
|
||||
assert row_ids == [row1.id, row4.id, row2.id, row3.id, row5.id]
|
||||
|
||||
|
||||
@pytest.mark.field_created_by
|
||||
@pytest.mark.django_db
|
||||
def test_created_by_field_view_aggregation(data_fixture):
|
||||
user_a = data_fixture.create_user(email="user1@baserow.io", first_name="User a")
|
||||
user_b = data_fixture.create_user(email="user2@baserow.io", first_name="User b")
|
||||
user_c = data_fixture.create_user(email="user3@baserow.io", first_name="User c")
|
||||
|
||||
database = data_fixture.create_database_application(user=user_a, name="Placeholder")
|
||||
data_fixture.create_user_workspace(workspace=database.workspace, user=user_b)
|
||||
data_fixture.create_user_workspace(workspace=database.workspace, user=user_c)
|
||||
table = data_fixture.create_database_table(name="Example", database=database)
|
||||
view = data_fixture.create_grid_view(table=table)
|
||||
field = data_fixture.create_created_by_field(
|
||||
user=user_a, table=table, name="created by"
|
||||
)
|
||||
model = table.get_model()
|
||||
view_handler = ViewHandler()
|
||||
|
||||
model.objects.create(created_by=user_c)
|
||||
model.objects.create(created_by=user_b)
|
||||
model.objects.create(created_by=user_a)
|
||||
model.objects.create(created_by=user_c)
|
||||
model.objects.create(created_by=None)
|
||||
|
||||
result = view_handler.get_field_aggregations(user_a, view, [(field, "empty_count")])
|
||||
assert result[field.db_column] == 1
|
||||
|
||||
result = view_handler.get_field_aggregations(
|
||||
user_a, view, [(field, "unique_count")]
|
||||
)
|
||||
assert result[field.db_column] == 3
|
||||
|
||||
result = view_handler.get_field_aggregations(
|
||||
user_a, view, [(field, "not_empty_count")]
|
||||
)
|
||||
assert result[field.db_column] == 4
|
||||
|
||||
result = view_handler.get_field_aggregations(user_a, view, [(field, "empty_count")])
|
||||
assert result[field.db_column] == 1
|
||||
|
|
|
@ -462,3 +462,44 @@ def test_last_modified_by_field_type_sorting(data_fixture):
|
|||
rows = view_handler.apply_sorting(grid_view, model.objects.all())
|
||||
row_ids = [row.id for row in rows]
|
||||
assert row_ids == [row1.id, row4.id, row2.id, row3.id, row5.id]
|
||||
|
||||
|
||||
@pytest.mark.field_last_modified_by
|
||||
@pytest.mark.django_db
|
||||
def test_last_modified_by_field_view_aggregations(data_fixture):
|
||||
user_a = data_fixture.create_user(email="user1@baserow.io", first_name="User a")
|
||||
user_b = data_fixture.create_user(email="user2@baserow.io", first_name="User b")
|
||||
user_c = data_fixture.create_user(email="user3@baserow.io", first_name="User c")
|
||||
|
||||
database = data_fixture.create_database_application(user=user_a, name="Placeholder")
|
||||
data_fixture.create_user_workspace(workspace=database.workspace, user=user_b)
|
||||
data_fixture.create_user_workspace(workspace=database.workspace, user=user_c)
|
||||
table = data_fixture.create_database_table(name="Example", database=database)
|
||||
view = data_fixture.create_grid_view(table=table)
|
||||
field = data_fixture.create_last_modified_by_field(
|
||||
user=user_a, table=table, name="Last modified by"
|
||||
)
|
||||
model = table.get_model()
|
||||
view_handler = ViewHandler()
|
||||
|
||||
model.objects.create(last_modified_by=user_c)
|
||||
model.objects.create(last_modified_by=user_b)
|
||||
model.objects.create(last_modified_by=user_a)
|
||||
model.objects.create(last_modified_by=user_c)
|
||||
model.objects.create(last_modified_by=None)
|
||||
|
||||
result = view_handler.get_field_aggregations(user_a, view, [(field, "empty_count")])
|
||||
assert result[field.db_column] == 1
|
||||
|
||||
result = view_handler.get_field_aggregations(
|
||||
user_a, view, [(field, "unique_count")]
|
||||
)
|
||||
assert result[field.db_column] == 3
|
||||
|
||||
result = view_handler.get_field_aggregations(
|
||||
user_a, view, [(field, "not_empty_count")]
|
||||
)
|
||||
assert result[field.db_column] == 4
|
||||
|
||||
result = view_handler.get_field_aggregations(user_a, view, [(field, "empty_count")])
|
||||
assert result[field.db_column] == 1
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "feature",
|
||||
"message": "Add aggregations support for last modified by and created by fields",
|
||||
"issue_number": 2114,
|
||||
"bullet_points": [],
|
||||
"created_at": "2024-05-09"
|
||||
}
|
|
@ -121,7 +121,9 @@ export class EmptyCountViewAggregationType extends ViewAggregationType {
|
|||
'number',
|
||||
'date',
|
||||
'last_modified',
|
||||
'last_modified_by',
|
||||
'created_on',
|
||||
'created_by',
|
||||
'link_row',
|
||||
'file',
|
||||
'single_select',
|
||||
|
@ -278,7 +280,9 @@ export class EmptyPercentageViewAggregationType extends ViewAggregationType {
|
|||
'number',
|
||||
'date',
|
||||
'last_modified',
|
||||
'last_modified_by',
|
||||
'created_on',
|
||||
'created_by',
|
||||
'link_row',
|
||||
'file',
|
||||
'single_select',
|
||||
|
@ -336,7 +340,9 @@ export class NotEmptyPercentageViewAggregationType extends ViewAggregationType {
|
|||
'number',
|
||||
'date',
|
||||
'last_modified',
|
||||
'last_modified_by',
|
||||
'created_on',
|
||||
'created_by',
|
||||
'link_row',
|
||||
'file',
|
||||
'single_select',
|
||||
|
@ -457,6 +463,8 @@ export class UniqueCountViewAggregationType extends ViewAggregationType {
|
|||
'single_select',
|
||||
'phone_number',
|
||||
'duration',
|
||||
'last_modified_by',
|
||||
'created_by',
|
||||
FormulaFieldType.compatibleWithFormulaTypes(
|
||||
'text',
|
||||
'char',
|
||||
|
|
Loading…
Add table
Reference in a new issue