Skip to content

Commit 9898aa1

Browse files
bram2wpicklepete
andauthored
Migrate baserow formulas to object (baserow#4080)
* Iimplement the migration * Further improvements to FormulaField. Introducing JSONFormulaField so that CollectionField.config works correctly. Updating so.. so many tests. * Further backend tweaks. Found issues in builder and dashboard. * Further backend tweaks to support the 'used properties' checks. * Add support for view filter component placeholders. For now it just used in ViewFilterTypeText. * Lots of frontend changes in AB/WA/Integrations to support the new formula object. * Fix link resolution * Re-create the migrations * Improvements added to JSONFormulaField to support multiple formula properties. Fixing oh-so-many tests in builder, premium and database. * Fixing frontend tests. * Addressing AI field feedback, adding BaserowFormulaObjectSerializer * Fixing e2e tests. --------- Co-authored-by: peter_baserow <peter@baserow.io>
1 parent 420ba13 commit 9898aa1

File tree

127 files changed

+2194
-889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+2194
-889
lines changed

backend/src/baserow/contrib/automation/formula_importer.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from typing import Dict
1+
from typing import Dict, Union
22

33
from baserow.contrib.automation.data_providers.registries import (
44
automation_data_provider_type_registry,
55
)
6-
from baserow.core.formula import get_parse_tree_for_formula
6+
from baserow.core.formula import BaserowFormulaObject, get_parse_tree_for_formula
77
from baserow.core.services.formula_importer import BaserowFormulaImporter
88

99

@@ -18,7 +18,9 @@ def get_data_provider_type_registry(self):
1818
return automation_data_provider_type_registry
1919

2020

21-
def import_formula(formula: str, id_mapping: Dict[str, str], **kwargs) -> str:
21+
def import_formula(
22+
formula: Union[str, BaserowFormulaObject], id_mapping: Dict[str, str], **kwargs
23+
) -> str:
2224
"""
2325
When a formula is used in an automation, it must be migrated when we import it
2426
because it could contain IDs referencing other objects.
@@ -30,8 +32,11 @@ def import_formula(formula: str, id_mapping: Dict[str, str], **kwargs) -> str:
3032
:return: The updated path.
3133
"""
3234

33-
if not formula:
34-
return formula
35+
# Figure out what our formula string is.
36+
formula_str = formula if isinstance(formula, str) else formula["formula"]
3537

36-
tree = get_parse_tree_for_formula(formula)
38+
if not formula_str:
39+
return formula_str
40+
41+
tree = get_parse_tree_for_formula(formula_str)
3742
return AutomationFormulaImporter(id_mapping, **kwargs).visit(tree)

backend/src/baserow/contrib/builder/api/elements/serializers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def get_workflow_actions(self, obj: ElementsAndWorkflowActions):
264264

265265
class PageParameterValueSerializer(serializers.Serializer):
266266
name = serializers.CharField()
267-
value = FormulaSerializerField(allow_blank=True)
267+
value = FormulaSerializerField()
268268

269269

270270
@extend_schema_serializer(exclude_fields=("config",))
@@ -363,7 +363,7 @@ class UpdateCollectionFieldSerializer(serializers.ModelSerializer):
363363
help_text=CollectionField._meta.get_field("type").help_text,
364364
)
365365

366-
value = FormulaSerializerField(allow_blank=True)
366+
value = FormulaSerializerField()
367367

368368

369369
class ChoiceOptionSerializer(serializers.ModelSerializer):
@@ -408,8 +408,6 @@ class MenuItemSerializer(serializers.ModelSerializer):
408408
)
409409
navigate_to_url = FormulaSerializerField(
410410
help_text=LinkElement._meta.get_field("navigate_to_url").help_text,
411-
default="",
412-
allow_blank=True,
413411
required=False,
414412
)
415413
page_parameters = PageParameterValueSerializer(

backend/src/baserow/contrib/builder/elements/collection_field_types.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Generator, TypedDict, Union
1+
from typing import Any, Dict, Generator, TypedDict
22

33
from django.core.validators import MinValueValidator
44

@@ -13,7 +13,7 @@
1313
FormulaSerializerField,
1414
OptionalFormulaSerializerField,
1515
)
16-
from baserow.core.formula.types import BaserowFormula
16+
from baserow.core.formula.types import BaserowFormulaObject
1717
from baserow.core.registry import Instance
1818

