Skip to content

Commit 3988349

Browse files
authored
Add iterator node (baserow#4099)
* Refactor the graph * Many other stuff
1 parent 7d57852 commit 3988349

File tree

115 files changed

+6362
-3915
lines changed

Some content is hidden

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

115 files changed

+6362
-3915
lines changed

backend/src/baserow/contrib/automation/api/nodes/errors.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_404_NOT_FOUND
22

3-
ERROR_AUTOMATION_NODE_BEFORE_INVALID = (
4-
"ERROR_AUTOMATION_NODE_BEFORE_INVALID",
3+
ERROR_AUTOMATION_UNEXPECTED_ERROR = (
4+
"ERROR_AUTOMATION_UNEXPECTED_ERROR",
5+
HTTP_400_BAD_REQUEST,
6+
"{e}",
7+
)
8+
9+
ERROR_AUTOMATION_NODE_REFERENCE_NODE_INVALID = (
10+
"ERROR_AUTOMATION_NODE_REFERENCE_NODE_INVALID",
511
HTTP_400_BAD_REQUEST,
612
"{e}",
713
)
@@ -24,11 +30,25 @@
2430
"{e}",
2531
)
2632

27-
ERROR_AUTOMATION_TRIGGER_NODE_MODIFICATION_DISALLOWED = (
28-
"ERROR_AUTOMATION_TRIGGER_NODE_MODIFICATION_DISALLOWED",
33+
34+
ERROR_AUTOMATION_TRIGGER_MUST_BE_FIRST_NODE = (
35+
"ERROR_AUTOMATION_TRIGGER_MUST_BE_FIRST_NODE",
36+
HTTP_400_BAD_REQUEST,
37+
"This operation is disallowed because a trigger must be the first node of "
38+
"the workflow",
39+
)
40+
41+
ERROR_AUTOMATION_FIRST_NODE_MUST_BE_TRIGGER = (
42+
"ERROR_AUTOMATION_FIRST_NODE_MUST_BE_TRIGGER",
43+
HTTP_400_BAD_REQUEST,
44+
"This operation is disallowed because an action can't be the first node of "
45+
"the workflow",
46+
)
47+
48+
ERROR_AUTOMATION_TRIGGER_ALREADY_EXISTS = (
49+
"ERROR_AUTOMATION_TRIGGER_ALREADY_EXISTS",
2950
HTTP_400_BAD_REQUEST,
30-
"Triggers can not be created, deleted or duplicated, "
31-
"they can only be replaced with a different type.",
51+
"This workflow already has a trigger",
3252
)
3353

3454
ERROR_AUTOMATION_NODE_NOT_DELETABLE = (

backend/src/baserow/contrib/automation/api/nodes/serializers.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)
1111
from baserow.contrib.automation.nodes.models import AutomationNode
1212
from baserow.contrib.automation.nodes.registries import automation_node_type_registry
13+
from baserow.contrib.automation.nodes.types import NodePosition
1314

1415

1516
class AutomationNodeSerializer(serializers.ModelSerializer):
@@ -19,42 +20,25 @@ class AutomationNodeSerializer(serializers.ModelSerializer):
1920
service = PolymorphicServiceSerializer(
2021
help_text="The service associated with this automation node."
2122
)
22-
simulate_until_node = serializers.SerializerMethodField(
23-
help_text="Whether to simulate the dispatching of the node."
24-
)
2523

2624
@extend_schema_field(OpenApiTypes.STR)
2725
def get_type(self, instance):
2826
return automation_node_type_registry.get_by_model(instance.specific_class).type
2927

30-
@extend_schema_field(OpenApiTypes.BOOL)
31-
def get_simulate_until_node(self, instance):
32-
if not instance.workflow.simulate_until_node:
33-
return False
34-
35-
return instance == instance.workflow.simulate_until_node.specific
36-
3728
class Meta:
3829
model = AutomationNode
3930
fields = (
4031
"id",
4132
"label",
42-
"order",
4333
"service",
4434
"workflow",
4535
"type",
46-
"previous_node_id",
47-
"previous_node_output",
48-
"simulate_until_node",
4936
)
5037

5138
extra_kwargs = {
5239
"id": {"read_only": True},
5340
"workflow_id": {"read_only": True},
5441
"type": {"read_only": True},
55-
"previous_node_id": {"read_only": True},
56-
"order": {"read_only": True, "help_text": "Lowest first."},
57-
"simulate_until_node": {"read_only": True},
5842
}
5943

6044

@@ -64,23 +48,33 @@ class CreateAutomationNodeSerializer(serializers.ModelSerializer):
6448
required=True,
6549
help_text="The type of the automation node",
6650
)
67-
before_id = serializers.IntegerField(
51+
reference_node_id = serializers.IntegerField(
6852
required=False,
69-
help_text="If provided, creates the node before the node with the given id.",
53+
allow_null=True,
54+
help_text="If provided, creates the node relative to the node with the "
55+
"given id.",
7056
)
71-
previous_node_id = serializers.IntegerField(
57+
position = serializers.ChoiceField(
58+
choices=NodePosition.choices,
7259
required=False,
73-
help_text="If provided, creates the node after this given id.",
60+
allow_blank=True,
61+
help_text="The position of the new node relative to the reference node.",
7462
)
75-
previous_node_output = serializers.CharField(
63+
output = serializers.CharField(
7664
required=False,
7765
allow_blank=True,
7866
help_text="The unique ID of the branch this node is an output for.",
7967
)
8068

8169
class Meta:
8270
model = AutomationNode
83-
fields = ("id", "type", "before_id", "previous_node_id", "previous_node_output")
71+
fields = (
72+
"id",
73+
"type",
74+
"reference_node_id",
75+
"position",
76+
"output",
77+
)
8478

8579

8680
class UpdateAutomationNodeSerializer(serializers.ModelSerializer):
@@ -93,17 +87,9 @@ class Meta:
9387
fields = (
9488
"label",
9589
"service",
96-
"previous_node_output",
9790
)
9891

9992

100-
class OrderAutomationNodesSerializer(serializers.Serializer):
101-
node_ids = serializers.ListField(
102-
child=serializers.IntegerField(),
103-
help_text=("The ids of the nodes in the order they are supposed to be set in."),
104-
)
105-
106-
10793
class ReplaceAutomationNodeSerializer(serializers.Serializer):
10894
new_type = serializers.ChoiceField(
10995
choices=lazy(automation_node_type_registry.get_types, list)(),
@@ -113,12 +99,18 @@ class ReplaceAutomationNodeSerializer(serializers.Serializer):
11399

114100

115101
class MoveAutomationNodeSerializer(serializers.Serializer):
116-
previous_node_id = serializers.IntegerField(
102+
reference_node_id = serializers.IntegerField(
117103
required=False,
118-
help_text="The ID of the node that should be before the moved node.",
104+
help_text="The reference node.",
105+
)
106+
position = serializers.ChoiceField(
107+
choices=NodePosition.choices,
108+
required=False,
109+
allow_blank=True,
110+
help_text="The new position relative to the reference node.",
119111
)
120-
previous_node_output = serializers.CharField(
112+
output = serializers.CharField(
121113
required=False,
122114
allow_blank=True,
123-
help_text="The output UID of the destination.",
115+
help_text="The new output.",
124116
)

backend/src/baserow/contrib/automation/api/nodes/urls.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
AutomationNodeView,
66
DuplicateAutomationNodeView,
77
MoveAutomationNodeView,
8-
OrderAutomationNodesView,
98
ReplaceAutomationNodeView,
109
SimulateDispatchAutomationNodeView,
1110
)
@@ -23,11 +22,6 @@
2322
AutomationNodeView.as_view(),
2423
name="item",
2524
),
26-
re_path(
27-
r"workflow/(?P<workflow_id>[0-9]+)/order/$",
28-
OrderAutomationNodesView.as_view(),
29-
name="order",
30-
),
3125
re_path(
3226
r"node/(?P<node_id>[0-9]+)/duplicate/$",
3327
DuplicateAutomationNodeView.as_view(),

0 commit comments

Comments
 (0)