Skip to content

Commit 968259a

Browse files
feat: Variable aggregation supports aggregating data into dictionary types. (#4907)
* feat: Variable aggregation supports outputting dictionary types. * fix placeholder_key * fix variable key can't null or empty * optimize: 语法优化。 * 小调整。 * feat: `Variable assign` supports convert type * Revert "feat: `Variable assign` supports convert type" This reverts commit 9c7657a.
1 parent f21f3cb commit 968259a

9 files changed

Lines changed: 52 additions & 15 deletions

File tree

apps/application/flow/step_node/variable_aggregation_node/i_variable_aggregation_node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class VariableListSerializer(serializers.Serializer):
1313
v_id = serializers.CharField(required=True, label=_("Variable id"))
14+
key = serializers.CharField(required=False, label=_("Key"), allow_null=True, allow_blank=True, )
1415
variable = serializers.ListField(required=True, label=_("Variable"))
1516

1617

apps/application/flow/step_node/variable_aggregation_node/impl/base_variable_aggregation_node.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def save_context(self, details, workflow_manage):
3131
self.context['exception_message'] = details.get('err_message')
3232

3333
def get_first_non_null(self, variable_list):
34-
3534
for variable in variable_list:
3635
v = self.workflow_manage.get_reference_field(
3736
variable.get('variable')[0],
@@ -40,12 +39,16 @@ def get_first_non_null(self, variable_list):
4039
return v
4140
return None
4241

43-
def set_variable_to_json(self, variable_list):
44-
42+
def set_variable_to_array(self, variable_list):
4543
return [self.workflow_manage.get_reference_field(
4644
variable.get('variable')[0],
4745
variable.get('variable')[1:]) for variable in variable_list]
4846

47+
def set_variable_to_dict(self, variable_list):
48+
return {(variable.get('key') or variable.get('variable')[-1]): self.workflow_manage.get_reference_field(
49+
variable.get('variable')[0],
50+
variable.get('variable')[1:]) for variable in variable_list}
51+
4952
def reset_variable(self, variable):
5053
value = self.workflow_manage.get_reference_field(
5154
variable.get('variable')[0],
@@ -65,9 +68,14 @@ def reset_group_list(self, group_list):
6568

6669
def execute(self, strategy, group_list, **kwargs) -> NodeResult:
6770
strategy_map = {'first_non_null': self.get_first_non_null,
68-
'variable_to_json': self.set_variable_to_json,
71+
'variable_to_array': self.set_variable_to_array,
72+
'variable_to_dict': self.set_variable_to_dict,
6973
}
7074

75+
# 向下兼容
76+
if strategy == 'variable_to_json':
77+
strategy = 'variable_to_array'
78+
7179
result = {item.get('field'): strategy_map[strategy](item.get('variable_list')) for item in group_list}
7280

7381
return NodeResult(

apps/application/flow/step_node/variable_splitting_node/impl/base_variable_splitting_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def save_context(self, details, workflow_manage):
4141
self.context['exception_message'] = details.get('err_message')
4242

4343
def execute(self, input_variable, variable_list, **kwargs) -> NodeResult:
44-
if type(input_variable).__name__ == "str":
44+
if isinstance(input_variable, str):
4545
try:
4646
input_variable = json.loads(input_variable)
4747
except Exception:

ui/src/components/execution-detail-card/index.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,11 @@
930930
</h5>
931931
<div class="p-8-12 border-t-dashed lighter pre-wrap">
932932
{{
933-
data.strategy === 'variable_to_json'
934-
? t('workflow.nodes.variableAggregationNode.placeholder1')
935-
: t('workflow.nodes.variableAggregationNode.placeholder')
933+
data.strategy === 'first_non_null'
934+
? t('workflow.nodes.variableAggregationNode.placeholder')
935+
: data.strategy === 'variable_to_dict'
936+
? t('workflow.nodes.variableAggregationNode.placeholder2')
937+
: t('workflow.nodes.variableAggregationNode.placeholder1')
936938
}}
937939
</div>
938940
</div>

ui/src/locales/lang/en-US/workflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default {
6161
ReferencingRequired: 'Referenced variable is required',
6262
ReferencingError: 'Invalid referenced variable',
6363
NoReferencing: 'Referenced variable does not exist',
64+
placeholder_key: 'Enter key',
6465
placeholder: 'Please select a variable',
6566
inputPlaceholder: 'Please enter variable',
6667
loop: 'Loop Variable',
@@ -323,7 +324,8 @@ You are a master of problem optimization, adept at accurately inferring user int
323324
text: 'Aggregate variables of each group according to the aggregation strategy',
324325
Strategy: 'Aggregation Strategy',
325326
placeholder: 'Return the first non-null value of each group',
326-
placeholder1: 'Return the set of variables for each group',
327+
placeholder1: 'Return the array of variables for each group',
328+
placeholder2: 'Return the dict of variables for each group',
327329
group: {
328330
noneError: 'Name cannot be empty',
329331
dupError: 'Name cannot be duplicated',

ui/src/locales/lang/zh-CN/workflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default {
6060
ReferencingRequired: '引用变量必填',
6161
ReferencingError: '引用变量错误',
6262
NoReferencing: '不存在的引用变量',
63+
placeholder_key: '请输入键名',
6364
placeholder: '请选择变量',
6465
inputPlaceholder: '请输入变量',
6566
loop: '循环变量',
@@ -304,7 +305,8 @@ export default {
304305
text: '按聚合策略聚合每组的变量',
305306
Strategy: '聚合策略',
306307
placeholder: '返回每组的第一个非空值',
307-
placeholder1: '返回每组变量的集合',
308+
placeholder1: '返回每组变量的数组(Array)',
309+
placeholder2: '返回每组变量的字典(Dict)',
308310
group: {
309311
noneError: '名称不能为空',
310312
dupError: '名称不能重复',

ui/src/locales/lang/zh-Hant/workflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default {
6060
ReferencingRequired: '引用變量必填',
6161
ReferencingError: '引用變量錯誤',
6262
NoReferencing: '不存在的引用變量',
63+
placeholder_key: '請輸入鍵名',
6364
placeholder: '請選擇變量',
6465
inputPlaceholder: '請輸入變量',
6566
loop: '循環變量',
@@ -322,7 +323,8 @@ export default {
322323
text: '按聚合策略聚合每組的變量',
323324
Strategy: '聚合策略',
324325
placeholder: '返回每組的第一個非空值',
325-
placeholder1: '返回每組變量的集合',
326+
placeholder1: '返回每組變量的數組(Array)',
327+
placeholder2: '返回每組變量的字典(Dict)',
326328
group: {
327329
noneError: '名稱不能為空',
328330
dupError: '名稱不能重複',

ui/src/workflow/nodes/variable-aggregation-node/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ class VariableAggregationNode extends AppNode {
1010
}
1111
}
1212

13+
class VariableAggregationNodeModel extends AppNodeModel {
14+
get_width() {
15+
return 450
16+
}
17+
}
18+
1319
export default {
1420
type: 'variable-aggregation-node',
15-
model: AppNodeModel,
21+
model: VariableAggregationNodeModel,
1622
view: VariableAggregationNode,
1723
}

ui/src/workflow/nodes/variable-aggregation-node/index.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
/>
3535
<el-option
3636
:label="t('workflow.nodes.variableAggregationNode.placeholder1')"
37-
value="variable_to_json"
37+
value="variable_to_array"
38+
/>
39+
<el-option
40+
:label="t('workflow.nodes.variableAggregationNode.placeholder2')"
41+
value="variable_to_dict"
3842
/>
3943
</el-select>
4044
</el-form-item>
@@ -77,10 +81,17 @@
7781
trigger: 'change',
7882
}"
7983
>
84+
<el-input
85+
v-if="form_data.strategy === 'variable_to_dict'"
86+
v-model="item.key"
87+
:placeholder="$t('workflow.variable.placeholder_key')"
88+
style="width: 100px; margin-right: 8px"
89+
maxlength="256"
90+
/>
8091
<NodeCascader
8192
ref="nodeCascaderRef"
8293
:nodeModel="nodeModel"
83-
style="width: 200px"
94+
:style="{ width: form_data.strategy === 'variable_to_dict' ? '200px' : '308px'}"
8495
:placeholder="$t('workflow.variable.placeholder')"
8596
v-model="item.variable"
8697
/>
@@ -149,7 +160,10 @@ const form = {
149160
const form_data = computed({
150161
get: () => {
151162
if (props.nodeModel.properties.node_data) {
152-
return props.nodeModel.properties.node_data
163+
// 向下兼容
164+
if (props.nodeModel.properties.node_data.strategy === 'variable_to_json') {
165+
props.nodeModel.properties.node_data.strategy = 'variable_to_array'
166+
}
153167
} else {
154168
set(props.nodeModel.properties, 'node_data', form)
155169
}

0 commit comments

Comments
 (0)