1919

@@ -24,16 +24,14 @@ class BooleanCollectionFieldType(CollectionFieldType):
2424
simple_formula_fields = ["value"]
2525

2626
class SerializedDict(TypedDict):
27-
value: bool
27+
value: BaserowFormulaObject
2828

2929
@property
3030
def serializer_field_overrides(self):
3131
return {
3232
"value": FormulaSerializerField(
3333
help_text="The boolean value.",
3434
required=False,
35-
allow_blank=True,
36-
default=False,
3735
),
3836
}
3937

@@ -45,7 +43,7 @@ class RatingCollectionFieldType(CollectionFieldType):
4543
simple_formula_fields = ["value"]
4644

4745
class SerializedDict(TypedDict):
48-
value: BaserowFormula
46+
value: BaserowFormulaObject
4947
color: str
5048
rating_style: str
5149
max_value: int
@@ -56,8 +54,6 @@ def serializer_field_overrides(self):
5654
"value": FormulaSerializerField(
5755
help_text="The rating value.",
5856
required=False,
59-
allow_blank=True,
60-
default="",
6157
),
6258
"color": serializers.CharField(
6359
help_text="The color of the rating.",
@@ -87,16 +83,14 @@ class TextCollectionFieldType(CollectionFieldType):
8783
simple_formula_fields = ["value"]
8884

8985
class SerializedDict(TypedDict):
90-
value: str
86+
value: BaserowFormulaObject
9187

9288
@property
9389
def serializer_field_overrides(self):
9490
return {
9591
"value": FormulaSerializerField(
9692
help_text="The formula for the text.",
9793
required=False,
98-
allow_blank=True,
99-
default="",
10094
),
10195
}
10296

@@ -171,8 +165,6 @@ def serializer_field_overrides(self):
171165
"link_name": FormulaSerializerField(
172166
help_text="The formula for the link name.",
173167
required=False,
174-
allow_blank=True,
175-
default="",
176168
),
177169
"variant": serializers.ChoiceField(
178170
choices=LinkElement.VARIANTS.choices,
@@ -238,24 +230,20 @@ class TagsCollectionFieldType(CollectionFieldType):
238230
simple_formula_fields = ["values"]
239231

240232
class SerializedDict(TypedDict):
241-
values: str
233+
values: BaserowFormulaObject
242234
colors_is_formula: bool
243-
colors: Union[BaserowFormula, str]
235+
colors: BaserowFormulaObject
244236

245237
@property
246238
def serializer_field_overrides(self):
247239
return {
248240
"values": FormulaSerializerField(
249241
help_text="The formula for the tags values",
250242
required=False,
251-
allow_blank=True,
252-
default="",
253243
),
254244
"colors": OptionalFormulaSerializerField(
255245
help_text="The formula or value for the tags colors",
256246
required=False,
257-
allow_blank=True,
258-
default="",
259247
is_formula_field_name="colors_is_formula",
260248
),
261249
"colors_is_formula": serializers.BooleanField(
@@ -291,16 +279,14 @@ class ButtonCollectionFieldType(CollectionFieldType):
291279
simple_formula_fields = ["label"]
292280

293281
class SerializedDict(TypedDict):
294-
label: str
282+
label: BaserowFormulaObject
295283

296284
@property
297285
def serializer_field_overrides(self):
298286
return {
299287
"label": FormulaSerializerField(
300288
help_text="The string value.",
301289
required=False,
302-
allow_blank=True,
303-
default="",
304290
),
305291
}
306292

@@ -316,22 +302,18 @@ class ImageCollectionFieldType(CollectionFieldType):
316302
simple_formula_fields = ["src", "alt"]
317303

318304
class SerializedDict(TypedDict):
319-
src: BaserowFormula
320-
alt: BaserowFormula
305+
src: BaserowFormulaObject
306+
alt: BaserowFormulaObject
321307

322308
@property
323309
def serializer_field_overrides(self):
324310
return {
325311
"src": FormulaSerializerField(
326312
help_text="A link to the image file",
327313
required=False,
328-
allow_blank=True,
329-
default="",
330314
),
331315
"alt": FormulaSerializerField(
332316
help_text="A brief text description of the image",
333317
required=False,
334-
allow_blank=True,
335-
default="",
336318
),
337319
}

0 commit comments

Comments
 (0)