@5minds/node-red-dashboard-2-processcube-dynamic-form 2.2.1 → 2.3.0-develop-c76baa-mfcjzrcm

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,26 +11,6 @@
11
11
  {{ action.label }}
12
12
  </v-btn>
13
13
  </div>
14
- <div>
15
- <v-btn
16
- class="ui-dynamic-form-footer-action-button ui-dynamic-form-footer-action-secondary"
17
- :disabled="formIsFinished"
18
- @click="handleSuspend"
19
- >
20
- Suspend
21
- </v-btn>
22
- </div>
23
- <div>
24
- <v-btn
25
- class="ui-dynamic-form-footer-action-terminate"
26
- :disabled="formIsFinished"
27
- @click="handleTerminate"
28
- variant="text"
29
- size="small"
30
- >
31
- Terminate
32
- </v-btn>
33
- </div>
34
14
  </div>
35
15
  <div class="ui-dynamic-form-footer-actions-right">
36
16
  <div v-for="(action, index) in rightSideActions" :key="`right-${index}`">
@@ -69,8 +49,8 @@ export default {
69
49
  leftSideActions() {
70
50
  const leftActions = this.actions.filter((action) => action.alignment === 'left' || !action.alignment);
71
51
  const sortPrimaryToLeft = (a, b) => {
72
- const aPrimary = a.primary === 'true';
73
- const bPrimary = b.primary === 'true';
52
+ const aPrimary = a.primary === 'primary';
53
+ const bPrimary = b.primary === 'primary';
74
54
  if (aPrimary && !bPrimary) return -1;
75
55
  if (!aPrimary && bPrimary) return 1;
76
56
  return 0;
@@ -81,8 +61,8 @@ export default {
81
61
  rightSideActions() {
82
62
  const rightActions = this.actions.filter((action) => action.alignment === 'right');
83
63
  const sortPrimaryToRight = (a, b) => {
84
- const aPrimary = a.primary === 'true';
85
- const bPrimary = b.primary === 'true';
64
+ const aPrimary = a.primary === 'primary';
65
+ const bPrimary = b.primary === 'primary';
86
66
  if (!aPrimary && bPrimary) return -1;
87
67
  if (aPrimary && !bPrimary) return 1;
88
68
  return 0;
@@ -93,29 +73,15 @@ export default {
93
73
  },
94
74
  methods: {
95
75
  getActionButtonClass(action) {
96
- return action.primary === 'true'
97
- ? 'ui-dynamic-form-footer-action-primary'
98
- : 'ui-dynamic-form-footer-action-secondary';
99
- },
100
- handleTerminate() {
101
- const terminateAction = {
102
- label: 'Terminate',
103
- alignment: 'left',
104
- primary: 'false',
105
- isTerminate: true,
106
- };
107
-
108
- this.actionCallback(terminateAction);
109
- },
110
- handleSuspend() {
111
- const suspendAction = {
112
- label: 'Suspend',
113
- alignment: 'left',
114
- primary: 'false',
115
- isSuspend: true,
116
- };
117
-
118
- this.actionCallback(suspendAction);
76
+ switch (action.primary) {
77
+ case 'primary':
78
+ return 'ui-dynamic-form-footer-action-primary';
79
+ case 'destructive':
80
+ return 'ui-dynamic-form-footer-action-terminate';
81
+ case 'secondary':
82
+ default:
83
+ return 'ui-dynamic-form-footer-action-secondary';
84
+ }
119
85
  },
120
86
  },
121
87
  };
@@ -235,12 +235,13 @@ export default {
235
235
  return !!this.userTask;
236
236
  },
237
237
  totalOutputs() {
238
- const outputsConfirmTerminate = 2;
238
+ const confirmOutputs = this.props.handle_confirmation_dialogs
239
+ ? (this.props.confirm_actions ? this.props.confirm_actions.length : 2)
240
+ : 0;
239
241
  return (
240
242
  this.props.options.length +
241
- (this.props.handle_confirmation_dialogs ? 2 : 0) +
242
- (this.props.trigger_on_change ? 1 : 0) +
243
- outputsConfirmTerminate
243
+ confirmOutputs +
244
+ (this.props.trigger_on_change ? 1 : 0)
244
245
  );
245
246
  },
246
247
  isConfirmDialog() {
@@ -896,6 +897,8 @@ export default {
896
897
  this.collapsed = this.props.collapse_when_finished;
897
898
  }
898
899
 
900
+ const hasConfirmField = formFields.some((field) => field.type === 'confirm');
901
+
899
902
  if (formFields) {
900
903
  formFields.forEach((field) => {
901
904
  this.formData[field.id] = field.defaultValue;
@@ -904,31 +907,63 @@ export default {
904
907
  const customForm = field.customForm ? JSON.parse(JSON.stringify(field.customForm)) : {};
905
908
  const confirmText = customForm.confirmButtonText ?? 'Confirm';
906
909
  const declineText = customForm.declineButtonText ?? 'Decline';
907
- const confirmActions = [
908
- {
909
- alignment: 'left',
910
- primary: 'true',
911
- label: confirmText,
912
- condition: '',
913
- isConfirmAction: true,
914
- confirmFieldId: field.id,
915
- confirmValue: true,
916
- },
917
- {
918
- alignment: 'left',
919
- primary: 'true',
920
- label: declineText,
921
- condition: '',
922
- isConfirmAction: true,
923
- confirmFieldId: field.id,
924
- confirmValue: false,
925
- },
926
- ];
927
- if (this.props.handle_confirmation_dialogs) {
928
- this.actions = confirmActions;
929
- } else {
930
- this.actions = [...this.actions, ...confirmActions];
910
+
911
+ const confirmActions = [
912
+ {
913
+ alignment: this.props.confirm_actions[1]?.alignment || 'left',
914
+ primary: this.props.confirm_actions[1]?.primary || 'destructive',
915
+ label: declineText,
916
+ condition: '',
917
+ isConfirmAction: true,
918
+ confirmFieldId: field.id,
919
+ confirmValue: false,
920
+ },
921
+ {
922
+ alignment: this.props.confirm_actions[0]?.alignment || 'right',
923
+ primary: this.props.confirm_actions[0]?.primary || 'primary',
924
+ label: confirmText,
925
+ condition: '',
926
+ isConfirmAction: true,
927
+ confirmFieldId: field.id,
928
+ confirmValue: true,
929
+ },
930
+ ];
931
+
932
+ const filteredActions = this.props.options.filter(action => {
933
+ if (!action.condition) return true;
934
+ try {
935
+ const usertaskWithContext = {
936
+ ...this.userTask,
937
+ isConfirmDialog: true
938
+ };
939
+ const func = Function('fields', 'usertask', 'msg', '"use strict"; return (' + action.condition + ')');
940
+ const result = func(this.formData, usertaskWithContext, this.msg);
941
+ return Boolean(result);
942
+ } catch (err) {
943
+ console.error('Error while evaluating condition: ' + err);
944
+ return false;
945
+ }
946
+ });
947
+
948
+ this.actions = [...filteredActions, ...confirmActions];
931
949
  }
950
+ });
951
+ }
952
+
953
+ if (!hasConfirmField && this.props.handle_confirmation_dialogs) {
954
+ this.actions = this.props.options.filter(action => {
955
+ if (!action.condition) return true;
956
+ try {
957
+ const usertaskWithContext = {
958
+ ...this.userTask,
959
+ isConfirmDialog: false
960
+ };
961
+ const func = Function('fields', 'usertask', 'msg', '"use strict"; return (' + action.condition + ')');
962
+ const result = func(this.formData, usertaskWithContext, this.msg);
963
+ return Boolean(result);
964
+ } catch (err) {
965
+ console.error('Error while evaluating condition: ' + err);
966
+ return false;
932
967
  }
933
968
  });
934
969
  }
@@ -954,38 +989,6 @@ export default {
954
989
  });
955
990
  },
956
991
  actionFn(action) {
957
- if (action.isTerminate) {
958
- this.showError('');
959
-
960
- const msg = this.msg ?? {};
961
- msg.payload = {
962
- formData: this.formData,
963
- userTask: this.userTask,
964
- isTerminate: true,
965
- };
966
-
967
- const terminateOutputIndex = this.totalOutputs - 1;
968
-
969
- this.send(msg, terminateOutputIndex);
970
- return;
971
- }
972
-
973
- if (action.isSuspend) {
974
- this.showError('');
975
-
976
- const msg = this.msg ?? {};
977
- msg.payload = {
978
- formData: this.formData,
979
- userTask: this.userTask,
980
- isSuspend: true,
981
- };
982
-
983
- const suspendOutputIndex = this.totalOutputs - 2;
984
-
985
- this.send(msg, suspendOutputIndex);
986
- return;
987
- }
988
-
989
992
  if (action.isConfirmAction && action.confirmFieldId) {
990
993
  this.formData[action.confirmFieldId] = action.confirmValue;
991
994
  }
@@ -1006,7 +1009,7 @@ export default {
1006
1009
  if (!allComplete) return;
1007
1010
  }
1008
1011
 
1009
- if (this.checkCondition(action.condition)) {
1012
+ if (this.checkCondition(action.condition, { isConfirmDialog: this.isConfirmDialog })) {
1010
1013
  this.showError('');
1011
1014
 
1012
1015
  const processedFormData = { ...this.formData };
@@ -1034,20 +1037,29 @@ export default {
1034
1037
 
1035
1038
  const msg = this.msg ?? {};
1036
1039
  msg.payload = { formData: processedFormData, userTask: this.userTask };
1037
- this.send(
1038
- msg,
1039
- this.actions.findIndex((element) => element.label === action.label) +
1040
- (this.isConfirmDialog ? this.props.options.length : 0)
1041
- );
1040
+
1041
+ let outputIndex;
1042
+ if (action.isConfirmAction) {
1043
+ const confirmActionIndex = action.confirmValue ? 1 : 0;
1044
+ outputIndex = this.props.options.length + confirmActionIndex;
1045
+ } else {
1046
+ outputIndex = this.props.options.findIndex((element) => element.label === action.label);
1047
+ }
1048
+ this.send(msg, outputIndex);
1042
1049
  } else {
1043
1050
  this.showError(action.errorMessage);
1044
1051
  }
1045
1052
  },
1046
- checkCondition(condition) {
1053
+ checkCondition(condition, context = {}) {
1047
1054
  if (condition === '') return true;
1048
1055
  try {
1049
- const func = Function('fields', 'userTask', 'msg', '"use strict"; return (' + condition + ')');
1050
- const result = func(this.formData, this.userTask, this.msg);
1056
+ const usertaskWithContext = {
1057
+ ...this.userTask,
1058
+ isConfirmDialog: context.isConfirmDialog || false
1059
+ };
1060
+
1061
+ const func = Function('fields', 'usertask', 'msg', '"use strict"; return (' + condition + ')');
1062
+ const result = func(this.formData, usertaskWithContext, this.msg);
1051
1063
  return Boolean(result);
1052
1064
  } catch (err) {
1053
1065
  console.error('Error while evaluating condition: ' + err);
@@ -168,7 +168,8 @@ code {
168
168
  min-height: 36px;
169
169
  padding: 8px 12px;
170
170
  box-sizing: border-box;
171
- flex-shrink: 0;
171
+ white-space: normal;
172
+ word-wrap: break-word;
172
173
  }
173
174
 
174
175
  @media screen and (min-width: 600px) {
@@ -177,10 +178,8 @@ code {
177
178
  }
178
179
 
179
180
  .ui-dynamic-form-footer-action-button {
180
- max-width: 200px;
181
- white-space: nowrap;
182
- overflow: hidden;
183
- text-overflow: ellipsis;
181
+ white-space: normal;
182
+ word-wrap: break-word;
184
183
  }
185
184
  }
186
185
 
@@ -287,15 +286,13 @@ code {
287
286
  font-size: 16px;
288
287
  width: 100%;
289
288
  box-sizing: border-box;
290
- white-space: nowrap;
291
- overflow: hidden;
292
- text-overflow: ellipsis;
289
+ white-space: normal;
290
+ word-wrap: break-word;
293
291
  }
294
292
 
295
293
  .ui-dynamic-form-footer-action-button .v-btn__content {
296
- white-space: nowrap !important;
297
- overflow: hidden !important;
298
- text-overflow: ellipsis !important;
294
+ white-space: normal !important;
295
+ word-wrap: break-word !important;
299
296
  max-width: 100% !important;
300
297
  display: block !important;
301
298
  }
@@ -310,9 +307,8 @@ code {
310
307
 
311
308
  .ui-dynamic-form-footer-action-primary .v-btn__content,
312
309
  .ui-dynamic-form-footer-action-secondary .v-btn__content {
313
- white-space: nowrap !important;
314
- overflow: hidden !important;
315
- text-overflow: ellipsis !important;
310
+ white-space: normal !important;
311
+ word-wrap: break-word !important;
316
312
  max-width: 100% !important;
317
313
  display: block !important;
318
314
  }