Skip to content

Commit

Permalink
Merge pull request #1954 from gh-PonyM/dev_lb
Browse files Browse the repository at this point in the history
feat(analytics): Add nullable field description to analytics table
  • Loading branch information
winged authored Feb 8, 2024
2 parents dfeaa09 + 475c4b2 commit a2326ec
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
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"],
)

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 @@ -2238,6 +2240,7 @@
input SaveAnalyticsTableInput {
slug: String!
name: String!
description: String
startingObject: StartingObject!
disableVisibilities: Boolean
meta: JSONString
Expand Down Expand Up @@ -3022,6 +3025,7 @@
MODIFIED_AT
SLUG
NAME
DESCRIPTION
}

enum SortableAnswerAttributes {
Expand Down

0 comments on commit a2326ec

Please sign in to comment.