Skip to content

Commit c92d4bb

Browse files
committed
Conditions #9
- Implement conditions validation & saving. - Implement conditions deletion. - Update variable dropdown in variable property overlay to show conditions when a condition is being applied. - Refactor ActionModel for deserializing. - Fix setVariant issues.
1 parent 357b80f commit c92d4bb

33 files changed

+48
-92
lines changed

lib/src/api/models/action/action.dart

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// All rights reserved. Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE.md file.
44

5-
import 'package:json_annotation/json_annotation.dart';
6-
75
import '../../mixins.dart';
8-
9-
part 'action.g.dart';
6+
import '../models.dart';
107

118
/// Type of the action to perform on a user interaction.
129
enum ActionType {
@@ -58,8 +55,7 @@ enum ActionType {
5855
}
5956

6057
/// Holds information about an action to perform on a user interaction.
61-
@JsonSerializable()
62-
class ActionModel with SerializableMixin {
58+
abstract class ActionModel with SerializableMixin {
6359
/// Type of the action.
6460
ActionType type;
6561

@@ -68,8 +64,25 @@ class ActionModel with SerializableMixin {
6864

6965
/// Factory constructor for creating a new [ActionModel] instance from
7066
/// JSON data.
71-
factory ActionModel.fromJson(Map json) => _$ActionModelFromJson(json);
72-
73-
@override
74-
Map toJson() => _$ActionModelToJson(this);
67+
factory ActionModel.fromJson(Map json) {
68+
final ActionType type = ActionType.values.byName(json['type']);
69+
switch (type) {
70+
case ActionType.navigation:
71+
return NavigationAction.fromJson(json);
72+
case ActionType.link:
73+
return LinkAction.fromJson(json);
74+
case ActionType.submit:
75+
return SubmitAction.fromJson(json);
76+
case ActionType.setValue:
77+
return SetValueAction.fromJson(json);
78+
case ActionType.setVariant:
79+
return SetVariantAction.fromJson(json);
80+
case ActionType.setVariable:
81+
return SetVariableAction.fromJson(json);
82+
case ActionType.callFunction:
83+
return CallFunctionAction.fromJson(json);
84+
case ActionType.callApi:
85+
return ApiCallAction.fromJson(json);
86+
}
87+
}
7588
}

lib/src/api/models/action/action.g.dart

Lines changed: 0 additions & 27 deletions
This file was deleted.

lib/src/api/models/reaction.dart

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class Reaction with EquatableMixin, SerializableMixin {
1717
final String name;
1818

1919
/// Action to be performed.
20-
@JsonKey(fromJson: actionFromJson)
2120
final ActionModel action;
2221

2322
/// Event that will trigger the action.
@@ -51,26 +50,3 @@ class Reaction with EquatableMixin, SerializableMixin {
5150
@override
5251
Map toJson() => _$ReactionToJson(this);
5352
}
54-
55-
/// A deserializer for [ActionModel].
56-
ActionModel actionFromJson(Map json) {
57-
final ActionType type = ActionModel.fromJson(json).type;
58-
switch (type) {
59-
case ActionType.navigation:
60-
return NavigationAction.fromJson(json);
61-
case ActionType.link:
62-
return LinkAction.fromJson(json);
63-
case ActionType.submit:
64-
return SubmitAction.fromJson(json);
65-
case ActionType.setValue:
66-
return SetValueAction.fromJson(json);
67-
case ActionType.setVariant:
68-
return SetVariantAction.fromJson(json);
69-
case ActionType.setVariable:
70-
return SetVariableAction.fromJson(json);
71-
case ActionType.callFunction:
72-
return CallFunctionAction.fromJson(json);
73-
case ActionType.callApi:
74-
return ApiCallAction.fromJson(json);
75-
}
76-
}

lib/src/api/models/reaction.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/accordion_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/app_bar_node.g.dart

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/auto_placeholder_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/button_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/canvas_node.g.dart

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/checkbox_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)