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

feat(analytics): Add nullable field description to analytics table #1954

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 3 additions & 6 deletions caluma/caluma_analytics/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@


class AnalyticsTableFilterSet(MetaFilterSet):
search = SearchFilter(fields=("slug", "name"))
search = SearchFilter(fields=("slug", "name", "description"))
slugs = MultipleChoiceFilter(field_name="slug")

class Meta:
model = models.AnalyticsTable
fields = (
"slug",
"name",
)
fields = ("slug", "name", "description")


class AnalyticsFieldFilterSet(MetaFilterSet):
Expand Down Expand Up @@ -53,7 +50,7 @@ class AnalyticsTableOrderSet(FilterSet):
meta = MetaFieldOrdering()
attribute = AttributeOrderingFactory(
models.AnalyticsTable,
fields=["created_at", "modified_at", "slug", "name"],
fields=["created_at", "modified_at", "slug", "name", "description"],
winged marked this conversation as resolved.
Show resolved Hide resolved
)

class Meta:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.16 on 2023-01-31 09:25

import localized_fields.fields.field
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("caluma_analytics", "0006_rename_form_slug_fields"),
]

operations = [
migrations.AddField(
model_name="analyticstable",
name="description",
field=localized_fields.fields.field.LocalizedField(
blank=True, null=True, required=[]
),
),
migrations.AddField(
model_name="historicalanalyticstable",
name="description",
field=localized_fields.fields.field.LocalizedField(
blank=True, null=True, required=[]
),
),
]
1 change: 1 addition & 0 deletions caluma/caluma_analytics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AnalyticsTable(SlugModel):

disable_visibilities = models.BooleanField(default=False)
name = LocalizedField(blank=False, null=False, required=False)
description = LocalizedField(blank=True, null=True, required=False)

starting_object = models.CharField(max_length=250, choices=STARTING_OBJECT_CHOICES)

Expand Down
1 change: 1 addition & 0 deletions caluma/caluma_analytics/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class Meta:
"result_data",
"fields",
"name",
"description",
"starting_object",
]

Expand Down
1 change: 1 addition & 0 deletions caluma/caluma_analytics/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Meta:
fields = [
"slug",
"name",
"description",
"starting_object",
"created_at",
"modified_at",
Expand Down
23 changes: 22 additions & 1 deletion caluma/caluma_analytics/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
}
"""

QUERY_SEARCH_TABLE = """
query($search: String!) {
allAnalyticsTables(filter: [{ search: $search }]) {
edges {
node {
slug
}
}
}
}
"""


def test_create_table(db, snapshot, schema_executor):
result = schema_executor(
Expand All @@ -71,15 +83,24 @@ def test_create_table(db, snapshot, schema_executor):
"table_input": {
"slug": "test-table",
"name": "Test table thingy",
"description": "Foo bar",
"startingObject": "CASES",
}
},
)

assert not result.errors
assert models.AnalyticsTable.objects.filter(pk="test-table").exists()
item = models.AnalyticsTable.objects.filter(pk="test-table").first()
assert str(item.description) == "Foo bar"

snapshot.assert_match(result.data)
assert result.data["saveAnalyticsTable"]["analyticsTable"]

result = schema_executor(QUERY_SEARCH_TABLE, variable_values={"search": "bar Foo"})
assert not result.errors
assert (
len(result.data["allAnalyticsTables"]["edges"]) == 1
), "Search in description should work"


@pytest.mark.parametrize(
Expand Down
4 changes: 4 additions & 0 deletions caluma/tests/__snapshots__/test_schema.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
meta: JSONString!
disableVisibilities: Boolean!
name: String!
description: String
startingObject: StartingObject
fields(offset: Int, before: String, after: String, first: Int, last: Int): AnalyticsFieldConnection!

Expand Down Expand Up @@ -211,6 +212,7 @@
input AnalyticsTableFilterSetType {
slug: String
name: String
description: String
createdByUser: String
createdByGroup: String
modifiedByUser: String
Expand Down Expand Up @@ -2224,6 +2226,7 @@
input SaveAnalyticsTableInput {
slug: String!
name: String!
description: String
startingObject: StartingObject!
disableVisibilities: Boolean
meta: JSONString
Expand Down Expand Up @@ -3001,6 +3004,7 @@
MODIFIED_AT
SLUG
NAME
DESCRIPTION
}

enum SortableAnswerAttributes {
Expand Down
Loading